use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldAcceptIssueIfFullyMatched.
@Test
public void shouldAcceptIssueIfFullyMatched() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
String path = "org/sonar/api/Issue.java";
RuleKey ruleKey = RuleKey.of("repo", "rule");
when(issue.ruleKey()).thenReturn(ruleKey);
IssuePattern matching = new IssuePattern(path, ruleKey.toString());
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();
verifyNoInteractions(chain);
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesAndPathUnknown.
@Test
public void shouldRefuseIssueIfRuleMatchesAndPathUnknown() {
String rule = "rule";
String path = "org/sonar/api/Issue.java";
String componentKey = "org.sonar.api.Issue";
RuleKey ruleKey = mock(RuleKey.class);
when(ruleKey.toString()).thenReturn(rule);
when(issue.ruleKey()).thenReturn(ruleKey);
when(issue.componentKey()).thenReturn(componentKey);
IssuePattern matching = mock(IssuePattern.class);
WildcardPattern rulePattern = mock(WildcardPattern.class);
when(matching.getRulePattern()).thenReturn(rulePattern);
when(rulePattern.match(rule)).thenReturn(true);
WildcardPattern pathPattern = mock(WildcardPattern.class);
when(matching.getResourcePattern()).thenReturn(pathPattern);
when(pathPattern.match(path)).thenReturn(false);
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(null);
assertThat(ignoreFilter.accept(issue, chain)).isFalse();
verifyZeroInteractions(chain);
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class PatternDecoderTest method shouldReadStarPatterns.
@Test
public void shouldReadStarPatterns() {
IssuePattern pattern = decoder.decodeLine("*;*;*");
assertThat(pattern.getResourcePattern().toString()).isEqualTo("*");
assertThat(pattern.getRulePattern().toString()).isEqualTo("*");
assertThat(pattern.isCheckLines()).isFalse();
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class PatternDecoderTest method shouldReadBlockPattern.
@Test
public void shouldReadBlockPattern() {
IssuePattern pattern = decoder.decodeLine("SONAR-OFF;SONAR-ON");
assertThat(pattern.getResourcePattern()).isNull();
assertThat(pattern.getBeginBlockRegexp()).isEqualTo("SONAR-OFF");
assertThat(pattern.getEndBlockRegexp()).isEqualTo("SONAR-ON");
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class PatternDecoderTest method shouldAcceptEmptyEndBlockRegexp.
@Test
public void shouldAcceptEmptyEndBlockRegexp() {
IssuePattern pattern = decoder.decodeLine("OFF;");
assertThat(pattern.getResourcePattern()).isNull();
assertThat(pattern.getBeginBlockRegexp()).isEqualTo("OFF");
assertThat(pattern.getEndBlockRegexp()).isEmpty();
}
Aggregations