diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-02-23 14:31:50 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-02-28 20:03:03 +0000 |
commit | 6e4a70051758cfbd010405c0c1ade369c9184229 (patch) | |
tree | ac0211fb2c9195bfab4234218ab964f357c1b1f0 /sonar-plugin-api-impl/src/test | |
parent | a3b2ced8fe9f767c70b691cbfe1fdc7a5833336e (diff) | |
download | sonarqube-6e4a70051758cfbd010405c0c1ade369c9184229.tar.gz sonarqube-6e4a70051758cfbd010405c0c1ade369c9184229.zip |
SONAR-16057 Filesystem tests fail with NPE
Diffstat (limited to 'sonar-plugin-api-impl/src/test')
-rw-r--r-- | sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java index 1665fb271b1..e516adec9b6 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultFileSystemTest.java @@ -112,13 +112,37 @@ public class DefaultFileSystemTest { } @Test - public void input_file_returns_null_if_file_not_found() { + public void inputFiles_using_optimized_predicates() { + fs.add(new TestInputFileBuilder("foo", "src/Foo.php").setLanguage("php").build()); + fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build()); + fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build()); + + assertThat(fs.inputFiles(fs.predicates().hasFilename("Foo.php"))).hasSize(1); + assertThat(fs.inputFiles(fs.predicates().hasFilename("unknown"))).isEmpty(); + assertThat(fs.inputFiles(fs.predicates().hasExtension("java"))).hasSize(2); + assertThat(fs.inputFiles(fs.predicates().hasExtension("unknown"))).isEmpty(); + } + + @Test + public void hasFiles_using_optimized_predicates() { + fs.add(new TestInputFileBuilder("foo", "src/Foo.php").setLanguage("php").build()); + fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build()); + fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build()); + + assertThat(fs.hasFiles(fs.predicates().hasFilename("Foo.php"))).isTrue(); + assertThat(fs.hasFiles(fs.predicates().hasFilename("unknown"))).isFalse(); + assertThat(fs.hasFiles(fs.predicates().hasExtension("java"))).isTrue(); + assertThat(fs.hasFiles(fs.predicates().hasExtension("unknown"))).isFalse(); + } + + @Test + public void inputFile_returns_null_if_file_not_found() { assertThat(fs.inputFile(fs.predicates().hasRelativePath("src/Bar.java"))).isNull(); assertThat(fs.inputFile(fs.predicates().hasLanguage("cobol"))).isNull(); } @Test - public void input_file_fails_if_too_many_results() { + public void inputFile_fails_if_too_many_results() { fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build()); fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build()); @@ -128,7 +152,7 @@ public class DefaultFileSystemTest { } @Test - public void input_file_supports_non_indexed_predicates() { + public void inputFile_supports_non_indexed_predicates() { fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build()); // it would fail if more than one java file |