Search in sources :

Example 1 with DefaultIssue

use of org.sonar.api.batch.sensor.issue.internal.DefaultIssue in project sonarqube by SonarSource.

the class ModuleIssuesTest method filter_issue.

@Test
public void filter_issue() {
    ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
    activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate();
    initModuleIssues();
    DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("")).forRule(SQUID_RULE_KEY);
    when(filters.accept(anyString(), any(ScannerReport.Issue.class))).thenReturn(false);
    boolean added = moduleIssues.initAndAddIssue(issue);
    assertThat(added).isFalse();
    verifyZeroInteractions(reportPublisher);
}
Also used : DefaultIssueLocation(org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) Test(org.junit.Test)

Example 2 with DefaultIssue

use of org.sonar.api.batch.sensor.issue.internal.DefaultIssue in project sonarqube by SonarSource.

the class ModuleIssuesTest method ignore_null_rule_of_active_rule.

@Test
public void ignore_null_rule_of_active_rule() {
    ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
    activeRulesBuilder.create(SQUID_RULE_KEY).activate();
    initModuleIssues();
    DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo")).forRule(SQUID_RULE_KEY);
    boolean added = moduleIssues.initAndAddIssue(issue);
    assertThat(added).isFalse();
    verifyZeroInteractions(reportPublisher);
}
Also used : DefaultIssueLocation(org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) Test(org.junit.Test)

Example 3 with DefaultIssue

use of org.sonar.api.batch.sensor.issue.internal.DefaultIssue in project sonarqube by SonarSource.

the class ModuleIssuesTest method ignore_null_active_rule.

@Test
public void ignore_null_active_rule() {
    ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
    initModuleIssues();
    DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo")).forRule(SQUID_RULE_KEY);
    boolean added = moduleIssues.initAndAddIssue(issue);
    assertThat(added).isFalse();
    verifyZeroInteractions(reportPublisher);
}
Also used : DefaultIssueLocation(org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) Test(org.junit.Test)

Example 4 with DefaultIssue

use of org.sonar.api.batch.sensor.issue.internal.DefaultIssue in project sonarqube by SonarSource.

the class ModuleIssuesTest method fail_if_rule_has_no_name_and_issue_has_no_message.

@Test
public void fail_if_rule_has_no_name_and_issue_has_no_message() {
    ruleBuilder.add(SQUID_RULE_KEY).setInternalKey(SQUID_RULE_KEY.rule());
    initModuleIssues();
    DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("")).forRule(SQUID_RULE_KEY);
    try {
        moduleIssues.initAndAddIssue(issue);
        fail();
    } catch (Exception e) {
        assertThat(e).isInstanceOf(MessageException.class);
    }
    verifyZeroInteractions(reportPublisher);
}
Also used : DefaultIssueLocation(org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation) MessageException(org.sonar.api.utils.MessageException) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) MessageException(org.sonar.api.utils.MessageException) Test(org.junit.Test)

Example 5 with DefaultIssue

use of org.sonar.api.batch.sensor.issue.internal.DefaultIssue in project sonarqube by SonarSource.

the class ModuleIssuesTest method add_issue_to_cache.

@Test
public void add_issue_to_cache() {
    ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
    activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate();
    initModuleIssues();
    DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo")).forRule(SQUID_RULE_KEY).overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL);
    when(filters.accept(anyString(), any(ScannerReport.Issue.class))).thenReturn(true);
    boolean added = moduleIssues.initAndAddIssue(issue);
    assertThat(added).isTrue();
    ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class);
    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.batchId()), argument.capture());
    assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
}
Also used : DefaultIssueLocation(org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 DefaultIssue (org.sonar.api.batch.sensor.issue.internal.DefaultIssue)8 DefaultIssueLocation (org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation)8 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)3 MessageException (org.sonar.api.utils.MessageException)2