Test SOCKS4 client: connect with faulty Socket

This commit is contained in:
2021-01-22 22:23:02 +01:00
parent cce39bb35c
commit 8b38d4481b

View File

@@ -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
*/