@Test
@UseDataProvider("allResolutionsBeforeClosing")
public void automatically_reopen_closed_issue_to_previous_resolution_of_closing_the_issue_if_most_recent_of_all_resolution_changes(String resolutionBeforeClosed) {
String randomPreviousStatus = ALL_STATUSES_LEADING_TO_CLOSED[new Random().nextInt(ALL_STATUSES_LEADING_TO_CLOSED.length)];
DefaultIssue[] issues = Arrays.stream(SUPPORTED_RESOLUTIONS_FOR_UNCLOSING)
.map(resolution -> {
DefaultIssue issue = newClosedIssue(resolution);
Date now = new Date();
addResolutionChange(issue, addDays(now, -60), null, RESOLUTION_FALSE_POSITIVE);
addResolutionChange(issue, addDays(now, -10), RESOLUTION_FALSE_POSITIVE, resolutionBeforeClosed);
addResolutionAndStatusChange(issue, now, randomPreviousStatus, STATUS_CLOSED, resolutionBeforeClosed, resolution);
return issue;
})
.toArray(DefaultIssue[]::new);
Date now = new Date();
workflow.start();
Arrays.stream(issues).forEach(issue -> {
workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now));
assertThat(issue.status()).isEqualTo(randomPreviousStatus);
assertThat(issue.resolution()).isEqualTo(resolutionBeforeClosed);
assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND));
assertThat(issue.closeDate()).isNull();
assertThat(issue.isChanged()).isTrue();
});
}