@Test public void testCloseUnderlyingFile() throws IOException { final boolean[] closed = new boolean[1]; File file = createFileWithContent(new ByteArrayInputStream(makeRandomArray(256))); RandomAccessFile raf = new RandomAccessFile(file, "r") { @Override public void close() throws IOException { closed[0] = true; super.close(); } }; FileSeekableStream stream = new FileSeekableStream(raf); try { FileUtil.read(stream); // Read until EOF assertEquals("EOF not reached (test case broken)", -1, stream.read()); assertFalse("Underlying stream closed before close", closed[0]); } finally { stream.close(); } assertTrue("Underlying stream not closed", closed[0]); } }
public void testCloseUnderlyingFile() throws IOException { final boolean[] closed = new boolean[1]; File file = createFileWithContent(new ByteArrayInputStream(makeRandomArray(256))); RandomAccessFile raf = new RandomAccessFile(file, "r") { @Override public void close() throws IOException { closed[0] = true; super.close(); } }; FileSeekableStream stream = new FileSeekableStream(raf); try { FileUtil.read(stream); // Read until EOF assertEquals("EOF not reached (test case broken)", -1, stream.read()); assertFalse("Underlying stream closed before close", closed[0]); } finally { stream.close(); } assertTrue("Underlying stream not closed", closed[0]); } }
@Test public void testCloseUnderlyingFile() throws IOException { final boolean[] closed = new boolean[1]; File file = createFileWithContent(new ByteArrayInputStream(makeRandomArray(256))); RandomAccessFile raf = new RandomAccessFile(file, "r") { @Override public void close() throws IOException { closed[0] = true; super.close(); } }; FileSeekableStream stream = new FileSeekableStream(raf); try { FileUtil.read(stream); // Read until EOF assertEquals("EOF not reached (test case broken)", -1, stream.read()); assertFalse("Underlying stream closed before close", closed[0]); } finally { stream.close(); } assertTrue("Underlying stream not closed", closed[0]); } }