ServerTCPNonBlockingTransportHandler extends TransportHandler { @Override public void closeConnection() throws IOException { if (serverSocket != null) { serverSocket.close(); } if (clientSocket != null) { clientSocket.close(); } } ServerTCPNonBlockingTransportHandler(long timeout, int port); @Override void closeConnection(); @Override void initialize(); void recheck(); void recheck(long timeout); @Override boolean isClosed(); @Override void closeClientConnection(); int getPort();  }
@Test public void testCloseConnection() throws IOException { handler.initialize(); new Socket().connect(new InetSocketAddress("localhost", handler.getPort())); handler.recheck(1000); handler.closeConnection(); Exception ex = null; try { new Socket().connect(new InetSocketAddress("localhost", handler.getPort())); } catch (IOException E) { ex = E; } assertNotNull(ex); }