Message { public void addMessageObserver(final MessageObserver observer) { if (observer == null) { throw new NullPointerException(); } ensureMessageObserverList().add(observer); } protected  Message();  Message(Type type); Type getType(); Message setType(CoAP.Type type); boolean isConfirmable(); Message setConfirmable(boolean con); abstract int getRawCode(); boolean isIntendedPayload(); void setUnintendedPayload(); boolean isUnintendedPayload(); void setReliabilityLayerParameters(ReliabilityLayerParameters parameter); ReliabilityLayerParameters getReliabilityLayerParameters(); int getMID(); boolean hasMID(); Message setMID(int mid); void removeMID(); boolean hasEmptyToken(); Token getToken(); byte[] getTokenBytes(); String getTokenString(); Message setToken(byte[] tokenBytes); Message setToken(Token token); OptionSet getOptions(); Message setOptions(OptionSet options); int getMaxResourceBodySize(); void setMaxResourceBodySize(int maxResourceBodySize); int getPayloadSize(); byte[] getPayload(); String getPayloadString(); Message setPayload(String payload); Message setPayload(byte[] payload); InetAddress getDestination(); int getDestinationPort(); InetAddress getSource(); int getSourcePort(); EndpointContext getDestinationContext(); EndpointContext getEffectiveDestinationContext(); EndpointContext getSourceContext(); Message setDestinationContext(EndpointContext peerContext); void setEffectiveDestinationContext(EndpointContext peerContext); Message setSourceContext(EndpointContext peerContext); boolean isAcknowledged(); void setAcknowledged(boolean acknowledged); boolean acknowledge(); boolean isRejected(); void setRejected(boolean rejected); boolean isTimedOut(); void setTimedOut(final boolean timedOut); boolean isCanceled(); void setCanceled(boolean canceled); void setReadyToSend(); void onConnecting(); void onDtlsRetransmission(int flight); boolean isSent(); void setSent(boolean sent); Throwable getSendError(); void setSendError(Throwable sendError); void onContextEstablished(EndpointContext endpointContext); void onComplete(); boolean waitForSent(long timeout); boolean isDuplicate(); void setDuplicate(boolean duplicate); byte[] getBytes(); void setBytes(byte[] bytes); boolean hasBlock(final BlockOption block2); long getNanoTimestamp(); void setNanoTimestamp(long timestamp); void cancel(); void retransmitting(); void offload(OffloadMode mode); OffloadMode getOffloadMode(); void setProtectFromOffload(); List<MessageObserver> getMessageObservers(); void addMessageObserver(final MessageObserver observer); void addMessageObserver(int index, final MessageObserver observer); void addMessageObservers(final List<MessageObserver> observers); void removeMessageObserver(final MessageObserver observer); static final int NONE; static final int MAX_MID; }
@Test public void testAddMessageObserver() { Request ping = new Request(null, Type.CON); ping.addMessageObserver(new MessageObserverAdapter() {}); assertThat(ping.getMessageObservers().size(), is(1)); }