### Question:
SocketConnectorBase implements SocketConnector { public Socket awaitConnection() throws InterruptedException { return awaitConnection(Long.MAX_VALUE); } SocketConnectorBase(InetAddress address, int port,
      int initialDelay, int retryDelay);  SocketConnectorBase(InetAddress address, int port,
      DelayStrategy delayStrategy); void run(); Socket awaitConnection(); Socket awaitConnection(long delay); void setExceptionHandler(ExceptionHandler exceptionHandler); void setSocketFactory(SocketFactory socketFactory); Socket call();  }### Answer:
@Test public void testConnect() throws Exception { Thread thread = new Thread(); thread.start(); Socket socket = connector.awaitConnection(2 * DELAY); assertNotNull(socket); thread.join(DELAY); assertFalse(thread.isAlive()); socket.close(); }
@Test public void testConnectionFails() throws Exception { serverSocket.close(); Thread thread = new Thread(); thread.start(); Socket socket = connector.awaitConnection(2 * DELAY); assertNull(socket); Exception lastException = exceptionHandler.awaitConnectionFailed(DELAY); assertTrue(lastException instanceof ConnectException); assertTrue(thread.isAlive()); thread.interrupt(); thread.join(4 * DELAY); assertFalse(thread.isAlive()); }
@Test public void testConnectEventually() throws Exception { serverSocket.close(); Thread thread = new Thread(); thread.start(); Socket socket = connector.awaitConnection(2 * DELAY); assertNull(socket); Exception lastException = exceptionHandler.awaitConnectionFailed(DELAY); assertTrue(lastException instanceof ConnectException); assertTrue(thread.isAlive()); SocketAddress address = serverSocket.getLocalSocketAddress(); serverSocket = new ServerSocket(); serverSocket.setReuseAddress(true); serverSocket.bind(address); socket = connector.awaitConnection(2 * DELAY); assertNotNull(socket); thread.join(DELAY); assertFalse(thread.isAlive()); socket.close(); }