@Test public void testRecentFirst() throws Exception { final SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(true)); final Set<FileVisitOption> options = Collections.emptySet(); Files.walkFileTree(base, options, 1, visitor); final List<PathWithAttributes> found = visitor.getSortedPaths(); assertNotNull(found); assertEquals("file count", 3, found.size()); assertEquals("1st: most recent; sorted=" + found, ccc, found.get(0).getPath()); assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); assertEquals("3rd: oldest; sorted=" + found, aaa, found.get(2).getPath()); }
@Test public void testRecentLast() throws Exception { final SortingVisitor visitor = new SortingVisitor(new PathSortByModificationTime(false)); final Set<FileVisitOption> options = Collections.emptySet(); Files.walkFileTree(base, options, 1, visitor); final List<PathWithAttributes> found = visitor.getSortedPaths(); assertNotNull(found); assertEquals("file count", 3, found.size()); assertEquals("1st: oldest first; sorted=" + found, aaa, found.get(0).getPath()); assertEquals("2nd; sorted=" + found, bbb, found.get(1).getPath()); assertEquals("3rd: most recent sorted; list=" + found, ccc, found.get(2).getPath()); } }
/** * Returns a sorted list of all files up to maxDepth under the basePath. * * @return a sorted list of files * @throws IOException */ List<PathWithAttributes> getSortedPaths() throws IOException { final SortingVisitor sort = new SortingVisitor(pathSorter); super.execute(sort); final List<PathWithAttributes> sortedPaths = sort.getSortedPaths(); return sortedPaths; }