InputFileFinder { public List<ClientInputFile> collect(Path dir) throws IOException { final List<ClientInputFile> files = new ArrayList<>(); Files.walkFileTree(dir, new FileCollector(dir, files)); return files; } InputFileFinder(@Nullable String srcGlobPattern, @Nullable String testsGlobPattern, @Nullable String excludeGlobPattern, Charset charset); List<ClientInputFile> collect(Path dir); static final String GLOB_PREFIX; }
@Test public void testDefault() throws IOException { fileFinder = new InputFileFinder(null, null, null, Charset.defaultCharset()); List<ClientInputFile> files = fileFinder.collect(root); assertThat(files).hasSize(2); assertThat(files).extracting("test").containsOnly(false); }
@Test public void testOverlapping() throws IOException { fileFinder = new InputFileFinder("**tests**", "**tests**", null, Charset.defaultCharset()); List<ClientInputFile> files = fileFinder.collect(root); assertThat(files).hasSize(1); assertThat(files).extracting("test").containsOnly(true); }
@Test public void testIgnoreHidden() throws IOException { fileFinder = new InputFileFinder(null, null, null, Charset.defaultCharset()); File hiddenFolder = temp.newFolder(".test"); Path hiddenSrc = hiddenFolder.toPath().resolve("Test.java"); List<ClientInputFile> files = fileFinder.collect(root); assertThat(files).extracting("path").doesNotContain(hiddenSrc); assertThat(files).extracting("path").contains(src1.toString()); }
@Test public void testDisjoint() throws IOException { fileFinder = new InputFileFinder("**abc**", "**abc**", null, Charset.defaultCharset()); List<ClientInputFile> files = fileFinder.collect(root); assertThat(files).isEmpty(); }
@Test public void testCharset() throws IOException { fileFinder = new InputFileFinder(null, null, null, StandardCharsets.US_ASCII); List<ClientInputFile> files = fileFinder.collect(root); assertThat(files).hasSize(2); assertThat(files).extracting("charset").containsOnly(StandardCharsets.US_ASCII); }
@Test public void testPatternAppliedToSourceFilesOnly() throws Exception { Path src = root.resolve("src"); test1 = src.resolve("FirstTest.java"); Path test2 = src.resolve("SecondTest.java"); Path externalTest = root.resolve("ExternalTest.java"); Files.createDirectories(src); Files.createFile(test1); Files.createFile(test2); Files.createFile(externalTest); fileFinder = new InputFileFinder("src/**", "*Test.*", null, Charset.defaultCharset()); List<ClientInputFile> files = fileFinder.collect(root); assertThat(files).extracting("path").containsOnly(test1.toString(), test2.toString(), src1.toString()); }
@Test public void testExclusions() throws IOException { fileFinder = new InputFileFinder(null, null, "tests/**", Charset.defaultCharset()); List<ClientInputFile> files = fileFinder.collect(root); assertThat(files).extracting("path").containsOnly(src1.toString()); }