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

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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");
}
}

View File

@@ -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);