diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-10-10 09:54:29 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-10-10 14:51:58 +0200 |
commit | 37915e1548b5a706b0aed606ee3250e3496850b0 (patch) | |
tree | a0e646c4f1fae129574d8fba3f515fe85cf2b879 /sonar-scanner-engine/src/test/java | |
parent | db2093a19f4cda810194cf9c0ab7a6db73b4a4a1 (diff) | |
download | sonarqube-37915e1548b5a706b0aed606ee3250e3496850b0.tar.gz sonarqube-37915e1548b5a706b0aed606ee3250e3496850b0.zip |
SONAR-9929 Filter secondary locations that are in a different file than primary location
Diffstat (limited to 'sonar-scanner-engine/src/test/java')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java index 8bbdee15b59..4ae19f7ef7b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java @@ -19,6 +19,7 @@ */ package org.sonar.scanner.issue; +import java.util.Arrays; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -182,6 +183,28 @@ public class ModuleIssuesTest { assertThat(argument.getValue().getMsg()).isEqualTo("Avoid Cycle"); } + // SONAR-9929 Filter secondary locations that are on different files + @Test + public void skip_cross_file_secondary_locations() { + ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME); + activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).setName(SQUID_RULE_NAME).activate(); + initModuleIssues(); + + DefaultIssue issue = new DefaultIssue() + .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo")) + .forRule(SQUID_RULE_KEY) + .addFlow(Arrays.asList(new DefaultIssueLocation().on(file).at(file.selectLine(4)).message("Location 1"), + new DefaultIssueLocation().on(new TestInputFileBuilder("foo", "src/Foo2.php").initMetadata("Foo\nBar\nBiz\n").build()).at(file.selectLine(3)).message("Location outside"))); + when(filters.accept(anyString(), any(ScannerReport.Issue.class))).thenReturn(true); + + boolean added = moduleIssues.initAndAddIssue(issue); + + assertThat(added).isTrue(); + ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class); + verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.batchId()), argument.capture()); + assertThat(argument.getValue().getFlow(0).getLocationList()).hasSize(1); + } + @Test public void filter_issue() { ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME); |