diff --git a/core/java/test/junit/net/i2p/socks/SOCKS4ClientTest.java b/core/java/test/junit/net/i2p/socks/SOCKS4ClientTest.java index f2211ac674..a7daa52f8c 100644 --- a/core/java/test/junit/net/i2p/socks/SOCKS4ClientTest.java +++ b/core/java/test/junit/net/i2p/socks/SOCKS4ClientTest.java @@ -109,6 +109,28 @@ public class SOCKS4ClientTest { 80); }); } + + /** + * Run into IOException while trying to connect due to closed input stream + */ + @Test + public void connect__ioExceptionWithSocket() { + assertThrows(IOException.class, () -> { + // Create an IOException by closing input stream before it can used + ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[]{}); + inputStream.close(); + + Socket socket = Mockito.mock(Socket.class); + Mockito.when(socket.getInputStream()).thenReturn(inputStream); + Mockito.when(socket.getOutputStream()).thenReturn(new ByteArrayOutputStream()); + + SOCKS4Client.connect( + socket, + "127.0.0.1", + 80 + ); + }); + } /** * Check that CONNECTION_REFUSED throws exception */