From 2dbbfd0e46a23e9012f981ba868bdbbd5988dd72 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 11 Feb 2014 22:47:32 +0100 Subject: SONAR-926 add missing tests --- .../filesystem/InputFileBuilderFactoryTest.java | 50 ++++++ .../scan/filesystem/InputFileBuilderTest.java | 172 +++++++++++++++++++++ .../filesystem/LanguageDetectionFactoryTest.java | 39 +++++ .../filesystem/PreviousFileHashLoaderTest.java | 87 +++++++++++ .../filesystem/PreviousFileHashesLoaderTest.java | 87 ----------- .../filesystem/StatusDetectionFactoryTest.java | 34 ++++ .../batch/scan/filesystem/StatusDetectionTest.java | 40 +++++ 7 files changed, 422 insertions(+), 87 deletions(-) create mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java create mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java create mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java create mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashesLoaderTest.java create mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionFactoryTest.java create mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java (limited to 'sonar-batch/src/test/java') diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java new file mode 100644 index 00000000000..5eba1db2260 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java @@ -0,0 +1,50 @@ +/* + * 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.Test; +import org.mockito.Mockito; +import org.sonar.api.resources.Project; +import org.sonar.api.scan.filesystem.PathResolver; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class InputFileBuilderFactoryTest { + @Test + public void create_builder() throws Exception { + PathResolver pathResolver = new PathResolver(); + Project project = new Project("struts"); + LanguageDetectionFactory langDetectionFactory = mock(LanguageDetectionFactory.class, Mockito.RETURNS_MOCKS); + StatusDetectionFactory statusDetectionFactory = mock(StatusDetectionFactory.class, Mockito.RETURNS_MOCKS); + DefaultModuleFileSystem fs = mock(DefaultModuleFileSystem.class); + + InputFileBuilderFactory factory = new InputFileBuilderFactory( + project, pathResolver, langDetectionFactory, + statusDetectionFactory); + InputFileBuilder builder = factory.create(fs); + + assertThat(builder.langDetection()).isNotNull(); + assertThat(builder.statusDetection()).isNotNull(); + assertThat(builder.pathResolver()).isSameAs(pathResolver); + assertThat(builder.fs()).isSameAs(fs); + assertThat(builder.moduleKey()).isEqualTo("struts"); + } +} 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 new file mode 100644 index 00000000000..4e19c94bd1b --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java @@ -0,0 +1,172 @@ +/* + * 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.apache.commons.io.Charsets; +import org.apache.commons.io.FileUtils; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.scan.filesystem.InputFile; +import org.sonar.api.scan.filesystem.PathResolver; +import org.sonar.api.scan.filesystem.internal.DefaultInputFile; +import org.sonar.api.utils.PathUtils; + +import java.io.File; +import java.util.Arrays; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class InputFileBuilderTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + LanguageDetection langDetection = mock(LanguageDetection.class); + StatusDetection statusDetection = mock(StatusDetection.class); + DefaultModuleFileSystem fs = mock(DefaultModuleFileSystem.class); + + @Test + public void create_input_file() throws Exception { + // file system + File basedir = temp.newFolder(); + File srcFile = new File(basedir, "src/main/java/foo/Bar.java"); + FileUtils.touch(srcFile); + FileUtils.write(srcFile, "single line"); + when(fs.baseDir()).thenReturn(basedir); + when(fs.sourceCharset()).thenReturn(Charsets.UTF_8); + + // lang + when(langDetection.language(any(InputFile.class))).thenReturn("java"); + + // status + when(statusDetection.status("src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")).thenReturn(InputFile.STATUS_ADDED); + + InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), + langDetection, statusDetection, fs); + DefaultInputFile inputFile = builder.create(srcFile, InputFile.TYPE_MAIN); + + assertThat(inputFile.name()).isEqualTo("Bar.java"); + assertThat(inputFile.file()).isEqualTo(srcFile.getAbsoluteFile()); + assertThat(inputFile.absolutePath()).isEqualTo(PathUtils.sanitize(srcFile.getAbsolutePath())); + assertThat(inputFile.language()).isEqualTo("java"); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY)).isEqualTo("struts:src/main/java/foo/Bar.java"); + assertThat(inputFile.path()).isEqualTo("src/main/java/foo/Bar.java"); + + assertThat(inputFile.attribute(InputFile.ATTRIBUTE_LINE_COUNT)).isEqualTo("1"); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH)).isNull(); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCEDIR_PATH)).isNull(); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY)).isNull(); + } + + @Test + public void return_null_if_file_outside_basedir() throws Exception { + // file system + File basedir = temp.newFolder(); + File otherDir = temp.newFolder(); + File srcFile = new File(otherDir, "src/main/java/foo/Bar.java"); + FileUtils.touch(srcFile); + when(fs.baseDir()).thenReturn(basedir); + + InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), + langDetection, statusDetection, fs); + DefaultInputFile inputFile = builder.create(srcFile, InputFile.TYPE_MAIN); + + assertThat(inputFile).isNull(); + } + + @Test + public void return_null_if_language_not_detected() throws Exception { + // file system + File basedir = temp.newFolder(); + File srcFile = new File(basedir, "src/main/java/foo/Bar.java"); + FileUtils.touch(srcFile); + FileUtils.write(srcFile, "single line"); + when(fs.baseDir()).thenReturn(basedir); + when(fs.sourceCharset()).thenReturn(Charsets.UTF_8); + + // lang + when(langDetection.language(any(InputFile.class))).thenReturn(null); + + InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), + langDetection, statusDetection, fs); + DefaultInputFile inputFile = builder.create(srcFile, InputFile.TYPE_MAIN); + + assertThat(inputFile).isNull(); + } + + @Test + public void fill_deprecated_data_of_java_file() throws Exception { + // file system + File basedir = temp.newFolder(); + File srcFile = new File(basedir, "src/main/java/foo/Bar.java"); + FileUtils.touch(srcFile); + FileUtils.write(srcFile, "single line"); + when(fs.baseDir()).thenReturn(basedir); + when(fs.sourceCharset()).thenReturn(Charsets.UTF_8); + File sourceDir = new File(basedir, "src/main/java"); + when(fs.sourceDirs()).thenReturn(Arrays.asList(sourceDir)); + + // lang + when(langDetection.language(any(InputFile.class))).thenReturn("java"); + + // status + when(statusDetection.status("src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")).thenReturn(InputFile.STATUS_ADDED); + + InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), + langDetection, statusDetection, fs); + DefaultInputFile inputFile = builder.create(srcFile, InputFile.TYPE_MAIN); + + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH)).isEqualTo("foo/Bar.java"); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCEDIR_PATH)).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath())); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY)).isEqualTo("struts:foo.Bar"); + } + + @Test + public void fill_deprecated_data_of_non_java_file() throws Exception { + // file system + File basedir = temp.newFolder(); + File srcFile = new File(basedir, "src/foo/Bar.php"); + FileUtils.touch(srcFile); + FileUtils.write(srcFile, "single line"); + when(fs.baseDir()).thenReturn(basedir); + when(fs.sourceCharset()).thenReturn(Charsets.UTF_8); + File sourceDir = new File(basedir, "src"); + when(fs.sourceDirs()).thenReturn(Arrays.asList(sourceDir)); + + // lang + when(langDetection.language(any(InputFile.class))).thenReturn("php"); + + // status + when(statusDetection.status("src/Bar.php", "6c1d64c0b3555892fe7273e954f6fb5a")).thenReturn(InputFile.STATUS_ADDED); + + InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), + langDetection, statusDetection, fs); + DefaultInputFile inputFile = builder.create(srcFile, InputFile.TYPE_MAIN); + + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH)).isEqualTo("foo/Bar.php"); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCEDIR_PATH)).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath())); + assertThat(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY)).isEqualTo("struts:foo/Bar.php"); + + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java new file mode 100644 index 00000000000..0df875cfe42 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java @@ -0,0 +1,39 @@ +/* + * 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.Test; +import org.sonar.api.config.Settings; +import org.sonar.api.resources.Java; +import org.sonar.api.resources.Languages; + +import static org.fest.assertions.Assertions.assertThat; + +public class LanguageDetectionFactoryTest { + @Test + public void testCreate() throws Exception { + Languages languages = new Languages(Java.INSTANCE); + LanguageDetectionFactory factory = new LanguageDetectionFactory(new Settings(), languages); + LanguageDetection languageDetection = factory.create(); + assertThat(languageDetection).isNotNull(); + assertThat(languageDetection.patternsByLanguage()).hasSize(1); + assertThat(languageDetection.patternsByLanguage().containsKey("java")).isTrue(); + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java new file mode 100644 index 00000000000..e886299bfbc --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashLoaderTest.java @@ -0,0 +1,87 @@ +/* + * 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.ExpectedException; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.database.model.Snapshot; +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.components.PastSnapshotFinder; +import org.sonar.core.source.SnapshotDataTypes; +import org.sonar.core.source.db.SnapshotDataDao; +import org.sonar.core.source.db.SnapshotDataDto; + +import java.util.Arrays; +import java.util.Date; +import java.util.Map; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class PreviousFileHashLoaderTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class); + Snapshot snapshot = mock(Snapshot.class); + SnapshotDataDao snapshotDataDao = mock(SnapshotDataDao.class); + PreviousFileHashLoader loader = new PreviousFileHashLoader(snapshot, snapshotDataDao, pastSnapshotFinder); + + @Test + public void should_return_null_if_no_previous_snapshot() throws Exception { + when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(new PastSnapshot("foo")); + + Map hashByRelativePath = loader.hashByRelativePath(); + assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull(); + } + + @Test + public void should_return_null_if_no_remote_hashes() throws Exception { + Snapshot previousSnapshot = mock(Snapshot.class); + PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot); + when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot); + + Map hashByRelativePath = loader.hashByRelativePath(); + assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull(); + } + + @Test + public void should_return_remote_hash() throws Exception { + Snapshot previousSnapshot = mock(Snapshot.class); + when(previousSnapshot.getId()).thenReturn(123); + PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot); + when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot); + + SnapshotDataDto snapshotDataDto = new SnapshotDataDto(); + snapshotDataDto.setData("src/main/java/foo/Bar.java=abcd1234"); + when(snapshotDataDao.selectSnapshotData(123, Arrays.asList(SnapshotDataTypes.FILE_HASHES))) + .thenReturn(Arrays.asList(snapshotDataDto)); + + Map hashByRelativePath = loader.hashByRelativePath(); + assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isEqualTo("abcd1234"); + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashesLoaderTest.java deleted file mode 100644 index 6b4e518a354..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/PreviousFileHashesLoaderTest.java +++ /dev/null @@ -1,87 +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.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.sonar.api.database.model.Snapshot; -import org.sonar.batch.components.PastSnapshot; -import org.sonar.batch.components.PastSnapshotFinder; -import org.sonar.core.source.SnapshotDataTypes; -import org.sonar.core.source.db.SnapshotDataDao; -import org.sonar.core.source.db.SnapshotDataDto; - -import java.util.Arrays; -import java.util.Date; -import java.util.Map; - -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class PreviousFileHashesLoaderTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class); - Snapshot snapshot = mock(Snapshot.class); - SnapshotDataDao snapshotDataDao = mock(SnapshotDataDao.class); - PreviousFileHashLoader loader = new PreviousFileHashLoader(snapshot, snapshotDataDao, pastSnapshotFinder); - - @Test - public void should_return_null_if_no_previous_snapshot() throws Exception { - when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(new PastSnapshot("foo")); - - Map hashByRelativePath = loader.hashByRelativePath(); - assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull(); - } - - @Test - public void should_return_null_if_no_remote_hashes() throws Exception { - Snapshot previousSnapshot = mock(Snapshot.class); - PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot); - when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot); - - Map hashByRelativePath = loader.hashByRelativePath(); - assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull(); - } - - @Test - public void should_return_remote_hash() throws Exception { - Snapshot previousSnapshot = mock(Snapshot.class); - when(previousSnapshot.getId()).thenReturn(123); - PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot); - when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot); - - SnapshotDataDto snapshotDataDto = new SnapshotDataDto(); - snapshotDataDto.setData("src/main/java/foo/Bar.java=abcd1234"); - when(snapshotDataDao.selectSnapshotData(123, Arrays.asList(SnapshotDataTypes.FILE_HASHES))) - .thenReturn(Arrays.asList(snapshotDataDto)); - - Map hashByRelativePath = loader.hashByRelativePath(); - assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isEqualTo("abcd1234"); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionFactoryTest.java new file mode 100644 index 00000000000..460d527848c --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionFactoryTest.java @@ -0,0 +1,34 @@ +/* + * 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.Test; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class StatusDetectionFactoryTest { + @Test + public void testCreate() throws Exception { + StatusDetectionFactory factory = new StatusDetectionFactory(mock(PreviousFileHashLoader.class)); + StatusDetection detection = factory.create(); + assertThat(detection).isNotNull(); + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java new file mode 100644 index 00000000000..79404404f8f --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java @@ -0,0 +1,40 @@ +/* + * 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 com.google.common.collect.ImmutableMap; +import org.junit.Test; +import org.sonar.api.scan.filesystem.InputFile; + +import static org.fest.assertions.Assertions.assertThat; + +public class StatusDetectionTest { + @Test + public void detect_status() throws Exception { + StatusDetection statusDetection = new StatusDetection(ImmutableMap.of( + "src/Foo.java", "ABCDE", + "src/Bar.java", "FGHIJ" + )); + + assertThat(statusDetection.status("src/Foo.java", "ABCDE")).isEqualTo(InputFile.STATUS_SAME); + assertThat(statusDetection.status("src/Foo.java", "XXXXX")).isEqualTo(InputFile.STATUS_CHANGED); + assertThat(statusDetection.status("src/Other.java", "QWERT")).isEqualTo(InputFile.STATUS_ADDED); + } +} -- cgit v1.2.3