@Test public void testPollFirstException() throws IOException { InputStreamFileInput subject = new InputStreamFileInput( runtime.getBufferAllocator(), provider(new ByteArrayInputStream("abcdef".getBytes("UTF-8")))); try { subject.poll(); fail(); } catch (IllegalStateException ile) { // OK } subject.close(); }
@Test public void testSingleProvider() throws IOException { InputStreamFileInput subject = new InputStreamFileInput( runtime.getBufferAllocator(), provider(new ByteArrayInputStream("abcdef".getBytes("UTF-8")))); assertEquals(true, subject.nextFile()); assertEquals("abcdef", bufferToString(subject.poll())); assertEquals(null, subject.poll()); subject.close(); }
@Test public void testMultipleProvider() throws IOException { InputStreamFileInput subject = new InputStreamFileInput( runtime.getBufferAllocator(), provider( new ByteArrayInputStream("abcdef".getBytes("UTF-8")), new ByteArrayInputStream("ghijkl".getBytes("UTF-8")), new ByteArrayInputStream("mnopqr".getBytes("UTF-8")))); assertEquals(true, subject.nextFile()); assertEquals("abcdef", bufferToString(subject.poll())); assertEquals(true, subject.nextFile()); assertEquals("ghijkl", bufferToString(subject.poll())); assertEquals(true, subject.nextFile()); assertEquals("mnopqr", bufferToString(subject.poll())); subject.close(); }
@Test public void testEmptyStream() throws IOException { InputStreamFileInput subject = new InputStreamFileInput( runtime.getBufferAllocator(), provider(new ByteArrayInputStream(new byte[0]))); assertEquals(true, subject.nextFile()); assertEquals(null, subject.poll()); subject.close(); }
@Test public void testInputStreamReadException() { InputStreamFileInput subject = new InputStreamFileInput( runtime.getBufferAllocator(), new InputStreamFileInput.Provider() { @Override public InputStream openNext() throws IOException { return new InputStream() { @Override public int read() throws IOException { throw new IOException("emulated exception"); } }; } @Override public void close() throws IOException { } }); assertEquals(true, subject.nextFile()); try { subject.poll(); fail(); } catch (RuntimeException re) { // OK } subject.close(); }