### Question:
SubAckDecoder extends DemuxDecoder { @Override void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { in.resetReaderIndex(); SubAckMessage message = new SubAckMessage(); if (!decodeCommonHeader(message, in)) { in.resetReaderIndex(); return; } int remainingLength = message.getRemainingLength(); message.setMessageID(in.readUnsignedShort()); remainingLength -= 2; if (in.readableBytes() < remainingLength ) { in.resetReaderIndex(); return; } for (int i = 0; i < remainingLength; i++) { byte qos = in.readByte(); message.addType(AbstractMessage.QOSType.values()[qos]); } out.add(message); }    }### Answer:
@Test public void testBadQos() throws Exception { initHeaderQos(m_buff, 0xAABB, AbstractMessage.QOSType.LEAST_ONE, AbstractMessage.QOSType.MOST_ONE, AbstractMessage.QOSType.MOST_ONE); m_msgdec.decode(null, m_buff, m_results); assertFalse(m_results.isEmpty()); SubAckMessage message = (SubAckMessage)m_results.get(0); assertNotNull(message); assertEquals(0xAABB, message.getMessageID().intValue()); List<AbstractMessage.QOSType> qoses = message.types(); assertEquals(3, qoses.size()); assertEquals(AbstractMessage.QOSType.LEAST_ONE, qoses.get(0)); assertEquals(AbstractMessage.QOSType.MOST_ONE, qoses.get(1)); assertEquals(AbstractMessage.QOSType.MOST_ONE, qoses.get(2)); assertEquals(AbstractMessage.SUBACK, message.getMessageType()); }
@Test public void testBugBadRemainingCalculation() throws Exception { byte[] overallMessage = new byte[] {(byte)0x90, 0x03, 0x00, 0x0A, 0x01}; m_buff = Unpooled.buffer(overallMessage.length); m_buff.writeBytes(overallMessage); m_msgdec.decode(null, m_buff, m_results); assertFalse(m_results.isEmpty()); SubAckMessage message = (SubAckMessage)m_results.get(0); assertNotNull(message); assertEquals(0x0A, message.getMessageID().intValue()); assertEquals(1, message.types().size()); assertEquals(AbstractMessage.QOSType.LEAST_ONE, message.types().get(0)); }