### Question:
UnsubscribeDecoder extends DemuxDecoder { @Override void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { in.resetReaderIndex(); UnsubscribeMessage message = new UnsubscribeMessage(); if (!decodeCommonHeader(message, in)) { in.resetReaderIndex(); return; } if (message.getQos() != AbstractMessage.QOSType.LEAST_ONE) { throw new CorruptedFrameException("Found an Usubscribe message with qos other than LEAST_ONE, was: " + message.getQos()); } int start = in.readerIndex(); message.setMessageID(in.readUnsignedShort()); int readed = in.readerIndex()- start; while (readed < message.getRemainingLength()) { message.addTopic(Utils.decodeString(in)); readed = in.readerIndex()- start; } out.add(message); }    }### Answer:
@Test(expected = CorruptedFrameException.class) public void testBadQos() throws Exception { m_buff = Unpooled.buffer(2); initHeaderBadQos(m_buff); m_msgdec.decode(null, m_buff, m_results); }
@Test public void testMultiTopic() throws Exception { m_buff = Unpooled.buffer(4); String topic1 = "a/b"; String topic2 = "c/d/e"; initMultiTopic(m_buff, 123, topic1, topic2); m_msgdec.decode(null, m_buff, m_results); assertFalse(m_results.isEmpty()); UnsubscribeMessage message = (UnsubscribeMessage)m_results.get(0); assertNotNull(message); assertEquals(2, message.topics().size()); assertEquals(topic1, message.topics().get(0)); assertEquals(topic2, message.topics().get(1)); assertEquals(AbstractMessage.UNSUBSCRIBE, message.getMessageType()); }
@Test public void testDecodeSingleTopic_bug() throws Exception { byte[] overallMessage = new byte[] {(byte)0xA2, 0x0A, 0x00, 0x01, 0x00, 0x06, 0x2F, 0x74, 0x6F, 0x70, 0x69, 0x63}; m_buff = Unpooled.buffer(overallMessage.length); m_buff.writeBytes(overallMessage); m_msgdec.decode(null, m_buff, m_results); assertFalse(m_results.isEmpty()); UnsubscribeMessage message = (UnsubscribeMessage)m_results.get(0); assertNotNull(message); assertEquals(0x01, (int)message.getMessageID()); }