### Question:
SubAckEncoder implements MessageEncoder<SubAckMessage> { public void encode(IoSession session, SubAckMessage message, ProtocolEncoderOutput out) throws Exception { if (message.types().isEmpty()) { throw new IllegalArgumentException("Found a suback message with empty topics"); } IoBuffer variableHeaderBuff = IoBuffer.allocate(4).setAutoExpand(true); Utils.writeWord(variableHeaderBuff, message.getMessageID()); for (AbstractMessage.QOSType c : message.types()) { byte ord = (byte) c.ordinal(); variableHeaderBuff.put((byte)c.ordinal()); } variableHeaderBuff.flip(); int variableHeaderSize = variableHeaderBuff.remaining(); IoBuffer buff = IoBuffer.allocate(2 + variableHeaderSize); buff.put((byte) (AbstractMessage.SUBACK << 4 )); buff.put(Utils.encodeRemainingLength(variableHeaderSize)); buff.put(variableHeaderBuff).flip(); out.write(buff); }  void encode(IoSession session, SubAckMessage message, ProtocolEncoderOutput out);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testEncodeWithNoQoss() throws Exception { SubAckMessage msg = new SubAckMessage(); msg.setMessageID(123); m_encoder.encode(null, msg, m_mockProtoEncoder); }
@Test public void testEncodeWithMultipleQos() throws Exception { SubAckMessage msg = new SubAckMessage(); int messageID = 0xAABB; msg.setMessageID(messageID); msg.addType(QOSType.MOST_ONE); msg.addType(QOSType.LEAST_ONE); msg.addType(QOSType.EXACTLY_ONCE); m_encoder.encode(null, msg, m_mockProtoEncoder); assertEquals((byte) (AbstractMessage.SUBACK << 4 ), m_mockProtoEncoder.getBuffer().get()); assertEquals(5, m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)0xAA, m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)0xBB, m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)QOSType.MOST_ONE.ordinal(), m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)QOSType.LEAST_ONE.ordinal(), m_mockProtoEncoder.getBuffer().get()); assertEquals((byte)QOSType.EXACTLY_ONCE.ordinal(), m_mockProtoEncoder.getBuffer().get()); }