PacketCodec extends ByteToMessageCodec<DatabasePacket> { @Override protected void decode(final ChannelHandlerContext context, final ByteBuf in, final List<Object> out) { int readableBytes = in.readableBytes(); if (!databasePacketCodecEngine.isValidHeader(readableBytes)) { return; } if (log.isDebugEnabled()) { log.debug("Read from client {} : \n {}", context.channel().id().asShortText(), ByteBufUtil.prettyHexDump(in)); } databasePacketCodecEngine.decode(context, in, out, readableBytes); }    }
@Test public void assertDecodeWithValidHeader() { when(byteBuf.readableBytes()).thenReturn(1); when(databasePacketCodecEngine.isValidHeader(1)).thenReturn(true); packetCodec.decode(context, byteBuf, Collections.emptyList()); verify(databasePacketCodecEngine).decode(context, byteBuf, Collections.emptyList(), 1); }
@Test public void assertDecodeWithInvalidHeader() { when(byteBuf.readableBytes()).thenReturn(1); when(databasePacketCodecEngine.isValidHeader(1)).thenReturn(false); packetCodec.decode(context, byteBuf, Collections.emptyList()); verify(databasePacketCodecEngine, times(0)).decode(context, byteBuf, Collections.emptyList(), 1); }