55import com .jme3 .scene .Mesh ;
66import com .jme3 .scene .Node ;
77import 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 ;
188import java .util .concurrent .ExecutionException ;
199import java .util .concurrent .ExecutorService ;
2010import java .util .concurrent .Executors ;
2111import java .util .concurrent .Future ;
2212import java .util .concurrent .ThreadFactory ;
2313import 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 )
3330public 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