@Override public boolean apply(InputFile f) { for (FilePredicate predicate : predicates) { if (predicate.apply(f)) { return true; } } return false; }
@Override public boolean apply(InputFile f) { return !predicate.apply(f); }
@Override public boolean apply(InputFile inputFile) { return unoptimizedPredicate.apply(inputFile); }
@Test public void matches_inclusion_pattern() { assertThat(predicates.matchesPathPattern("src/main/**/Action.java").apply(javaFile)).isTrue(); assertThat(predicates.matchesPathPattern("Action.java").apply(javaFile)).isFalse(); assertThat(predicates.matchesPathPattern("src/**/*.php").apply(javaFile)).isFalse(); }
@Test public void does_not_match_exclusion_patterns() { assertThat(predicates.doesNotMatchPathPatterns(new String[] {}).apply(javaFile)).isTrue(); assertThat(predicates.doesNotMatchPathPatterns(new String[] {"src/other/**.java", "src/**/*.php"}).apply(javaFile)).isTrue(); assertThat(predicates.doesNotMatchPathPatterns(new String[] {"src/other/**.java", "src/main/**/Action.java"}).apply(javaFile)).isFalse(); }
@Test public void has_relative_path() { assertThat(predicates.hasRelativePath("src/main/java/struts/Action.java").apply(javaFile)).isTrue(); assertThat(predicates.hasRelativePath("src/main/java/struts/Other.java").apply(javaFile)).isFalse(); // path is normalized assertThat(predicates.hasRelativePath("src/main/java/../java/struts/Action.java").apply(javaFile)).isTrue(); assertThat(predicates.hasRelativePath("src\\main\\java\\struts\\Action.java").apply(javaFile)).isTrue(); assertThat(predicates.hasRelativePath("src\\main\\java\\struts\\Other.java").apply(javaFile)).isFalse(); assertThat(predicates.hasRelativePath("src\\main\\java\\struts\\..\\struts\\Action.java").apply(javaFile)).isTrue(); }
@Test public void has_languages() { assertThat(predicates.hasLanguages(Arrays.asList("java", "php")).apply(javaFile)).isTrue(); assertThat(predicates.hasLanguages(Arrays.asList("cobol", "php")).apply(javaFile)).isFalse(); assertThat(predicates.hasLanguages(Collections.<String>emptyList()).apply(javaFile)).isTrue(); }
@Test public void matches_inclusion_patterns() { assertThat(predicates.matchesPathPatterns(new String[] {"src/other/**.java", "src/main/**/Action.java"}).apply(javaFile)).isTrue(); assertThat(predicates.matchesPathPatterns(new String[] {}).apply(javaFile)).isTrue(); assertThat(predicates.matchesPathPatterns(new String[] {"src/other/**.java", "src/**/*.php"}).apply(javaFile)).isFalse(); }
@Test public void does_not_match_exclusion_pattern() { assertThat(predicates.doesNotMatchPathPattern("src/main/**/Action.java").apply(javaFile)).isFalse(); assertThat(predicates.doesNotMatchPathPattern("Action.java").apply(javaFile)).isTrue(); assertThat(predicates.doesNotMatchPathPattern("src/**/*.php").apply(javaFile)).isTrue(); }
@Test public void has_absolute_path() throws Exception { String path = javaFile.file().getAbsolutePath(); assertThat(predicates.hasAbsolutePath(path).apply(javaFile)).isTrue(); assertThat(predicates.hasAbsolutePath(path.replaceAll("/", "\\\\")).apply(javaFile)).isTrue(); assertThat(predicates.hasAbsolutePath(temp.newFile().getAbsolutePath()).apply(javaFile)).isFalse(); assertThat(predicates.hasAbsolutePath("src/main/java/struts/Action.java").apply(javaFile)).isFalse(); }
@Test public void has_path() throws Exception { // is relative path assertThat(predicates.hasPath("src/main/java/struts/Action.java").apply(javaFile)).isTrue(); assertThat(predicates.hasPath("src/main/java/struts/Other.java").apply(javaFile)).isFalse(); // is absolute path String path = javaFile.file().getAbsolutePath(); assertThat(predicates.hasAbsolutePath(path).apply(javaFile)).isTrue(); assertThat(predicates.hasPath(temp.newFile().getAbsolutePath()).apply(javaFile)).isFalse(); }
@Test public void hasExtension() { assertThat(predicates.hasExtension("java").apply(javaFile)).isTrue(); } }
@Test public void is_file() throws Exception { // relative file assertThat(predicates.is(new File(javaFile.relativePath())).apply(javaFile)).isTrue(); // absolute file assertThat(predicates.is(javaFile.file()).apply(javaFile)).isTrue(); assertThat(predicates.is(javaFile.file().getAbsoluteFile()).apply(javaFile)).isTrue(); assertThat(predicates.is(new File(javaFile.file().toURI())).apply(javaFile)).isTrue(); assertThat(predicates.is(temp.newFile()).apply(javaFile)).isFalse(); }
@Test public void hasFilename() { assertThat(predicates.hasFilename("Action.java").apply(javaFile)).isTrue(); }
@Test public void all() { assertThat(predicates.all().apply(javaFile)).isTrue(); }
@Test public void none() { assertThat(predicates.none().apply(javaFile)).isFalse(); }