ListFilesFileVisitor extends SimpleFileVisitor<Path> { public List<Path> getPaths() { return paths; }  List<Path> getPaths(); List<File> getFiles(); @Override FileVisitResult visitFile(Path file, BasicFileAttributes attrs); @Override FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs); @Override FileVisitResult postVisitDirectory(Path dir, IOException exc);  }
@Test public void testWalkOnExistingFile() throws IOException { final File file = new File(baseLocation, "file.txt"); Files.walkFileTree(file.toPath(), visitor); assertFalse(visitor.getPaths().isEmpty()); assertEquals(file.toPath(), visitor.getPaths().get(0)); }
@Test public void testOnEmptyDir() throws IOException { final File emptyDir = new File(baseLocation, "emptyDir"); Files.walkFileTree(emptyDir.toPath(), visitor); assertFalse(visitor.getPaths().isEmpty()); assertEquals(emptyDir.toPath(), visitor.getPaths().get(0)); }
@Test public void testOnFileTree() throws IOException { final File emptyDir = baseLocation; Files.walkFileTree(emptyDir.toPath(), visitor); assertEquals(5, visitor.getPaths().size(), visitor.getPaths().stream().map(Path::toString).collect(Collectors.joining(System.lineSeparator()))); assertTrue(visitor.getPaths().contains(new File(baseLocation, "dir/dir2").toPath())); assertTrue(visitor.getPaths().contains(new File(baseLocation, "dir/dir3/file2.txt").toPath())); assertTrue(visitor.getPaths().contains(new File(baseLocation, "dir/file1.txt").toPath())); assertTrue(visitor.getPaths().contains(new File(baseLocation, "emptyDir").toPath())); assertTrue(visitor.getPaths().contains(new File(baseLocation, "file.txt").toPath())); }