Search in sources :

Example 1 with DeprecatedIssueAdapterForFilter

use of org.sonar.scanner.issue.DeprecatedIssueAdapterForFilter in project sonarqube by SonarSource.

the class DeprecatedIssueAdapterForFilterTest method improve_coverage.

@Test
public void improve_coverage() {
    DefaultInputModule module = new DefaultInputModule(PROJECT_KEY);
    ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
    when(projectAnalysisInfo.analysisDate()).thenReturn(ANALYSIS_DATE);
    DeprecatedIssueAdapterForFilter issue = new DeprecatedIssueAdapterForFilter(module, projectAnalysisInfo, org.sonar.scanner.protocol.output.ScannerReport.Issue.newBuilder().setRuleRepository("repo").setRuleKey("key").setSeverity(Severity.BLOCKER).setMsg("msg").build(), COMPONENT_KEY);
    DeprecatedIssueAdapterForFilter issue2 = new DeprecatedIssueAdapterForFilter(module, projectAnalysisInfo, org.sonar.scanner.protocol.output.ScannerReport.Issue.newBuilder().setRuleRepository("repo").setRuleKey("key").setSeverity(Severity.BLOCKER).setMsg("msg").setTextRange(TextRange.newBuilder().setStartLine(1)).setGap(2.0).build(), COMPONENT_KEY);
    try {
        issue.key();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    assertThat(issue.componentKey()).isEqualTo(COMPONENT_KEY);
    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "key"));
    try {
        issue.language();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    assertThat(issue.severity()).isEqualTo("BLOCKER");
    assertThat(issue.message()).isEqualTo("msg");
    assertThat(issue.line()).isNull();
    assertThat(issue2.line()).isEqualTo(1);
    assertThat(issue.effortToFix()).isNull();
    assertThat(issue2.effortToFix()).isEqualTo(2.0);
    assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
    assertThat(issue.resolution()).isNull();
    try {
        issue.reporter();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    assertThat(issue.assignee()).isNull();
    assertThat(issue.creationDate()).isEqualTo(ANALYSIS_DATE);
    assertThat(issue.updateDate()).isNull();
    assertThat(issue.closeDate()).isNull();
    assertThat(issue.attribute(PROJECT_KEY)).isNull();
    try {
        issue.authorLogin();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    try {
        issue.comments();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    try {
        issue.isNew();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    try {
        issue.debt();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    assertThat(issue.projectKey()).isEqualTo(PROJECT_KEY);
    try {
        issue.projectUuid();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    try {
        issue.componentUuid();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
    try {
        issue.tags();
        fail("Should be unsupported");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
    }
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectAnalysisInfo(org.sonar.scanner.ProjectAnalysisInfo) DeprecatedIssueAdapterForFilter(org.sonar.scanner.issue.DeprecatedIssueAdapterForFilter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)1 DeprecatedIssueAdapterForFilter (org.sonar.scanner.issue.DeprecatedIssueAdapterForFilter)1