From 7225efced992c5b9f3a70e650e29dbe2140cab20 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Sun, 7 Oct 2018 21:31:00 +0300 Subject: [PATCH] JUnit4 -> JUnit5 --- build.gradle | 8 +- .../test/java/mc/core/TestBlockLocation.java | 18 +-- .../test/java/mc/core/TestEntityLocation.java | 20 +-- .../mc/core/TestImmutableEntityLocation.java | 34 +++-- core/src/test/java/mc/core/text/TestText.java | 12 +- .../mc/core/utils/TestCompactedCoords.java | 9 +- .../test/java/mc/core/h2db/TestH2Player.java | 10 +- .../mc/core/h2db/TestH2PlayerManager.java | 26 ++-- .../h2db/service/H2PlayerServiceTest.java | 125 ++++++++++-------- .../packets/TestByteArrayInputNetStream.java | 14 +- .../packets/TestChunkdataPacket.java | 22 +-- .../packets/TestPlayerAbilitiesPacket.java | 24 ++-- .../TestBlockLocationSerializer.java | 14 +- 13 files changed, 175 insertions(+), 161 deletions(-) diff --git a/build.gradle b/build.gradle index 0daec8e..0eeddb5 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,7 @@ subprojects { slf4j_version = '1.7.25' spring_version = '5.1.0.RELEASE' lombok_version = '1.18.2' + junit_version = '5.3.1' } configurations { @@ -42,12 +43,17 @@ subprojects { compileOnly (group: 'org.projectlombok', name: 'lombok', version: lombok_version) /* Testing */ - testCompile (group: 'junit', name: 'junit', version: '4.12') + testImplementation (group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit_version) + testRuntimeOnly(group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit_version) testCompile (group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version) testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.10.19') testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version) } + test { + useJUnitPlatform() + } + task copyDep(type: Copy) { into 'libs' from configurations.compile + configurations.runtime - configurations.compile_excludeCopy diff --git a/core/src/test/java/mc/core/TestBlockLocation.java b/core/src/test/java/mc/core/TestBlockLocation.java index 620919f..559d434 100644 --- a/core/src/test/java/mc/core/TestBlockLocation.java +++ b/core/src/test/java/mc/core/TestBlockLocation.java @@ -1,28 +1,28 @@ package mc.core; import mc.core.world.block.BlockLocation; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class TestBlockLocation { +class TestBlockLocation { private static final ThreadLocalRandom rnd = ThreadLocalRandom.current(); private static final int minI = 0, maxI = 10; private int x, y, z; - @Before - public void before() { + @BeforeEach + void before() { x = rnd.nextInt(minI, maxI); y = rnd.nextInt(minI, maxI); z = rnd.nextInt(minI, maxI); } @Test - public void testEquals() { + void testEquals() { BlockLocation loc1 = new BlockLocation(x, y, z); BlockLocation loc2 = new BlockLocation(x, y, z); assertEquals(loc1, loc2); @@ -32,7 +32,7 @@ public class TestBlockLocation { } @Test - public void testClone() { + void testClone() { BlockLocation locOrig = new BlockLocation(x, y, z); BlockLocation locClone = locOrig.clone(); assertEquals(locOrig, locClone); diff --git a/core/src/test/java/mc/core/TestEntityLocation.java b/core/src/test/java/mc/core/TestEntityLocation.java index c6b1c62..9a45675 100644 --- a/core/src/test/java/mc/core/TestEntityLocation.java +++ b/core/src/test/java/mc/core/TestEntityLocation.java @@ -1,22 +1,22 @@ package mc.core; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class TestEntityLocation { +class TestEntityLocation { private static final ThreadLocalRandom rnd = ThreadLocalRandom.current(); private static final double minD = 0.0d, maxD = 10.0d; private static final float minF = 0.0f, maxF = 359.9f; private double x, y, z; private float yaw, pitch; - @Before - public void before() { + @BeforeEach + void before() { x = rnd.nextDouble(minD, maxD); y = rnd.nextDouble(minD, maxD); z = rnd.nextDouble(minD, maxD); @@ -25,7 +25,7 @@ public class TestEntityLocation { } @Test - public void testEquals() { + void testEquals() { EntityLocation loc1 = new EntityLocation(x, y, z, yaw, pitch); EntityLocation loc2 = new EntityLocation(x, y, z, yaw, pitch); assertEquals(loc1, loc2); @@ -38,14 +38,14 @@ public class TestEntityLocation { } @Test - public void testClone() { + void testClone() { EntityLocation locOrig = new EntityLocation(x, y, z, yaw, pitch); EntityLocation locClone = locOrig.clone(); assertEquals(locOrig, locClone); } @Test - public void testGetBlockXZ() { + void testGetBlockXZ() { EntityLocation location; location = new EntityLocation(0d, 0, 0d, 0f, 0f); diff --git a/core/src/test/java/mc/core/TestImmutableEntityLocation.java b/core/src/test/java/mc/core/TestImmutableEntityLocation.java index 2f6a958..85cf4a9 100644 --- a/core/src/test/java/mc/core/TestImmutableEntityLocation.java +++ b/core/src/test/java/mc/core/TestImmutableEntityLocation.java @@ -1,32 +1,30 @@ package mc.core; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -public class TestImmutableEntityLocation { - @Rule - public ExpectedException thrown = ExpectedException.none(); +class TestImmutableEntityLocation { @Test - public void testSetValue() { + void testSetValue() { EntityLocation location = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f); - thrown.expect(UnsupportedOperationException.class); - location.setX(1); - location.setY(1); - location.setZ(1); - location.setYaw(1); - location.setPitch(1); - location.setXYZ(1, 2, 3); - location.setYawPitch(1, 2); - location.set(EntityLocation.ZERO()); + assertThrows(UnsupportedOperationException.class, () -> { + location.setX(1); + location.setY(1); + location.setZ(1); + location.setYaw(1); + location.setPitch(1); + location.setXYZ(1, 2, 3); + location.setYawPitch(1, 2); + location.set(EntityLocation.ZERO()); + }); } @Test - public void testClone() { + void testClone() { EntityLocation locOrig = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f); EntityLocation locClone = locOrig.clone(); diff --git a/core/src/test/java/mc/core/text/TestText.java b/core/src/test/java/mc/core/text/TestText.java index 78370a1..4b90e29 100644 --- a/core/src/test/java/mc/core/text/TestText.java +++ b/core/src/test/java/mc/core/text/TestText.java @@ -1,12 +1,12 @@ package mc.core.text; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -public class TestText { +class TestText { @Test - public void testToPlain() { + void testToPlain() { final String m1 = "mes"; final String m2 = "sage"; final String message = m1 + m2; @@ -26,7 +26,7 @@ public class TestText { } @Test - public void testEquals() { + void testEquals() { assertEquals(Text.of(), Text.of("")); assertEquals(Text.of(), Text.builder().build()); assertEquals(Text.of(), Text.builder("").build()); @@ -44,7 +44,7 @@ public class TestText { } @Test - public void testEmpty() { + void testEmpty() { assertTrue(Text.of().isEmpty()); assertTrue(Text.of((String) null).isEmpty()); assertTrue(Text.of((Text) null).isEmpty()); diff --git a/core/src/test/java/mc/core/utils/TestCompactedCoords.java b/core/src/test/java/mc/core/utils/TestCompactedCoords.java index b357cef..7c82efb 100644 --- a/core/src/test/java/mc/core/utils/TestCompactedCoords.java +++ b/core/src/test/java/mc/core/utils/TestCompactedCoords.java @@ -1,15 +1,14 @@ package mc.core.utils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestCompactedCoords { +class TestCompactedCoords { @Test - public void testXZ() { + void testXZ() { ThreadLocalRandom random = ThreadLocalRandom.current(); for (int i = 0; i < 100; i++) { diff --git a/h2_playermanager/src/test/java/mc/core/h2db/TestH2Player.java b/h2_playermanager/src/test/java/mc/core/h2db/TestH2Player.java index 4149c22..5f60bdb 100644 --- a/h2_playermanager/src/test/java/mc/core/h2db/TestH2Player.java +++ b/h2_playermanager/src/test/java/mc/core/h2db/TestH2Player.java @@ -1,15 +1,15 @@ package mc.core.h2db; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -public class TestH2Player { +class TestH2Player { @Test - public void testEquals() { + void testEquals() { UUID uuid = UUID.randomUUID(); H2Player player1 = new H2Player(); diff --git a/h2_playermanager/src/test/java/mc/core/h2db/TestH2PlayerManager.java b/h2_playermanager/src/test/java/mc/core/h2db/TestH2PlayerManager.java index 7a83b65..c8fdf48 100644 --- a/h2_playermanager/src/test/java/mc/core/h2db/TestH2PlayerManager.java +++ b/h2_playermanager/src/test/java/mc/core/h2db/TestH2PlayerManager.java @@ -4,21 +4,21 @@ import mc.core.EntityLocation; import mc.core.h2db.service.H2PlayerService; import mc.core.player.Player; import mc.core.world.World; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestSpringConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class TestH2PlayerManager { +class TestH2PlayerManager { @Autowired private H2PlayerService h2PlayerService; @Autowired @@ -27,7 +27,7 @@ public class TestH2PlayerManager { private H2PlayerManager playerManager; @Test - public void testCreatePlayer() { + void testCreatePlayer() { final String playerName = "NEW_PLAYER"; final Player newPlayer = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld); @@ -45,7 +45,7 @@ public class TestH2PlayerManager { } @Test - public void testJoinServer() { + void testJoinServer() { assertEquals(0, playerManager.getCountPlayers()); final String playerName = "NEW_PLAYER"; @@ -57,7 +57,7 @@ public class TestH2PlayerManager { } @Test - public void testLeftServer() { + void testLeftServer() { assertEquals(0, playerManager.getCountPlayers()); final String playerName = "NEW_PLAYER"; @@ -87,7 +87,7 @@ public class TestH2PlayerManager { } @Test - public void testGetPlayer() { + void testGetPlayer() { assertEquals(0, playerManager.getCountPlayers()); final String playerName = "NEW_PLAYER"; @@ -104,7 +104,7 @@ public class TestH2PlayerManager { } @Test - public void testGetPlayers() { + void testGetPlayers() { assertEquals(0, playerManager.getCountPlayers()); final String playerName = "NEW_PLAYER"; @@ -128,7 +128,7 @@ public class TestH2PlayerManager { } @Test - public void testGetCountPlayers() { + void testGetCountPlayers() { assertEquals(0, playerManager.getCountPlayers()); final String playerName = "NEW_PLAYER"; @@ -145,7 +145,7 @@ public class TestH2PlayerManager { } @Test - public void testGetOfflinePlayer() { + void testGetOfflinePlayer() { final String playerName = "NEW_PLAYER"; final Player player = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld); playerManager.joinServer(player); diff --git a/h2_playermanager/src/test/java/mc/core/h2db/service/H2PlayerServiceTest.java b/h2_playermanager/src/test/java/mc/core/h2db/service/H2PlayerServiceTest.java index 6b2ff03..6440b3e 100644 --- a/h2_playermanager/src/test/java/mc/core/h2db/service/H2PlayerServiceTest.java +++ b/h2_playermanager/src/test/java/mc/core/h2db/service/H2PlayerServiceTest.java @@ -3,21 +3,22 @@ package mc.core.h2db.service; import mc.core.EntityLocation; import mc.core.h2db.H2Player; import mc.core.h2db.TestSpringConfig; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; -@RunWith(SpringJUnit4ClassRunner.class) +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestSpringConfig.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class H2PlayerServiceTest { +class H2PlayerServiceTest { @Autowired private H2PlayerService h2PlayerService; @@ -43,91 +44,101 @@ public class H2PlayerServiceTest { } @Test - public void save() { + void save() { H2Player player = buildPlayer(); H2Player savedPlayer = h2PlayerService.save(player); player.setId(savedPlayer.getId()); //FIXME костыль, однако - Assert.assertEquals(player, savedPlayer); - } - - @Test(expected = Exception.class) - public void save_NameEmpty() { - H2Player player = buildPlayer(); - player.setName(""); - h2PlayerService.save(player); - } - - @Test(expected = Exception.class) - public void save_NameNull() { - H2Player player = buildPlayer(); - player.setName(null); - h2PlayerService.save(player); - } - - @Test(expected = Exception.class) - public void save_UuidNull() { - H2Player player = buildPlayer(); - player.setUuid(null); - h2PlayerService.save(player); - } - - @Test(expected = Exception.class) - public void save_LocationNull() { - H2Player player = buildPlayer(); - player.setLocation(null); - h2PlayerService.save(player); + assertEquals(player, savedPlayer); } @Test - public void remove() { + void save_NameEmpty() { + assertThrows(Exception.class, () -> { + H2Player player = buildPlayer(); + player.setName(""); + h2PlayerService.save(player); + }); + } + + @Test + void save_NameNull() { + assertThrows(Exception.class, () -> { + H2Player player = buildPlayer(); + player.setName(null); + h2PlayerService.save(player); + }); + } + + @Test + void save_UuidNull() { + assertThrows(Exception.class, () -> { + H2Player player = buildPlayer(); + player.setUuid(null); + h2PlayerService.save(player); + }); + } + + @Test + void save_LocationNull() { + assertThrows(Exception.class, () -> { + H2Player player = buildPlayer(); + player.setLocation(null); + h2PlayerService.save(player); + }); + } + + @Test + void remove() { H2Player player = h2PlayerService.save(buildPlayer()); h2PlayerService.remove(player); H2Player player2 = h2PlayerService.getById(player.getId()); - Assert.assertNull(player2); - } - - @Test(expected = Exception.class) - public void remove_NotExists() { - H2Player player = h2PlayerService.save(buildPlayer()); - h2PlayerService.remove(player); - h2PlayerService.remove(player); + assertNull(player2); } @Test - public void getByName() { + void remove_NotExists() { + assertThrows(Exception.class, () -> { + H2Player player = h2PlayerService.save(buildPlayer()); + h2PlayerService.remove(player); + h2PlayerService.remove(player); + }); + } + + @Test + void getByName() { H2Player player = h2PlayerService.save(buildPlayer()); H2Player player2 = h2PlayerService.getByName(player.getName()); - Assert.assertEquals(player, player2); + assertEquals(player, player2); } @Test - public void getByName_NotExists() { - Assert.assertNull(h2PlayerService.getByName("UNKNOW_PLAYER")); + void getByName_NotExists() { + assertNull(h2PlayerService.getByName("UNKNOW_PLAYER")); } @Test - public void getByName_Empty() { - Assert.assertNull(h2PlayerService.getByName("")); + void getByName_Empty() { + assertNull(h2PlayerService.getByName("")); } @Test - public void getByName_Null() { - Assert.assertNull(h2PlayerService.getByName(null)); + void getByName_Null() { + assertNull(h2PlayerService.getByName(null)); } @Test - public void getById() { + void getById() { H2Player player = h2PlayerService.save(buildPlayer()); H2Player player2 = h2PlayerService.getById(player.getId()); - Assert.assertEquals(player, player2); + assertEquals(player, player2); } @Test - public void getById_NotExists() { - Assert.assertNull(h2PlayerService.getById(9999)); + void getById_NotExists() { + assertNull(h2PlayerService.getById(9999)); } } diff --git a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestByteArrayInputNetStream.java b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestByteArrayInputNetStream.java index 72d1574..b73500d 100644 --- a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestByteArrayInputNetStream.java +++ b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestByteArrayInputNetStream.java @@ -1,17 +1,17 @@ package mc.core.network.proto_1_12_2.packets; import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Random; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class TestByteArrayInputNetStream { +class TestByteArrayInputNetStream { private Random rnd = new Random(); @Test - public void testReadByte() { + void testReadByte() { final byte b0 = (byte) rnd.nextInt(); ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream(); netStream.writeByte(b0); @@ -23,7 +23,7 @@ public class TestByteArrayInputNetStream { } @Test - public void testReadInt() { + void testReadInt() { final int i0 = rnd.nextInt(); ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream(); netStream.writeInt(i0); @@ -35,7 +35,7 @@ public class TestByteArrayInputNetStream { } @Test - public void testReadFloat() { + void testReadFloat() { final float f0 = rnd.nextFloat(); ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream(); netStream.writeFloat(f0); @@ -43,6 +43,6 @@ public class TestByteArrayInputNetStream { ByteArrayInputNetStream netInputStream = new ByteArrayInputNetStream(buffer); float f1 = netInputStream.readFloat(); - assertEquals(f0, f1, 0.0f); + assertEquals(f0, f1, 0.00001f); } } \ No newline at end of file diff --git a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestChunkdataPacket.java b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestChunkdataPacket.java index 449a672..cabb163 100644 --- a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestChunkdataPacket.java +++ b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestChunkdataPacket.java @@ -9,31 +9,31 @@ import mc.core.world.block.BlockFactory; import mc.core.world.block.BlockType; import mc.core.world.chunk.Chunk; import mc.core.world.chunk.ChunkSection; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class TestChunkdataPacket { +class TestChunkdataPacket { private static byte[] expectedPacketData; private World world; - @BeforeClass - public static void beforeClassTest() throws IOException { + @BeforeAll + static void beforeClassTest() throws IOException { InputStream inputStream = TestChunkdataPacket.class.getResourceAsStream("ChunkDataPacket.bin"); expectedPacketData = ByteStreams.toByteArray(inputStream); } - @Before - public void prepareWorld() { + @BeforeEach + void prepareWorld() { final ChunkSection chunkSection = mock(ChunkSection.class); when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> { int y = (int)invocation.getArguments()[1]; @@ -77,7 +77,7 @@ public class TestChunkdataPacket { } @Test - public void test() { + void test() { ChunkDataPacket packet = new ChunkDataPacket(); packet.setX(0); packet.setZ(0); diff --git a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestPlayerAbilitiesPacket.java b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestPlayerAbilitiesPacket.java index ec9b150..cf4344c 100644 --- a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestPlayerAbilitiesPacket.java +++ b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/packets/TestPlayerAbilitiesPacket.java @@ -1,19 +1,19 @@ package mc.core.network.proto_1_12_2.packets; import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Random; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class TestPlayerAbilitiesPacket { +class TestPlayerAbilitiesPacket { private Random rnd = new Random(); private PlayerAbilitiesPacket packet; - @Before - public void before() { + @BeforeEach + void before() { packet = new PlayerAbilitiesPacket(); packet.setGodMode(rnd.nextBoolean()); packet.setFlying(rnd.nextBoolean()); @@ -23,7 +23,7 @@ public class TestPlayerAbilitiesPacket { } @Test - public void test() { + void test() { ByteArrayOutputNetStream netOutputStream = new ByteArrayOutputNetStream(); packet.writeSelf(netOutputStream); @@ -31,10 +31,10 @@ public class TestPlayerAbilitiesPacket { PlayerAbilitiesPacket outPkt = new PlayerAbilitiesPacket(); outPkt.readSelf(netInputStream); - assertEquals("god mode", packet.isGodMode(), outPkt.isGodMode()); - assertEquals("flying", packet.isFlying(), outPkt.isFlying()); - assertEquals("can fly", packet.isCanFly(), outPkt.isCanFly()); - assertEquals("instant destroy block", packet.isInstantDestroyBlocks(), outPkt.isInstantDestroyBlocks()); - assertEquals("flying speed", packet.getFlyingSpeed(), outPkt.getFlyingSpeed(), 0.0f); + assertEquals(packet.isGodMode(), outPkt.isGodMode(), "god mode"); + assertEquals(packet.isFlying(), outPkt.isFlying(), "flying"); + assertEquals(packet.isCanFly(), outPkt.isCanFly(), "can fly"); + assertEquals(packet.isInstantDestroyBlocks(), outPkt.isInstantDestroyBlocks(), "instant destroy block"); + assertEquals(packet.getFlyingSpeed(), outPkt.getFlyingSpeed(), 0.00001f, "flying speed"); } } diff --git a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/serializers/TestBlockLocationSerializer.java b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/serializers/TestBlockLocationSerializer.java index 28db9ea..51d6498 100644 --- a/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/serializers/TestBlockLocationSerializer.java +++ b/proto_1.12.2/src/test/java/mc/core/network/proto_1_12_2/serializers/TestBlockLocationSerializer.java @@ -1,27 +1,27 @@ package mc.core.network.proto_1_12_2.serializers; import mc.core.world.block.BlockLocation; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.concurrent.ThreadLocalRandom; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class TestBlockLocationSerializer { +class TestBlockLocationSerializer { private static final ThreadLocalRandom rnd = ThreadLocalRandom.current(); private static final int minI = 0, maxI = 10; private int x, y, z; - @Before - public void before() { + @BeforeEach + void before() { x = rnd.nextInt(minI, maxI); y = rnd.nextInt(minI, maxI); z = rnd.nextInt(minI, maxI); } @Test - public void test() { + void test() { BlockLocation location = new BlockLocation(x, y, z); final long serializedCoords = BlockLocationSerializer.toLong(location);