### Question:
CoAPMessage { public synchronized boolean addOptionHeader(CoAPOptionHeader option) { boolean ok = okToAddHeader(option); if (ok) { get(option).add(option); } return ok; } CoAPMessage(int version, CoAPMessageType messageType,
            CoAPCode methodCode, int messageId, byte[] token);  CoAPMessage(CoAPMessageType messageType, CoAPCode methodCode,
            int messageId, byte[] token); void setVersion(short version); int getVersion(); void setMessageType(CoAPMessageType messageType); CoAPMessageType getMessageType(); int getOptionCount(); void setCode(CoAPCode code); CoAPCode getCode(); void setToken(byte[] token); byte[] getToken(); void setMessageId(int messageId); int getMessageId(); synchronized boolean addOptionHeader(CoAPOptionHeader option); boolean removeOptionHeader(CoAPOptionHeader option); void setPayload(byte[] payload); byte[] getPayload(); List<CoAPOptionHeader> getOptionHeaders(); List<CoAPOptionHeader> getOptionHeaders(CoAPOptionName optionName); void setOptionHeaders(List<CoAPOptionHeader> headers); int getRetransmissions(); int getTimeout(); void messageRetransmitted(); boolean messageCanceled(); void setMessageCanceled(boolean canceled); void setSocketAddress(InetSocketAddress remoteSocketAddress); InetSocketAddress getSocketAddress(); String getIdentifier(); CoAPOptionHeader getUriHostOptionHeader(); byte[] encoded(); boolean isObserveMessage(); long getMaxAge(); String logMessage(); static final String MESSAGE_ID; static final String TOKEN; static final String URI; }### Answer:
@Test public void testAddUriHeaders() { CoAPOptionHeader h = new CoAPOptionHeader(CoAPOptionName.URI_HOST); assertTrue(resp.addOptionHeader(h)); assertFalse(resp.addOptionHeader(h)); h = new CoAPOptionHeader(CoAPOptionName.URI_PORT); assertTrue(resp.addOptionHeader(h)); assertFalse(resp.addOptionHeader(h)); h = new CoAPOptionHeader(CoAPOptionName.URI_PATH); assertTrue(resp.addOptionHeader(h)); assertTrue(resp.addOptionHeader(h)); h = new CoAPOptionHeader(CoAPOptionName.URI_QUERY); assertTrue(resp.addOptionHeader(h)); assertTrue(resp.addOptionHeader(h)); }
@Test public void testAddMaxAgeHeader() { CoAPOptionHeader h = new CoAPOptionHeader(CoAPOptionName.MAX_AGE); assertTrue(resp.addOptionHeader(h)); assertFalse(resp.addOptionHeader(h)); }
@Test public void testAddEtagHeader() { CoAPOptionHeader h = new CoAPOptionHeader(CoAPOptionName.ETAG); assertTrue(resp.addOptionHeader(h)); assertTrue(resp.addOptionHeader(h)); assertTrue(req.addOptionHeader(h)); assertTrue(req.addOptionHeader(h)); }
@Test public void testAddIfNoneMatchHeader() { CoAPOptionHeader h = new CoAPOptionHeader(CoAPOptionName.IF_NONE_MATCH); assertTrue(resp.addOptionHeader(h)); assertFalse(resp.addOptionHeader(h)); assertNull(h.getValue()); assertEquals(0, h.getLength()); }
@Test public void testAddObserveHeader() { int value = 20; byte[] bytes = BitUtil.splitIntToBytes(value); CoAPOptionHeader h = new CoAPOptionHeader(CoAPOptionName.OBSERVE, bytes); assertTrue(req.addOptionHeader(h)); assertTrue(resp.addOptionHeader(h)); }