ServerTCPNonBlockingTransportHandler extends TransportHandler { @Override public void initialize() throws IOException { serverSocket = new ServerSocket(port); callable = new AcceptorCallable(serverSocket); task = new FutureTask(callable); thread = new Thread(task); thread.start(); recheck(); } 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 testInitialize() throws InterruptedException { try { handler.initialize(); assertFalse(handler.isInitialized()); handler.recheck(); assertFalse(handler.isInitialized()); new Socket().connect(new InetSocketAddress("localhost", handler.getPort())); handler.recheck(1000); assertTrue(handler.isInitialized()); } catch (IOException ex) { fail("Encountered Exception"); } finally { try { handler.closeConnection(); } catch (IOException ex) { } } }