3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Refactor tests to be one general test per method and include plugin

Dieser Commit ist enthalten in:
Myles 2018-11-17 13:46:32 +00:00
Ursprung 149b3c2e29
Commit 69aa7be6c5
3 geänderte Dateien mit 39 neuen und 6 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -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 {

11
pom.xml
Datei anzeigen

@ -127,4 +127,15 @@
</dependency>
</dependencies>
<build>
<plugins>
<!-- Run any tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
</project>