@Test public void load_issues_from_report() throws Exception { when(issueFilter.accept(any(DefaultIssue.class), eq(FILE))).thenReturn(true); fileSourceRepository.addLines(FILE_REF, "line 1;", "line 2;"); ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder() .setTextRange(TextRange.newBuilder().setStartLine(2).build()) .setMsg("the message") .setRuleRepository("java") .setRuleKey("S001") .setSeverity(Constants.Severity.BLOCKER) .setGap(3.14) .build(); reportReader.putIssues(FILE.getReportAttributes().getRef(), asList(reportIssue)); Input<DefaultIssue> input = underTest.create(FILE); Collection<DefaultIssue> issues = input.getIssues(); assertThat(issues).hasSize(1); DefaultIssue issue = Iterators.getOnlyElement(issues.iterator()); // fields set by analysis report assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("java", "S001")); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); assertThat(issue.line()).isEqualTo(2); assertThat(issue.effortToFix()).isEqualTo(3.14); assertThat(issue.gap()).isEqualTo(3.14); assertThat(issue.message()).isEqualTo("the message"); // fields set by compute engine assertThat(issue.checksum()).isEqualTo(input.getLineHashSequence().getHashForLine(2)); assertThat(issue.tags()).isEmpty(); assertInitializedIssue(issue); }
@Test public void ignore_issue_from_common_rule() throws Exception { when(issueFilter.accept(any(DefaultIssue.class), eq(FILE))).thenReturn(false); fileSourceRepository.addLines(FILE_REF, "line 1;", "line 2;"); DefaultIssue ceIssue = new DefaultIssue() .setRuleKey( RuleKey.of(CommonRuleKeys.commonRepositoryForLang("java"), "InsufficientCoverage")) .setMessage("not enough coverage") .setGap(10.0); when(commonRuleEngine.process(FILE)).thenReturn(asList(ceIssue)); Input<DefaultIssue> input = underTest.create(FILE); assertThat(input.getIssues()).isEmpty(); }
@Test public void load_issues_of_compute_engine_common_rules() throws Exception { when(issueFilter.accept(any(DefaultIssue.class), eq(FILE))).thenReturn(true); fileSourceRepository.addLines(FILE_REF, "line 1;", "line 2;"); DefaultIssue ceIssue = new DefaultIssue() .setRuleKey( RuleKey.of(CommonRuleKeys.commonRepositoryForLang("java"), "InsufficientCoverage")) .setMessage("not enough coverage") .setGap(10.0); when(commonRuleEngine.process(FILE)).thenReturn(asList(ceIssue)); Input<DefaultIssue> input = underTest.create(FILE); assertThat(input.getIssues()).containsOnly(ceIssue); assertInitializedIssue(input.getIssues().iterator().next()); }
@Test public void ignore_issue_from_report() throws Exception { when(issueFilter.accept(any(DefaultIssue.class), eq(FILE))).thenReturn(false); fileSourceRepository.addLines(FILE_REF, "line 1;", "line 2;"); ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder() .setTextRange(TextRange.newBuilder().setStartLine(2).build()) .setMsg("the message") .setRuleRepository("java") .setRuleKey("S001") .setSeverity(Constants.Severity.BLOCKER) .setGap(3.14) .build(); reportReader.putIssues(FILE.getReportAttributes().getRef(), asList(reportIssue)); Input<DefaultIssue> input = underTest.create(FILE); Collection<DefaultIssue> issues = input.getIssues(); assertThat(issues).isEmpty(); }