@Test public void testStaleWhenClosed() throws Exception { conn.bind(socket); conn.ensureOpen(); conn.close(); Assert.assertTrue(conn.isStale()); }
@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()); }
@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()); }