SystemFileSystem extends AbstractFileSystem { @Override public Set<File> findFiles(File path) { Set<File> result = Sets.newHashSet(); findFilesRecursiveHelper(path, result); return result; } @Inject  SystemFileSystem(); @Override File getTemporaryDirectory(String prefix); @Override File getTemporaryDirectory(String prefix, Lifetime lifetime); @Override void cleanUpTempDirs(); @Override void setLifetime(File path, Lifetime lifetime); @Override Set<File> findFiles(File path); @Override File[] listFiles(File path); @Override boolean exists(File f); @Override String getName(File f); @Override boolean isFile(File f); @Override boolean isDirectory(File f); @Override boolean isExecutable(File f); @Override boolean isReadable(File f); @Override void setExecutable(File f); @Override void setNonExecutable(File f); @Override void makeDirsForFile(File f); @Override void makeDirs(File f); @Override void copyFile(File src, File dest); @Override void write(String contents, File f); @Override void deleteRecursively(File file); @Override File getResourceAsFile(String resource); @Override String fileToString(File f);  }
@Test public void testFindFiles() throws Exception { touchAndCreate(tempDir, "file"); touchAndCreate(tempDir, "bar/baz"); assertThat(makeFilenamesRelative(fs.findFiles(tempDir), tempDir)) .containsExactly("file", "bar/baz"); }
@Test public void testFindFilesWithGlob() throws Exception { touchAndCreate(tempDir, "foo"); touchAndCreate(tempDir, "blah.java"); touchAndCreate(tempDir, "bar/baz"); touchAndCreate(tempDir, "bar/foo.java"); touchAndCreate(tempDir, "bar/bar.java"); touchAndCreate(tempDir, "bar/baz.java"); touchAndCreate(tempDir, "babar/baz.java"); assertThat(fs.findFiles(tempDir, asList("*.java"), asList())).containsExactly("blah.java"); assertThat(fs.findFiles(tempDir, asList("**bar/[^/]*\.java$", which won't match bar/baz.java, for instance, assertThat(fs.findFiles(tempDir, asList("**/bar/*.java"), asList())).isEmpty(); assertThat(fs.findFiles(tempDir, asList("**bar/*.java"), asList())) .containsExactly("bar/foo.java", "bar/bar.java", "bar/baz.java", "babar/baz.java"); }
@Test public void testFindFilesWithGlobAndDifferentRelativePath() throws Exception { touchAndCreate(tempDir, "a/b/foo"); touchAndCreate(tempDir, "a/b/blah.java"); touchAndCreate(tempDir, "a/b/bar/foo.java"); touchAndCreate(tempDir, "a/c/bar/bar.java"); touchAndCreate(tempDir, "a/c/bar/baz.java"); touchAndCreate(tempDir, "a/c/babar/baz.java"); assertThat(fs.findFiles(tempDir, new File(tempDir, "a/b"), asList("**.java"), asList())) .containsExactly("a/b/blah.java", "a/b/bar/foo.java"); assertThat(fs.findFiles(tempDir, new File(tempDir, "a/c"), asList("**.java"), asList())) .containsExactly("a/c/bar/bar.java", "a/c/bar/baz.java", "a/c/babar/baz.java"); }
@Test public void testFindFilesWithGlobAndExclusions() throws Exception { touchAndCreate(tempDir, "foo"); touchAndCreate(tempDir, "blah.java"); touchAndCreate(tempDir, "bar/baz"); touchAndCreate(tempDir, "bar/foo.java"); touchAndCreate(tempDir, "bar/bar.java"); touchAndCreate(tempDir, "bar/baz.java"); touchAndCreate(tempDir, "babar/baz.java"); assertThat(fs.findFiles(tempDir, asList("**.java"), asList())) .containsExactly( "blah.java", "bar/foo.java", "bar/bar.java", "bar/baz.java", "babar/baz.java"); assertThat(fs.findFiles(tempDir, asList("**.java"), asList("**babar**"))) .containsExactly("blah.java", "bar/foo.java", "bar/bar.java", "bar/baz.java"); assertThat(fs.findFiles(tempDir, asList("**"), asList("**.java"))) .containsExactly("foo", "bar/baz"); }