test/java/nio/file/Files/StreamTest.java

Print this page
rev 7982 : 8017513: Support for closeable streams
8022237: j.u.s.BaseStream.onClose() has an issue in implementation or requires spec clarification
8022572: Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed
Summary: BaseStream implements AutoCloseable; Remove CloseableStream and DelegatingStream
Reviewed-by: alanb, mduigou, psandoz
Contributed-by: brian.goetz@oracle.com

*** 41,58 **** import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; - import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.function.BiPredicate; ! import java.util.stream.CloseableStream; import java.util.stream.Collectors; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.testng.Assert.*; --- 41,57 ---- import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.function.BiPredicate; ! import java.util.stream.Stream; import java.util.stream.Collectors; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.testng.Assert.*;
*** 136,173 **** void cleanupTestFolder() throws IOException { TestUtil.removeAll(testFolder); } public void testBasic() { ! try (CloseableStream<Path> s = Files.list(testFolder)) { ! Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); assertEquals(actual, level1); } catch (IOException ioe) { fail("Unexpected IOException"); } ! try (CloseableStream<Path> s = Files.list(testFolder.resolve("empty"))) { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); assertEquals(count, 0, "Expect empty stream."); } catch (IOException ioe) { fail("Unexpected IOException"); } } public void testWalk() { ! try (CloseableStream<Path> s = Files.walk(testFolder)) { ! Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); assertEquals(actual, all); } catch (IOException ioe) { fail("Unexpected IOException"); } } public void testWalkOneLevel() { ! try (CloseableStream<Path> s = Files.walk(testFolder, 1)) { Object[] actual = s.filter(path -> ! path.equals(testFolder)) ! .sorted(Comparator.naturalOrder()) .toArray(); assertEquals(actual, level1); } catch (IOException ioe) { fail("Unexpected IOException"); } --- 135,172 ---- void cleanupTestFolder() throws IOException { TestUtil.removeAll(testFolder); } public void testBasic() { ! try (Stream<Path> s = Files.list(testFolder)) { ! Object[] actual = s.sorted().toArray(); assertEquals(actual, level1); } catch (IOException ioe) { fail("Unexpected IOException"); } ! try (Stream<Path> s = Files.list(testFolder.resolve("empty"))) { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); assertEquals(count, 0, "Expect empty stream."); } catch (IOException ioe) { fail("Unexpected IOException"); } } public void testWalk() { ! try (Stream<Path> s = Files.walk(testFolder)) { ! Object[] actual = s.sorted().toArray(); assertEquals(actual, all); } catch (IOException ioe) { fail("Unexpected IOException"); } } public void testWalkOneLevel() { ! try (Stream<Path> s = Files.walk(testFolder, 1)) { Object[] actual = s.filter(path -> ! path.equals(testFolder)) ! .sorted() .toArray(); assertEquals(actual, level1); } catch (IOException ioe) { fail("Unexpected IOException"); }
*** 174,193 **** } public void testWalkFollowLink() { // If link is not supported, the directory structure won't have link. // We still want to test the behavior with FOLLOW_LINKS option. ! try (CloseableStream<Path> s = Files.walk(testFolder, FileVisitOption.FOLLOW_LINKS)) { ! Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); assertEquals(actual, all_folowLinks); } catch (IOException ioe) { fail("Unexpected IOException"); } } private void validateFileSystemLoopException(Path start, Path... causes) { ! try (CloseableStream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { try { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); fail("Should got FileSystemLoopException, but got " + count + "elements."); } catch (UncheckedIOException uioe) { IOException ioe = uioe.getCause(); --- 173,192 ---- } public void testWalkFollowLink() { // If link is not supported, the directory structure won't have link. // We still want to test the behavior with FOLLOW_LINKS option. ! try (Stream<Path> s = Files.walk(testFolder, FileVisitOption.FOLLOW_LINKS)) { ! Object[] actual = s.sorted().toArray(); assertEquals(actual, all_folowLinks); } catch (IOException ioe) { fail("Unexpected IOException"); } } private void validateFileSystemLoopException(Path start, Path... causes) { ! try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { try { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); fail("Should got FileSystemLoopException, but got " + count + "elements."); } catch (UncheckedIOException uioe) { IOException ioe = uioe.getCause();
*** 280,311 **** } public void testFind() throws IOException { PathBiPredicate pred = new PathBiPredicate((path, attrs) -> true); ! try (CloseableStream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { Set<Path> result = s.collect(Collectors.toCollection(TreeSet::new)); assertEquals(pred.visited(), all); assertEquals(result.toArray(new Path[0]), pred.visited()); } pred = new PathBiPredicate((path, attrs) -> attrs.isSymbolicLink()); ! try (CloseableStream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> assertTrue(Files.isSymbolicLink(path))); assertEquals(pred.visited(), all); } pred = new PathBiPredicate((path, attrs) -> path.getFileName().toString().startsWith("e")); ! try (CloseableStream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> assertEquals(path.getFileName().toString(), "empty")); assertEquals(pred.visited(), all); } pred = new PathBiPredicate((path, attrs) -> path.getFileName().toString().startsWith("l") && attrs.isRegularFile()); ! try (CloseableStream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> fail("Expect empty stream")); assertEquals(pred.visited(), all); } } --- 279,310 ---- } public void testFind() throws IOException { PathBiPredicate pred = new PathBiPredicate((path, attrs) -> true); ! try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { Set<Path> result = s.collect(Collectors.toCollection(TreeSet::new)); assertEquals(pred.visited(), all); assertEquals(result.toArray(new Path[0]), pred.visited()); } pred = new PathBiPredicate((path, attrs) -> attrs.isSymbolicLink()); ! try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> assertTrue(Files.isSymbolicLink(path))); assertEquals(pred.visited(), all); } pred = new PathBiPredicate((path, attrs) -> path.getFileName().toString().startsWith("e")); ! try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> assertEquals(path.getFileName().toString(), "empty")); assertEquals(pred.visited(), all); } pred = new PathBiPredicate((path, attrs) -> path.getFileName().toString().startsWith("l") && attrs.isRegularFile()); ! try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) { s.forEach(path -> fail("Expect empty stream")); assertEquals(pred.visited(), all); } }
*** 315,350 **** Path tmpfile = Files.createTempFile("blah", "txt"); try { // zero lines assertTrue(Files.size(tmpfile) == 0, "File should be empty"); ! try (CloseableStream<String> s = Files.lines(tmpfile, US_ASCII)) { assertEquals(s.mapToInt(l -> 1).reduce(0, Integer::sum), 0, "No line expected"); } // one line byte[] hi = { (byte)'h', (byte)'i' }; Files.write(tmpfile, hi); ! try (CloseableStream<String> s = Files.lines(tmpfile, US_ASCII)) { List<String> lines = s.collect(Collectors.toList()); assertTrue(lines.size() == 1, "One line expected"); assertTrue(lines.get(0).equals("hi"), "'Hi' expected"); } // two lines using platform's line separator List<String> expected = Arrays.asList("hi", "there"); Files.write(tmpfile, expected, US_ASCII); assertTrue(Files.size(tmpfile) > 0, "File is empty"); ! try (CloseableStream<String> s = Files.lines(tmpfile, US_ASCII)) { List<String> lines = s.collect(Collectors.toList()); assertTrue(lines.equals(expected), "Unexpected lines"); } // MalformedInputException byte[] bad = { (byte)0xff, (byte)0xff }; Files.write(tmpfile, bad); ! try (CloseableStream<String> s = Files.lines(tmpfile, US_ASCII)) { try { List<String> lines = s.collect(Collectors.toList()); throw new RuntimeException("UncheckedIOException expected"); } catch (UncheckedIOException ex) { assertTrue(ex.getCause() instanceof MalformedInputException, --- 314,349 ---- Path tmpfile = Files.createTempFile("blah", "txt"); try { // zero lines assertTrue(Files.size(tmpfile) == 0, "File should be empty"); ! try (Stream<String> s = Files.lines(tmpfile, US_ASCII)) { assertEquals(s.mapToInt(l -> 1).reduce(0, Integer::sum), 0, "No line expected"); } // one line byte[] hi = { (byte)'h', (byte)'i' }; Files.write(tmpfile, hi); ! try (Stream<String> s = Files.lines(tmpfile, US_ASCII)) { List<String> lines = s.collect(Collectors.toList()); assertTrue(lines.size() == 1, "One line expected"); assertTrue(lines.get(0).equals("hi"), "'Hi' expected"); } // two lines using platform's line separator List<String> expected = Arrays.asList("hi", "there"); Files.write(tmpfile, expected, US_ASCII); assertTrue(Files.size(tmpfile) > 0, "File is empty"); ! try (Stream<String> s = Files.lines(tmpfile, US_ASCII)) { List<String> lines = s.collect(Collectors.toList()); assertTrue(lines.equals(expected), "Unexpected lines"); } // MalformedInputException byte[] bad = { (byte)0xff, (byte)0xff }; Files.write(tmpfile, bad); ! try (Stream<String> s = Files.lines(tmpfile, US_ASCII)) { try { List<String> lines = s.collect(Collectors.toList()); throw new RuntimeException("UncheckedIOException expected"); } catch (UncheckedIOException ex) { assertTrue(ex.getCause() instanceof MalformedInputException,
*** 376,386 **** try { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); try { ! try (CloseableStream<Path> s = Files.list(fakeRoot)) { s.forEach(path -> assertEquals(path.getFileName().toString(), "DirectoryIteratorException")); } } catch (UncheckedIOException uioe) { fail("Unexpected exception."); } --- 375,385 ---- try { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); try { ! try (Stream<Path> s = Files.list(fakeRoot)) { s.forEach(path -> assertEquals(path.getFileName().toString(), "DirectoryIteratorException")); } } catch (UncheckedIOException uioe) { fail("Unexpected exception."); }
*** 396,406 **** fail("Shoule throw DirectoryIteratorException"); } catch (DirectoryIteratorException die) { } try { ! try (CloseableStream<Path> s = Files.list(fakeRoot)) { s.forEach(path -> fail("should not get here")); } } catch (UncheckedIOException uioe) { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } catch (DirectoryIteratorException die) { --- 395,405 ---- fail("Shoule throw DirectoryIteratorException"); } catch (DirectoryIteratorException die) { } try { ! try (Stream<Path> s = Files.list(fakeRoot)) { s.forEach(path -> fail("should not get here")); } } catch (UncheckedIOException uioe) { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } catch (DirectoryIteratorException die) {
*** 425,462 **** FaultyFileSystem fs = (FaultyFileSystem) fsp.newFileSystem(testFolder, null); try { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); ! try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir2"))) { // only one file s.forEach(path -> assertEquals(path.getFileName().toString(), "IOException")); } ! try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); // ordered as depth-first assertEquals(result, new String[] { "empty", "IOException", "file"}); } fsp.setFaultyMode(true); ! try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir2"))) { s.forEach(path -> fail("should have caused exception")); } catch (UncheckedIOException uioe) { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } ! try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to IOException"); } catch (UncheckedIOException uioe) { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } ! try (CloseableStream<Path> s = Files.walk( fakeRoot.resolve("empty").resolve("IOException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to IOException"); --- 424,461 ---- FaultyFileSystem fs = (FaultyFileSystem) fsp.newFileSystem(testFolder, null); try { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); ! try (Stream<Path> s = Files.list(fakeRoot.resolve("dir2"))) { // only one file s.forEach(path -> assertEquals(path.getFileName().toString(), "IOException")); } ! try (Stream<Path> s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); // ordered as depth-first assertEquals(result, new String[] { "empty", "IOException", "file"}); } fsp.setFaultyMode(true); ! try (Stream<Path> s = Files.list(fakeRoot.resolve("dir2"))) { s.forEach(path -> fail("should have caused exception")); } catch (UncheckedIOException uioe) { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } ! try (Stream<Path> s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to IOException"); } catch (UncheckedIOException uioe) { assertTrue(uioe.getCause() instanceof FaultyFileSystem.FaultyException); } ! try (Stream<Path> s = Files.walk( fakeRoot.resolve("empty").resolve("IOException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to IOException");
*** 500,576 **** try { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); // validate setting ! try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "SecurityException", "sample" }); } ! try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir2", "SecurityException", "fileInSE", "file" }); } if (supportsLinks) { ! try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "d1", "f1", "lnDir2", "SecurityException", "lnDirSE", "lnFileSE" }); } } // execute test fsp.setFaultyMode(true); // ignore file cause SecurityException ! try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "empty", "sample" }); } // skip folder cause SecurityException ! try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir2", "file" }); } if (supportsLinks) { // not following links ! try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir", "d1", "f1", "lnDir2", "lnDirSE", "lnFileSE" }); } // following links ! try (CloseableStream<Path> s = Files.walk(fakeRoot.resolve("dir"), FileVisitOption.FOLLOW_LINKS)) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); // ?? Should fileInSE show up? // With FaultyFS, it does as no exception thrown for link to "SecurityException" with read on "lnXxxSE" assertEqualsNoOrder(result, new String[] { "dir", "d1", "f1", "lnDir2", "file", "lnDirSE", "lnFileSE", "fileInSE" }); } } // list instead of walk ! try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "sample" }); } ! try (CloseableStream<Path> s = Files.list(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "file" }); } // root cause SecurityException should be reported ! try (CloseableStream<Path> s = Files.walk( fakeRoot.resolve("dir2").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException"); --- 499,575 ---- try { fsp.setFaultyMode(false); Path fakeRoot = fs.getRoot(); // validate setting ! try (Stream<Path> s = Files.list(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "SecurityException", "sample" }); } ! try (Stream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir2", "SecurityException", "fileInSE", "file" }); } if (supportsLinks) { ! try (Stream<Path> s = Files.list(fakeRoot.resolve("dir"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "d1", "f1", "lnDir2", "SecurityException", "lnDirSE", "lnFileSE" }); } } // execute test fsp.setFaultyMode(true); // ignore file cause SecurityException ! try (Stream<Path> s = Files.walk(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "empty", "sample" }); } // skip folder cause SecurityException ! try (Stream<Path> s = Files.walk(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir2", "file" }); } if (supportsLinks) { // not following links ! try (Stream<Path> s = Files.walk(fakeRoot.resolve("dir"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "dir", "d1", "f1", "lnDir2", "lnDirSE", "lnFileSE" }); } // following links ! try (Stream<Path> s = Files.walk(fakeRoot.resolve("dir"), FileVisitOption.FOLLOW_LINKS)) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); // ?? Should fileInSE show up? // With FaultyFS, it does as no exception thrown for link to "SecurityException" with read on "lnXxxSE" assertEqualsNoOrder(result, new String[] { "dir", "d1", "f1", "lnDir2", "file", "lnDirSE", "lnFileSE", "fileInSE" }); } } // list instead of walk ! try (Stream<Path> s = Files.list(fakeRoot.resolve("empty"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "sample" }); } ! try (Stream<Path> s = Files.list(fakeRoot.resolve("dir2"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); assertEqualsNoOrder(result, new String[] { "file" }); } // root cause SecurityException should be reported ! try (Stream<Path> s = Files.walk( fakeRoot.resolve("dir2").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException");
*** 577,587 **** } catch (SecurityException se) { assertTrue(se.getCause() instanceof FaultyFileSystem.FaultyException); } // Walk a file cause SecurityException, we should get SE ! try (CloseableStream<Path> s = Files.walk( fakeRoot.resolve("dir").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException"); --- 576,586 ---- } catch (SecurityException se) { assertTrue(se.getCause() instanceof FaultyFileSystem.FaultyException); } // Walk a file cause SecurityException, we should get SE ! try (Stream<Path> s = Files.walk( fakeRoot.resolve("dir").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException");
*** 588,608 **** } catch (SecurityException se) { assertTrue(se.getCause() instanceof FaultyFileSystem.FaultyException); } // List a file cause SecurityException, we should get SE as cannot read attribute ! try (CloseableStream<Path> s = Files.list( fakeRoot.resolve("dir2").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException"); } catch (SecurityException se) { assertTrue(se.getCause() instanceof FaultyFileSystem.FaultyException); } ! try (CloseableStream<Path> s = Files.list( fakeRoot.resolve("dir").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException"); --- 587,607 ---- } catch (SecurityException se) { assertTrue(se.getCause() instanceof FaultyFileSystem.FaultyException); } // List a file cause SecurityException, we should get SE as cannot read attribute ! try (Stream<Path> s = Files.list( fakeRoot.resolve("dir2").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException"); } catch (SecurityException se) { assertTrue(se.getCause() instanceof FaultyFileSystem.FaultyException); } ! try (Stream<Path> s = Files.list( fakeRoot.resolve("dir").resolve("SecurityException"))) { String[] result = s.map(path -> path.getFileName().toString()) .toArray(String[]::new); fail("should not reach here due to SecurityException");
*** 625,660 **** TestUtil.removeAll(triggerDir); } } public void testConstructException() { ! try (CloseableStream<String> s = Files.lines(testFolder.resolve("notExist"), Charset.forName("UTF-8"))) { s.forEach(l -> fail("File is not even exist!")); } catch (IOException ioe) { assertTrue(ioe instanceof NoSuchFileException); } } public void testClosedStream() throws IOException { ! try (CloseableStream<Path> s = Files.list(testFolder)) { s.close(); ! Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); ! assertTrue(actual.length <= level1.length); } ! try (CloseableStream<Path> s = Files.walk(testFolder)) { s.close(); ! Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); fail("Operate on closed stream should throw IllegalStateException"); } catch (IllegalStateException ex) { // expected } ! try (CloseableStream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, (p, attr) -> true)) { s.close(); ! Object[] actual = s.sorted(Comparator.naturalOrder()).toArray(); fail("Operate on closed stream should throw IllegalStateException"); } catch (IllegalStateException ex) { // expected } } --- 624,661 ---- TestUtil.removeAll(triggerDir); } } public void testConstructException() { ! try (Stream<String> s = Files.lines(testFolder.resolve("notExist"), Charset.forName("UTF-8"))) { s.forEach(l -> fail("File is not even exist!")); } catch (IOException ioe) { assertTrue(ioe instanceof NoSuchFileException); } } public void testClosedStream() throws IOException { ! try (Stream<Path> s = Files.list(testFolder)) { s.close(); ! Object[] actual = s.sorted().toArray(); ! fail("Operate on closed stream should throw IllegalStateException"); ! } catch (IllegalStateException ex) { ! // expected } ! try (Stream<Path> s = Files.walk(testFolder)) { s.close(); ! Object[] actual = s.sorted().toArray(); fail("Operate on closed stream should throw IllegalStateException"); } catch (IllegalStateException ex) { // expected } ! try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, (p, attr) -> true)) { s.close(); ! Object[] actual = s.sorted().toArray(); fail("Operate on closed stream should throw IllegalStateException"); } catch (IllegalStateException ex) { // expected } }