Code example for SocketException

0
 
    @Test 
    public void testSetSocketTimeoutException() throws Exception { 
        conn.bind(socket);
 
        Mockito.doThrow(new SocketException()).when(socket).setSoTimeout(Mockito.anyInt());
 
        conn.setSocketTimeout(123);
 
        Mockito.verify(socket, Mockito.times(1)).setSoTimeout(123);
    } 
 
    @Test 
    public void testGetSocketTimeout() throws Exception { 
        Assert.assertEquals(-1, conn.getSocketTimeout());
 
        Mockito.when(socket.getSoTimeout()).thenReturn(345);
        conn.bind(socket);
 
        Assert.assertEquals(345, conn.getSocketTimeout());
    }