forked from I2P_Developers/i2p.i2p
Test SOCKS4 client: connect with faulty Socket
This commit is contained in:
@@ -109,6 +109,28 @@ public class SOCKS4ClientTest {
|
|||||||
80);
|
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
|
* Check that CONNECTION_REFUSED throws exception
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user