### Question:
FileSystemUtil { public static List<FileStatus> listDirectories(final FileSystem fs, Path path, boolean recursive, PathFilter... filters) throws IOException { List<FileStatus> statuses = new ArrayList<>(); listDirectories(fs, path, recursive, statuses, mergeFilters(filters)); return statuses; }  static List<FileStatus> listDirectories(final FileSystem fs, Path path, boolean recursive, PathFilter... filters); static List<FileStatus> listFiles(FileSystem fs, Path path, boolean recursive, PathFilter... filters); static List<FileStatus> listAll(FileSystem fs, Path path, boolean recursive, PathFilter... filters); static PathFilter mergeFilters(PathFilter filter, PathFilter[] filters); static PathFilter mergeFilters(final PathFilter... filters); static final PathFilter DUMMY_FILTER; }### Answer:
@Test public void testListDirectoriesWithoutFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listDirectories(fs, base, false); assertEquals("Directory count should match", 4, statuses.size()); }
@Test public void testListDirectoriesWithFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listDirectories(fs, base, false, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith("a"); } }); assertEquals("Directory count should match", 3, statuses.size()); Collections.sort(statuses); assertEquals("Directory name should match", ".a", statuses.get(0).getPath().getName()); assertEquals("Directory name should match", "_a", statuses.get(1).getPath().getName()); assertEquals("Directory name should match", "a", statuses.get(2).getPath().getName()); }
@Test public void testListDirectoriesRecursiveWithoutFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listDirectories(fs, base, true); assertEquals("Directory count should match", 5, statuses.size()); }
@Test public void testListDirectoriesRecursiveWithFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listDirectories(fs, base, true, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith("a"); } }); assertEquals("Directory count should match", 4, statuses.size()); Collections.sort(statuses); assertEquals("Directory name should match", ".a", statuses.get(0).getPath().getName()); assertEquals("Directory name should match", "_a", statuses.get(1).getPath().getName()); assertEquals("Directory name should match", "a", statuses.get(2).getPath().getName()); assertEquals("Directory name should match", "aa", statuses.get(3).getPath().getName()); }
@Test public void testListDirectoriesEmptyResult() throws IOException { List<FileStatus> statuses = FileSystemUtil.listDirectories(fs, base, false, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().startsWith("abc"); } }); assertEquals("Directory count should match", 0, statuses.size()); }