diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-09-06 12:32:26 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 11:34:59 +0200 |
commit | 579aa0457917229ed583c782563552ae957e121d (patch) | |
tree | 449ea57572c995e1490d8dbfc80dd96b14bdddcf /sonar-scanner-engine/src/test/java/org | |
parent | 38ef0887b448e1c96b84b1631c293d553da39cb1 (diff) | |
download | sonarqube-579aa0457917229ed583c782563552ae957e121d.tar.gz sonarqube-579aa0457917229ed583c782563552ae957e121d.zip |
SONAR-9701 Don't publish empty modules
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java index 5d45fca8155..5b0406bdfc1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java @@ -21,6 +21,7 @@ package org.sonar.scanner.report; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import org.junit.Before; import org.junit.Rule; @@ -207,6 +208,62 @@ public class ComponentsPublisherTest { } @Test + public void should_skip_empty_modules_for_short_living_branches() throws IOException { + ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); + when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12")); + + ProjectDefinition rootDef = ProjectDefinition.create() + .setKey("foo") + .setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0") + .setName("Root project") + .setDescription("Root description") + .setBaseDir(temp.newFolder()) + .setWorkDir(temp.newFolder()); + DefaultInputModule root = new DefaultInputModule(rootDef, 1); + + ProjectDefinition emptyModuleDef = ProjectDefinition.create() + .setKey("modEmpty") + .setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0") + .setName("Empty module") + .setDescription("Empty module") + .setBaseDir(temp.newFolder()) + .setWorkDir(temp.newFolder()); + DefaultInputModule emptyModule = new DefaultInputModule(emptyModuleDef, 2); + + ProjectDefinition notEmptyModuleDef = ProjectDefinition.create() + .setKey("modNotEmpty") + .setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0") + .setName("Module") + .setDescription("Module") + .setBaseDir(temp.newFolder()) + .setWorkDir(temp.newFolder()); + DefaultInputModule notEmptyModule = new DefaultInputModule(notEmptyModuleDef, 3); + + moduleHierarchy = mock(InputModuleHierarchy.class); + when(moduleHierarchy.root()).thenReturn(root); + when(moduleHierarchy.isRoot(root)).thenReturn(true); + when(moduleHierarchy.children(root)).thenReturn(Arrays.asList(emptyModule, notEmptyModule)); + when(moduleHierarchy.children(emptyModule)).thenReturn(Collections.emptyList()); + when(moduleHierarchy.children(notEmptyModule)).thenReturn(Collections.emptyList()); + when(branchConfiguration.branchType()).thenReturn(BranchType.SHORT); + + // dir with files + DefaultInputDir dir = new DefaultInputDir("modNotEmpty", "src", 4); + tree.index(dir, notEmptyModule); + + // Only an unchanged file, so module should also be skipped + DefaultInputFile file = new TestInputFileBuilder("modNotEmpty", "src/Foo.java", 5).setLines(2).setStatus(InputFile.Status.SAME).build(); + tree.index(file, dir); + + ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree, branchConfiguration); + publisher.publish(writer); + + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue(); + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isFalse(); + assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isFalse(); + } + + @Test public void should_set_directory_status() throws IOException { ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12")); @@ -320,7 +377,6 @@ public class ComponentsPublisherTest { assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isFalse(); } - @Test public void add_components_without_version_and_name() throws IOException { ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); |