Skip to content

Commit 759c99d

Browse files
authored
JUnit4 to JUnit5 (iluwatar#1589)
* Getting @test from JUnit5 instead of JUnit4 * Changed FixedStepGameLoopTest.java imports and tests to JUnit5 * JUnit4 to JUnit5 * JUnit4 to JUnit5 * JUnit4 to JUnit5 * JUnit4 to JUnit5
1 parent e9f73bc commit 759c99d

File tree

6 files changed

+44
-47
lines changed

6 files changed

+44
-47
lines changed

game-loop/src/test/java/com/iluwatar/gameloop/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
package com.iluwatar.gameloop;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2929

game-loop/src/test/java/com/iluwatar/gameloop/FixedStepGameLoopTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323

2424
package com.iluwatar.gameloop;
2525

26-
import org.junit.After;
27-
import org.junit.Assert;
28-
import org.junit.Before;
29-
import org.junit.Test;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.BeforeEach;
3031

3132
/**
3233
* FixedStepGameLoop unit test class.
@@ -35,20 +36,20 @@ public class FixedStepGameLoopTest {
3536

3637
private FixedStepGameLoop gameLoop;
3738

38-
@Before
39+
@BeforeEach
3940
public void setup() {
4041
gameLoop = new FixedStepGameLoop();
4142
}
4243

43-
@After
44+
@AfterEach
4445
public void tearDown() {
4546
gameLoop = null;
4647
}
4748

4849
@Test
4950
public void testUpdate() {
5051
gameLoop.update();
51-
Assert.assertEquals(0.01f, gameLoop.controller.getBulletPosition(), 0);
52+
assertEquals(0.01f, gameLoop.controller.getBulletPosition(), 0);
5253
}
5354

5455
}

game-loop/src/test/java/com/iluwatar/gameloop/FrameBasedGameLoopTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
package com.iluwatar.gameloop;
2525

26-
import org.junit.After;
27-
import org.junit.Assert;
28-
import org.junit.Before;
29-
import org.junit.Test;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
28+
import org.junit.jupiter.api.AfterEach;
29+
import org.junit.jupiter.api.BeforeEach;
3030

3131
/**
3232
* FrameBasedGameLoop unit test class.
@@ -35,19 +35,19 @@ public class FrameBasedGameLoopTest {
3535

3636
private FrameBasedGameLoop gameLoop;
3737

38-
@Before
38+
@BeforeEach
3939
public void setup() {
4040
gameLoop = new FrameBasedGameLoop();
4141
}
4242

43-
@After
43+
@AfterEach
4444
public void tearDown() {
4545
gameLoop = null;
4646
}
4747

48-
@Test
48+
@org.junit.jupiter.api.Test
4949
public void testUpdate() {
5050
gameLoop.update();
51-
Assert.assertEquals(0.5f, gameLoop.controller.getBulletPosition(), 0);
51+
assertEquals(0.5f, gameLoop.controller.getBulletPosition(), 0);
5252
}
5353
}

game-loop/src/test/java/com/iluwatar/gameloop/GameControllerTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,33 @@
2323

2424
package com.iluwatar.gameloop;
2525

26-
import org.junit.After;
27-
import org.junit.Assert;
28-
import org.junit.Before;
29-
import org.junit.Test;
26+
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.BeforeEach;
3029

3130
public class GameControllerTest {
3231

3332
private GameController controller;
3433

35-
@Before
34+
@BeforeEach
3635
public void setup() {
3736
controller = new GameController();
3837
}
3938

40-
@After
39+
@AfterEach
4140
public void tearDown() {
4241
controller = null;
4342
}
4443

45-
@Test
44+
@org.junit.jupiter.api.Test
4645
public void testMoveBullet() {
4746
controller.moveBullet(1.5f);
48-
Assert.assertEquals(1.5f, controller.bullet.getPosition(), 0);
47+
Assertions.assertEquals(1.5f, controller.bullet.getPosition(), 0);
4948
}
5049

51-
@Test
50+
@org.junit.jupiter.api.Test
5251
public void testGetBulletPosition() {
53-
Assert.assertEquals(controller.bullet.getPosition(), controller.getBulletPosition(), 0);
52+
Assertions.assertEquals(controller.bullet.getPosition(), controller.getBulletPosition(), 0);
5453
}
5554

5655
}

game-loop/src/test/java/com/iluwatar/gameloop/GameLoopTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323

2424
package com.iluwatar.gameloop;
2525

26-
import org.junit.After;
27-
import org.junit.Assert;
28-
import org.junit.Before;
29-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.Assertions;
28+
import org.junit.jupiter.api.BeforeEach;
3029

3130
/**
3231
* GameLoop unit test class.
@@ -38,34 +37,34 @@ public class GameLoopTest {
3837
/**
3938
* Create mock implementation of GameLoop.
4039
*/
41-
@Before
40+
@BeforeEach
4241
public void setup() {
4342
gameLoop = new GameLoop() {
4443
@Override
4544
protected void processGameLoop() {}
4645
};
4746
}
4847

49-
@After
48+
@AfterEach
5049
public void tearDown() {
5150
gameLoop = null;
5251
}
5352

54-
@Test
53+
@org.junit.jupiter.api.Test
5554
public void testRun() {
5655
gameLoop.run();
57-
Assert.assertEquals(GameStatus.RUNNING, gameLoop.status);
56+
Assertions.assertEquals(GameStatus.RUNNING, gameLoop.status);
5857
}
5958

60-
@Test
59+
@org.junit.jupiter.api.Test
6160
public void testStop() {
6261
gameLoop.stop();
63-
Assert.assertEquals(GameStatus.STOPPED, gameLoop.status);
62+
Assertions.assertEquals(GameStatus.STOPPED, gameLoop.status);
6463
}
6564

66-
@Test
65+
@org.junit.jupiter.api.Test
6766
public void testIsGameRunning() {
68-
Assert.assertFalse(gameLoop.isGameRunning());
67+
Assertions.assertFalse(gameLoop.isGameRunning());
6968
}
7069

7170
}

game-loop/src/test/java/com/iluwatar/gameloop/VariableStepGameLoopTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323

2424
package com.iluwatar.gameloop;
2525

26-
import java.lang.reflect.InvocationTargetException;
27-
import org.junit.After;
28-
import org.junit.Assert;
29-
import org.junit.Before;
30-
import org.junit.Test;
26+
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.BeforeEach;
3129

3230
/**
3331
* VariableStepGameLoop unit test class.
@@ -36,19 +34,19 @@ public class VariableStepGameLoopTest {
3634

3735
private VariableStepGameLoop gameLoop;
3836

39-
@Before
37+
@BeforeEach
4038
public void setup() {
4139
gameLoop = new VariableStepGameLoop();
4240
}
4341

44-
@After
42+
@AfterEach
4543
public void tearDown() {
4644
gameLoop = null;
4745
}
4846

49-
@Test
47+
@org.junit.jupiter.api.Test
5048
public void testUpdate() {
5149
gameLoop.update(20L);
52-
Assert.assertEquals(0.01f, gameLoop.controller.getBulletPosition(), 0);
50+
Assertions.assertEquals(0.01f, gameLoop.controller.getBulletPosition(), 0);
5351
}
5452
}

0 commit comments

Comments
 (0)