### Question:
CoapTcpMessaging extends CoapMessaging { @Override public void onConnected(InetSocketAddress remoteAddress) { CoapPacket packet = new CoapPacket(remoteAddress); packet.setCode(Code.C701_CSM); packet.headers().putSignallingOptions( SignalingOptions.capabilities(ownCapability.getMaxMessageSizeInt(), ownCapability.isBlockTransferEnabled()) ); LOGGER.info("[" + remoteAddress + "] CoAP sent [" + packet.toString(false, false, false, true) + "]"); coapTransporter.sendPacket(packet, remoteAddress, TransportContext.NULL); super.onConnected(remoteAddress); } CoapTcpMessaging(CoapTransport coapTransport, CoapTcpCSMStorage csmStorage, boolean useBlockWiseTransfer, int maxMessageSize); @Override void ping(InetSocketAddress destination, Callback<CoapPacket> callback); @Override void makeRequest(CoapPacket packet, Callback<CoapPacket> callback, TransportContext transContext); @Override void sendResponse(CoapPacket request, CoapPacket response, TransportContext transContext); @Override void onConnected(InetSocketAddress remoteAddress); @Override void onDisconnected(InetSocketAddress remoteAddress); @Override void makePrioritisedRequest(CoapPacket packet, Callback<CoapPacket> callback, TransportContext transContext);  }### Answer:
@Test public void shouldSendCapabilities_whenConnected_noBlocking() throws CoapException, IOException { SignalingOptions signOpt = new SignalingOptions(); signOpt.setMaxMessageSize(501); signOpt.setBlockWiseTransfer(false); tcpMessaging.onConnected(LOCAL_5683); assertSent(newCoapPacket(LOCAL_5683).code(Code.C701_CSM).signalling(signOpt)); }
@Test public void shouldSendCapabilities_whenConnected_withBlocking() throws CoapException, IOException { tcpMessaging = new CoapTcpMessaging(coapTransport, csmStorage, true, 10501); tcpMessaging.start(coapRequestHandler); SignalingOptions signOpt = new SignalingOptions(); signOpt.setMaxMessageSize(10501); signOpt.setBlockWiseTransfer(true); tcpMessaging.onConnected(LOCAL_5683); assertSent(newCoapPacket(LOCAL_5683).code(Code.C701_CSM).signalling(signOpt)); }
@Test public void should_call_handler_when_connected() { Consumer<InetSocketAddress> handler = mock(Consumer.class); tcpMessaging.setConnectHandler(handler); tcpMessaging.onConnected(LOCAL_1_5683); verify(handler).accept(eq(LOCAL_1_5683)); tcpMessaging.onConnected(LOCAL_5683); verify(handler).accept(eq(LOCAL_5683)); }