use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class IgnoreIssuesFilterTest method shouldPassToChainIfMatcherHasNoPatternForIssue.
@Test
public void shouldPassToChainIfMatcherHasNoPatternForIssue() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
when(chain.accept(issue)).thenReturn(true);
assertThat(underTest.accept(issue, chain)).isTrue();
verify(chain).accept(any());
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class IgnoreIssuesFilterTest method shouldAcceptIfRulePatternDoesNotMatch.
@Test
public void shouldAcceptIfRulePatternDoesNotMatch() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
WildcardPattern pattern = mock(WildcardPattern.class);
when(pattern.match(ruleKey.toString())).thenReturn(false);
underTest.addRuleExclusionPatternForComponent(component, pattern);
assertThat(underTest.accept(issue, chain)).isFalse();
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class IgnoreIssuesFilterTest method shouldRejectIfRulePatternMatchesDeprecatedRule.
@Test
public void shouldRejectIfRulePatternMatchesDeprecatedRule() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder().setRuleKey(ruleKey).setDeprecatedKeys(singleton(RuleKey.of("repo", "rule"))).build()));
IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
WildcardPattern pattern = WildcardPattern.create("repo:rule");
underTest.addRuleExclusionPatternForComponent(component, pattern);
assertThat(underTest.accept(issue, chain)).isFalse();
verify(analysisWarnings).addUnique("A multicriteria issue exclusion uses the rule key 'repo:rule' that has been changed. The pattern should be updated to 'foo:bar'");
assertThat(logTester.logs()).contains("A multicriteria issue exclusion uses the rule key 'repo:rule' that has been changed. The pattern should be updated to 'foo:bar'");
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesButNotPath.
@Test
public void shouldRefuseIssueIfRuleMatchesButNotPath() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
String path = "org/sonar/api/Issue.java";
String componentKey = "org.sonar.api.Issue";
RuleKey ruleKey = RuleKey.of("repo", "rule");
when(issue.ruleKey()).thenReturn(ruleKey);
when(issue.componentKey()).thenReturn(componentKey);
IssuePattern matching = new IssuePattern("no match", "repo:rule");
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(issue.getComponent()).thenReturn(createComponentWithPath(path));
ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
assertThat(ignoreFilter.accept(issue, chain)).isFalse();
verifyNoInteractions(chain, analysisWarnings);
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldPassToChainIfRuleDoesNotMatch.
@Test
public void shouldPassToChainIfRuleDoesNotMatch() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
RuleKey ruleKey = RuleKey.of("repo", "rule");
when(issue.ruleKey()).thenReturn(ruleKey);
IssuePattern matching = new IssuePattern("**", "unknown");
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
assertThat(ignoreFilter.accept(issue, chain)).isTrue();
verify(chain).accept(issue);
}
Aggregations