Search in sources :

Example 6 with IssuePattern

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);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Example 7 with IssuePattern

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);
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) WildcardPattern(org.sonar.api.utils.WildcardPattern) Test(org.junit.Test)

Example 8 with IssuePattern

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();
}
Also used : IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Example 9 with IssuePattern

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");
}
Also used : IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Example 10 with IssuePattern

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();
}
Also used : IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Aggregations

IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)17 Test (org.junit.Test)16 RuleKey (org.sonar.api.rule.RuleKey)6 DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)5 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 InputComponent (org.sonar.api.batch.fs.InputComponent)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 AnalysisWarnings (org.sonar.api.notifications.AnalysisWarnings)1 WildcardPattern (org.sonar.api.utils.WildcardPattern)1 DefaultFilterableIssue (org.sonar.scanner.issue.DefaultFilterableIssue)1 LineRange (org.sonar.scanner.issue.ignore.pattern.LineRange)1