### Question:
OFVersionDetector extends ByteToMessageDecoder { @Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) { if (!in.isReadable()) { LOG.debug("not enough data"); in.release(); return; } final byte version = in.readByte(); final short messageType = in.getUnsignedByte(in.readerIndex()); if (messageType == EncodeConstants.OF_HELLO_MESSAGE_TYPE_VALUE || OF_VERSIONS.contains(version)) { LOG.debug("detected version: {}", version); if (!filterPacketIns || EncodeConstants.OF_PACKETIN_MESSAGE_TYPE_VALUE != messageType) { ByteBuf messageBuffer = in.slice(); out.add(new VersionMessageWrapper(version, messageBuffer)); messageBuffer.retain(); } else { LOG.debug("dropped packetin"); statisticsCounters.incrementCounter(CounterEventTypes.US_DROPPED_PACKET_IN); } } else { LOG.warn("detected version: {} - currently not supported", version); } in.skipBytes(in.readableBytes()); } OFVersionDetector(); void setFilterPacketIns(final boolean enabled);  }### Answer:
@Test public void testDecode13ProtocolMessage() { detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), list); Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes()); }
@Test public void testDecode10ProtocolMessage() { detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"), list); Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes()); }
@Test public void testDecodeEmptyProtocolMessage() { ByteBuf byteBuffer = ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01").skipBytes(8); detector.decode(channelHandlerContext, byteBuffer, list); assertEquals(0, byteBuffer.refCnt()); }
@Test public void testDecodeNotSupportedVersionProtocolMessage() { detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("02 01 00 08 00 00 00 01"), list); Assert.assertEquals("List is not empty", 0, list.size()); }
@Test public void testDecodeHelloProtocolMessage() { detector.decode(channelHandlerContext, ByteBufUtils.hexStringToByteBuf("05 00 00 08 00 00 00 01"), list); Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)).getMessageBuffer().readableBytes()); }