Skip to content

Commit c3eed46

Browse files
committed
Migrate test baseline to JUnit 5 platform
1 parent 994c552 commit c3eed46

File tree

8 files changed

+165
-209
lines changed

8 files changed

+165
-209
lines changed

common.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ repositories {
3838

3939
dependencies {
4040
// Adding dependencies here will add the dependencies to each subproject.
41-
testImplementation libs.junit4
41+
testImplementation platform(libs.junit.bom)
42+
testImplementation libs.junit.jupiter
4243
testImplementation libs.mokito.core
44+
testImplementation libs.mokito.junit.jupiter
4345
testImplementation libs.groovy.test
46+
testRuntimeOnly libs.junit.platform.launcher
4447
}
4548

4649
// Uncomment if you want to see the status of every test that is run and
@@ -76,6 +79,7 @@ javadoc {
7679
}
7780

7881
test {
82+
useJUnitPlatform()
7983
testLogging {
8084
exceptionFormat = 'full'
8185
}
@@ -227,4 +231,4 @@ tasks.withType(Checkstyle) {
227231
html.required.set(true)
228232
}
229233
include("**/com/jme3/renderer/**/*.java")
230-
}
234+
}

gradle/libs.versions.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jbullet = "com.github.stephengold:jbullet:1.0.3"
2121
jinput = "net.java.jinput:jinput:2.0.9"
2222
jna = "net.java.dev.jna:jna:5.10.0"
2323
jnaerator-runtime = "com.nativelibs4java:jnaerator-runtime:0.12"
24-
junit4 = "junit:junit:4.13.2"
24+
junit-bom = "org.junit:junit-bom:5.12.2"
25+
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
26+
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" }
2527
lwjgl2 = "org.jmonkeyengine:lwjgl:2.9.5"
2628
lwjgl3-awt = "org.jmonkeyengine:lwjgl3-awt:0.2.4"
2729

@@ -35,6 +37,7 @@ lwjgl3-opengl = { module = "org.lwjgl:lwjgl-opengl", version.ref = "lwjgl3"
3537
lwjgl3-sdl = { module = "org.lwjgl:lwjgl-sdl", version.ref = "lwjgl3" }
3638

3739
mokito-core = "org.mockito:mockito-core:3.12.4"
40+
mokito-junit-jupiter = "org.mockito:mockito-junit-jupiter:3.12.4"
3841

3942
nifty = { module = "com.github.nifty-gui:nifty", version.ref = "nifty" }
4043
nifty-default-controls = { module = "com.github.nifty-gui:nifty-default-controls", version.ref = "nifty" }

jme3-core/src/test/java/com/jme3/material/MaterialTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747

4848
import java.util.Arrays;
4949
import java.util.EnumSet;
50-
import static org.junit.Assert.*;
51-
import org.junit.Test;
52-
import org.junit.runner.RunWith;
53-
import org.mockito.junit.MockitoJUnitRunner;
50+
import org.junit.jupiter.api.Test;
51+
52+
import static org.junit.jupiter.api.Assertions.assertEquals;
53+
import static org.junit.jupiter.api.Assertions.assertThrows;
54+
import static org.junit.jupiter.api.Assertions.assertTrue;
5455

55-
@RunWith(MockitoJUnitRunner.class)
5656
public class MaterialTest {
5757

5858
private Material material;
@@ -65,16 +65,18 @@ public EnumSet<Caps> getCaps() {
6565
}
6666
});
6767

68-
@Test(expected = IllegalArgumentException.class)
68+
@Test
6969
public void testSelectNonExistentTechnique() {
7070
material("Common/MatDefs/Gui/Gui.j3md");
71-
material.selectTechnique("Doesn't Exist", renderManager);
71+
assertThrows(IllegalArgumentException.class,
72+
() -> material.selectTechnique("Doesn't Exist", renderManager));
7273
}
7374

74-
@Test(expected = UnsupportedOperationException.class)
75+
@Test
7576
public void testSelectDefaultTechnique_NoCaps() {
7677
material("Common/MatDefs/Gui/Gui.j3md");
77-
material.selectTechnique("Default", renderManager);
78+
assertThrows(UnsupportedOperationException.class,
79+
() -> material.selectTechnique("Default", renderManager));
7880
}
7981

8082
@Test

jme3-core/src/test/java/com/jme3/material/plugins/J3MLoaderTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
import com.jme3.texture.Texture;
1313
import java.io.IOException;
1414
import java.util.EnumSet;
15-
import org.junit.Before;
16-
import org.junit.Test;
17-
import org.junit.runner.RunWith;
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.api.extension.ExtendWith;
1818
import org.mockito.Mock;
1919
import org.mockito.Mockito;
20-
import org.mockito.junit.MockitoJUnitRunner;
20+
import org.mockito.junit.jupiter.MockitoExtension;
2121

22-
import static org.mockito.Matchers.any;
23-
import static org.mockito.Mockito.verify;
24-
import static org.junit.Assert.*;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.mockito.ArgumentMatchers.any;
2524
import static org.mockito.Mockito.when;
25+
import static org.mockito.Mockito.verify;
2626

2727
/**
2828
* @author Daniel Johansson
2929
* @since 2015-07-20
3030
*/
31-
@RunWith(MockitoJUnitRunner.class)
31+
@ExtendWith(MockitoExtension.class)
3232
public class J3MLoaderTest {
3333

3434
private J3MLoader j3MLoader;
@@ -45,13 +45,13 @@ public class J3MLoaderTest {
4545
@Mock
4646
private MaterialDef materialDef;
4747

48-
@Before
48+
@BeforeEach
4949
@SuppressWarnings("unchecked")
5050
public void setUp() throws Exception {
5151
when(assetKey.getExtension()).thenReturn(".j3m");
5252
when(assetInfo.getManager()).thenReturn(assetManager);
5353
when(assetInfo.getKey()).thenReturn(assetKey);
54-
when(assetManager.loadAsset(any(AssetKey.class))).thenReturn(materialDef);
54+
Mockito.lenient().when(assetManager.loadAsset(any(AssetKey.class))).thenReturn(materialDef);
5555

5656
j3MLoader = new J3MLoader();
5757
}

jme3-core/src/test/java/com/jme3/material/plugins/LoadJ3mdTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
import com.jme3.shader.Shader;
4040
import com.jme3.system.*;
4141
import java.util.*;
42-
import static org.junit.Assert.assertEquals;
43-
import org.junit.Test;
44-
import org.junit.runner.RunWith;
45-
import org.mockito.junit.MockitoJUnitRunner;
42+
import org.junit.jupiter.api.Test;
43+
44+
import static org.junit.jupiter.api.Assertions.assertEquals;
45+
import static org.junit.jupiter.api.Assertions.assertThrows;
4646

47-
@RunWith(MockitoJUnitRunner.class)
4847
public class LoadJ3mdTest {
4948

5049
private Material material;
@@ -57,22 +56,22 @@ public EnumSet<Caps> getCaps() {
5756
}
5857
});
5958

60-
@Test(expected = IllegalArgumentException.class)
59+
@Test
6160
public void testBadBooleans1() {
6261
supportGlsl(100);
63-
material("bad-booleans1.j3md"); // DepthTest yes
62+
assertThrows(IllegalArgumentException.class, () -> material("bad-booleans1.j3md")); // DepthTest yes
6463
}
6564

66-
@Test(expected = IllegalArgumentException.class)
65+
@Test
6766
public void testBadBooleans2() {
6867
supportGlsl(100);
69-
material("bad-booleans2.j3md"); // DepthWrite on
68+
assertThrows(IllegalArgumentException.class, () -> material("bad-booleans2.j3md")); // DepthWrite on
7069
}
7170

72-
@Test(expected = IllegalArgumentException.class)
71+
@Test
7372
public void testBadBooleans3() {
7473
supportGlsl(100);
75-
material("bad-booleans3.j3md"); // Wireframe true
74+
assertThrows(IllegalArgumentException.class, () -> material("bad-booleans3.j3md")); // Wireframe true
7675
}
7776

7877
@Test

jme3-core/src/test/java/com/jme3/scene/threadwarden/SceneGraphThreadWardenGeometryExtendedTest.java

Lines changed: 39 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,34 @@
55
import com.jme3.scene.Mesh;
66
import com.jme3.scene.Node;
77
import com.jme3.scene.shape.Box;
8-
import org.junit.After;
9-
import org.junit.Before;
10-
import org.junit.BeforeClass;
11-
import org.junit.Test;
12-
import org.junit.runner.RunWith;
13-
import org.junit.runners.Parameterized;
14-
import org.mockito.Mockito;
15-
16-
import java.util.Arrays;
17-
import java.util.Collection;
188
import java.util.concurrent.ExecutionException;
199
import java.util.concurrent.ExecutorService;
2010
import java.util.concurrent.Executors;
2111
import java.util.concurrent.Future;
2212
import java.util.concurrent.ThreadFactory;
2313
import java.util.function.Consumer;
14+
import java.util.stream.Stream;
15+
import org.junit.jupiter.api.AfterEach;
16+
import org.junit.jupiter.api.BeforeAll;
17+
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.params.ParameterizedTest;
19+
import org.junit.jupiter.params.provider.Arguments;
20+
import org.junit.jupiter.params.provider.MethodSource;
21+
import org.mockito.Mockito;
2422

25-
import static org.junit.Assert.assertTrue;
26-
import static org.junit.Assert.fail;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2725

2826
/**
2927
* Parameterized tests for SceneGraphThreadWarden class with Geometry objects.
3028
* These tests verify that various scene graph mutations are properly checked for thread safety.
3129
*/
32-
@RunWith(Parameterized.class)
3330
public class SceneGraphThreadWardenGeometryExtendedTest {
3431

3532
private static ExecutorService executorService;
3633

37-
private final String testName;
38-
private final Consumer<Geometry> action;
39-
4034
@SuppressWarnings({"ReassignedVariable", "AssertWithSideEffects"})
41-
@BeforeClass
35+
@BeforeAll
4236
public static void setupClass() {
4337
// Make sure assertions are enabled
4438
boolean assertsEnabled = false;
@@ -48,70 +42,46 @@ public static void setupClass() {
4842
}
4943
}
5044

51-
@Before
45+
@BeforeEach
5246
public void setup() {
5347
executorService = newSingleThreadDaemonExecutor();
5448
}
5549

56-
@After
50+
@AfterEach
5751
public void tearDown() {
5852
executorService.shutdown();
5953
SceneGraphThreadWarden.reset();
6054
}
6155

62-
/**
63-
* Constructor for the parameterized test.
64-
*
65-
* @param testName A descriptive name for the test
66-
* @param action The action to perform on the spatial
67-
*/
68-
public SceneGraphThreadWardenGeometryExtendedTest(String testName, Consumer<Geometry> action) {
69-
this.testName = testName;
70-
this.action = action;
71-
}
72-
7356
/**
7457
* Define the parameters for the test.
7558
* Each parameter is a pair of (test name, action to perform on spatial).
7659
*/
77-
@Parameterized.Parameters(name = "{0}")
78-
public static Collection<Object[]> data() {
60+
static Stream<Arguments> data() {
7961
Material mockMaterial = Mockito.mock(Material.class);
8062
Box box = new Box(1, 1, 1);
8163

82-
return Arrays.asList(new Object[][] {
83-
{
84-
"setMaterial",
85-
(Consumer<Geometry>) spatial -> spatial.setMaterial(mockMaterial)
86-
},
87-
{
88-
"setMesh",
89-
(Consumer<Geometry>) spatial -> spatial.setMesh(box)
90-
},
91-
{
92-
"setLodLevel",
93-
(Consumer<Geometry>) spatial -> {
94-
// Need to set a mesh with LOD levels first
64+
return Stream.of(
65+
Arguments.of("setMaterial", (Consumer<Geometry>) spatial -> spatial.setMaterial(mockMaterial)),
66+
Arguments.of("setMesh", (Consumer<Geometry>) spatial -> spatial.setMesh(box)),
67+
Arguments.of("setLodLevel", (Consumer<Geometry>) spatial -> {
9568
Mesh mesh = new Box(1, 1, 1);
9669
mesh.setLodLevels(new com.jme3.scene.VertexBuffer[]{
97-
mesh.getBuffer(com.jme3.scene.VertexBuffer.Type.Index)
70+
mesh.getBuffer(com.jme3.scene.VertexBuffer.Type.Index)
9871
});
9972
spatial.setMesh(mesh);
10073
spatial.setLodLevel(0);
101-
}
102-
},
103-
{
104-
"removeFromParent",
105-
(Consumer<Geometry>) Geometry::removeFromParent
106-
}
107-
});
74+
}),
75+
Arguments.of("removeFromParent", (Consumer<Geometry>) Geometry::removeFromParent)
76+
);
10877
}
10978

11079
/**
11180
* Test that scene graph mutation is fine on the main thread when the object is attached to the root.
11281
*/
113-
@Test
114-
public void testMutationOnMainThreadOnAttachedObject() {
82+
@ParameterizedTest(name = "{0}")
83+
@MethodSource("data")
84+
public void testMutationOnMainThreadOnAttachedObject(String testName, Consumer<Geometry> action) {
11585
Node rootNode = new Node("root");
11686
SceneGraphThreadWarden.setup(rootNode);
11787

@@ -126,8 +96,9 @@ public void testMutationOnMainThreadOnAttachedObject() {
12696
/**
12797
* Test that scene graph mutation is fine on the main thread when the object is not attached to the root.
12898
*/
129-
@Test
130-
public void testMutationOnMainThreadOnDetachedObject() {
99+
@ParameterizedTest(name = "{0}")
100+
@MethodSource("data")
101+
public void testMutationOnMainThreadOnDetachedObject(String testName, Consumer<Geometry> action) {
131102
Node rootNode = new Node("root");
132103
SceneGraphThreadWarden.setup(rootNode);
133104

@@ -141,8 +112,10 @@ public void testMutationOnMainThreadOnDetachedObject() {
141112
/**
142113
* Test that scene graph mutation is fine on a non-main thread when the object is not attached to the root.
143114
*/
144-
@Test
145-
public void testMutationOnNonMainThreadOnDetachedObject() throws ExecutionException, InterruptedException {
115+
@ParameterizedTest(name = "{0}")
116+
@MethodSource("data")
117+
public void testMutationOnNonMainThreadOnDetachedObject(String testName, Consumer<Geometry> action)
118+
throws ExecutionException, InterruptedException {
146119
Node rootNode = new Node("root");
147120
SceneGraphThreadWarden.setup(rootNode);
148121

@@ -162,8 +135,10 @@ public void testMutationOnNonMainThreadOnDetachedObject() throws ExecutionExcept
162135
/**
163136
* Test that scene graph mutation is not allowed on a non-main thread when the object is attached to the root.
164137
*/
165-
@Test
166-
public void testMutationOnNonMainThreadOnAttachedObject() throws InterruptedException {
138+
@ParameterizedTest(name = "{0}")
139+
@MethodSource("data")
140+
public void testMutationOnNonMainThreadOnAttachedObject(String testName, Consumer<Geometry> action)
141+
throws InterruptedException {
167142
Node rootNode = new Node("root");
168143
SceneGraphThreadWarden.setup(rootNode);
169144

@@ -182,8 +157,8 @@ public void testMutationOnNonMainThreadOnAttachedObject() throws InterruptedExce
182157
fail("Expected an IllegalThreadSceneGraphMutation exception");
183158
} catch (ExecutionException e) {
184159
// This is expected - verify it's the right exception type
185-
assertTrue("Expected IllegalThreadSceneGraphMutation, got: " + e.getCause().getClass().getName(),
186-
e.getCause() instanceof IllegalThreadSceneGraphMutation);
160+
assertTrue(e.getCause() instanceof IllegalThreadSceneGraphMutation,
161+
"Expected IllegalThreadSceneGraphMutation, got: " + e.getCause().getClass().getName());
187162
}
188163
}
189164

@@ -204,4 +179,4 @@ private static ThreadFactory daemonThreadFactory() {
204179
return t;
205180
};
206181
}
207-
}
182+
}

0 commit comments

Comments
 (0)