public class ReflectionPacketDeserializerTest {
@Test
public void deserializesCorrectly() throws IOException, Exception {
// create a new deserializer
ReflectionPacketDeserializer packetDeserializer = new ReflectionPacketDeserializer(8, P008_TestPacket.class);
// build the fake inputstream
// The stream represents the data shown in the "assertEqual" tests
ByteBuf buffer = Unpooled.buffer();
buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
String source = "0 0 1 0 0 0 2 0 0 0 3 0 20 21 22 23 24 25 4 0 116 0 111 0 116 0 111 0 4 0 26 27 28 29 5 0 0 0 5 0 30 31 32 33 34 6 7 0 0 0 4 0 116 0 105 0 116 0 105 0";
String[] bytes = source.split("\\s");
for (String byteString : bytes) {
buffer.writeByte(Byte.parseByte(byteString));
}
// the header isn't parsed by using reflection
buffer.readByte();
buffer.readByte();
// deserializer the object
P008_TestPacket testIncomingPacket = (P008_TestPacket) packetDeserializer.deserialize(buffer);
// test that the deserializer correctly extracted all values
assertEquals(1, testIncomingPacket.getUnsignedInteger1());
assertEquals(2, testIncomingPacket.getUnsignedInteger2());
assertEquals(3, testIncomingPacket.getUnsignedShort1());