1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public void splitSqlScriptDelimitedWithSemicolon() {
50
50
String cleanedStatement3 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)" ;
51
51
char delim = ';' ;
52
52
String script = rawStatement1 + delim + rawStatement2 + delim + rawStatement3 + delim ;
53
- List <String > statements = new ArrayList <String >();
53
+ List <String > statements = new ArrayList <>();
54
54
splitSqlScript (script , delim , statements );
55
55
assertEquals ("wrong number of statements" , 3 , statements .size ());
56
56
assertEquals ("statement 1 not split correctly" , cleanedStatement1 , statements .get (0 ));
@@ -65,7 +65,7 @@ public void splitSqlScriptDelimitedWithNewLine() {
65
65
String statement3 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)" ;
66
66
char delim = '\n' ;
67
67
String script = statement1 + delim + statement2 + delim + statement3 + delim ;
68
- List <String > statements = new ArrayList <String >();
68
+ List <String > statements = new ArrayList <>();
69
69
splitSqlScript (script , delim , statements );
70
70
assertEquals ("wrong number of statements" , 3 , statements .size ());
71
71
assertEquals ("statement 1 not split correctly" , statement1 , statements .get (0 ));
@@ -79,36 +79,30 @@ public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
79
79
String statement2 = "do something else" ;
80
80
char delim = '\n' ;
81
81
String script = statement1 + delim + statement2 + delim ;
82
- List <String > statements = new ArrayList <String >();
82
+ List <String > statements = new ArrayList <>();
83
83
splitSqlScript (script , DEFAULT_STATEMENT_SEPARATOR , statements );
84
84
assertEquals ("wrong number of statements" , 1 , statements .size ());
85
85
assertEquals ("script should have been 'stripped' but not actually 'split'" , script .replace ('\n' , ' ' ),
86
86
statements .get (0 ));
87
87
}
88
88
89
- /**
90
- * See <a href="https://jira.spring.io/browse/SPR-13218">SPR-13218</a>
91
- */
92
- @ Test
89
+ @ Test // SPR-13218
93
90
public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes () throws Exception {
94
91
String statement1 = "select '1' as \" Dogbert's owner's\" from dual" ;
95
92
String statement2 = "select '2' as \" Dilbert's\" from dual" ;
96
93
char delim = ';' ;
97
94
String script = statement1 + delim + statement2 + delim ;
98
- List <String > statements = new ArrayList <String >();
95
+ List <String > statements = new ArrayList <>();
99
96
splitSqlScript (script , ';' , statements );
100
97
assertEquals ("wrong number of statements" , 2 , statements .size ());
101
98
assertEquals ("statement 1 not split correctly" , statement1 , statements .get (0 ));
102
99
assertEquals ("statement 2 not split correctly" , statement2 , statements .get (1 ));
103
100
}
104
101
105
- /**
106
- * See <a href="https://jira.spring.io/browse/SPR-11560">SPR-11560</a>
107
- */
108
- @ Test
102
+ @ Test // SPR-11560
109
103
public void readAndSplitScriptWithMultipleNewlinesAsSeparator () throws Exception {
110
104
String script = readScript ("db-test-data-multi-newline.sql" );
111
- List <String > statements = new ArrayList <String >();
105
+ List <String > statements = new ArrayList <>();
112
106
splitSqlScript (script , "\n \n " , statements );
113
107
114
108
String statement1 = "insert into T_TEST (NAME) values ('Keith')" ;
@@ -122,7 +116,7 @@ public void readAndSplitScriptWithMultipleNewlinesAsSeparator() throws Exception
122
116
@ Test
123
117
public void readAndSplitScriptContainingComments () throws Exception {
124
118
String script = readScript ("test-data-with-comments.sql" );
125
- List <String > statements = new ArrayList <String >();
119
+ List <String > statements = new ArrayList <>();
126
120
splitSqlScript (script , ';' , statements );
127
121
128
122
String statement1 = "insert into customer (id, name) values (1, 'Rod; Johnson'), (2, 'Adrian Collier')" ;
@@ -138,13 +132,10 @@ public void readAndSplitScriptContainingComments() throws Exception {
138
132
assertEquals ("statement 4 not split correctly" , statement4 , statements .get (3 ));
139
133
}
140
134
141
- /**
142
- * See <a href="https://jira.spring.io/browse/SPR-10330">SPR-10330</a>
143
- */
144
- @ Test
135
+ @ Test // SPR-10330
145
136
public void readAndSplitScriptContainingCommentsWithLeadingTabs () throws Exception {
146
137
String script = readScript ("test-data-with-comments-and-leading-tabs.sql" );
147
- List <String > statements = new ArrayList <String >();
138
+ List <String > statements = new ArrayList <>();
148
139
splitSqlScript (script , ';' , statements );
149
140
150
141
String statement1 = "insert into customer (id, name) values (1, 'Sam Brannen')" ;
@@ -157,13 +148,10 @@ public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Excepti
157
148
assertEquals ("statement 3 not split correctly" , statement3 , statements .get (2 ));
158
149
}
159
150
160
- /**
161
- * See <a href="https://jira.spring.io/browse/SPR-9531">SPR-9531</a>
162
- */
163
- @ Test
151
+ @ Test // SPR-9531
164
152
public void readAndSplitScriptContainingMuliLineComments () throws Exception {
165
153
String script = readScript ("test-data-with-multi-line-comments.sql" );
166
- List <String > statements = new ArrayList <String >();
154
+ List <String > statements = new ArrayList <>();
167
155
splitSqlScript (script , ';' , statements );
168
156
169
157
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')" ;
@@ -176,10 +164,12 @@ public void readAndSplitScriptContainingMuliLineComments() throws Exception {
176
164
177
165
@ Test
178
166
public void containsDelimiters () {
179
- assertTrue ("test with ';' is wrong" , !containsSqlScriptDelimiters ("select 1\n select ';'" , ";" ));
180
- assertTrue ("test with delimiter ; is wrong" , containsSqlScriptDelimiters ("select 1; select 2" , ";" ));
181
- assertTrue ("test with '\\ n' is wrong" , !containsSqlScriptDelimiters ("select 1; select '\\ n\n ';" , "\n " ));
182
- assertTrue ("test with delimiter \\ n is wrong" , containsSqlScriptDelimiters ("select 1\n select 2" , "\n " ));
167
+ assertFalse (containsSqlScriptDelimiters ("select 1\n select ';'" , ";" ));
168
+ assertTrue (containsSqlScriptDelimiters ("select 1; select 2" , ";" ));
169
+ assertFalse (containsSqlScriptDelimiters ("select 1; select '\\ n\n ';" , "\n " ));
170
+ assertTrue (containsSqlScriptDelimiters ("select 1\n select 2" , "\n " ));
171
+ assertFalse (containsSqlScriptDelimiters ("select 1\n select 2" , "\n \n " ));
172
+ assertTrue (containsSqlScriptDelimiters ("select 1\n \n select 2" , "\n \n " ));
183
173
}
184
174
185
175
private String readScript (String path ) throws Exception {
0 commit comments