FileUtil { public static File[] findFiles(File dir, FileFilter filter) throws FileNotFoundException { if (!dir.exists()) { throw new FileNotFoundException("Directory " + dir + " does not exist."); } if (!dir.isDirectory()) { throw new FileNotFoundException("File " + dir + " is not a directory."); } ArrayList<File> files = new ArrayList<File>(); File[] allFiles = dir.listFiles(); if (allFiles != null && allFiles.length > 0) { for (File f : allFiles) { if (f.isFile()) { if (filter.accept(f)) { files.add(f); } } } } File[] r = files.toArray(new File[0]); Arrays.sort(r); return r; } private  FileUtil(); static boolean equals(File file1, File file2); static boolean isValidFileExtension(String extension); static String parseFileExtension(String filename); static File[] findFiles(File dir, FileFilter filter); static void copy(File sourceFile, File targetFile); static boolean copy(File sourceFile, File targetFile, boolean overwrite);  }
@Test(expected=FileNotFoundException.class) public void findFilesThrowsException0() throws Exception { FileUtil.findFiles(new File("target/samplelogs2"), null); }
@Test(expected=FileNotFoundException.class) public void findFilesThrowsException1() throws Exception { FileUtil.findFiles(new File("build.xml"), null); }
@Test public void fileNameDateTimeComparatorClass() throws Exception { File targetDir = new File("target/sample/fileNameDateTimeComparatorClass"); targetDir.mkdirs(); File file0 = new File(targetDir, "sample1-2009-06-25.log"); file0.createNewFile(); File file1 = new File(targetDir, "sample2-2009-06-23.log"); file1.createNewFile(); File file2 = new File(targetDir, "sample3-2009-06-24.log"); file2.createNewFile(); File[] files = FileUtil.findFiles(targetDir, new FileNameDateTimeFilter(new DateTime(2009,6,25,0,0,0,0,DateTimeZone.UTC))); Arrays.sort(files, new FileUtil.FileNameDateTimeComparator("yyyy-MM-dd", DateTimeZone.UTC)); Assert.assertEquals(3, files.length); Assert.assertEquals(file1, files[0]); Assert.assertEquals(file2, files[1]); Assert.assertEquals(file0, files[2]); }