diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-24 22:58:22 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-26 12:15:58 +0100 |
commit | e4810500228a85c72bf4937874de3f37dba39d48 (patch) | |
tree | 8ae86202e20d3f8db52f8f981f0bd075a134db75 /sonar-batch/src/test | |
parent | a7b8340e5f16f8411e44d7cffe472a28bf63c8b9 (diff) | |
download | sonarqube-e4810500228a85c72bf4937874de3f37dba39d48.tar.gz sonarqube-e4810500228a85c72bf4937874de3f37dba39d48.zip |
Remove unused classes
Diffstat (limited to 'sonar-batch/src/test')
8 files changed, 178 insertions, 221 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java index 372a863bd88..7acfba1e423 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java @@ -55,15 +55,15 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { public static final int FILE_SNAPSHOT_ID = 3003; public static final int COVERAGE_METRIC_ID = 2; - private MeasurePersister measurePersister; - private RuleFinder ruleFinder = mock(RuleFinder.class); - private ResourcePersister resourcePersister = mock(ResourcePersister.class); - private MemoryOptimizer memoryOptimizer = mock(MemoryOptimizer.class); - private Project project = new Project("foo"); - private JavaPackage aPackage = new JavaPackage("org.foo"); - private JavaFile aFile = new JavaFile("org.foo.Bar"); - private Snapshot projectSnapshot = snapshot(PROJECT_SNAPSHOT_ID); - private Snapshot packageSnapshot = snapshot(PACKAGE_SNAPSHOT_ID); + MeasurePersister measurePersister; + RuleFinder ruleFinder = mock(RuleFinder.class); + ResourcePersister resourcePersister = mock(ResourcePersister.class); + MemoryOptimizer memoryOptimizer = mock(MemoryOptimizer.class); + Project project = new Project("foo"); + JavaPackage aPackage = new JavaPackage("org.foo"); + JavaFile aFile = new JavaFile("org.foo.Bar"); + Snapshot projectSnapshot = snapshot(PROJECT_SNAPSHOT_ID); + Snapshot packageSnapshot = snapshot(PACKAGE_SNAPSHOT_ID); @Before public void mockResourcePersister() { diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java new file mode 100644 index 00000000000..20680042062 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java @@ -0,0 +1,81 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.batch.scan.filesystem; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.fs.FilePredicate; +import org.sonar.api.batch.fs.internal.DefaultInputFile; + +import java.io.File; + +import static org.fest.assertions.Assertions.assertThat; + +public class AdditionalFilePredicatesTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Test + public void key() throws Exception { + FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java"); + + DefaultInputFile inputFile = new DefaultInputFile("Action.java").setKey("struts:Action.java"); + assertThat(predicate.apply(inputFile)).isTrue(); + + inputFile = new DefaultInputFile("Filter.java").setKey("struts:Filter.java"); + assertThat(predicate.apply(inputFile)).isFalse(); + } + + @Test + public void deprecated_key() throws Exception { + FilePredicate predicate = new AdditionalFilePredicates.DeprecatedKeyPredicate("struts:Action.java"); + + DefaultInputFile inputFile = new DefaultInputFile("Action.java").setDeprecatedKey("struts:Action.java"); + assertThat(predicate.apply(inputFile)).isTrue(); + + inputFile = new DefaultInputFile("Filter.java").setDeprecatedKey("struts:Filter.java"); + assertThat(predicate.apply(inputFile)).isFalse(); + } + + @Test + public void absolute_path_of_source_dir() throws Exception { + File dir = temp.newFolder(); + FilePredicate predicate = new AdditionalFilePredicates.SourceDirPredicate(dir.getAbsolutePath()); + + DefaultInputFile inputFile = new DefaultInputFile("Action.java").setSourceDirAbsolutePath(dir.getAbsolutePath()); + assertThat(predicate.apply(inputFile)).isTrue(); + + inputFile = new DefaultInputFile("Filter.java").setSourceDirAbsolutePath(temp.newFolder().getAbsolutePath()); + assertThat(predicate.apply(inputFile)).isFalse(); + } + + @Test + public void path_relative_to_source_dir() throws Exception { + FilePredicate predicate = new AdditionalFilePredicates.SourceRelativePathPredicate("foo/Bar.php"); + + DefaultInputFile inputFile = new DefaultInputFile("src/php/foo/Bar.php").setPathRelativeToSourceDir("foo/Bar.php"); + assertThat(predicate.apply(inputFile)).isTrue(); + + inputFile = new DefaultInputFile("foo/Bar.php").setPathRelativeToSourceDir("Bar.php"); + assertThat(predicate.apply(inputFile)).isFalse(); + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFilterTest.java deleted file mode 100644 index c08dbe3b1c4..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFilterTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -import java.io.File; - -import static org.fest.assertions.Assertions.assertThat; - -public class ExclusionFilterTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void accept() throws Exception { - ExclusionFilter sourceRelativeFilter = new ExclusionFilter("**/*Foo.java"); - ExclusionFilter absoluteFilter = new ExclusionFilter("file:**/src/main/**Foo.java"); - - File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.java"); - InputFile inputFile = new DefaultInputFile("src/main/java/org/MyFoo.java") - .setFile(file) - .setPathRelativeToSourceDir("org/MyFoo.java"); - - assertThat(sourceRelativeFilter.accept(inputFile)).isFalse(); - assertThat(absoluteFilter.accept(inputFile)).isFalse(); - - file = new File(temp.newFolder(), "src/main/java/org/Other.java"); - inputFile = new DefaultInputFile("src/main/java/org/Other.java") - .setFile(file) - .setPathRelativeToSourceDir("org/Other.java"); - assertThat(sourceRelativeFilter.accept(inputFile)).isTrue(); - assertThat(absoluteFilter.accept(inputFile)).isTrue(); - } - - @Test - public void test_toString() { - ExclusionFilter filter = new ExclusionFilter("**/*Foo.java"); - assertThat(filter.toString()).isEqualTo("Excludes: **/*Foo.java"); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java index 6083f224a5c..4c0cd44c4cc 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.config.Settings; import org.sonar.api.scan.filesystem.FileExclusions; import org.sonar.api.scan.filesystem.ModuleFileSystem; @@ -59,13 +60,17 @@ public class ExclusionFiltersTest { filter.prepare(fs); java.io.File file = temp.newFile(); + DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/FooDao.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.MAIN)).isFalse(); + // test are excluded by default if no sonar.tests nor sonar.test.inclusions + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/FooDao.java", InputFile.Type.MAIN)).isTrue(); + inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); // test are excluded by default if no sonar.tests nor sonar.test.inclusions - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.TEST)).isFalse(); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse(); } @Test @@ -78,12 +83,15 @@ public class ExclusionFiltersTest { java.io.File file = temp.newFile(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.MAIN)).isTrue(); + DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); - assertThat(filter.accept(file, "src/main/java2/com/mycompany/FooDao.java", InputFile.Type.MAIN)).isFalse(); + inputFile = new DefaultInputFile("src/main/java2/com/mycompany/FooDao.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); // source inclusions do not apply to tests - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.TEST)).isFalse(); + inputFile = new DefaultInputFile("src/main/java/com/mycompany/FooDao.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse(); } @Test @@ -97,11 +105,12 @@ public class ExclusionFiltersTest { java.io.File file = temp.newFile(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.MAIN)).isTrue(); - - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.TEST)).isFalse(); + DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse(); - assertThat(filter.accept(file, "src/test/java/com/mycompany/Foo.java", InputFile.Type.TEST)).isTrue(); + inputFile = new DefaultInputFile("src/test/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue(); } @Test @@ -115,12 +124,15 @@ public class ExclusionFiltersTest { java.io.File file = temp.newFile(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.MAIN)).isFalse(); + DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); - assertThat(filter.accept(file, "src/main/java2/com/mycompany/FooDao.java", InputFile.Type.MAIN)).isTrue(); + inputFile = new DefaultInputFile("src/main/java2/com/mycompany/FooDao.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); // source inclusions do not apply to tests - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.TEST)).isFalse(); + inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse(); } @Test @@ -134,11 +146,14 @@ public class ExclusionFiltersTest { java.io.File file = temp.newFile(); // test inclusions do not apply to main code - assertThat(filter.accept(file, "src/test/java/com/mycompany/Foo.java", InputFile.Type.MAIN)).isFalse(); + DefaultInputFile inputFile = new DefaultInputFile("src/test/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); - assertThat(filter.accept(file, "src/test2/java/com/mycompany/FooTest.java", InputFile.Type.TEST)).isFalse(); + inputFile = new DefaultInputFile("src/test2/java/com/mycompany/FooTest.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isFalse(); - assertThat(filter.accept(file, "src/test/java/com/mycompany/Foo.java", InputFile.Type.TEST)).isTrue(); + inputFile = new DefaultInputFile("src/test/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue(); } @Test @@ -151,9 +166,11 @@ public class ExclusionFiltersTest { java.io.File file = temp.newFile(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.MAIN)).isFalse(); + DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/FooDto.java", InputFile.Type.MAIN)).isTrue(); + inputFile = new DefaultInputFile("src/main/java/com/mycompany/FooDto.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); } @Test @@ -167,12 +184,15 @@ public class ExclusionFiltersTest { filter.prepare(fs); java.io.File file = temp.newFile(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/FooDao.java", InputFile.Type.MAIN)).isFalse(); + DefaultInputFile inputFile = new DefaultInputFile("src/main/java/com/mycompany/FooDao.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); - assertThat(filter.accept(file, "src/main/java/com/mycompany/Foo.java", InputFile.Type.MAIN)).isTrue(); + inputFile = new DefaultInputFile("src/main/java/com/mycompany/Foo.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); // source exclusions do not apply to tests - assertThat(filter.accept(file, "src/test/java/com/mycompany/FooDao.java", InputFile.Type.TEST)).isTrue(); + inputFile = new DefaultInputFile("src/test/java/com/mycompany/FooDao.java").setFile(file); + assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue(); } @Test @@ -187,9 +207,11 @@ public class ExclusionFiltersTest { filter.prepare(fs); - assertThat(filter.accept(includedFile, "src/main/java/org/bar/Foo.java", InputFile.Type.MAIN)).isTrue(); + DefaultInputFile inputFile = new DefaultInputFile("src/main/java/org/bar/Foo.java").setFile(includedFile); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); - assertThat(filter.accept(excludedFile, "src/main/java/org/bar/Bar.java", InputFile.Type.MAIN)).isFalse(); + inputFile = new DefaultInputFile("src/main/java/org/bar/Bar.java").setFile(excludedFile); + assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileSystemLoggerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileSystemLoggerTest.java deleted file mode 100644 index e1f852e3f09..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileSystemLoggerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.slf4j.Logger; -import org.sonar.api.config.Settings; - -import java.io.File; - -import static org.mockito.AdditionalMatchers.and; -import static org.mockito.Matchers.contains; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -public class FileSystemLoggerTest { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void log() { -// DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", mock(Settings.class), mock(InputFileCache.class), mock(FileIndex.class)); -// File src = temp.newFolder("src"); -// File test = temp.newFolder("test"); -// File base = temp.newFolder("base"); -// fs.setBaseDir(base); -// fs.addSourceDir(src); -// fs.addTestDir(test); -// -// Logger slf4j = mock(Logger.class); -// new FileSystemLogger(fs).doLog(slf4j); -// -// verify(slf4j).info(and(contains("Base dir:"), contains(base.getAbsolutePath()))); -// verify(slf4j).info(and(contains("Source dirs:"), contains(src.getAbsolutePath()))); -// verify(slf4j).info(and(contains("Test dirs:"), contains(test.getAbsolutePath()))); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InclusionFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InclusionFilterTest.java deleted file mode 100644 index 21afc18791c..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InclusionFilterTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -import java.io.File; - -import static org.fest.assertions.Assertions.assertThat; - -public class InclusionFilterTest { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void accept() throws Exception { - InclusionFilter sourceRelativeFilter = new InclusionFilter("**/*Foo.java"); - InclusionFilter absoluteFilter = new InclusionFilter("file:**/src/main/**Foo.java"); - - File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.java"); - InputFile inputFile = new DefaultInputFile("src/main/java/org/MyFoo.java") - .setFile(file) - .setPathRelativeToSourceDir("org/MyFoo.java"); - - assertThat(sourceRelativeFilter.accept(inputFile)).isTrue(); - assertThat(absoluteFilter.accept(inputFile)).isTrue(); - - file = new File(temp.newFolder(), "src/main/java/org/Other.java"); - inputFile = new DefaultInputFile("src/main/java/org/Other.java") - .setFile(file) - .setPathRelativeToSourceDir("org/Other.java"); - assertThat(sourceRelativeFilter.accept(inputFile)).isFalse(); - assertThat(absoluteFilter.accept(inputFile)).isFalse(); - } - - @Test - public void test_toString() { - InclusionFilter filter = new InclusionFilter("**/*Foo.java"); - assertThat(filter.toString()).isEqualTo("Includes: **/*Foo.java"); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java index fadd7426a0c..b4b0100ec02 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java @@ -49,7 +49,7 @@ public class InputFileBuilderTest { AnalysisMode analysisMode = mock(AnalysisMode.class); @Test - public void create_input_file() throws Exception { + public void complete_input_file() throws Exception { // file system File basedir = temp.newFolder(); File srcFile = new File(basedir, "src/main/java/foo/Bar.java"); @@ -67,8 +67,10 @@ public class InputFileBuilderTest { InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, analysisMode); - DefaultInputFile inputFile = builder.create(srcFile, InputFile.Type.MAIN); + DefaultInputFile inputFile = builder.create(srcFile); + inputFile = builder.complete(inputFile, InputFile.Type.MAIN); + assertThat(inputFile.type()).isEqualTo(InputFile.Type.MAIN); assertThat(inputFile.file()).isEqualTo(srcFile.getAbsoluteFile()); assertThat(inputFile.absolutePath()).isEqualTo(PathUtils.sanitize(srcFile.getAbsolutePath())); assertThat(inputFile.language()).isEqualTo("java"); @@ -91,7 +93,7 @@ public class InputFileBuilderTest { InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, analysisMode); - DefaultInputFile inputFile = builder.create(srcFile, InputFile.Type.MAIN); + DefaultInputFile inputFile = builder.create(srcFile); assertThat(inputFile).isNull(); } @@ -111,7 +113,8 @@ public class InputFileBuilderTest { InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, analysisMode); - DefaultInputFile inputFile = builder.create(srcFile, InputFile.Type.MAIN); + DefaultInputFile inputFile = builder.create(srcFile); + inputFile = builder.complete(inputFile, InputFile.Type.MAIN); assertThat(inputFile).isNull(); } @@ -137,7 +140,8 @@ public class InputFileBuilderTest { InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, analysisMode); - DefaultInputFile inputFile = builder.create(srcFile, InputFile.Type.MAIN); + DefaultInputFile inputFile = builder.create(srcFile); + inputFile = builder.complete(inputFile, InputFile.Type.MAIN); assertThat(inputFile.pathRelativeToSourceDir()).isEqualTo("foo/Bar.java"); assertThat(inputFile.sourceDirAbsolutePath()).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath())); @@ -165,7 +169,8 @@ public class InputFileBuilderTest { InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), langDetection, statusDetection, fs, analysisMode); - DefaultInputFile inputFile = builder.create(srcFile, InputFile.Type.MAIN); + DefaultInputFile inputFile = builder.create(srcFile); + inputFile = builder.complete(inputFile, InputFile.Type.MAIN); assertThat(inputFile.pathRelativeToSourceDir()).isEqualTo("foo/Bar.php"); assertThat(inputFile.sourceDirAbsolutePath()).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath())); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java index 3cfbb4bd64d..ae0b094f25d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java @@ -26,10 +26,12 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.RelativePathIndex; import org.sonar.batch.index.Caches; import org.sonar.batch.index.CachesTest; import static org.fest.assertions.Assertions.assertThat; +import static org.fest.assertions.Fail.fail; public class InputFileCacheTest { @@ -52,18 +54,47 @@ public class InputFileCacheTest { @Test public void should_add_input_file() throws Exception { InputFileCache cache = new InputFileCache(caches); - cache.put("struts", new DefaultInputFile("src/main/java/Foo.java").setFile(temp.newFile("Foo.java"))); + DefaultInputFile fooFile = new DefaultInputFile("src/main/java/Foo.java").setFile(temp.newFile("Foo.java")); + cache.put("struts", fooFile); cache.put("struts-core", new DefaultInputFile("src/main/java/Bar.java").setFile(temp.newFile("Bar.java"))); + // index by relative path is automatically fed + assertThat(cache.get("struts", RelativePathIndex.ID, "src/main/java/Foo.java").relativePath()) + .isEqualTo("src/main/java/Foo.java"); + assertThat(cache.byModule("struts")).hasSize(1); assertThat(cache.byModule("struts-core")).hasSize(1); assertThat(cache.all()).hasSize(2); for (InputFile inputFile : cache.all()) { assertThat(inputFile.relativePath()).startsWith("src/main/java/"); } + + cache.remove("struts", fooFile); + assertThat(cache.all()).hasSize(1); + cache.removeModule("struts"); assertThat(cache.byModule("struts")).hasSize(0); assertThat(cache.byModule("struts-core")).hasSize(1); assertThat(cache.all()).hasSize(1); } + + @Test + public void only_relative_path_index_is_supported() throws Exception { + InputFileCache cache = new InputFileCache(caches); + DefaultInputFile input = new DefaultInputFile("src/main/java/Foo.java").setFile(temp.newFile("Foo.java")); + + try { + cache.index("struts", "unsupported-index", "index-value", input); + fail(); + } catch (UnsupportedOperationException e) { + assertThat(e).hasMessage("Only relative path index is supported yet"); + } + + try { + cache.get("struts", "unsupported-index", "index-value"); + fail(); + } catch (UnsupportedOperationException e) { + assertThat(e).hasMessage("Only relative path index is supported yet"); + } + } } |