Skip to content

Commit 1c4241a

Browse files
committed
Convert complex tests to JUnit Jupiter
1 parent c3eed46 commit 1c4241a

File tree

19 files changed

+382
-323
lines changed

19 files changed

+382
-323
lines changed

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/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
}

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import com.jme3.asset.AssetManager;
3535
import com.jme3.asset.DesktopAssetManager;
3636
import com.jme3.export.binary.BinaryExporter;
37-
import org.junit.Assert;
38-
import org.junit.Test;
37+
import org.junit.jupiter.api.Test;
38+
39+
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3941

4042
/**
4143
* Test cloning/saving/loading a RenderState. Related issues include #1718 and
@@ -66,42 +68,42 @@ public void testHashInvalidation() {
6668
// Test setFrontStencilMask invalidates hash
6769
state.setFrontStencilMask(0x12345678);
6870
int hash2 = state.contentHashCode();
69-
Assert.assertNotEquals("setFrontStencilMask should invalidate hash", hash1, hash2);
71+
assertNotEquals(hash1, hash2, "setFrontStencilMask should invalidate hash");
7072

7173
// Test setBackStencilMask invalidates hash
7274
hash1 = state.contentHashCode();
7375
state.setBackStencilMask(0x87654321);
7476
hash2 = state.contentHashCode();
75-
Assert.assertNotEquals("setBackStencilMask should invalidate hash", hash1, hash2);
77+
assertNotEquals(hash1, hash2, "setBackStencilMask should invalidate hash");
7678

7779
// Test setFrontStencilReference invalidates hash
7880
hash1 = state.contentHashCode();
7981
state.setFrontStencilReference(42);
8082
hash2 = state.contentHashCode();
81-
Assert.assertNotEquals("setFrontStencilReference should invalidate hash", hash1, hash2);
83+
assertNotEquals(hash1, hash2, "setFrontStencilReference should invalidate hash");
8284

8385
// Test setBackStencilReference invalidates hash
8486
hash1 = state.contentHashCode();
8587
state.setBackStencilReference(99);
8688
hash2 = state.contentHashCode();
87-
Assert.assertNotEquals("setBackStencilReference should invalidate hash", hash1, hash2);
89+
assertNotEquals(hash1, hash2, "setBackStencilReference should invalidate hash");
8890

8991
// Test flipFaceCull invalidates hash
9092
state.setFaceCullMode(RenderState.FaceCullMode.Back);
9193
hash1 = state.contentHashCode();
9294
state.flipFaceCull();
9395
hash2 = state.contentHashCode();
94-
Assert.assertNotEquals("flipFaceCull should invalidate hash", hash1, hash2);
95-
Assert.assertEquals("flipFaceCull should flip Back to Front",
96-
RenderState.FaceCullMode.Front, state.getFaceCullMode());
96+
assertNotEquals(hash1, hash2, "flipFaceCull should invalidate hash");
97+
assertEquals(RenderState.FaceCullMode.Front, state.getFaceCullMode(),
98+
"flipFaceCull should flip Back to Front");
9799

98100
// Test flipFaceCull again (Front to Back)
99101
hash1 = state.contentHashCode();
100102
state.flipFaceCull();
101103
hash2 = state.contentHashCode();
102-
Assert.assertNotEquals("flipFaceCull should invalidate hash (Front to Back)", hash1, hash2);
103-
Assert.assertEquals("flipFaceCull should flip Front to Back",
104-
RenderState.FaceCullMode.Back, state.getFaceCullMode());
104+
assertNotEquals(hash1, hash2, "flipFaceCull should invalidate hash (Front to Back)");
105+
assertEquals(RenderState.FaceCullMode.Back, state.getFaceCullMode(),
106+
"flipFaceCull should flip Front to Back");
105107
}
106108

107109
@Test
@@ -175,14 +177,14 @@ private static void test() {
175177
* Test a clone for equality.
176178
*/
177179
RenderState clone = testObject.clone();
178-
Assert.assertEquals(testObject, clone);
180+
assertEquals(testObject, clone);
179181

180182
if (testSerialization) {
181183
/*
182184
* Test a save-and-load copy for equality.
183185
*/
184186
RenderState copy = BinaryExporter.saveAndLoad(assetManager, testObject);
185-
Assert.assertEquals(testObject, copy);
187+
assertEquals(testObject, copy);
186188
}
187189
}
188190

0 commit comments

Comments
 (0)