Archived
0

JUnit4 -> JUnit5

This commit is contained in:
2018-10-07 21:31:00 +03:00
parent 7a8a3e6ad4
commit 7225efced9
13 changed files with 175 additions and 161 deletions

View File

@@ -22,6 +22,7 @@ subprojects {
slf4j_version = '1.7.25' slf4j_version = '1.7.25'
spring_version = '5.1.0.RELEASE' spring_version = '5.1.0.RELEASE'
lombok_version = '1.18.2' lombok_version = '1.18.2'
junit_version = '5.3.1'
} }
configurations { configurations {
@@ -42,12 +43,17 @@ subprojects {
compileOnly (group: 'org.projectlombok', name: 'lombok', version: lombok_version) compileOnly (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
/* Testing */ /* 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.slf4j', name: 'slf4j-simple', version: slf4j_version)
testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.10.19') testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.10.19')
testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version) testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version)
} }
test {
useJUnitPlatform()
}
task copyDep(type: Copy) { task copyDep(type: Copy) {
into 'libs' into 'libs'
from configurations.compile + configurations.runtime - configurations.compile_excludeCopy from configurations.compile + configurations.runtime - configurations.compile_excludeCopy

View File

@@ -1,28 +1,28 @@
package mc.core; package mc.core;
import mc.core.world.block.BlockLocation; import mc.core.world.block.BlockLocation;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class TestBlockLocation { class TestBlockLocation {
private static final ThreadLocalRandom rnd = ThreadLocalRandom.current(); private static final ThreadLocalRandom rnd = ThreadLocalRandom.current();
private static final int minI = 0, maxI = 10; private static final int minI = 0, maxI = 10;
private int x, y, z; private int x, y, z;
@Before @BeforeEach
public void before() { void before() {
x = rnd.nextInt(minI, maxI); x = rnd.nextInt(minI, maxI);
y = rnd.nextInt(minI, maxI); y = rnd.nextInt(minI, maxI);
z = rnd.nextInt(minI, maxI); z = rnd.nextInt(minI, maxI);
} }
@Test @Test
public void testEquals() { void testEquals() {
BlockLocation loc1 = new BlockLocation(x, y, z); BlockLocation loc1 = new BlockLocation(x, y, z);
BlockLocation loc2 = new BlockLocation(x, y, z); BlockLocation loc2 = new BlockLocation(x, y, z);
assertEquals(loc1, loc2); assertEquals(loc1, loc2);
@@ -32,7 +32,7 @@ public class TestBlockLocation {
} }
@Test @Test
public void testClone() { void testClone() {
BlockLocation locOrig = new BlockLocation(x, y, z); BlockLocation locOrig = new BlockLocation(x, y, z);
BlockLocation locClone = locOrig.clone(); BlockLocation locClone = locOrig.clone();
assertEquals(locOrig, locClone); assertEquals(locOrig, locClone);

View File

@@ -1,22 +1,22 @@
package mc.core; package mc.core;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class TestEntityLocation { class TestEntityLocation {
private static final ThreadLocalRandom rnd = ThreadLocalRandom.current(); private static final ThreadLocalRandom rnd = ThreadLocalRandom.current();
private static final double minD = 0.0d, maxD = 10.0d; private static final double minD = 0.0d, maxD = 10.0d;
private static final float minF = 0.0f, maxF = 359.9f; private static final float minF = 0.0f, maxF = 359.9f;
private double x, y, z; private double x, y, z;
private float yaw, pitch; private float yaw, pitch;
@Before @BeforeEach
public void before() { void before() {
x = rnd.nextDouble(minD, maxD); x = rnd.nextDouble(minD, maxD);
y = rnd.nextDouble(minD, maxD); y = rnd.nextDouble(minD, maxD);
z = rnd.nextDouble(minD, maxD); z = rnd.nextDouble(minD, maxD);
@@ -25,7 +25,7 @@ public class TestEntityLocation {
} }
@Test @Test
public void testEquals() { void testEquals() {
EntityLocation loc1 = new EntityLocation(x, y, z, yaw, pitch); EntityLocation loc1 = new EntityLocation(x, y, z, yaw, pitch);
EntityLocation loc2 = new EntityLocation(x, y, z, yaw, pitch); EntityLocation loc2 = new EntityLocation(x, y, z, yaw, pitch);
assertEquals(loc1, loc2); assertEquals(loc1, loc2);
@@ -38,14 +38,14 @@ public class TestEntityLocation {
} }
@Test @Test
public void testClone() { void testClone() {
EntityLocation locOrig = new EntityLocation(x, y, z, yaw, pitch); EntityLocation locOrig = new EntityLocation(x, y, z, yaw, pitch);
EntityLocation locClone = locOrig.clone(); EntityLocation locClone = locOrig.clone();
assertEquals(locOrig, locClone); assertEquals(locOrig, locClone);
} }
@Test @Test
public void testGetBlockXZ() { void testGetBlockXZ() {
EntityLocation location; EntityLocation location;
location = new EntityLocation(0d, 0, 0d, 0f, 0f); location = new EntityLocation(0d, 0, 0d, 0f, 0f);

View File

@@ -1,32 +1,30 @@
package mc.core; package mc.core;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.rules.ExpectedException;
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 { class TestImmutableEntityLocation {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testSetValue() { void testSetValue() {
EntityLocation location = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f); EntityLocation location = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f);
thrown.expect(UnsupportedOperationException.class); assertThrows(UnsupportedOperationException.class, () -> {
location.setX(1); location.setX(1);
location.setY(1); location.setY(1);
location.setZ(1); location.setZ(1);
location.setYaw(1); location.setYaw(1);
location.setPitch(1); location.setPitch(1);
location.setXYZ(1, 2, 3); location.setXYZ(1, 2, 3);
location.setYawPitch(1, 2); location.setYawPitch(1, 2);
location.set(EntityLocation.ZERO()); location.set(EntityLocation.ZERO());
});
} }
@Test @Test
public void testClone() { void testClone() {
EntityLocation locOrig = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f); EntityLocation locOrig = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f);
EntityLocation locClone = locOrig.clone(); EntityLocation locClone = locOrig.clone();

View File

@@ -1,12 +1,12 @@
package mc.core.text; 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 @Test
public void testToPlain() { void testToPlain() {
final String m1 = "mes"; final String m1 = "mes";
final String m2 = "sage"; final String m2 = "sage";
final String message = m1 + m2; final String message = m1 + m2;
@@ -26,7 +26,7 @@ public class TestText {
} }
@Test @Test
public void testEquals() { void testEquals() {
assertEquals(Text.of(), Text.of("")); assertEquals(Text.of(), Text.of(""));
assertEquals(Text.of(), Text.builder().build()); assertEquals(Text.of(), Text.builder().build());
assertEquals(Text.of(), Text.builder("").build()); assertEquals(Text.of(), Text.builder("").build());
@@ -44,7 +44,7 @@ public class TestText {
} }
@Test @Test
public void testEmpty() { void testEmpty() {
assertTrue(Text.of().isEmpty()); assertTrue(Text.of().isEmpty());
assertTrue(Text.of((String) null).isEmpty()); assertTrue(Text.of((String) null).isEmpty());
assertTrue(Text.of((Text) null).isEmpty()); assertTrue(Text.of((Text) null).isEmpty());

View File

@@ -1,15 +1,14 @@
package mc.core.utils; package mc.core.utils;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
class TestCompactedCoords {
public class TestCompactedCoords {
@Test @Test
public void testXZ() { void testXZ() {
ThreadLocalRandom random = ThreadLocalRandom.current(); ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {

View File

@@ -1,15 +1,15 @@
package mc.core.h2db; package mc.core.h2db;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.UUID; import java.util.UUID;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class TestH2Player { class TestH2Player {
@Test @Test
public void testEquals() { void testEquals() {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
H2Player player1 = new H2Player(); H2Player player1 = new H2Player();

View File

@@ -4,21 +4,21 @@ import mc.core.EntityLocation;
import mc.core.h2db.service.H2PlayerService; import mc.core.h2db.service.H2PlayerService;
import mc.core.player.Player; import mc.core.player.Player;
import mc.core.world.World; import mc.core.world.World;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration; 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 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}) @ContextConfiguration(classes = {TestSpringConfig.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class TestH2PlayerManager { class TestH2PlayerManager {
@Autowired @Autowired
private H2PlayerService h2PlayerService; private H2PlayerService h2PlayerService;
@Autowired @Autowired
@@ -27,7 +27,7 @@ public class TestH2PlayerManager {
private H2PlayerManager playerManager; private H2PlayerManager playerManager;
@Test @Test
public void testCreatePlayer() { void testCreatePlayer() {
final String playerName = "NEW_PLAYER"; final String playerName = "NEW_PLAYER";
final Player newPlayer = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld); final Player newPlayer = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld);
@@ -45,7 +45,7 @@ public class TestH2PlayerManager {
} }
@Test @Test
public void testJoinServer() { void testJoinServer() {
assertEquals(0, playerManager.getCountPlayers()); assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER"; final String playerName = "NEW_PLAYER";
@@ -57,7 +57,7 @@ public class TestH2PlayerManager {
} }
@Test @Test
public void testLeftServer() { void testLeftServer() {
assertEquals(0, playerManager.getCountPlayers()); assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER"; final String playerName = "NEW_PLAYER";
@@ -87,7 +87,7 @@ public class TestH2PlayerManager {
} }
@Test @Test
public void testGetPlayer() { void testGetPlayer() {
assertEquals(0, playerManager.getCountPlayers()); assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER"; final String playerName = "NEW_PLAYER";
@@ -104,7 +104,7 @@ public class TestH2PlayerManager {
} }
@Test @Test
public void testGetPlayers() { void testGetPlayers() {
assertEquals(0, playerManager.getCountPlayers()); assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER"; final String playerName = "NEW_PLAYER";
@@ -128,7 +128,7 @@ public class TestH2PlayerManager {
} }
@Test @Test
public void testGetCountPlayers() { void testGetCountPlayers() {
assertEquals(0, playerManager.getCountPlayers()); assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER"; final String playerName = "NEW_PLAYER";
@@ -145,7 +145,7 @@ public class TestH2PlayerManager {
} }
@Test @Test
public void testGetOfflinePlayer() { void testGetOfflinePlayer() {
final String playerName = "NEW_PLAYER"; final String playerName = "NEW_PLAYER";
final Player player = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld); final Player player = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld);
playerManager.joinServer(player); playerManager.joinServer(player);

View File

@@ -3,21 +3,22 @@ package mc.core.h2db.service;
import mc.core.EntityLocation; import mc.core.EntityLocation;
import mc.core.h2db.H2Player; import mc.core.h2db.H2Player;
import mc.core.h2db.TestSpringConfig; import mc.core.h2db.TestSpringConfig;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration; 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.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@RunWith(SpringJUnit4ClassRunner.class) import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {TestSpringConfig.class}) @ContextConfiguration(classes = {TestSpringConfig.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class H2PlayerServiceTest { class H2PlayerServiceTest {
@Autowired @Autowired
private H2PlayerService h2PlayerService; private H2PlayerService h2PlayerService;
@@ -43,91 +44,101 @@ public class H2PlayerServiceTest {
} }
@Test @Test
public void save() { void save() {
H2Player player = buildPlayer(); H2Player player = buildPlayer();
H2Player savedPlayer = h2PlayerService.save(player); H2Player savedPlayer = h2PlayerService.save(player);
player.setId(savedPlayer.getId()); //FIXME костыль, однако player.setId(savedPlayer.getId()); //FIXME костыль, однако
Assert.assertEquals(player, savedPlayer); 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);
} }
@Test @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()); H2Player player = h2PlayerService.save(buildPlayer());
h2PlayerService.remove(player); h2PlayerService.remove(player);
H2Player player2 = h2PlayerService.getById(player.getId()); H2Player player2 = h2PlayerService.getById(player.getId());
Assert.assertNull(player2); assertNull(player2);
}
@Test(expected = Exception.class)
public void remove_NotExists() {
H2Player player = h2PlayerService.save(buildPlayer());
h2PlayerService.remove(player);
h2PlayerService.remove(player);
} }
@Test @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 player = h2PlayerService.save(buildPlayer());
H2Player player2 = h2PlayerService.getByName(player.getName()); H2Player player2 = h2PlayerService.getByName(player.getName());
Assert.assertEquals(player, player2); assertEquals(player, player2);
} }
@Test @Test
public void getByName_NotExists() { void getByName_NotExists() {
Assert.assertNull(h2PlayerService.getByName("UNKNOW_PLAYER")); assertNull(h2PlayerService.getByName("UNKNOW_PLAYER"));
} }
@Test @Test
public void getByName_Empty() { void getByName_Empty() {
Assert.assertNull(h2PlayerService.getByName("")); assertNull(h2PlayerService.getByName(""));
} }
@Test @Test
public void getByName_Null() { void getByName_Null() {
Assert.assertNull(h2PlayerService.getByName(null)); assertNull(h2PlayerService.getByName(null));
} }
@Test @Test
public void getById() { void getById() {
H2Player player = h2PlayerService.save(buildPlayer()); H2Player player = h2PlayerService.save(buildPlayer());
H2Player player2 = h2PlayerService.getById(player.getId()); H2Player player2 = h2PlayerService.getById(player.getId());
Assert.assertEquals(player, player2); assertEquals(player, player2);
} }
@Test @Test
public void getById_NotExists() { void getById_NotExists() {
Assert.assertNull(h2PlayerService.getById(9999)); assertNull(h2PlayerService.getById(9999));
} }
} }

View File

@@ -1,17 +1,17 @@
package mc.core.network.proto_1_12_2.packets; package mc.core.network.proto_1_12_2.packets;
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream; import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Random; 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(); private Random rnd = new Random();
@Test @Test
public void testReadByte() { void testReadByte() {
final byte b0 = (byte) rnd.nextInt(); final byte b0 = (byte) rnd.nextInt();
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream(); ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
netStream.writeByte(b0); netStream.writeByte(b0);
@@ -23,7 +23,7 @@ public class TestByteArrayInputNetStream {
} }
@Test @Test
public void testReadInt() { void testReadInt() {
final int i0 = rnd.nextInt(); final int i0 = rnd.nextInt();
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream(); ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
netStream.writeInt(i0); netStream.writeInt(i0);
@@ -35,7 +35,7 @@ public class TestByteArrayInputNetStream {
} }
@Test @Test
public void testReadFloat() { void testReadFloat() {
final float f0 = rnd.nextFloat(); final float f0 = rnd.nextFloat();
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream(); ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
netStream.writeFloat(f0); netStream.writeFloat(f0);
@@ -43,6 +43,6 @@ public class TestByteArrayInputNetStream {
ByteArrayInputNetStream netInputStream = new ByteArrayInputNetStream(buffer); ByteArrayInputNetStream netInputStream = new ByteArrayInputNetStream(buffer);
float f1 = netInputStream.readFloat(); float f1 = netInputStream.readFloat();
assertEquals(f0, f1, 0.0f); assertEquals(f0, f1, 0.00001f);
} }
} }

View File

@@ -9,31 +9,31 @@ import mc.core.world.block.BlockFactory;
import mc.core.world.block.BlockType; import mc.core.world.block.BlockType;
import mc.core.world.chunk.Chunk; import mc.core.world.chunk.Chunk;
import mc.core.world.chunk.ChunkSection; import mc.core.world.chunk.ChunkSection;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class TestChunkdataPacket { class TestChunkdataPacket {
private static byte[] expectedPacketData; private static byte[] expectedPacketData;
private World world; private World world;
@BeforeClass @BeforeAll
public static void beforeClassTest() throws IOException { static void beforeClassTest() throws IOException {
InputStream inputStream = TestChunkdataPacket.class.getResourceAsStream("ChunkDataPacket.bin"); InputStream inputStream = TestChunkdataPacket.class.getResourceAsStream("ChunkDataPacket.bin");
expectedPacketData = ByteStreams.toByteArray(inputStream); expectedPacketData = ByteStreams.toByteArray(inputStream);
} }
@Before @BeforeEach
public void prepareWorld() { void prepareWorld() {
final ChunkSection chunkSection = mock(ChunkSection.class); final ChunkSection chunkSection = mock(ChunkSection.class);
when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> { when(chunkSection.getSkyLight(anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> {
int y = (int)invocation.getArguments()[1]; int y = (int)invocation.getArguments()[1];
@@ -77,7 +77,7 @@ public class TestChunkdataPacket {
} }
@Test @Test
public void test() { void test() {
ChunkDataPacket packet = new ChunkDataPacket(); ChunkDataPacket packet = new ChunkDataPacket();
packet.setX(0); packet.setX(0);
packet.setZ(0); packet.setZ(0);

View File

@@ -1,19 +1,19 @@
package mc.core.network.proto_1_12_2.packets; package mc.core.network.proto_1_12_2.packets;
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream; import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Random; 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 Random rnd = new Random();
private PlayerAbilitiesPacket packet; private PlayerAbilitiesPacket packet;
@Before @BeforeEach
public void before() { void before() {
packet = new PlayerAbilitiesPacket(); packet = new PlayerAbilitiesPacket();
packet.setGodMode(rnd.nextBoolean()); packet.setGodMode(rnd.nextBoolean());
packet.setFlying(rnd.nextBoolean()); packet.setFlying(rnd.nextBoolean());
@@ -23,7 +23,7 @@ public class TestPlayerAbilitiesPacket {
} }
@Test @Test
public void test() { void test() {
ByteArrayOutputNetStream netOutputStream = new ByteArrayOutputNetStream(); ByteArrayOutputNetStream netOutputStream = new ByteArrayOutputNetStream();
packet.writeSelf(netOutputStream); packet.writeSelf(netOutputStream);
@@ -31,10 +31,10 @@ public class TestPlayerAbilitiesPacket {
PlayerAbilitiesPacket outPkt = new PlayerAbilitiesPacket(); PlayerAbilitiesPacket outPkt = new PlayerAbilitiesPacket();
outPkt.readSelf(netInputStream); outPkt.readSelf(netInputStream);
assertEquals("god mode", packet.isGodMode(), outPkt.isGodMode()); assertEquals(packet.isGodMode(), outPkt.isGodMode(), "god mode");
assertEquals("flying", packet.isFlying(), outPkt.isFlying()); assertEquals(packet.isFlying(), outPkt.isFlying(), "flying");
assertEquals("can fly", packet.isCanFly(), outPkt.isCanFly()); assertEquals(packet.isCanFly(), outPkt.isCanFly(), "can fly");
assertEquals("instant destroy block", packet.isInstantDestroyBlocks(), outPkt.isInstantDestroyBlocks()); assertEquals(packet.isInstantDestroyBlocks(), outPkt.isInstantDestroyBlocks(), "instant destroy block");
assertEquals("flying speed", packet.getFlyingSpeed(), outPkt.getFlyingSpeed(), 0.0f); assertEquals(packet.getFlyingSpeed(), outPkt.getFlyingSpeed(), 0.00001f, "flying speed");
} }
} }

View File

@@ -1,27 +1,27 @@
package mc.core.network.proto_1_12_2.serializers; package mc.core.network.proto_1_12_2.serializers;
import mc.core.world.block.BlockLocation; import mc.core.world.block.BlockLocation;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.concurrent.ThreadLocalRandom; 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 ThreadLocalRandom rnd = ThreadLocalRandom.current();
private static final int minI = 0, maxI = 10; private static final int minI = 0, maxI = 10;
private int x, y, z; private int x, y, z;
@Before @BeforeEach
public void before() { void before() {
x = rnd.nextInt(minI, maxI); x = rnd.nextInt(minI, maxI);
y = rnd.nextInt(minI, maxI); y = rnd.nextInt(minI, maxI);
z = rnd.nextInt(minI, maxI); z = rnd.nextInt(minI, maxI);
} }
@Test @Test
public void test() { void test() {
BlockLocation location = new BlockLocation(x, y, z); BlockLocation location = new BlockLocation(x, y, z);
final long serializedCoords = BlockLocationSerializer.toLong(location); final long serializedCoords = BlockLocationSerializer.toLong(location);