Ejemplo n.º 1
0
 @Test
 public void testStaleWhenClosed() throws Exception {
   conn.bind(socket);
   conn.ensureOpen();
   conn.close();
   Assert.assertTrue(conn.isStale());
 }
Ejemplo n.º 2
0
  @Test
  public void testNotStaleWhenHasData() throws Exception {
    final ByteArrayInputStream instream =
        Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}));
    Mockito.when(socket.getInputStream()).thenReturn(instream);

    conn.bind(socket);
    conn.ensureOpen();

    Assert.assertFalse(conn.isStale());
  }
Ejemplo n.º 3
0
  @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);
    conn.ensureOpen();

    Assert.assertTrue(conn.isStale());
  }