diff --git a/common/src/test/java/us/myles/ViaVersion/common/test/type/ItemTypeTest.java b/common/src/test/java/us/myles/ViaVersion/common/test/type/ItemTypeTest.java index 2e0350036..d9b2cd3fe 100644 --- a/common/src/test/java/us/myles/ViaVersion/common/test/type/ItemTypeTest.java +++ b/common/src/test/java/us/myles/ViaVersion/common/test/type/ItemTypeTest.java @@ -9,13 +9,15 @@ import us.myles.ViaVersion.api.type.Type; public class ItemTypeTest { @Test - public void test() throws Exception { - ByteBuf buf = Unpooled.buffer(); - + public void testEmptyItemRead() throws Exception { // Test empty item read Assertions.assertNull(Type.ITEM.read(Unpooled.wrappedBuffer(new byte[]{-1, -1}))); Assertions.assertNull(Type.FLAT_ITEM.read(Unpooled.wrappedBuffer(new byte[]{-1, -1}))); Assertions.assertNull(Type.FLAT_VAR_INT_ITEM.read(Unpooled.wrappedBuffer(new byte[]{0}))); + } + + @Test + public void testNormalItemRead() throws Exception { // Test item read Assertions.assertEquals( @@ -44,6 +46,11 @@ public class ItemTypeTest { 0 })) ); + } + + @Test + public void testEmptyItemWrite() throws Exception { + ByteBuf buf = Unpooled.buffer(); // Test item empty write Type.ITEM.write(buf, null); @@ -52,6 +59,11 @@ public class ItemTypeTest { Assertions.assertArrayEquals(toBytes(buf), new byte[]{-1, -1}); Type.FLAT_VAR_INT_ITEM.write(buf, null); Assertions.assertArrayEquals(toBytes(buf), new byte[]{0}); + } + + @Test + public void testNormalItemWrite() throws Exception { + ByteBuf buf = Unpooled.buffer(); // Test item write Type.ITEM.write(buf, new Item((int) Short.MAX_VALUE, (byte) -128, (short) 257, null)); diff --git a/common/src/test/java/us/myles/ViaVersion/common/test/type/StringTypeTest.java b/common/src/test/java/us/myles/ViaVersion/common/test/type/StringTypeTest.java index 8041aaf1d..0230723e8 100644 --- a/common/src/test/java/us/myles/ViaVersion/common/test/type/StringTypeTest.java +++ b/common/src/test/java/us/myles/ViaVersion/common/test/type/StringTypeTest.java @@ -10,14 +10,17 @@ import us.myles.ViaVersion.api.type.Type; public class StringTypeTest { @Test - public void test() throws Exception { + public void testStringWrite() throws Exception { // Write final ByteBuf buf = Unpooled.buffer(); Type.STRING.write(buf, "\uD83E\uDDFD"); // Sponge Emoji Assertions.assertEquals(ByteBufUtil.hexDump(buf), "04f09fa7bd"); - buf.clear(); + } - // Read Write + @Test + public void testStringRead() throws Exception { + // Write + final ByteBuf buf = Unpooled.buffer(); Type.STRING.write(buf, new String(new char[Short.MAX_VALUE])); Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE])); @@ -26,8 +29,11 @@ public class StringTypeTest { Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD")); Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD")); + } + public void testStringReadOverflowException() throws Exception { // Read exception + final ByteBuf buf = Unpooled.buffer(); Type.VAR_INT.write(buf, (Short.MAX_VALUE + 1) * 4); for (int i = 0; i < Short.MAX_VALUE / 2 + 1; i++) { buf.writeBytes(new byte[]{0x04, (byte) 0xf0, (byte) 0x9f, (byte) 0xa7, (byte) 0xbd}); // Sponge emoji @@ -38,8 +44,12 @@ public class StringTypeTest { Type.STRING.read(buf); } }); + } + @Test + public void testStringWriteOverflowException() { // Write exceptions + final ByteBuf buf = Unpooled.buffer(); Assertions.assertThrows(IllegalArgumentException.class, new Executable() { @Override public void execute() throws Throwable { diff --git a/pom.xml b/pom.xml index d1868db3e..fa99a5f7d 100644 --- a/pom.xml +++ b/pom.xml @@ -127,4 +127,15 @@ + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + +