### Question:
CoapUdpMessaging extends CoapMessaging { @Override public void sendResponse(CoapPacket request, CoapPacket resp, TransportContext ctx) { putToDuplicationDetector(request, resp); if (resp.getMessageType() == MessageType.NonConfirmable || request.getMessageType() == MessageType.NonConfirmable) { resp.setMessageId(getNextMID()); } send(resp, request.getRemoteAddress(), ctx); } CoapUdpMessaging(CoapTransport coapTransport); final void init(int duplicationListSize,
            ScheduledExecutorService scheduledExecutor, boolean isSelfCreatedExecutor,
            MessageIdSupplier idContext,
            int maxQueueSize, CoapTransaction.Priority defaultPriority,
            long delayedTransactionTimeout, DuplicatedCoapMessageCallback duplicatedCoapMessageCallback); ScheduledExecutorService getScheduledExecutor(); @Override synchronized void start(CoapRequestHandler coapRequestHandler); void setSpecialCoapTransactionPriority(CoapTransaction.Priority specialCoapTransactionPriority); @Override void stop0(); void setTransmissionTimeout(TransmissionTimeout transmissionTimeout); @Override void sendResponse(CoapPacket request, CoapPacket resp, TransportContext ctx); @Override void ping(InetSocketAddress destination, Callback<CoapPacket> callback); @Override void makeRequest(final CoapPacket packet, final Callback<CoapPacket> callback, final TransportContext transContext); @Override void makePrioritisedRequest(CoapPacket packet, Callback<CoapPacket> callback, TransportContext transContext); int getNumberOfTransactions();  }### Answer:
@Test public void shouldSetMessageIdOnSendNonResponse() throws IOException, CoapException { initServer(); mid = 1000; udpMessaging.sendResponse(newCoapPacket(LOCAL_5683).mid(0).build(), newCoapPacket(LOCAL_5683).mid(0).non(Code.C205_CONTENT).build(), TransportContext.NULL); assertSent(newCoapPacket(LOCAL_5683).mid(1000).non(Code.C205_CONTENT)); }
@Test public void shouldSetMessageIdOnSend_resetResponse_toNonRequest() throws IOException, CoapException { initServer(); mid = 1000; udpMessaging.sendResponse(newCoapPacket(LOCAL_5683).mid(0).non().get().build(), newCoapPacket(LOCAL_5683).mid(0).reset().build(), TransportContext.NULL); assertSent(newCoapPacket(LOCAL_5683).mid(1000).reset()); }
@Test public void shouldNotSetMessageId_onSendAckResponse() throws IOException, CoapException { initServer(); udpMessaging.sendResponse(newCoapPacket(LOCAL_5683).mid(2).build(), newCoapPacket(LOCAL_5683).mid(2).ack(Code.C205_CONTENT).build(), TransportContext.NULL); assertSent(newCoapPacket(LOCAL_5683).mid(2).ack(Code.C205_CONTENT)); }