diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-10 01:19:57 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-10 01:19:57 +0200 |
commit | 7cdb8cbfb54bcb028300674f18ce08ea3ee35858 (patch) | |
tree | f3bffef9fac71d13c4e48553e7b4bc2c49625efc /sonar-plugin-api/src/test | |
parent | c2a0f4f06564c1d62f08d4e20489f70f0f4ad223 (diff) | |
download | sonarqube-7cdb8cbfb54bcb028300674f18ce08ea3ee35858.tar.gz sonarqube-7cdb8cbfb54bcb028300674f18ce08ea3ee35858.zip |
SONAR-3677 refactor API
Diffstat (limited to 'sonar-plugin-api/src/test')
4 files changed, 168 insertions, 96 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/InputFilesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/InputFilesTest.java new file mode 100644 index 00000000000..cb1f210b454 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/InputFilesTest.java @@ -0,0 +1,46 @@ +/* + * 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.api.scan.filesystem; + +import com.google.common.collect.Lists; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.scan.filesystem.internal.InputFileBuilder; + +import java.io.File; + +import static org.fest.assertions.Assertions.assertThat; + +public class InputFilesTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Test + public void test_toFiles() throws Exception { + File file1 = temp.newFile(); + File file2 = temp.newFile(); + InputFile input1 = new InputFileBuilder(file1, "src/main/java/Foo.java").build(); + InputFile input2 = new InputFileBuilder(file2, "src/main/java/Bar.java").build(); + + assertThat(InputFiles.toFiles(Lists.newArrayList(input1, input2))).containsOnly(file1, file2); + } +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java deleted file mode 100644 index 4d821c0bf8e..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java +++ /dev/null @@ -1,96 +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.api.scan.filesystem; - -import com.google.common.collect.Lists; -import org.apache.commons.lang.CharEncoding; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.List; - -/** - * @since 3.5 - */ -public class SimpleModuleFileSystem implements ModuleFileSystem { - private File baseDir; - private File buildDir; - private List<File> sourceDirs = Lists.newArrayList(); - private List<File> testDirs = Lists.newArrayList(); - private List<File> binaryDirs = Lists.newArrayList(); - - public SimpleModuleFileSystem(File baseDir) { - this.baseDir = baseDir; - this.buildDir = new File(baseDir, "build"); - } - - @Override - public String moduleKey() { - return null; - } - - public File baseDir() { - return baseDir; - } - - public File buildDir() { - return buildDir; - } - - public List<File> sourceDirs() { - return sourceDirs; - } - - public List<File> testDirs() { - return testDirs; - } - - public List<File> binaryDirs() { - return binaryDirs; - } - - public SimpleModuleFileSystem addSourceDir(File d) { - sourceDirs.add(d); - return this; - } - - public SimpleModuleFileSystem addTestDir(File d) { - testDirs.add(d); - return this; - } - - public SimpleModuleFileSystem addBinaryDir(File d) { - binaryDirs.add(d); - return this; - } - - public List<File> files(FileQuery query) { - return Collections.emptyList(); - } - - public Charset sourceCharset() { - return Charset.forName(CharEncoding.UTF_8); - } - - public File workingDir() { - return new File(baseDir, "work"); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/internal/DefaultInputFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/internal/DefaultInputFileTest.java new file mode 100644 index 00000000000..a418721f796 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/internal/DefaultInputFileTest.java @@ -0,0 +1,92 @@ +/* + * 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.api.scan.filesystem.internal; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.scan.filesystem.InputFile; + +import java.io.File; +import java.io.IOException; + +import static org.fest.assertions.Assertions.assertThat; + +public class DefaultInputFileTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Test + public void test_attributes() throws IOException { + File file = temp.newFile(); + InputFile input = new InputFileBuilder(file, "src/main/java/Foo.java") + .attribute("foo", "bar") + .type(InputFile.TYPE_TEST) + .extension("jav") + .hash("ABC") + .status(InputFile.STATUS_ADDED) + .language("java") + .build(); + + assertThat(input.attributes()).hasSize(6); + assertThat(input.attribute("unknown")).isNull(); + assertThat(input.attribute("foo")).isEqualTo("bar"); + assertThat(input.attribute(InputFile.ATTRIBUTE_TYPE)).isEqualTo(InputFile.TYPE_TEST); + assertThat(input.attribute(InputFile.ATTRIBUTE_EXTENSION)).isEqualTo("jav"); + assertThat(input.attribute(InputFile.ATTRIBUTE_HASH)).isEqualTo("ABC"); + assertThat(input.attribute(InputFile.ATTRIBUTE_LANGUAGE)).isEqualTo("java"); + assertThat(input.attribute(InputFile.ATTRIBUTE_STATUS)).isEqualTo(InputFile.STATUS_ADDED); + + assertThat(input.has(InputFile.ATTRIBUTE_LANGUAGE, "java")).isTrue(); + assertThat(input.has(InputFile.ATTRIBUTE_LANGUAGE, "php")).isFalse(); + assertThat(input.has("unknown", "xxx")).isFalse(); + } + + @Test + public void test_file() throws Exception { + File sourceDir = temp.newFolder(); + File file = temp.newFile("Foo.java"); + InputFile input = new InputFileBuilder(file, "src/main/java/Foo.java") + .sourceDir(sourceDir) + .build(); + + assertThat(input.name()).isEqualTo("Foo.java"); + assertThat(input.file()).isEqualTo(file); + assertThat(input.attribute(InputFile.ATTRIBUTE_SOURCEDIR_PATH)).isEqualTo(sourceDir.getAbsolutePath()); + assertThat(input.relativePath()).isEqualTo("src/main/java/Foo.java"); + assertThat(input.path()).isEqualTo(file.getCanonicalPath()); + } + + @Test + public void test_equals_and_hashCode() throws Exception { + File file1 = temp.newFile(); + InputFile input1 = new InputFileBuilder(file1, "src/main/java/Foo.java").build(); + InputFile input1a = new InputFileBuilder(file1, "src/main/java/Foo.java").build(); + InputFile input2 = new InputFileBuilder(temp.newFile(), "src/main/java/Bar.java").build(); + + assertThat(input1.equals(input1)).isTrue(); + assertThat(input1.equals(input1a)).isTrue(); + assertThat(input1.equals(input2)).isFalse(); + assertThat(input1.hashCode()).isEqualTo(input1.hashCode()); + assertThat(input1.hashCode()).isEqualTo(input1a.hashCode()); + + } +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/internal/InputFileBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/internal/InputFileBuilderTest.java new file mode 100644 index 00000000000..6e70f14fa1d --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/internal/InputFileBuilderTest.java @@ -0,0 +1,30 @@ +/* + * 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.api.scan.filesystem.internal; + +import org.junit.Test; + +public class InputFileBuilderTest { + @Test + public void just_for_coverage() throws Exception { + InputFileBuilder._FOR_UNIT_TESTING_ONLY_(); + // do not fail + } +} |