### Question:
SubAckDecoder extends MqttDecoder { public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { SubAckMessage message = new SubAckMessage(); if (decodeCommonHeader(message, in) == NEED_DATA) { return NEED_DATA; } int remainingLength = message.getRemainingLength(); message.setMessageID(Utils.readWord(in)); remainingLength -= 2; if (in.remaining() < remainingLength ) { return NEED_DATA; } for (int i = 0; i < remainingLength; i++) { byte qos = in.get(); message.addType(QOSType.values()[qos]); } 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 { initHeaderQos(m_buff, 0xAABB, QOSType.LEAST_ONE, QOSType.MOST_ONE, QOSType.MOST_ONE); m_buff.flip(); MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder); assertEquals(MessageDecoderResult.OK, res); assertEquals(0xAABB, m_mockProtoDecoder.getMessage().getMessageID().intValue()); List<QOSType> qoses = m_mockProtoDecoder.getMessage().types(); assertEquals(3, qoses.size()); assertEquals(QOSType.LEAST_ONE, qoses.get(0)); assertEquals(QOSType.MOST_ONE, qoses.get(1)); assertEquals(QOSType.MOST_ONE, qoses.get(2)); assertEquals(AbstractMessage.SUBACK, m_mockProtoDecoder.getMessage().getMessageType()); }
@Test public void testBugBadRemainingCalculation() throws Exception { byte[] overallMessage = new byte[] {(byte)0x90, 0x03, 0x00, 0x0A, 0x01}; 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()); assertEquals(MessageDecoder.OK, res); SubAckMessage message = (SubAckMessage) m_mockProtoDecoder.getMessage(); assertEquals(0x0A, message.getMessageID().intValue()); assertEquals(1, message.types().size()); assertEquals(AbstractMessage.QOSType.LEAST_ONE, message.types().get(0)); }