### Question:
FileSystemUtil { public static List<FileStatus> listFiles(FileSystem fs, Path path, boolean recursive, PathFilter... filters) throws IOException { List<FileStatus> statuses = new ArrayList<>(); listFiles(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 testListFilesWithoutFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listFiles(fs, new Path(base, "a"), false); assertEquals("File count should match", 3, statuses.size()); }
@Test public void testListFilesWithFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listFiles(fs, new Path(base, "a"), false, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith(".txt"); } }); assertEquals("File count should match", 3, statuses.size()); Collections.sort(statuses); assertEquals("File name should match", ".f.txt", statuses.get(0).getPath().getName()); assertEquals("File name should match", "_f.txt", statuses.get(1).getPath().getName()); assertEquals("File name should match", "f.txt", statuses.get(2).getPath().getName()); }
@Test public void testListFilesRecursiveWithoutFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listFiles(fs, base, true); assertEquals("File count should match", 11, statuses.size()); }
@Test public void testListFilesRecursiveWithFilter() throws IOException { List<FileStatus> statuses = FileSystemUtil.listFiles(fs, base, true, new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith("a") || path.getName().endsWith(".txt"); } }); assertEquals("File count should match", 8, statuses.size()); }
@Test public void testListFilesEmptyResult() throws IOException { List<FileStatus> statuses = FileSystemUtil.listFiles(fs, base, false); assertEquals("File count should match", 0, statuses.size()); }