### Question:
FileSystemUtil { public static List<FileStatus> listAll(FileSystem fs, Path path, boolean recursive, PathFilter... filters) throws IOException { List<FileStatus> statuses = new ArrayList<>(); listAll(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 testListAllWithoutFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listAll(fs, new Path(base, "a"), false); assertEquals("Directory and file count should match", 4, statuses.size()); }
@Test public void testListAllWithFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listAll(fs, new Path(base, "a"), false, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith("a") || path.getName().endsWith(".txt"); } }); assertEquals("Directory and file count should match", 4, statuses.size()); }
@Test public void testListAllRecursiveWithoutFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listAll(fs, new Path(base, "a"), true); assertEquals("Directory and file count should match", 7, statuses.size()); }
@Test public void testListAllRecursiveWithFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listAll(fs, new Path(base, "a"), true, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith("a") || path.getName().endsWith(".txt"); } }); assertEquals("Directory and file count should match", 7, statuses.size()); }
@Test public void testListAllEmptyResult() throws IOException { List<FileStatus> statuses = FileSystemUtil.listAll(fs, base, false, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().startsWith("xyz"); } }); assertEquals("Directory and file count should match", 0, statuses.size()); }