### Question:
FileSystemUtil { public static PathFilter mergeFilters(PathFilter filter, PathFilter[] filters) { if (filters == null || filters.length == 0) { return filter; } int length = filters.length; PathFilter[] newFilters = Arrays.copyOf(filters, length + 1); newFilters[length] = filter; return mergeFilters(newFilters); }  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 testMergeFiltersWithMissingParameters() { PathFilter filter = new PathFilter() { @Override public boolean accept(Path path) { return path.getName().startsWith("a"); } }; assertEquals("Should have returned initial filter", filter, FileSystemUtil.mergeFilters(filter, null)); assertEquals("Should have returned initial filter", filter, FileSystemUtil.mergeFilters(filter, new PathFilter[]{})); assertEquals("Should have returned dummy filter", FileSystemUtil.DUMMY_FILTER, FileSystemUtil.mergeFilters()); }
@Test public void mergeFiltersTrue() { Path file = new Path("abc.txt"); PathFilter firstFilter = new PathFilter() { @Override public boolean accept(Path path) { return path.getName().startsWith("a"); } }; PathFilter secondFilter = new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith(".txt"); } }; assertTrue("Path should have been included in the path list", FileSystemUtil.mergeFilters(firstFilter, secondFilter).accept(file)); assertTrue("Path should have been included in the path list", FileSystemUtil.mergeFilters(firstFilter, new PathFilter[] {secondFilter}).accept(file)); }
@Test public void mergeFiltersFalse() { Path file = new Path("abc.txt"); PathFilter firstFilter = new PathFilter() { @Override public boolean accept(Path path) { return path.getName().startsWith("a"); } }; PathFilter secondFilter = new PathFilter() { @Override public boolean accept(Path path) { return path.getName().endsWith(".csv"); } }; assertFalse("Path should have been excluded from the path list", FileSystemUtil.mergeFilters(firstFilter, secondFilter).accept(file)); assertFalse("Path should have been excluded from the path list", FileSystemUtil.mergeFilters(firstFilter, new PathFilter[] {secondFilter}).accept(file)); }