Skip to content

Commit 5a42fdb

Browse files
authored
Migrate to Junit5 (#2684)
* Migrate test baseline to JUnit 5 platform * Convert complex tests to JUnit Jupiter * Convert remaining tests to JUnit Jupiter
1 parent 7ed36ea commit 5a42fdb

File tree

85 files changed

+1010
-1006
lines changed

Some content is hidden

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

85 files changed

+1010
-1006
lines changed

common.gradle

Lines changed: 5 additions & 1 deletion
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
@@ -79,6 +82,7 @@ javadoc {
7982
}
8083

8184
test {
85+
useJUnitPlatform()
8286
testLogging {
8387
exceptionFormat = 'full'
8488
}

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.18.1"
2323
jnaerator-runtime = "com.nativelibs4java:jnaerator-runtime:0.12"
24-
junit4 = "junit:junit:4.13.2"
24+
junit-bom = "org.junit:junit-bom:5.13.4"
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-android-examples/src/test/java/org/jmonkeyengine/jme3androidexamples/ExampleUnitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.jmonkeyengine.jme3androidexamples;
22

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

5-
import static org.junit.Assert.*;
5+
import static org.junit.jupiter.api.Assertions.*;
66

77
/**
88
* To work on unit tests, switch the Test Artifact in the Build Variants view.

jme3-core/src/test/java/com/jme3/SetupTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@
3131
*/
3232
package com.jme3;
3333

34-
import org.junit.Test;
34+
import org.junit.jupiter.api.Test;
35+
36+
import static org.junit.jupiter.api.Assertions.assertThrows;
3537

3638
/**
3739
*
3840
* @author davidB
3941
*/
4042
public class SetupTest {
4143

42-
@Test(expected=AssertionError.class)
44+
@Test
4345
public void testAssertionEnabled() {
44-
assert false;
46+
assertThrows(AssertionError.class, () -> {
47+
assert false;
48+
});
4549
}
4650
}

jme3-core/src/test/java/com/jme3/anim/AnimComposerTest.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535
import com.jme3.util.clone.Cloner;
3636
import java.util.Set;
3737
import java.util.TreeSet;
38-
import org.junit.Assert;
39-
import org.junit.Test;
38+
import org.junit.jupiter.api.Test;
39+
40+
import static org.junit.jupiter.api.Assertions.assertEquals;
41+
import static org.junit.jupiter.api.Assertions.assertNotNull;
42+
import static org.junit.jupiter.api.Assertions.assertThrows;
4043

4144
/**
4245
* @author Remy Van Doosselaer
@@ -47,16 +50,16 @@ public class AnimComposerTest {
4750
public void testGetAnimClips() {
4851
AnimComposer composer = new AnimComposer();
4952

50-
Assert.assertNotNull(composer.getAnimClips());
51-
Assert.assertEquals(0, composer.getAnimClips().size());
53+
assertNotNull(composer.getAnimClips());
54+
assertEquals(0, composer.getAnimClips().size());
5255
}
5356

5457
@Test
5558
public void testGetAnimClipsNames() {
5659
AnimComposer composer = new AnimComposer();
5760

58-
Assert.assertNotNull(composer.getAnimClipsNames());
59-
Assert.assertEquals(0, composer.getAnimClipsNames().size());
61+
assertNotNull(composer.getAnimClipsNames());
62+
assertEquals(0, composer.getAnimClipsNames().size());
6063
}
6164

6265
@Test
@@ -71,8 +74,8 @@ public void testMakeLayer() {
7174
layers.add("Default");
7275
layers.add(layerName);
7376

74-
Assert.assertNotNull(composer.getLayer(layerName));
75-
Assert.assertEquals(layers, composer.getLayerNames());
77+
assertNotNull(composer.getLayer(layerName));
78+
assertEquals(layers, composer.getLayerNames());
7679
}
7780

7881
@Test
@@ -86,29 +89,31 @@ public void testMakeAction() {
8689

8790
final Action action = composer.makeAction(animName);
8891

89-
Assert.assertNotNull(action);
92+
assertNotNull(action);
9093
}
9194

92-
@Test(expected = UnsupportedOperationException.class)
95+
@Test
9396
public void testGetAnimClipsIsNotModifiable() {
9497
AnimComposer composer = new AnimComposer();
9598

96-
composer.getAnimClips().add(new AnimClip("test"));
99+
assertThrows(UnsupportedOperationException.class,
100+
() -> composer.getAnimClips().add(new AnimClip("test")));
97101
}
98102

99-
@Test(expected = UnsupportedOperationException.class)
103+
@Test
100104
public void testGetAnimClipsNamesIsNotModifiable() {
101105
AnimComposer composer = new AnimComposer();
102106

103-
composer.getAnimClipsNames().add("test");
107+
assertThrows(UnsupportedOperationException.class,
108+
() -> composer.getAnimClipsNames().add("test"));
104109
}
105110

106111
@Test
107112
public void testHasDefaultLayer() {
108113
AnimComposer composer = new AnimComposer();
109114

110115
AnimLayer defaultLayer = composer.getLayer("Default");
111-
Assert.assertNotNull(defaultLayer);
116+
assertNotNull(defaultLayer);
112117
}
113118

114119
@Test
@@ -122,7 +127,7 @@ public void testMissingDefaultLayerIssue2341() {
122127

123128
AnimComposer clone = (AnimComposer) composer.jmeClone();
124129
clone.cloneFields(new Cloner(), composer);
125-
Assert.assertNotNull(clone.getLayer(AnimComposer.DEFAULT_LAYER));
130+
assertNotNull(clone.getLayer(AnimComposer.DEFAULT_LAYER));
126131
}
127132

128133
}

jme3-core/src/test/java/com/jme3/anim/ArmatureMaskTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
*/
3232
package com.jme3.anim;
3333

34-
import org.junit.Assert;
35-
import org.junit.Test;
34+
import org.junit.jupiter.api.Assertions;
35+
import org.junit.jupiter.api.Test;
3636

3737
/**
3838
* Test constructors and modification methods of the ArmatureMask class.
@@ -81,7 +81,7 @@ public void testMaskAll() {
8181

8282
for (ArmatureMask testMask : maskArray) {
8383
for (Joint testJoint : jointList) {
84-
Assert.assertTrue(testMask.contains(testJoint));
84+
Assertions.assertTrue(testMask.contains(testJoint));
8585
}
8686
}
8787
}
@@ -104,7 +104,7 @@ public void testMaskNone() {
104104

105105
for (ArmatureMask testMask : maskArray) {
106106
for (Joint testJoint : jointList) {
107-
Assert.assertFalse(testMask.contains(testJoint));
107+
Assertions.assertFalse(testMask.contains(testJoint));
108108
}
109109
}
110110
}
@@ -132,9 +132,9 @@ public void testMask12() {
132132
for (ArmatureMask testMask : maskArray) {
133133
for (Joint testJoint : jointList) {
134134
if (testJoint == j1 || testJoint == j2) {
135-
Assert.assertTrue(testMask.contains(testJoint));
135+
Assertions.assertTrue(testMask.contains(testJoint));
136136
} else {
137-
Assert.assertFalse(testMask.contains(testJoint));
137+
Assertions.assertFalse(testMask.contains(testJoint));
138138
}
139139
}
140140
}

jme3-core/src/test/java/com/jme3/anim/JointCloneTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
package com.jme3.anim;
3333

3434
import com.jme3.util.clone.Cloner;
35-
import org.junit.Assert;
36-
import org.junit.Test;
35+
import org.junit.jupiter.api.Assertions;
36+
import org.junit.jupiter.api.Test;
3737

3838
/**
3939
* Test cloning a Joint.
@@ -49,11 +49,11 @@ public class JointCloneTest {
4949
@Test
5050
public void testInitialTransform() {
5151
Joint testJoint = new Joint("testJoint");
52-
Assert.assertTrue(testJoint.getInitialTransform().isIdentity());
52+
Assertions.assertTrue(testJoint.getInitialTransform().isIdentity());
5353

5454
Joint clone = Cloner.deepClone(testJoint);
5555
clone.getInitialTransform().setScale(2f);
5656

57-
Assert.assertTrue(testJoint.getInitialTransform().isIdentity());
57+
Assertions.assertTrue(testJoint.getInitialTransform().isIdentity());
5858
}
5959
}

jme3-core/src/test/java/com/jme3/anim/tween/action/ClipActionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
package com.jme3.anim.tween.action;
3333

3434
import com.jme3.anim.AnimClip;
35-
import org.junit.Test;
36-
import static org.junit.Assert.assertEquals;
37-
import static org.junit.Assert.assertThrows;
35+
import org.junit.jupiter.api.Test;
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertThrows;
3838

3939
/**
4040
* Test for ClipAction.

jme3-core/src/test/java/com/jme3/asset/LoadShaderSourceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.jme3.shader.plugins.GLSLLoader;
3636
import com.jme3.system.JmeSystem;
3737
import com.jme3.system.MockJmeSystemDelegate;
38-
import org.junit.Test;
38+
import org.junit.jupiter.api.Test;
3939

4040
public class LoadShaderSourceTest {
4141

jme3-core/src/test/java/com/jme3/asset/TestLocators.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import com.jme3.audio.plugins.WAVLoader;
88
import com.jme3.system.JmeSystem;
99
import com.jme3.texture.plugins.AWTLoader;
10-
import org.junit.Assert;
11-
import org.junit.Test;
10+
import org.junit.jupiter.api.Test;
11+
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
1214

1315
public class TestLocators {
1416

@@ -19,8 +21,8 @@ public void testAbsoluteLocators() {
1921
am.registerLoader(WAVLoader.class, "wav");
2022
am.registerLoader(AWTLoader.class, "jpg");
2123

22-
Assert.assertNotNull(am.loadAudio("Sound/Effects/Gun.wav"));
23-
Assert.assertNotNull(am.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
24+
assertNotNull(am.loadAudio("Sound/Effects/Gun.wav"));
25+
assertNotNull(am.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
2426
}
2527

2628
/**
@@ -32,7 +34,7 @@ public void testCustomLoader() {
3234
am.registerLocator("/", ClasspathLocator.class);
3335
am.registerLoader(TextLoader.class, "fnt");
3436
String result = (String)am.loadAsset("Interface/Fonts/Console.fnt");
35-
Assert.assertTrue(result.startsWith("info face=\"Lucida Console\" size=11 bold=0 italic=0 charset=\"\" unicode=1" +
37+
assertTrue(result.startsWith("info face=\"Lucida Console\" size=11 bold=0 italic=0 charset=\"\" unicode=1" +
3638
" stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 outline=0"));
3739
}
3840

@@ -50,19 +52,19 @@ public void testManyLocators() {
5052
am.registerLocator("/", ClasspathLocator.class);
5153

5254
// Try loading from jme3-core resources using the ClasspathLocator.
53-
Assert.assertNotNull("Failed to load from classpath",
54-
am.locateAsset(new AssetKey<>("Interface/Fonts/Default.fnt")));
55+
assertNotNull(am.locateAsset(new AssetKey<>("Interface/Fonts/Default.fnt")),
56+
"Failed to load from classpath");
5557

5658
// Try loading from the "town.zip" file using the ZipLocator.
57-
Assert.assertNotNull("Failed to load from town.zip file",
58-
am.locateAsset(new ModelKey("casaamarela.jpg")));
59+
assertNotNull(am.locateAsset(new ModelKey("casaamarela.jpg")),
60+
"Failed to load from town.zip file");
5961

6062
// Try loading from the Google Code Archive website using the HttpZipLocator.
61-
Assert.assertNotNull("Failed to load from wildhouse.zip on googleapis.com",
62-
am.locateAsset(new ModelKey("glasstile2.png")));
63+
assertNotNull(am.locateAsset(new ModelKey("glasstile2.png")),
64+
"Failed to load from wildhouse.zip on googleapis.com");
6365

6466
// Try loading from the GitHub website using the UrlLocator.
65-
Assert.assertNotNull("Failed to load from HTTP",
66-
am.locateAsset(new TextureKey("beginner-physics.png")));
67+
assertNotNull(am.locateAsset(new TextureKey("beginner-physics.png")),
68+
"Failed to load from HTTP");
6769
}
6870
}

0 commit comments

Comments
 (0)