/** * Determines how two dates compare up to no more than the specified * most significant field. * * @param date1 the first date, not <code>null</code> * @param date2 the second date, not <code>null</code> * @param field the field from <code>Calendar</code> * @return a negative integer, zero, or a positive integer as the first * date is less than, equal to, or greater than the second. * @throws IllegalArgumentException if any argument is <code>null</code> * @see #truncate(Calendar, int) * @see #truncatedCompareTo(Date, Date, int) * @since 2.6 */ public static int truncatedCompareTo(Date date1, Date date2, int field) { Date truncatedDate1 = truncate(date1, field); Date truncatedDate2 = truncate(date2, field); return truncatedDate1.compareTo(truncatedDate2); }
/** * Determines how two calendars compare up to no more than the specified * most significant field. * * @param cal1 the first calendar, not <code>null</code> * @param cal2 the second calendar, not <code>null</code> * @param field the field from <code>Calendar</code> * @return a negative integer, zero, or a positive integer as the first * calendar is less than, equal to, or greater than the second. * @throws IllegalArgumentException if any argument is <code>null</code> * @see #truncate(Calendar, int) * @see #truncatedCompareTo(Date, Date, int) * @since 2.6 */ public static int truncatedCompareTo(Calendar cal1, Calendar cal2, int field) { Calendar truncatedCal1 = truncate(cal1, field); Calendar truncatedCal2 = truncate(cal2, field); return truncatedCal1.getTime().compareTo(truncatedCal2.getTime()); }
@Test public void setIssueMoved_changes_componentUuid_adds_a_change() { String oldComponentUuid = "a"; String newComponentUuid = "b"; issue.setComponentUuid(oldComponentUuid); underTest.setIssueMoved(issue, newComponentUuid, context); assertThat(issue.changes()).hasSize(1); FieldDiffs fieldDiffs = issue.changes().get(0); assertThat(fieldDiffs.creationDate()).isEqualTo(context.date()); assertThat(fieldDiffs.diffs()).hasSize(1); Map.Entry<String, FieldDiffs.Diff> entry = fieldDiffs.diffs().entrySet().iterator().next(); assertThat(entry.getKey()).isEqualTo("file"); assertThat(entry.getValue().oldValue()).isEqualTo(oldComponentUuid); assertThat(entry.getValue().newValue()).isEqualTo(newComponentUuid); assertThat(issue.componentUuid()).isEqualTo(newComponentUuid); assertThat(issue.isChanged()).isTrue(); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(context.date(), Calendar.SECOND)); } }
@Test @UseDataProvider("allResolutionsBeforeClosing") public void automatically_reopen_closed_issue_to_previous_resolution_from_changelog(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); addResolutionAndStatusChange(issue, new Date(), 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(); }); }
@Test @UseDataProvider("allStatusesLeadingToClosed") public void automatically_reopen_closed_issue_to_its_previous_status_from_changelog(String previousStatus) { DefaultIssue[] issues = Arrays.stream(SUPPORTED_RESOLUTIONS_FOR_UNCLOSING) .map(resolution -> { DefaultIssue issue = newClosedIssue(resolution); setStatusPreviousToClosed(issue, previousStatus); 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(previousStatus); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); assertThat(issue.closeDate()).isNull(); assertThat(issue.isChanged()).isTrue(); }); }
@Test public void automatically_reopen_closed_issue_to_no_resolution_if_no_previous_one_changelog() { 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); setStatusPreviousToClosed(issue, randomPreviousStatus); 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()).isNull(); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); assertThat(issue.closeDate()).isNull(); assertThat(issue.isChanged()).isTrue(); }); }
@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(); }); }
@Test @UseDataProvider("allStatusesLeadingToClosed") public void automatically_reopen_closed_issue_to_most_recent_previous_status_from_changelog(String previousStatus) { DefaultIssue[] issues = Arrays.stream(SUPPORTED_RESOLUTIONS_FOR_UNCLOSING) .map(resolution -> { DefaultIssue issue = newClosedIssue(resolution); Date now = new Date(); addStatusChange(issue, addDays(now, -60), STATUS_OPEN, STATUS_CONFIRMED); addStatusChange(issue, addDays(now, -10), STATUS_CONFIRMED, previousStatus); setStatusPreviousToClosed(issue, previousStatus); 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(previousStatus); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); assertThat(issue.closeDate()).isNull(); assertThat(issue.isChanged()).isTrue(); }); }
@Test public void close_open_dead_issue() { workflow.start(); DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setResolution(null) .setStatus(STATUS_OPEN) .setNew(false) .setBeingClosed(true); Date now = new Date(); workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now)); assertThat(issue.resolution()).isEqualTo(RESOLUTION_FIXED); assertThat(issue.status()).isEqualTo(STATUS_CLOSED); assertThat(issue.closeDate()).isNotNull(); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); }
@Test public void close_reopened_dead_issue() { workflow.start(); DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setResolution(null) .setStatus(STATUS_REOPENED) .setNew(false) .setBeingClosed(true); Date now = new Date(); workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now)); assertThat(issue.resolution()).isEqualTo(RESOLUTION_FIXED); assertThat(issue.status()).isEqualTo(STATUS_CLOSED); assertThat(issue.closeDate()).isNotNull(); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); }
@Test public void close_confirmed_dead_issue() { workflow.start(); DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setResolution(null) .setStatus(STATUS_CONFIRMED) .setNew(false) .setBeingClosed(true); Date now = new Date(); workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now)); assertThat(issue.resolution()).isEqualTo(RESOLUTION_FIXED); assertThat(issue.status()).isEqualTo(STATUS_CLOSED); assertThat(issue.closeDate()).isNotNull(); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); }
@Test public void automatically_close_resolved_issue() { workflow.start(); DefaultIssue issue = new DefaultIssue() .setKey("ABCDE") .setRuleKey(RuleKey.of("js", "S001")) .setResolution(RESOLUTION_FIXED) .setStatus(STATUS_RESOLVED) .setNew(false) .setBeingClosed(true); Date now = new Date(); workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now)); assertThat(issue.resolution()).isEqualTo(RESOLUTION_FIXED); assertThat(issue.status()).isEqualTo(STATUS_CLOSED); assertThat(issue.closeDate()).isNotNull(); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(now, Calendar.SECOND)); }
assertThat(issue.attribute("key")).isEqualTo("value"); assertThat(issue.authorLogin()).isEqualTo("pierre"); assertThat(issue.creationDate()).isEqualTo(DateUtils.truncate(createdAt, Calendar.SECOND)); assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(updatedAt, Calendar.SECOND)); assertThat(issue.closeDate()).isEqualTo(DateUtils.truncate(closedAt, Calendar.SECOND)); assertThat(issue.isNew()).isFalse();
public DefaultIssue setCreationDate(Date d) { // d is not marked as Nullable but we still allow null parameter for unit testing. this.creationDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null); return this; }
/** * 获取天开始的瞬间时间点 * * @param d * 时间点 * @return 仅日期 * @see #truncate(Date) */ public static Date dayBegin(Date d) { return org.apache.commons.lang.time.DateUtils.truncate(d, Calendar.DATE); }
/** * 去除 天以后的部分,仅保留年和月,实际上就是当月的开始时间 * * @param d * 时间 * @return 时间的年和月部分,指向该月的开始 */ public static final Date monthBegin(Date date) { return org.apache.commons.lang.time.DateUtils.truncate(date, Calendar.MONTH); }
/** * Get today. * * @return today */ public static Date today() { return DateUtils.truncate(new Date(), Calendar.DATE); }
public DefaultIssue setUpdateDate(@Nullable Date d) { this.updateDate = (d != null ? DateUtils.truncate(d, Calendar.SECOND) : null); return this; }