Search in sources :

Example 1 with FilterableIssue

use of org.sonar.api.scan.issue.filter.FilterableIssue in project sonarqube by SonarSource.

the class NoSonarFilterTest method should_accept_issues_on_no_sonar_rules.

@Test
public void should_accept_issues_on_no_sonar_rules() {
    // The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !!
    FilterableIssue issue = mock(FilterableIssue.class);
    when(issue.componentKey()).thenReturn("struts:org.apache.Action");
    when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "NoSonarCheck"));
    Set<Integer> noSonarLines = ImmutableSet.of(31, 55);
    filter.addComponent("struts:org.apache.Action", noSonarLines);
    when(issue.line()).thenReturn(31);
    assertThat(filter.accept(issue, chain)).isTrue();
    when(issue.line()).thenReturn(222);
    assertThat(filter.accept(issue, chain)).isTrue();
    verify(chain, times(2)).accept(issue);
}
Also used : FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue) Test(org.junit.Test)

Example 2 with FilterableIssue

use of org.sonar.api.scan.issue.filter.FilterableIssue in project sonarqube by SonarSource.

the class NoSonarFilterTest method should_ignore_lines_commented_with_nosonar.

@Test
public void should_ignore_lines_commented_with_nosonar() {
    FilterableIssue issue = mock(FilterableIssue.class);
    when(issue.componentKey()).thenReturn("struts:org.apache.Action");
    when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "AvoidCycles"));
    Set<Integer> noSonarLines = ImmutableSet.of(31, 55);
    filter.addComponent("struts:org.apache.Action", noSonarLines);
    // issue on file
    when(issue.line()).thenReturn(null);
    assertThat(filter.accept(issue, chain)).isTrue();
    // issue on lines
    when(issue.line()).thenReturn(31);
    assertThat(filter.accept(issue, chain)).isFalse();
    when(issue.line()).thenReturn(222);
    assertThat(filter.accept(issue, chain)).isTrue();
    verify(chain, times(2)).accept(issue);
}
Also used : FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue) Test(org.junit.Test)

Example 3 with FilterableIssue

use of org.sonar.api.scan.issue.filter.FilterableIssue in project sonarqube by SonarSource.

the class IssueFilters method accept.

public boolean accept(String componentKey, ScannerReport.Issue rawIssue) {
    IssueFilterChain filterChain = new DefaultIssueFilterChain(filters);
    FilterableIssue fIssue = new DefaultFilterableIssue(module, projectAnalysisInfo, rawIssue, componentKey);
    if (filterChain.accept(fIssue)) {
        return acceptDeprecated(componentKey, rawIssue);
    }
    return false;
}
Also used : IssueFilterChain(org.sonar.api.scan.issue.filter.IssueFilterChain) FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue)

Example 4 with FilterableIssue

use of org.sonar.api.scan.issue.filter.FilterableIssue in project sonarqube by SonarSource.

the class PatternMatcherTest method create.

private FilterableIssue create(Rule rule, String component, Integer line) {
    FilterableIssue mockIssue = mock(FilterableIssue.class);
    RuleKey ruleKey = null;
    if (rule != null) {
        ruleKey = rule.ruleKey();
    }
    when(mockIssue.ruleKey()).thenReturn(ruleKey);
    when(mockIssue.componentKey()).thenReturn(component);
    when(mockIssue.line()).thenReturn(line);
    return mockIssue;
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue)

Example 5 with FilterableIssue

use of org.sonar.api.scan.issue.filter.FilterableIssue in project sonarqube by SonarSource.

the class IssuePatternTest method create.

private FilterableIssue create(Rule rule, String component, Integer line) {
    FilterableIssue mockIssue = mock(FilterableIssue.class);
    RuleKey ruleKey = null;
    if (rule != null) {
        ruleKey = rule.ruleKey();
    }
    when(mockIssue.ruleKey()).thenReturn(ruleKey);
    when(mockIssue.componentKey()).thenReturn(component);
    when(mockIssue.line()).thenReturn(line);
    return mockIssue;
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue)

Aggregations

FilterableIssue (org.sonar.api.scan.issue.filter.FilterableIssue)5 Test (org.junit.Test)2 RuleKey (org.sonar.api.rule.RuleKey)2 IssueFilterChain (org.sonar.api.scan.issue.filter.IssueFilterChain)1