SocketInternetObservingStrategy extends EndpointInternetObservingStrategy { Socket connectSocketTo(SocketAddress socketAddress, int timeout) throws IOException { final Socket socket = new Socket(); socket.connect(socketAddress, timeout); return socket; } @VisibleForTesting  SocketInternetObservingStrategy(@NonNull Builder builder); @NonNull static SocketInternetObservingStrategy create(); @NonNull static Builder builder();  }
@Test public void shouldLogError_whenProblemClosingSocket() throws IOException { SocketInternetObservingStrategy sut = spy(detailedStrategyBuilder().build()); Socket socket = mock(Socket.class); doThrow(IOException.class).when(socket).close(); doReturn(socket).when(sut).connectSocketTo(any(SocketAddress.class), anyInt()); sut.observe().blockingFirst(); verify(sut).onError(anyString(), any(Exception.class)); }