use of com.flowpowered.network.Codec in project Glowstone by GlowstoneMC.
the class BaseProtocolTest method testProtocol.
@Test
public void testProtocol() throws Exception {
Map<Class<? extends Message>, Codec.CodecRegistration> inboundMap = getField(inboundCodecs, CodecLookupService.class, "messages");
Map<Class<? extends Message>, Codec.CodecRegistration> outboundMap = getField(outboundCodecs, CodecLookupService.class, "messages");
Set<Class<? extends Message>> inboundSet = new HashSet<>(inboundMap.keySet());
Set<Class<? extends Message>> outboundSet = new HashSet<>(outboundMap.keySet());
for (Message message : testMessages) {
boolean any = false;
Class<? extends Message> clazz = message.getClass();
// test inbound
Codec.CodecRegistration registration = inboundCodecs.find(clazz);
if (registration != null) {
inboundSet.remove(clazz);
checkCodec(registration, message);
any = true;
}
// test outbound
registration = outboundCodecs.find(clazz);
if (registration != null) {
outboundSet.remove(clazz);
checkCodec(registration, message);
any = true;
}
assertThat("Codec missing for: " + message, any, is(true));
}
// special case: HeldItemMessage is excluded from tests
inboundSet.remove(HeldItemMessage.class);
outboundSet.remove(HeldItemMessage.class);
assertThat("Did not test inbound classes: " + inboundSet, inboundSet.isEmpty(), is(true));
// todo: enable the outbound check for PlayProtocol
if (!(protocol instanceof PlayProtocol)) {
assertThat("Did not test outbound classes: " + outboundSet, outboundSet.isEmpty(), is(true));
}
}
Aggregations