use of org.sonar.core.issue.DefaultIssue in project sonarqube by SonarSource.
the class UpdateConflictResolverTest method severity_changed_by_user_should_be_kept.
@Test
public void severity_changed_by_user_should_be_kept() {
DefaultIssue issue = new DefaultIssue().setKey("ABCDE").setRuleKey(RuleKey.of("squid", "AvoidCycles")).setComponentKey("struts:org.apache.struts.Action").setNew(false).setStatus(Issue.STATUS_OPEN);
// Changed by scan
issue.setSeverity(Severity.BLOCKER);
issue.setManualSeverity(false);
// Issue as seen and changed by end-user
IssueDto dbIssue = new IssueDto().setKee("ABCDE").setStatus(Issue.STATUS_OPEN).setSeverity(Severity.INFO).setManualSeverity(true);
new UpdateConflictResolver().mergeFields(dbIssue, issue);
assertThat(issue.severity()).isEqualTo(Severity.INFO);
assertThat(issue.manualSeverity()).isTrue();
}
use of org.sonar.core.issue.DefaultIssue in project sonarqube by SonarSource.
the class UpdateConflictResolverTest method should_reload_issue_and_resolve_conflict.
@Test
public void should_reload_issue_and_resolve_conflict() {
DefaultIssue issue = new DefaultIssue().setKey("ABCDE").setType(RuleType.CODE_SMELL).setRuleKey(RuleKey.of("squid", "AvoidCycles")).setComponentKey("struts:org.apache.struts.Action").setNew(false).setStatus(Issue.STATUS_OPEN);
// Issue as seen and changed by end-user
IssueMapper mapper = mock(IssueMapper.class);
when(mapper.selectByKey("ABCDE")).thenReturn(new IssueDto().setKee("ABCDE").setType(RuleType.CODE_SMELL).setRuleId(10).setRuleKey("squid", "AvoidCycles").setComponentKey("struts:org.apache.struts.Action").setLine(10).setStatus(Issue.STATUS_OPEN).setAssignee("arthur"));
new UpdateConflictResolver().resolve(issue, mapper);
ArgumentCaptor<IssueDto> argument = ArgumentCaptor.forClass(IssueDto.class);
verify(mapper).update(argument.capture());
IssueDto updatedIssue = argument.getValue();
assertThat(updatedIssue.getKee()).isEqualTo("ABCDE");
assertThat(updatedIssue.getAssignee()).isEqualTo("arthur");
}
use of org.sonar.core.issue.DefaultIssue in project sonarqube by SonarSource.
the class CommentDensityRuleTest method issue_if_not_enough_comments.
@Test
public void issue_if_not_enough_comments() {
activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, ImmutableMap.of(CommonRuleKeys.INSUFFICIENT_COMMENT_DENSITY_PROPERTY, "25"), 1_000L));
measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_DENSITY_KEY, Measure.newMeasureBuilder().create(10.0, 1));
measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.COMMENT_LINES_KEY, Measure.newMeasureBuilder().create(40));
measureRepository.addRawMeasure(FILE.getReportAttributes().getRef(), CoreMetrics.NCLOC_KEY, Measure.newMeasureBuilder().create(360));
DefaultIssue issue = underTest.processFile(FILE, "java");
assertThat(issue.ruleKey()).isEqualTo(RULE_KEY);
assertThat(issue.severity()).isEqualTo(Severity.CRITICAL);
// min_comments = (min_percent * ncloc) / (1 - min_percent)
// -> threshold of 25% for 360 ncloc is 120 comment lines. 40 are already written.
assertThat(issue.effortToFix()).isEqualTo(120.0 - 40.0);
assertThat(issue.message()).isEqualTo("80 more comment lines need to be written to reach the minimum threshold of 25.0% comment density.");
}
use of org.sonar.core.issue.DefaultIssue in project sonarqube by SonarSource.
the class TestErrorRuleTest method no_issues_if_test_measures_are_absent.
@Test
public void no_issues_if_test_measures_are_absent() throws Exception {
activeRuleHolder.put(new ActiveRule(RULE_KEY, Severity.CRITICAL, Collections.<String, String>emptyMap(), 1_000L));
DefaultIssue issue = underTest.processFile(FILE, "java");
assertThat(issue).isNull();
}
use of org.sonar.core.issue.DefaultIssue in project sonarqube by SonarSource.
the class MovedIssueVisitorTest method onIssue_throws_ISE_if_issue_has_different_component_uuid_from_component_but_it_is_not_the_one_of_original_file.
@Test
public void onIssue_throws_ISE_if_issue_has_different_component_uuid_from_component_but_it_is_not_the_one_of_original_file() {
DefaultIssue issue = mockIssue("other component uuid");
when(issue.toString()).thenReturn("[bad issue, bad!]");
when(movedFilesRepository.getOriginalFile(FILE)).thenReturn(Optional.of(new MovedFilesRepository.OriginalFile(6451, "original uuid", "original key")));
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Issue [bad issue, bad!] doesn't belong to file original uuid registered as original " + "file of current file ReportComponent{ref=1, key='key_1', type=FILE}");
underTest.onIssue(FILE, issue);
}
Aggregations