Skip to content

Commit 3f5d995

Browse files
authored
Upgrade from JUnit 4 to JUnit Jupiter 6.0.3 (#1146)
- Replace junit:junit:4.13.2 with JUnit Jupiter/Platform 6.0.3 via BOM - Migrate all test imports from org.junit to org.junit.jupiter.api - Convert @Before/@after to @BeforeEach/@AfterEach - Replace @rule TemporaryFolder with @tempdir - Replace @test(timeout=) with @timeout annotation - Default java_test_suite wrapper to runner="junit5" with auto-injected runtime deps for the Jupiter engine and platform
1 parent 1428cf8 commit 3f5d995

56 files changed

Lines changed: 407 additions & 189 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MODULE.bazel.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel/java.MODULE.bazel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ maven.install(
5353
"io.netty:netty-transport",
5454
"io.sentry:sentry-logback:8.34.1",
5555
"jakarta.annotation:jakarta.annotation-api:3.0.0",
56-
"junit:junit:4.13.2",
56+
"org.junit.jupiter:junit-jupiter-api",
57+
"org.junit.jupiter:junit-jupiter-engine",
58+
"org.junit.jupiter:junit-jupiter-params",
59+
"org.junit.platform:junit-platform-launcher",
60+
"org.junit.platform:junit-platform-reporting",
5761
"org.assertj:assertj-core:3.27.7",
5862
"org.eclipse.jetty:jetty-server:%s" % JETTY_VERSION,
5963
"org.eclipse.jetty.websocket:websocket-jetty-server:%s" % JETTY_VERSION,
@@ -66,9 +70,11 @@ maven.install(
6670
"io.micronaut.jaxrs:micronaut-jaxrs-bom:4.10.0",
6771
"io.micronaut.validation:micronaut-validation-bom:4.12.0",
6872
"com.fasterxml.jackson:jackson-bom:2.21.0",
73+
"org.junit:junit-bom:6.0.3",
6974
],
7075
generate_compat_repositories = True,
7176
known_contributing_modules = [
77+
"",
7278
"moon-base",
7379
"protobuf",
7480
],

bazel/rules/java.bzl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,28 @@ load("@rules_java//java:defs.bzl", _java_binary = "java_binary", _java_library =
2121
load("@rules_jvm_external//:defs.bzl", _artifact = "artifact")
2222

2323
artifact = _artifact
24-
java_test_suite = _java_test_suite
24+
25+
_JUNIT_RUNTIME_DEPS = [
26+
_artifact("org.junit.jupiter:junit-jupiter-engine"),
27+
_artifact("org.junit.platform:junit-platform-launcher"),
28+
_artifact("org.junit.platform:junit-platform-reporting"),
29+
]
30+
31+
def java_test_suite(runner = "junit5", runtime_deps = [], **kwargs):
32+
"""java_test_suite defaulting to JUnit 5 (Jupiter).
33+
34+
Automatically adds JUnit Jupiter engine and platform runtime deps.
35+
36+
Args:
37+
runner: Test runner to use. Defaults to "junit5".
38+
runtime_deps: Additional runtime dependencies.
39+
**kwargs: Arguments passed to java_test_suite.
40+
"""
41+
_java_test_suite(
42+
runner = runner,
43+
runtime_deps = runtime_deps + _JUNIT_RUNTIME_DEPS,
44+
**kwargs
45+
)
2546

2647
_NULLAWAY_PLUGIN = "//bazel/rules:nullaway"
2748

domains/games/apis/mcpserver/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ java_test_suite(
102102
":tools",
103103
"//domains/games/libs/chess_com_client",
104104
"//domains/platform/libs/json",
105-
artifact("junit:junit"),
105+
artifact("org.junit.jupiter:junit-jupiter-api"),
106106
artifact("org.assertj:assertj-core"),
107107
],
108108
)

domains/games/apis/mcpserver/src/test/java/com/muchq/games/mcpserver/tools/ChessComGamesToolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.List;
1111
import java.util.Map;
1212
import java.util.Optional;
13-
import org.junit.Test;
13+
import org.junit.jupiter.api.Test;
1414

1515
public class ChessComGamesToolTest {
1616

domains/games/apis/mcpserver/src/test/java/com/muchq/games/mcpserver/tools/ChessComPlayerToolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010
import java.util.Map;
1111
import java.util.Optional;
12-
import org.junit.Test;
12+
import org.junit.jupiter.api.Test;
1313

1414
public class ChessComPlayerToolTest {
1515

domains/games/apis/mcpserver/src/test/java/com/muchq/games/mcpserver/tools/ChessComStatsToolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.muchq.platform.json.JsonUtils;
88
import java.util.Map;
99
import java.util.Optional;
10-
import org.junit.Test;
10+
import org.junit.jupiter.api.Test;
1111

1212
public class ChessComStatsToolTest {
1313

domains/games/apis/mcpserver/src/test/java/com/muchq/games/mcpserver/tools/ServerTimeToolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.time.Instant;
77
import java.time.ZoneId;
88
import java.util.Map;
9-
import org.junit.Test;
9+
import org.junit.jupiter.api.Test;
1010

1111
public class ServerTimeToolTest {
1212
private static final Instant FIXED_INSTANT = Instant.parse("2024-01-15T10:30:45.123Z");

domains/games/apis/one_d4/BUILD.bazel

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ java_test_suite(
260260
":engine",
261261
":model",
262262
":motifs",
263-
artifact("junit:junit"),
263+
artifact("org.junit.jupiter:junit-jupiter-api"),
264264
artifact("org.assertj:assertj-core"),
265265
],
266266
)
@@ -284,7 +284,7 @@ java_test_suite(
284284
deps = [
285285
":model",
286286
":motifs",
287-
artifact("junit:junit"),
287+
artifact("org.junit.jupiter:junit-jupiter-api"),
288288
artifact("org.assertj:assertj-core"),
289289
],
290290
)
@@ -299,7 +299,7 @@ java_test_suite(
299299
":engine",
300300
":model",
301301
":motifs",
302-
artifact("junit:junit"),
302+
artifact("org.junit.jupiter:junit-jupiter-api"),
303303
artifact("org.assertj:assertj-core"),
304304
],
305305
)
@@ -310,7 +310,7 @@ java_test_suite(
310310
srcs = ["src/test/java/com/muchq/games/one_d4/queue/InMemoryIndexQueueTest.java"],
311311
deps = [
312312
":queue",
313-
artifact("junit:junit"),
313+
artifact("org.junit.jupiter:junit-jupiter-api"),
314314
artifact("org.assertj:assertj-core"),
315315
],
316316
)
@@ -336,7 +336,7 @@ java_test_suite(
336336
"//domains/games/libs/chessql:compiler",
337337
"//domains/games/libs/chessql:parser",
338338
artifact("com.fasterxml.jackson.core:jackson-databind"),
339-
artifact("junit:junit"),
339+
artifact("org.junit.jupiter:junit-jupiter-api"),
340340
artifact("org.assertj:assertj-core"),
341341
artifact("org.jdbi:jdbi3-core"),
342342
],
@@ -361,7 +361,7 @@ java_test_suite(
361361
":queue",
362362
"//domains/games/libs/chessql:compiler",
363363
"//domains/games/libs/chessql:parser",
364-
artifact("junit:junit"),
364+
artifact("org.junit.jupiter:junit-jupiter-api"),
365365
artifact("org.assertj:assertj-core"),
366366
],
367367
)
@@ -374,7 +374,7 @@ java_test_suite(
374374
],
375375
deps = [
376376
":module",
377-
artifact("junit:junit"),
377+
artifact("org.junit.jupiter:junit-jupiter-api"),
378378
artifact("org.assertj:assertj-core"),
379379
],
380380
)
@@ -395,7 +395,7 @@ java_test_suite(
395395
":test_db",
396396
"//domains/games/libs/chessql:compiler",
397397
"//domains/games/libs/chessql:parser",
398-
artifact("junit:junit"),
398+
artifact("org.junit.jupiter:junit-jupiter-api"),
399399
artifact("org.assertj:assertj-core"),
400400
artifact("org.jdbi:jdbi3-core"),
401401
],
@@ -453,7 +453,7 @@ java_test_suite(
453453
artifact("io.micronaut:micronaut-http-server-netty"),
454454
artifact("io.micronaut:micronaut-inject"),
455455
artifact("io.micronaut:micronaut-runtime"),
456-
artifact("junit:junit"),
456+
artifact("org.junit.jupiter:junit-jupiter-api"),
457457
artifact("org.assertj:assertj-core"),
458458
],
459459
)
@@ -481,7 +481,7 @@ java_test_suite(
481481
"//domains/games/libs/chessql:compiler",
482482
"//domains/games/libs/chessql:parser",
483483
artifact("com.fasterxml.jackson.core:jackson-databind"),
484-
artifact("junit:junit"),
484+
artifact("org.junit.jupiter:junit-jupiter-api"),
485485
artifact("org.assertj:assertj-core"),
486486
artifact("org.jdbi:jdbi3-core"),
487487
],
@@ -500,7 +500,7 @@ java_test_suite(
500500
":test_db",
501501
"//domains/games/libs/chessql:compiler",
502502
"//domains/games/libs/chessql:parser",
503-
artifact("junit:junit"),
503+
artifact("org.junit.jupiter:junit-jupiter-api"),
504504
artifact("org.assertj:assertj-core"),
505505
artifact("org.jdbi:jdbi3-core"),
506506
],
@@ -522,7 +522,7 @@ java_test_suite(
522522
artifact("io.micronaut:micronaut-http-server-netty"),
523523
artifact("io.micronaut:micronaut-inject"),
524524
artifact("io.micronaut:micronaut-runtime"),
525-
artifact("junit:junit"),
525+
artifact("org.junit.jupiter:junit-jupiter-api"),
526526
artifact("org.assertj:assertj-core"),
527527
],
528528
)

domains/games/apis/one_d4/src/test/java/com/muchq/games/one_d4/IndexerModuleTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
import java.io.UncheckedIOException;
88
import java.nio.file.Files;
99
import java.nio.file.Path;
10-
import org.junit.Rule;
11-
import org.junit.Test;
12-
import org.junit.rules.TemporaryFolder;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.io.TempDir;
1312

1413
public class IndexerModuleTest {
1514

16-
@Rule public TemporaryFolder tmp = new TemporaryFolder();
15+
@TempDir Path tmp;
1716

1817
@Test
1918
public void readJdbcUrl_returnsEnvVar_whenSet() {
@@ -35,7 +34,7 @@ public void readJdbcUrl_ignoresBlankEnvVar() {
3534

3635
@Test
3736
public void readJdbcUrl_ignoresNullEnvVar_andReadsFile() throws IOException {
38-
Path configFile = tmp.newFile("db_config").toPath();
37+
Path configFile = Files.createFile(tmp.resolve("db_config"));
3938
Files.writeString(configFile, "jdbc:postgresql://file-host:5432/chess\n");
4039

4140
String result = IndexerModule.readJdbcUrl(null, configFile);
@@ -50,7 +49,7 @@ public void readJdbcUrl_returnsDefault_whenFileIsMissing() {
5049

5150
@Test
5251
public void readJdbcUrl_returnsDefault_whenFileIsEmpty() throws IOException {
53-
Path configFile = tmp.newFile("db_config_empty").toPath();
52+
Path configFile = Files.createFile(tmp.resolve("db_config_empty"));
5453
Files.writeString(configFile, " ");
5554

5655
String result = IndexerModule.readJdbcUrl(null, configFile);
@@ -59,7 +58,7 @@ public void readJdbcUrl_returnsDefault_whenFileIsEmpty() throws IOException {
5958

6059
@Test
6160
public void readJdbcUrl_envVarTakesPrecedenceOverFile() throws IOException {
62-
Path configFile = tmp.newFile("db_config_precedence").toPath();
61+
Path configFile = Files.createFile(tmp.resolve("db_config_precedence"));
6362
Files.writeString(configFile, "jdbc:postgresql://file-host/db");
6463

6564
String result = IndexerModule.readJdbcUrl("jdbc:postgresql://env-host/db", configFile);
@@ -69,7 +68,7 @@ public void readJdbcUrl_envVarTakesPrecedenceOverFile() throws IOException {
6968
@Test
7069
public void readJdbcUrl_throwsUncheckedIOException_onNonFileNotFoundIOError() {
7170
// A directory path will cause an IOException (not NoSuchFileException) when read as a file
72-
Path dirPath = tmp.getRoot().toPath();
71+
Path dirPath = tmp;
7372

7473
assertThatThrownBy(() -> IndexerModule.readJdbcUrl(null, dirPath))
7574
.isInstanceOf(UncheckedIOException.class)
@@ -104,6 +103,6 @@ public void parseThreads_respectsValidValue() {
104103
}
105104

106105
private Path missingPath() {
107-
return tmp.getRoot().toPath().resolve("nonexistent_db_config");
106+
return tmp.resolve("nonexistent_db_config");
108107
}
109108
}

0 commit comments

Comments
 (0)