/** * Returns true if both date are in the same year, month and day of month, false otherwise. * @param actual the actual date. expected not be null * @param other the other date. expected not be null * @return true if both date are in the same year, month and day of month, false otherwise */ private static boolean areInSameDayOfMonth(Date actual, Date other) { return areInSameMonth(actual, other) && dayOfMonthOf(actual) == dayOfMonthOf(other); }
protected String toStringOf(Calendar c) { return DateUtil.formatAsDatetime(c); }
protected String toStringOf(Date d) { return DateUtil.formatAsDatetimeWithMs(d); }
/** * Creates a new <code>{@link ShouldBeAfter}</code>. * @param actual the actual value in the failed assertion. * @param year the year to compare the actual date's year to. * @return the created {@code ErrorMessageFactory}. */ public static ErrorMessageFactory shouldBeAfter(Date actual, int year) { Date januaryTheFirstOfGivenYear = parse(year + "-01-01"); return new ShouldBeAfter(actual, januaryTheFirstOfGivenYear, StandardComparisonStrategy.instance()); }
private ShouldBeInSameHourWindow(Date actual, Date other) { super("%nExpecting:%n <%s>%nto be close to:%n <%s>%nby less than one hour (strictly) but difference was: " + formatTimeDifference(actual, other), actual, other); } }
/** * Returns true if both date are in the same year, month, day of month and hour, false otherwise. * @param actual the actual date. expected not be null * @param other the other date. expected not be null * @return true if both date are in the same year, month, day of month and hour, false otherwise. */ private static boolean areInSameHour(Date actual, Date other) { return areInSameDayOfMonth(actual, other) && hourOfDayOf(actual) == hourOfDayOf(other); }
/** * Returns true if both date are in the same year and month, false otherwise. * @param actual the actual date. expected not be null * @param other the other date. expected not be null * @return true if both date are in the same year and month, false otherwise */ private static boolean areInSameMonth(Date actual, Date other) { return areInSameYear(actual, other) && monthOf(actual) == monthOf(other); }
/** * Returns true if both date are in the same year, month, day of month, hour and minute, false otherwise. * @param actual the actual date. expected not be null * @param other the other date. expected not be null * @return true if both date are in the same year, month, day of month, hour and minute, false otherwise. */ private static boolean areInSameMinute(Date actual, Date other) { return areInSameHour(actual, other) && minuteOf(actual) == minuteOf(other); }
/** * Verifies that the actual {@code Date} day of week is equal to the given day of week. * @param info contains information about the assertion. * @param actual the "actual" {@code Date}. * @param dayOfWeek the day of week to compare actual day of week to, see {@link Calendar#DAY_OF_WEEK} for valid values * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the actual {@code Date} week is not equal to the given day of week. */ public void assertHasDayOfWeek(AssertionInfo info, Date actual, int dayOfWeek) { assertNotNull(info, actual); if (dayOfWeekOf(actual) != dayOfWeek) throw failures.failure(info, shouldHaveDateField(actual, "day of week", dayOfWeek)); }
/** * Verifies that the actual {@code Date} millisecond is equal to the given millisecond. * @param info contains information about the assertion. * @param actual the "actual" {@code Date}. * @param millisecond the millisecond to compare actual millisecond to * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the actual {@code Date} millisecond is not equal to the given millisecond. */ public void assertHasMillisecond(AssertionInfo info, Date actual, int millisecond) { assertNotNull(info, actual); if (millisecondOf(actual) != millisecond) throw failures.failure(info, shouldHaveDateField(actual, "millisecond", millisecond)); }
/** * Creates a new <code>{@link ShouldBeAfter}</code>. * @param actual the actual value in the failed assertion. * @param year the year to compare the actual date's year to. * @return the created {@code ErrorMessageFactory}. */ public static ErrorMessageFactory shouldBeAfter(Date actual, int year) { Date januaryTheFirstOfGivenYear = parse(year + "-01-01"); return new ShouldBeAfter(actual, januaryTheFirstOfGivenYear, StandardComparisonStrategy.instance()); }
private ShouldBeInSameMinuteWindow(Date actual, Date other) { super("%nExpecting:%n <%s>%nto be close to:%n <%s>%nby less than one minute (strictly) but difference was: " + formatTimeDifference(actual, other), actual, other); } }
/** * Returns true if both date are in the same year, month, day of month and hour, false otherwise. * @param actual the actual date. expected not be null * @param other the other date. expected not be null * @return true if both date are in the same year, month, day of month and hour, false otherwise. */ private static boolean areInSameHour(Date actual, Date other) { return areInSameDayOfMonth(actual, other) && hourOfDayOf(actual) == hourOfDayOf(other); }
/** * Returns true if both date are in the same year and month, false otherwise. * @param actual the actual date. expected not be null * @param other the other date. expected not be null * @return true if both date are in the same year and month, false otherwise */ private static boolean areInSameMonth(Date actual, Date other) { return areInSameYear(actual, other) && monthOf(actual) == monthOf(other); }
/** * Returns true if both date are in the same year, month, day of month, hour and minute, false otherwise. * @param actual the actual date. expected not be null * @param other the other date. expected not be null * @return true if both date are in the same year, month, day of month, hour and minute, false otherwise. */ private static boolean areInSameMinute(Date actual, Date other) { return areInSameHour(actual, other) && minuteOf(actual) == minuteOf(other); }
/** * Verifies that the actual {@code Date} day of week is equal to the given day of week. * @param info contains information about the assertion. * @param actual the "actual" {@code Date}. * @param dayOfWeek the day of week to compare actual day of week to, see {@link Calendar#DAY_OF_WEEK} for valid values * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the actual {@code Date} week is not equal to the given day of week. */ public void assertHasDayOfWeek(AssertionInfo info, Date actual, int dayOfWeek) { assertNotNull(info, actual); if (dayOfWeekOf(actual) != dayOfWeek) throw failures.failure(info, shouldHaveDateField(actual, "day of week", dayOfWeek)); }
/** * Verifies that the actual {@code Date} millisecond is equal to the given millisecond. * @param info contains information about the assertion. * @param actual the "actual" {@code Date}. * @param millisecond the millisecond to compare actual millisecond to * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the actual {@code Date} millisecond is not equal to the given millisecond. */ public void assertHasMillisecond(AssertionInfo info, Date actual, int millisecond) { assertNotNull(info, actual); if (millisecondOf(actual) != millisecond) throw failures.failure(info, shouldHaveDateField(actual, "millisecond", millisecond)); }
@Test public void getUserProfileReturnsCreationDate() { UserRepresentation userRepresentation = new UserRepresentation(); Date creationDate = DateUtil.parse("2018-01-31"); userRepresentation.setCreatedTimestamp(creationDate.getTime()); userRepresentation.setEmail("davy.van.roy@gmail.com"); when(keycloakRepository.getUser("davy")).thenReturn(userRepresentation); when(keycloakRepository.getUserIdentities("davy")).thenReturn(Stream.empty()); UserProfile userProfile = profileService.getUserProfile(() -> "davy"); assertThat(userProfile.getCreatedAt()).isEqualTo(creationDate.getTime()); }
private ShouldBeInSameSecondWindow(Date actual, Date other) { super("%nExpecting:%n <%s>%nto be close to:%n <%s>%nby less than one second (strictly) but difference was: " + formatTimeDifference(actual, other), actual, other); }
/** * Verifies that the actual {@code Date} hour od day is equal to the given hour of day (24-hour clock). * @param info contains information about the assertion. * @param actual the "actual" {@code Date}. * @param hourOfDay the hour of day to compare actual hour of day to (24-hour clock) * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the actual {@code Date} hour is not equal to the given hour. */ public void assertHasHourOfDay(AssertionInfo info, Date actual, int hourOfDay) { assertNotNull(info, actual); if (hourOfDayOf(actual) != hourOfDay) throw failures.failure(info, shouldHaveDateField(actual, "hour", hourOfDay)); }