### Question:
ConnAckMessage extends Message { @Override protected void readMessage(InputStream in, int msgLength) throws IOException { if (msgLength != MESSAGE_LENGTH) { throw new IllegalStateException( "Message Length must be 2 for CONNACK. Current value: " + msgLength); } in.read(); int result = in.read(); switch (result) { case 0: status = ConnectionStatus.ACCEPTED; break; case 1: status = ConnectionStatus.UNACCEPTABLE_PROTOCOL_VERSION; break; case 2: status = ConnectionStatus.IDENTIFIER_REJECTED; break; case 3: status = ConnectionStatus.SERVER_UNAVAILABLE; break; case 4: status = ConnectionStatus.BAD_USERNAME_OR_PASSWORD; break; case 5: status = ConnectionStatus.NOT_AUTHORIZED; break; default: throw new UnsupportedOperationException( "Unsupported CONNACK code: " + result); } } ConnAckMessage();  ConnAckMessage(Header header);  ConnAckMessage(ConnectionStatus status); ConnectionStatus getStatus(); @Override void setDup(boolean dup); @Override void setRetained(boolean retain); @Override void setQos(QoS qos); final static int MESSAGE_LENGTH; }### Answer:
@Test(expected = IllegalStateException.class) public void wrongLengthDataThrowsException() throws IOException { byte[] data = new byte[] { 0, 1, 2 }; ByteArrayInputStream bais = new ByteArrayInputStream(data); ConnAckMessage msg = new ConnAckMessage(); msg.readMessage(bais, 3); }