/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadNonPartialContentByteForByteOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringByteForByte(is), content); // try several additional reads, which should all return -1 (= EOF)... int tries = 5; while (--tries > 0) { assertEquals(is.read(), -1); } }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadNonPartialEmptyContentOk() throws Exception { String content = ""; ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadNonPartialWithoutContentLengthOk() throws Exception { String content = ""; ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(content, false)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test public void testReadNonPartialContentOk() throws Exception { String content = m_content; ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); assertEquals(slurpAsStringWithBuffer(is), content); }
/** * Tests that we can read non-partial content and return the expected contents. */ @Test(expectedExceptions = IOException.class) public void testReadClosedStreamFail() throws Exception { ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(m_content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); is.close(); // simulate an early close... is.read(); // should fail! }
/** * Tests that we call {@link InputStream#close()} multiple times. */ @Test public void testDoubleClosedStreamOk() throws Exception { ConnectionHandler handler = new TestConnectionHandler(new CompleteContentConnection(m_content, true)); ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL); is.close(); // simulate an early close... is.close(); // not a problem... }