### Question:
CoapUdpMessaging extends CoapMessaging { @Override public void makeRequest(final CoapPacket packet, final Callback<CoapPacket> callback, final TransportContext transContext) { makeRequestInternal(packet, callback, transContext, defaultPriority); } 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 shouldFail_toMakeSecondRequestFromQueue() throws Exception { initServer(); CompletableFuture<CoapPacket> resp1 = makeRequest(newCoapPacket(LOCAL_5683).mid(100).get().uriPath("/10")); CompletableFuture<CoapPacket> resp2 = makeRequest(newCoapPacket(LOCAL_5683).mid(101).get().uriPath("/11")); given(coapTransport.sendPacket(any(), any(), any())).willReturn(exceptionFuture()); receive(newCoapPacket(LOCAL_5683).mid(100).ack(Code.C205_CONTENT).payload("ABC")); assertEquals("ABC", resp1.get().getPayloadString()); assertThatThrownBy(resp2::get).hasCauseExactlyInstanceOf(IOException.class); }
@Test public void should_receive_onSent_callback_when_message_is_sent() throws Exception { initServer(); RequestCallback callback = mock(RequestCallback.class); CompletableFuture<Boolean> fut = new CompletableFuture<>(); given(coapTransport.sendPacket(any(), any(), any())).willReturn(fut); udpMessaging.makeRequest(newCoapPacket(LOCAL_1_5683).con().get().uriPath("/test").build(), callback, TransportContext.NULL); verify(callback, never()).onSent(); fut.complete(true); verify(callback).onSent(); }
@Test public void should_receive_onSent_callback_when_NON_message_is_sent() throws Exception { initServer(); RequestCallback callback = mock(RequestCallback.class); given(coapTransport.sendPacket(any(), any(), any())).willReturn(CompletableFuture.completedFuture(true)); udpMessaging.makeRequest(newCoapPacket(LOCAL_1_5683).non().get().uriPath("/test").build(), callback, TransportContext.NULL); verify(callback).onSent(); }
@Test public void network_fail_when_sending_NON_request() throws Exception { initServer(); RequestCallback callback = mock(RequestCallback.class); given(coapTransport.sendPacket(any(), any(), any())).willReturn(exceptionFuture()); udpMessaging.makeRequest(newCoapPacket(LOCAL_1_5683).non().token(12).get().uriPath("/test").build(), callback, TransportContext.NULL); verify(callback, never()).onSent(); verify(callback).callException(any()); }
@Test public void shouldSetMessageIdOnMakeRequest() throws IOException, CoapException { initServer(); mid = 1000; udpMessaging.makeRequest(newCoapPacket(LOCAL_5683).mid(0).get().uriPath("/test").build(), Callback.ignore(), TransportContext.NULL); assertSent(newCoapPacket(LOCAL_5683).mid(1000).get().uriPath("/test")); }