### Question:
ConnectMessage extends Message { public void setWill(String willTopic, String will) { setWill(willTopic, will, QoS.AT_MOST_ONCE, false); } ConnectMessage();  ConnectMessage(Header header);  ConnectMessage(String clientId, boolean cleanSession, int keepAlive); void setCredentials(String username); void setCredentials(String username, String password); void setWill(String willTopic, String will); void setWill(String willTopic, String will, QoS willQoS,
			boolean retainWill); @Override void setDup(boolean dup); @Override void setRetained(boolean retain); @Override void setQos(QoS qos); String getProtocolId(); byte getProtocolVersion(); String getClientId(); int getKeepAlive(); String getUsername(); String getPassword(); boolean isCleanSession(); String getWillTopic(); String getWill(); QoS getWillQoS(); boolean isWillRetained(); boolean hasUsername(); boolean hasPassword(); boolean hasWill();  }### Answer:
@Test public void willFlagsAreCorrect() { ConnectMessage msg = new ConnectMessage("Test", false, 20); msg.setWill("WillTopic", "Will text"); byte flags = msg.toBytes()[11]; assertEquals(0, flags & CLEAN_SESSION_MASK); assertEquals(WILL_MASK, flags & WILL_MASK); assertEquals(0, flags & WILL_QoS_MASK); assertEquals(0, flags & WILL_RETAIN_MASK); assertEquals(0, flags & PASSWORD_MASK); assertEquals(0, flags & USERNAME_MASK); msg.setWill("WillTopic", "Will text", QoS.AT_LEAST_ONCE, false); flags = msg.toBytes()[11]; assertEquals(0, flags & CLEAN_SESSION_MASK); assertEquals(WILL_MASK, flags & WILL_MASK); assertEquals(QoS.AT_LEAST_ONCE.val << 3, flags & WILL_QoS_MASK); assertEquals(0, flags & WILL_RETAIN_MASK); assertEquals(0, flags & PASSWORD_MASK); assertEquals(0, flags & USERNAME_MASK); msg.setWill("WillTopic", "Will text", QoS.EXACTLY_ONCE, false); flags = msg.toBytes()[11]; assertEquals(0, flags & CLEAN_SESSION_MASK); assertEquals(WILL_MASK, flags & WILL_MASK); assertEquals(QoS.EXACTLY_ONCE.val << 3, flags & WILL_QoS_MASK); assertEquals(0, flags & WILL_RETAIN_MASK); assertEquals(0, flags & PASSWORD_MASK); assertEquals(0, flags & USERNAME_MASK); msg.setWill("WillTopic", "Will text", QoS.EXACTLY_ONCE, true); flags = msg.toBytes()[11]; assertEquals(0, flags & CLEAN_SESSION_MASK); assertEquals(WILL_MASK, flags & WILL_MASK); assertEquals(QoS.EXACTLY_ONCE.val << 3, flags & WILL_QoS_MASK); assertEquals(WILL_RETAIN_MASK, flags & WILL_RETAIN_MASK); assertEquals(0, flags & PASSWORD_MASK); assertEquals(0, flags & USERNAME_MASK); }
@Test(expected = IllegalArgumentException.class) public void willTopisIsNullButWillNot() { ConnectMessage msg = new ConnectMessage("test", true, 10000); msg.setWill(null, "1111"); }