-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathBlockTest.java
More file actions
94 lines (83 loc) · 2.88 KB
/
BlockTest.java
File metadata and controls
94 lines (83 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (C) 2018 JSQLParser.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package net.sf.jsqlparser.statement;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author Tobias Warneke (t.warneke@gmx.net)
*/
public class BlockTest {
public BlockTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getStatements method, of class Block.
*/
@Test
public void testGetStatements() throws JSQLParserException {
Statements stmts = CCJSqlParserUtil.parseStatements("begin\nselect * from feature;\nend");
assertEquals("BEGIN\n"
+ "SELECT * FROM feature;\n"
+ "END;\n", stmts.toString());
}
@Test
public void testBlock2() throws JSQLParserException {
Statements stmts = CCJSqlParserUtil.parseStatements("begin\n"
+ "update table1 set a = 'xx' where b = 'condition1';\n"
+ "update table1 set a = 'xx' where b = 'condition2';\n"
+ "end;");
assertEquals("BEGIN\n"
+ "UPDATE table1 SET a = 'xx' WHERE b = 'condition1';\n"
+ "UPDATE table1 SET a = 'xx' WHERE b = 'condition2';\n"
+ "END;\n"
+ "", stmts.toString());
}
@Test
public void testBlock3() throws JSQLParserException {
Statements stmts = CCJSqlParserUtil.parseStatements("begin\nselect * from feature;\nend");
Block block =(Block) stmts.getStatements().get(0);
assertFalse(block.getStatements().getStatements().isEmpty());
}
@Test
public void testBlockToStringIsNullSafe() throws JSQLParserException {
Block block = new Block();
block.setStatements(null);
assertEquals("BEGIN\n"
+ "END", block.toString());
}
}