### Question:
UnsubscribeDecoder extends MqttDecoder { public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { UnsubscribeMessage message = new UnsubscribeMessage(); if (decodeCommonHeader(message, in) == NEED_DATA) { return NEED_DATA; } if (message.getQos() != QOSType.LEAST_ONE) { return NOT_OK; } int start = in.position(); message.setMessageID(Utils.readWord(in)); int readed = in.position() - start; while (readed < message.getRemainingLength()) { message.addTopic(Utils.decodeString(in)); readed = in.position() - start; } out.write(message); return OK; }  MessageDecoderResult decodable(IoSession session, IoBuffer in); MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out);  }### Answer:
@Test public void testBadQos() throws Exception { m_buff = IoBuffer.allocate(2); initHeaderBadQos(m_buff); m_buff.flip(); MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder); assertEquals(MessageDecoderResult.NOT_OK, res); }
@Test public void testMultiTopic() throws Exception { m_buff = IoBuffer.allocate(4).setAutoExpand(true); String topic1 = "a/b"; String topic2 = "c/d/e"; initMultiTopic(m_buff, 123, topic1, topic2); m_buff.flip(); MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder); assertEquals(MessageDecoderResult.OK, res); assertEquals(2, m_mockProtoDecoder.getMessage().topics().size()); assertEquals(topic1, m_mockProtoDecoder.getMessage().topics().get(0)); assertEquals(topic2, m_mockProtoDecoder.getMessage().topics().get(1)); assertEquals(AbstractMessage.UNSUBSCRIBE, m_mockProtoDecoder.getMessage().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 = IoBuffer.allocate(overallMessage.length).setAutoExpand(true); m_buff.put(overallMessage); m_buff.flip(); MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder); assertNotNull(m_mockProtoDecoder.getMessage()); UnsubscribeMessage message = (UnsubscribeMessage) m_mockProtoDecoder.getMessage(); }