Skip to content

Commit 4eca3bd

Browse files
authored
Move database-commons tests to JUnit Jupiter (#10772)
1 parent cb2568f commit 4eca3bd

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

modules/database-commons/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@ description = "Testcontainers :: Database-Commons"
33
dependencies {
44
api project(':testcontainers')
55

6+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
7+
8+
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
69
testImplementation 'org.assertj:assertj-core:3.27.4'
710
}
11+
12+
test {
13+
useJUnitPlatform()
14+
}

modules/database-commons/src/test/java/org/testcontainers/ext/ScriptScannerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package org.testcontainers.ext;
22

33
import org.apache.commons.lang3.StringUtils;
4-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
55

66
import java.util.regex.Pattern;
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

10-
public class ScriptScannerTest {
10+
class ScriptScannerTest {
1111

1212
@Test
13-
public void testHugeStringLiteral() {
13+
void testHugeStringLiteral() {
1414
String script = "/* a comment */ \"" + StringUtils.repeat('~', 10000) + "\";";
1515
ScriptScanner scanner = scanner(script);
1616
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.COMMENT);
@@ -20,7 +20,7 @@ public void testHugeStringLiteral() {
2020
}
2121

2222
@Test
23-
public void testPgIdentifierWithDollarSigns() {
23+
void testPgIdentifierWithDollarSigns() {
2424
ScriptScanner scanner = scanner(
2525
"this$is$a$valid$postgreSQL$identifier " +
2626
"$a$While this is a quoted string$a$$ --just followed by a dollar sign"
@@ -32,7 +32,7 @@ public void testPgIdentifierWithDollarSigns() {
3232
}
3333

3434
@Test
35-
public void testQuotedLiterals() {
35+
void testQuotedLiterals() {
3636
ScriptScanner scanner = scanner("'this \\'is a literal' \"this \\\" is a literal\"");
3737
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING);
3838
assertThat(scanner.getCurrentMatch()).isEqualTo("'this \\'is a literal'");

modules/database-commons/src/test/java/org/testcontainers/ext/ScriptSplittingTest.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.testcontainers.ext;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

55
import java.util.ArrayList;
66
import java.util.Arrays;
@@ -10,10 +10,10 @@
1010
import static org.assertj.core.api.Assertions.assertThat;
1111
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1212

13-
public class ScriptSplittingTest {
13+
class ScriptSplittingTest {
1414

1515
@Test
16-
public void testStringDemarcation() {
16+
void testStringDemarcation() {
1717
String script = "SELECT 'foo `bar`'; SELECT 'foo -- `bar`'; SELECT 'foo /* `bar`';";
1818

1919
List<String> expected = Arrays.asList("SELECT 'foo `bar`'", "SELECT 'foo -- `bar`'", "SELECT 'foo /* `bar`'");
@@ -22,7 +22,7 @@ public void testStringDemarcation() {
2222
}
2323

2424
@Test
25-
public void testIssue1547Case1() {
25+
void testIssue1547Case1() {
2626
String script =
2727
"create database if not exists ttt;\n" +
2828
"\n" +
@@ -51,7 +51,7 @@ public void testIssue1547Case1() {
5151
}
5252

5353
@Test
54-
public void testIssue1547Case2() {
54+
void testIssue1547Case2() {
5555
String script =
5656
"CREATE TABLE bar (\n" +
5757
" end_time VARCHAR(255)\n" +
@@ -69,7 +69,7 @@ public void testIssue1547Case2() {
6969
}
7070

7171
@Test
72-
public void testSplittingEnquotedSemicolon() {
72+
void testSplittingEnquotedSemicolon() {
7373
String script = "CREATE TABLE `bar;bar` (\n" + " end_time VARCHAR(255)\n" + ");";
7474

7575
List<String> expected = Arrays.asList("CREATE TABLE `bar;bar` ( end_time VARCHAR(255) )");
@@ -78,7 +78,7 @@ public void testSplittingEnquotedSemicolon() {
7878
}
7979

8080
@Test
81-
public void testUnusualSemicolonPlacement() {
81+
void testUnusualSemicolonPlacement() {
8282
String script = "SELECT 1;;;;;SELECT 2;\n;SELECT 3\n; SELECT 4;\n SELECT 5";
8383

8484
List<String> expected = Arrays.asList("SELECT 1", "SELECT 2", "SELECT 3", "SELECT 4", "SELECT 5");
@@ -87,7 +87,7 @@ public void testUnusualSemicolonPlacement() {
8787
}
8888

8989
@Test
90-
public void testCommentedSemicolon() {
90+
void testCommentedSemicolon() {
9191
String script =
9292
"CREATE TABLE bar (\n" + " foo VARCHAR(255)\n" + "); \nDROP PROCEDURE IF EXISTS -- ;\n" + " count_foo";
9393

@@ -100,7 +100,7 @@ public void testCommentedSemicolon() {
100100
}
101101

102102
@Test
103-
public void testStringEscaping() {
103+
void testStringEscaping() {
104104
String script =
105105
"SELECT \"a /* string literal containing comment characters like -- here\";\n" +
106106
"SELECT \"a 'quoting' \\\"scenario ` involving BEGIN keyword\\\" here\";\n" +
@@ -116,7 +116,7 @@ public void testStringEscaping() {
116116
}
117117

118118
@Test
119-
public void testBlockCommentExclusion() {
119+
void testBlockCommentExclusion() {
120120
String script = "INSERT INTO bar (foo) /* ; */ VALUES ('hello world');";
121121

122122
List<String> expected = Arrays.asList("INSERT INTO bar (foo) VALUES ('hello world')");
@@ -125,7 +125,7 @@ public void testBlockCommentExclusion() {
125125
}
126126

127127
@Test
128-
public void testBeginEndKeywordCorrectDetection() {
128+
void testBeginEndKeywordCorrectDetection() {
129129
String script =
130130
"INSERT INTO something_end (begin_with_the_token, another_field) /*end*/ VALUES /* end */ (' begin ', `end`)-- begin\n;";
131131

@@ -137,7 +137,7 @@ public void testBeginEndKeywordCorrectDetection() {
137137
}
138138

139139
@Test
140-
public void testCommentInStrings() {
140+
void testCommentInStrings() {
141141
String script =
142142
"CREATE TABLE bar (foo VARCHAR(255));\n" +
143143
"\n" +
@@ -161,7 +161,7 @@ public void testCommentInStrings() {
161161
}
162162

163163
@Test
164-
public void testMultipleBeginEndDetection() {
164+
void testMultipleBeginEndDetection() {
165165
String script =
166166
"CREATE TABLE bar (foo VARCHAR(255));\n" +
167167
"\n" +
@@ -205,7 +205,7 @@ public void testMultipleBeginEndDetection() {
205205
}
206206

207207
@Test
208-
public void testProcedureBlock() {
208+
void testProcedureBlock() {
209209
String script =
210210
"CREATE PROCEDURE count_foo()\n" +
211211
" BEGIN\n" +
@@ -264,15 +264,15 @@ public void testProcedureBlock() {
264264
}
265265

266266
@Test
267-
public void testUnclosedBlockComment() {
267+
void testUnclosedBlockComment() {
268268
String script = "SELECT 'foo `bar`'; /*";
269269
assertThatThrownBy(() -> doSplit(script, ScriptUtils.DEFAULT_STATEMENT_SEPARATOR))
270270
.isInstanceOf(ScriptUtils.ScriptParseException.class)
271271
.hasMessageContaining("*/");
272272
}
273273

274274
@Test
275-
public void testIssue1452Case() {
275+
void testIssue1452Case() {
276276
String script =
277277
"create table test (text VARCHAR(255));\n" +
278278
"\n" +
@@ -288,7 +288,7 @@ public void testIssue1452Case() {
288288
}
289289

290290
@Test
291-
public void testIfLoopBlocks() {
291+
void testIfLoopBlocks() {
292292
String script =
293293
"BEGIN\n" +
294294
" rec_loop: LOOP\n" +
@@ -310,7 +310,7 @@ public void testIfLoopBlocks() {
310310
}
311311

312312
@Test
313-
public void testIfLoopBlocksSpecificSeparator() {
313+
void testIfLoopBlocksSpecificSeparator() {
314314
String script =
315315
"BEGIN\n" +
316316
" rec_loop: LOOP\n" +
@@ -336,14 +336,14 @@ public void testIfLoopBlocksSpecificSeparator() {
336336
}
337337

338338
@Test
339-
public void oracleStyleBlocks() {
339+
void oracleStyleBlocks() {
340340
String script = "BEGIN END; /\n" + "BEGIN END;";
341341
List<String> expected = Arrays.asList("BEGIN END;", "BEGIN END;");
342342
splitAndCompare(script, expected, "/");
343343
}
344344

345345
@Test
346-
public void testMultiProcedureMySQLScript() {
346+
void testMultiProcedureMySQLScript() {
347347
String script =
348348
"CREATE PROCEDURE doiterate(p1 INT)\n" +
349349
" BEGIN\n" +
@@ -398,7 +398,7 @@ public void testMultiProcedureMySQLScript() {
398398
}
399399

400400
@Test
401-
public void testDollarQuotedStrings() {
401+
void testDollarQuotedStrings() {
402402
String script =
403403
"CREATE FUNCTION f ()\n" +
404404
"RETURNS INT\n" +
@@ -418,7 +418,7 @@ public void testDollarQuotedStrings() {
418418
}
419419

420420
@Test
421-
public void testNestedDollarQuotedString() {
421+
void testNestedDollarQuotedString() {
422422
//see https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING
423423
String script =
424424
"CREATE FUNCTION f() AS $function$\n" +
@@ -439,7 +439,7 @@ public void testNestedDollarQuotedString() {
439439
}
440440

441441
@Test
442-
public void testUnclosedDollarQuotedString() {
442+
void testUnclosedDollarQuotedString() {
443443
String script = "SELECT $tag$ ..... $";
444444
assertThatThrownBy(() -> doSplit(script, ScriptUtils.DEFAULT_STATEMENT_SEPARATOR))
445445
.isInstanceOf(ScriptUtils.ScriptParseException.class)
@@ -470,12 +470,12 @@ private List<String> doSplit(String script, String separator) {
470470
}
471471

472472
@Test
473-
public void testIgnoreDelimitersInLiteralsAndComments() {
473+
void testIgnoreDelimitersInLiteralsAndComments() {
474474
assertThat(ScriptUtils.containsSqlScriptDelimiters("'@' /*@*/ \"@\" $tag$@$tag$ --@", "@")).isFalse();
475475
}
476476

477477
@Test
478-
public void testContainsDelimiters() {
478+
void testContainsDelimiters() {
479479
assertThat(ScriptUtils.containsSqlScriptDelimiters("'@' /*@*/ @ \"@\" --@", "@")).isTrue();
480480
}
481481
}

0 commit comments

Comments
 (0)