Search in sources :

Example 1 with Codec

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));
    }
}
Also used : Codec(com.flowpowered.network.Codec) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) Message(com.flowpowered.network.Message) PlayProtocol(net.glowstone.net.protocol.PlayProtocol) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

Codec (com.flowpowered.network.Codec)1 Message (com.flowpowered.network.Message)1 HashSet (java.util.HashSet)1 HeldItemMessage (net.glowstone.net.message.play.inv.HeldItemMessage)1 PlayProtocol (net.glowstone.net.protocol.PlayProtocol)1 Test (org.junit.jupiter.api.Test)1