### Question:
SubAckEncoder extends DemuxEncoder<SubAckMessage> { @Override protected void encode(ChannelHandlerContext chc, SubAckMessage message, ByteBuf out) { if (message.types().isEmpty()) { throw new IllegalArgumentException("Found a suback message with empty topics"); } ByteBuf variableHeaderBuff = chc.alloc().buffer(4); variableHeaderBuff.writeShort(message.getMessageID()); for (AbstractMessage.QOSType c : message.types()) { variableHeaderBuff.writeByte(c.ordinal()); } int variableHeaderSize = variableHeaderBuff.readableBytes(); ByteBuf buff = chc.alloc().buffer(2 + variableHeaderSize); buff.writeByte(AbstractMessage.SUBACK << 4 ); buff.writeBytes(Utils.encodeRemainingLength(variableHeaderSize)); buff.writeBytes(variableHeaderBuff); out.writeBytes(buff); }    }### Answer:
@Test(expected = IllegalArgumentException.class) public void testEncodeWithNoQoss() throws Exception { SubAckMessage msg = new SubAckMessage(); msg.setMessageID(123); m_encoder.encode(m_mockedContext, msg, m_out); }
@Test public void testEncodeWithMultipleQos() throws Exception { SubAckMessage msg = new SubAckMessage(); int messageID = 0xAABB; msg.setMessageID(messageID); msg.addType(AbstractMessage.QOSType.MOST_ONE); msg.addType(AbstractMessage.QOSType.LEAST_ONE); msg.addType(AbstractMessage.QOSType.EXACTLY_ONCE); m_encoder.encode(m_mockedContext, msg, m_out); assertEquals((byte) (AbstractMessage.SUBACK << 4 ), m_out.readByte()); assertEquals(5, m_out.readByte()); assertEquals((byte)0xAA, m_out.readByte()); assertEquals((byte)0xBB, m_out.readByte()); assertEquals((byte)AbstractMessage.QOSType.MOST_ONE.ordinal(), m_out.readByte()); assertEquals((byte)AbstractMessage.QOSType.LEAST_ONE.ordinal(), m_out.readByte()); assertEquals((byte)AbstractMessage.QOSType.EXACTLY_ONCE.ordinal(), m_out.readByte()); }