use of org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT in project sonarqube by SonarSource.
the class NotificationFactoryTest method newIssuesChangesNotification_maps_all_issues.
@Test
public void newIssuesChangesNotification_maps_all_issues() {
Set<DefaultIssue> issues = IntStream.range(0, 3 + new Random().nextInt(5)).mapToObj(i -> new DefaultIssue().setRuleKey(RuleKey.of("repo_" + i, "rule_" + i)).setKey("issue_key_" + i).setStatus("status_" + i)).collect(Collectors.toSet());
ReportComponent project = ReportComponent.builder(PROJECT, 1).build();
long analysisDate = new Random().nextLong();
issues.stream().map(DefaultIssue::ruleKey).forEach(ruleKey -> ruleRepository.add(ruleKey));
treeRootHolder.setRoot(project);
analysisMetadata.setAnalysisDate(analysisDate);
analysisMetadata.setBranch(newNonMainBranch(BranchType.BRANCH, randomAlphabetic(12)));
IssuesChangesNotification expected = mock(IssuesChangesNotification.class);
when(issuesChangesSerializer.serialize(any(IssuesChangesNotificationBuilder.class))).thenReturn(expected);
IssuesChangesNotification notification = underTest.newIssuesChangesNotification(issues, emptyMap());
assertThat(notification).isSameAs(expected);
IssuesChangesNotificationBuilder builder = verifyAndCaptureIssueChangeNotificationBuilder();
assertThat(builder.getIssues()).hasSize(issues.size());
Map<String, ChangedIssue> changedIssuesByKey = builder.getIssues().stream().collect(uniqueIndex(ChangedIssue::getKey));
issues.forEach(issue -> {
ChangedIssue changedIssue = changedIssuesByKey.get(issue.key());
assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
assertThat(changedIssue.getNewResolution()).isEmpty();
assertThat(changedIssue.getAssignee()).isEmpty();
assertThat(changedIssue.getRule().getKey()).isEqualTo(issue.ruleKey());
assertThat(changedIssue.getRule().getName()).isEqualTo(ruleRepository.getByKey(issue.ruleKey()).getName());
});
}
Aggregations