Search in sources :

Example 6 with DefaultIssueLocation

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

the class ModuleIssuesTest method use_severity_from_active_rule_if_no_severity_on_issue.

@Test
public void use_severity_from_active_rule_if_no_severity_on_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("Foo")).forRule(SQUID_RULE_KEY);
    when(filters.accept(anyString(), any(ScannerReport.Issue.class))).thenReturn(true);
    moduleIssues.initAndAddIssue(issue);
    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.INFO);
}
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)

Example 7 with DefaultIssueLocation

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

the class ModuleIssuesTest method fail_on_unknown_rule.

@Test
public void fail_on_unknown_rule() {
    initModuleIssues();
    DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo")).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 8 with DefaultIssueLocation

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

the class ModuleIssuesTest method use_rule_name_if_no_message.

@Test
public void use_rule_name_if_no_message() {
    ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
    activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).setName(SQUID_RULE_NAME).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(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().getMsg()).isEqualTo("Avoid Cycle");
}
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