use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldAcceptIssueIfMatchesDeprecatedRuleKey.
@Test
public void shouldAcceptIssueIfMatchesDeprecatedRuleKey() {
RuleKey ruleKey = RuleKey.of("repo", "rule");
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder().setRuleKey(ruleKey).setDeprecatedKeys(singleton(RuleKey.of("repo2", "deprecated"))).build()));
String path = "org/sonar/api/Issue.java";
when(issue.ruleKey()).thenReturn(ruleKey);
IssuePattern matching = new IssuePattern("org/**", "repo2:deprecated");
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(issue.getComponent()).thenReturn(createComponentWithPath(path));
ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
assertThat(ignoreFilter.accept(issue, chain)).isTrue();
verify(analysisWarnings).addUnique("A multicriteria issue enforce uses the rule key 'repo2:deprecated' that has been changed. The pattern should be updated to 'repo:rule'");
verifyNoInteractions(chain);
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class IssueExclusionsLoaderTest method populateRuleExclusionPatterns.
@Test
public void populateRuleExclusionPatterns() {
IssuePattern pattern1 = new IssuePattern("org/foo/Bar*.java", "*");
IssuePattern pattern2 = new IssuePattern("org/foo/Hell?.java", "checkstyle:MagicNumber");
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(Arrays.asList(pattern1, pattern2));
IssueExclusionsLoader loader = new IssueExclusionsLoader(exclusionPatternInitializer, ignoreIssuesFilter, mock(AnalysisWarnings.class));
DefaultInputFile file1 = TestInputFileBuilder.create("foo", "org/foo/Bar.java").build();
loader.addMulticriteriaPatterns(file1);
DefaultInputFile file2 = TestInputFileBuilder.create("foo", "org/foo/Baz.java").build();
loader.addMulticriteriaPatterns(file2);
DefaultInputFile file3 = TestInputFileBuilder.create("foo", "org/foo/Hello.java").build();
loader.addMulticriteriaPatterns(file3);
verify(ignoreIssuesFilter).addRuleExclusionPatternForComponent(file1, pattern1.getRulePattern());
verify(ignoreIssuesFilter).addRuleExclusionPatternForComponent(file3, pattern2.getRulePattern());
verifyNoMoreInteractions(ignoreIssuesFilter);
}
Aggregations