Code example for SocketTimeoutException

0
    @Test 
    public void testNotStaleWhenTimeout() throws Exception { 
        final InputStream instream = Mockito.mock(InputStream.class);
        Mockito.when(socket.getInputStream()).thenReturn(instream);
        Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
            .thenThrow(new SocketTimeoutException());
 
        conn.bind(socket);
        conn.ensureOpen();
 
        Assert.assertFalse(conn.isStale());
    } 
 
    @Test 
    public void testStaleWhenIOError() throws Exception { 
        final InputStream instream = Mockito.mock(InputStream.class);
        Mockito.when(socket.getInputStream()).thenReturn(instream);
        Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
            .thenThrow(new SocketException());
 
        conn.bind(socket);