NPipeSocket extends Socket { @Override public void connect(SocketAddress endpoint, int timeout) throws IOException { DockerCloudUtils.requireNonNull(endpoint, "Address cannot be null."); if (!(endpoint instanceof NPipeSocketAddress)) { throw new IOException("Can only connect to endpoints of type " + NPipeSocketAddress.class.getName()); } impl.connect(endpoint, timeout); connected = true; } NPipeSocket(); private  NPipeSocket(NPipeSocketImpl impl); @Override void bind(SocketAddress bindpoint); @Override boolean isConnected(); @Override boolean isBound(); @Override SocketAddress getLocalSocketAddress(); @Override void connect(SocketAddress endpoint, int timeout); @Override synchronized void close(); @Override boolean isClosed();  }
@Test public void connect() throws IOException { NPipeSocket socket = new NPipeSocket(); NPipeSocketImpl impl = socket.getImpl(); assertThat(socket.isConnected()).isFalse(); assertThat(impl.isConnected()).isFalse(); socket.connect(createTestSocket()); assertThat(socket.isConnected()).isTrue(); assertThat(impl.isConnected()).isTrue(); assertThatExceptionOfType(IOException.class) .isThrownBy(() -> socket.connect(new InetSocketAddress(InetAddress.getLocalHost(), 80))); assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> socket.connect(null)); }