Package org.assertj.core.internal
Class Dates
java.lang.Object
org.assertj.core.internal.Dates
Reusable assertions for
Dates.- Author:
- Joel Costigliola, William Delanoue
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassertHasDayOfMonth(AssertionInfo info, Date actual, int dayOfMonth) Verifies that the actualDateday of month is equal to the given day of month.voidassertHasDayOfWeek(AssertionInfo info, Date actual, int dayOfWeek) Verifies that the actualDateday of week is equal to the given day of week.voidassertHasHourOfDay(AssertionInfo info, Date actual, int hourOfDay) Verifies that the actualDatehour od day is equal to the given hour of day (24-hour clock).voidassertHasMillisecond(AssertionInfo info, Date actual, int millisecond) Verifies that the actualDatemillisecond is equal to the given millisecond.voidassertHasMinute(AssertionInfo info, Date actual, int minute) Verifies that the actualDateminute is equal to the given minute.voidassertHasMonth(AssertionInfo info, Date actual, int month) Verifies that the actualDatemonth is equal to the given month, month value starting at 1 (January=1, February=2, ...).voidassertHasSameTime(AssertionInfo info, Date actual, Date expected) Verifies that the actualDatehas same time as the givenDate.voidassertHasSecond(AssertionInfo info, Date actual, int second) Verifies that the actualDatesecond is equal to the given second.voidassertHasTime(AssertionInfo info, Date actual, long timestamp) Verifies that the actualDatetime is equal to the given timestamp.voidassertHasYear(AssertionInfo info, Date actual, int year) Verifies that the actualDateyear is equal to the given year.voidassertIsAfter(AssertionInfo info, Date actual, Date other) Verifies that the actualDateis strictly after the given one.voidassertIsAfterOrEqualTo(AssertionInfo info, Date actual, Date other) Verifies that the actualDateis after or equal to the given one.voidassertIsAfterYear(AssertionInfo info, Date actual, int year) Verifies that the actualDateis strictly after the given year.voidassertIsBefore(AssertionInfo info, Date actual, Date other) Verifies that the actualDateis strictly before the given one.voidassertIsBeforeOrEqualTo(AssertionInfo info, Date actual, Date other) Verifies that the actualDateis before or equal to the given one.voidassertIsBeforeYear(AssertionInfo info, Date actual, int year) Verifies that the actualDateis strictly before the given year.voidassertIsBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) Verifies that the actualDateis in start:end period.
start date belongs to the period if inclusiveStart is true.
end date belongs to the period if inclusiveEnd is true.voidassertIsCloseTo(AssertionInfo info, Date actual, Date other, long deltaInMilliseconds) Verifies that the actualDateis close to the other date by less than delta, if difference is equals to delta it is ok.
Note that delta expressed in milliseconds.
Use handy TimeUnit to convert a duration in milliseconds, for example you can express a delta of 5 seconds withTimeUnit.SECONDS.toMillis(5).voidassertIsEqualWithPrecision(AssertionInfo info, Date actual, Date other, TimeUnit precision) Verifies that the actualDateis equal to the given one with precision.voidassertIsInSameDayAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare chronologically in the same day of month (and thus in the same month and year).voidassertIsInSameHourAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare in the same hour (and thus in the same day of month, month and year).voidassertIsInSameHourWindowAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare chronologically in the same hour, day of month, month and year.voidassertIsInSameMinuteAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare in the same minute, hour, day of month, month and year.voidassertIsInSameMinuteWindowAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare chronologically in the same minute.voidassertIsInSameMonthAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare chronologically in the same month (and thus in the same year).voidassertIsInSameSecondAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare in the same second, minute, hour, day of month, month and year.voidassertIsInSameSecondWindowAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare chronologically in the same second.voidassertIsInSameYearAs(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDateare in the same year.voidassertIsInTheFuture(AssertionInfo info, Date actual) Verifies that the actualDateis strictly in the future.voidassertIsInThePast(AssertionInfo info, Date actual) Verifies that the actualDateis strictly in the past.voidassertIsNotBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) Verifies that the actualDateis not in start:end period..
start date belongs to the period if inclusiveStart is true.
end date belongs to the period if inclusiveEnd is true.voidassertIsToday(AssertionInfo info, Date actual) Verifies that the actualDateis today, by comparing only year, month and day of actual to today (ie.Comparator<?> voidhasSameTimeAs(AssertionInfo info, Date actual, Date date) Verifies that the actualDateis equal to the given date by comparing their time.static Datesinstance()Returns the singleton instance of this class.
-
Constructor Details
-
Dates
-
-
Method Details
-
instance
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
getComparator
-
assertIsBefore
Verifies that the actualDateis strictly before the given one.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the other date to compare actual with.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if the actualDateis not strictly before the given one.
-
assertIsBeforeOrEqualTo
Verifies that the actualDateis before or equal to the given one.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the other date to compare actual with.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if the actualDateis not before or equal to the given one.
-
assertIsAfter
Verifies that the actualDateis strictly after the given one.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the given Date.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if the actualDateis not strictly after the given one.
-
assertIsAfterOrEqualTo
Verifies that the actualDateis after or equal to the given one.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the given Date.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if the actualDateis not after or equal to the given one.
-
assertIsEqualWithPrecision
public void assertIsEqualWithPrecision(AssertionInfo info, Date actual, Date other, TimeUnit precision) Verifies that the actualDateis equal to the given one with precision.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the given Date.precision- maximum precision for the comparison.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if the actualDateis not equal to the given one.
-
assertIsBetween
public void assertIsBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) Verifies that the actualDateis in start:end period.
start date belongs to the period if inclusiveStart is true.
end date belongs to the period if inclusiveEnd is true.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.start- the period start, expected not to be null.end- the period end, expected not to be null.inclusiveStart- whether to include start date in period.inclusiveEnd- whether to include end date in period.- Throws:
AssertionError- ifactualisnull.NullPointerException- if startDateisnull.NullPointerException- if endDateisnull.AssertionError- if the actualDateis not in start:end period.
-
assertIsNotBetween
public void assertIsNotBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) Verifies that the actualDateis not in start:end period..
start date belongs to the period if inclusiveStart is true.
end date belongs to the period if inclusiveEnd is true.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.start- the period start, expected not to be null.end- the period end, expected not to be null.inclusiveStart- whether to include start date in period.inclusiveEnd- whether to include end date in period.- Throws:
AssertionError- ifactualisnull.NullPointerException- if startDateisnull.NullPointerException- if endDateisnull.AssertionError- if the actualDateis in start:end period.
-
assertIsInThePast
Verifies that the actualDateis strictly in the past.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateis not in the past.
-
assertIsToday
Verifies that the actualDateis today, by comparing only year, month and day of actual to today (ie. we don't check hours).- Parameters:
info- contains information about the assertion.actual- the "actual"Date.- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateis not today.
-
assertIsInTheFuture
Verifies that the actualDateis strictly in the future.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateis not in the future.
-
assertIsBeforeYear
Verifies that the actualDateis strictly before the given year.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.year- the year to compare actual year to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateyear is after or equal to the given year.
-
assertIsAfterYear
Verifies that the actualDateis strictly after the given year.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.year- the year to compare actual year to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateyear is before or equal to the given year.
-
assertHasYear
Verifies that the actualDateyear is equal to the given year.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.year- the year to compare actual year to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateyear is not equal to the given year.
-
assertHasMonth
Verifies that the actualDatemonth is equal to the given month, month value starting at 1 (January=1, February=2, ...).- Parameters:
info- contains information about the assertion.actual- the "actual"Date.month- the month to compare actual month to, seeCalendar.MONTHfor valid values- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDatemonth is not equal to the given month.
-
assertHasDayOfMonth
Verifies that the actualDateday of month is equal to the given day of month.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.dayOfMonth- the day of month to compare actual day of month to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDatemonth is not equal to the given day of month.
-
assertHasDayOfWeek
Verifies that the actualDateday of week is equal to the given day of week.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.dayOfWeek- the day of week to compare actual day of week to, seeCalendar.DAY_OF_WEEKfor valid values- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateweek is not equal to the given day of week.
-
assertHasHourOfDay
Verifies that the actualDatehour od day is equal to the given hour of day (24-hour clock).- Parameters:
info- contains information about the assertion.actual- the "actual"Date.hourOfDay- the hour of day to compare actual hour of day to (24-hour clock)- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDatehour is not equal to the given hour.
-
assertHasMinute
Verifies that the actualDateminute is equal to the given minute.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.minute- the minute to compare actual minute to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDateminute is not equal to the given minute.
-
assertHasSecond
Verifies that the actualDatesecond is equal to the given second.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.second- the second to compare actual second to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDatesecond is not equal to the given second.
-
assertHasMillisecond
Verifies that the actualDatemillisecond is equal to the given millisecond.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.millisecond- the millisecond to compare actual millisecond to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDatemillisecond is not equal to the given millisecond.
-
assertIsInSameYearAs
Verifies that actual and givenDateare in the same year.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not in the same year.
-
assertIsInSameMonthAs
Verifies that actual and givenDateare chronologically in the same month (and thus in the same year).- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same month.
-
assertIsInSameDayAs
Verifies that actual and givenDateare chronologically in the same day of month (and thus in the same month and year).- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same day of month.
-
assertIsInSameHourAs
Verifies that actual and givenDateare in the same hour (and thus in the same day of month, month and year).- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same hour.
-
assertIsInSameHourWindowAs
Verifies that actual and givenDateare chronologically in the same hour, day of month, month and year.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same hour.
-
assertIsInSameMinuteAs
Verifies that actual and givenDateare in the same minute, hour, day of month, month and year.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same minute.
-
assertIsInSameMinuteWindowAs
Verifies that actual and givenDateare chronologically in the same minute.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same minute.
-
assertIsInSameSecondAs
Verifies that actual and givenDateare in the same second, minute, hour, day of month, month and year.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same second.
-
assertIsInSameSecondWindowAs
Verifies that actual and givenDateare chronologically in the same second.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if actual and givenDateare not chronologically speaking in the same second.
-
assertIsCloseTo
Verifies that the actualDateis close to the other date by less than delta, if difference is equals to delta it is ok.
Note that delta expressed in milliseconds.
Use handy TimeUnit to convert a duration in milliseconds, for example you can express a delta of 5 seconds withTimeUnit.SECONDS.toMillis(5).- Parameters:
info- contains information about the assertion.actual- the "actual"Date.other- the givenDateto compare actualDateto.deltaInMilliseconds- the delta used for date comparison, expressed in milliseconds- Throws:
AssertionError- ifactualisnull.NullPointerException- if otherDateisnull.AssertionError- if the actualDateweek is not close to the given date by less than delta.
-
assertHasTime
Verifies that the actualDatetime is equal to the given timestamp.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.timestamp- the timestamp to compare actual time to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDatetime is not equal to the given timestamp.
-
assertHasSameTime
Verifies that the actualDatehas same time as the givenDate.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.expected- the "expected"Dateto compare actual time to- Throws:
AssertionError- ifactualisnull.AssertionError- ifexpectedisnull.AssertionError- if the actualDatetime is not equal to the givenDate.
-
hasSameTimeAs
Verifies that the actualDateis equal to the given date by comparing their time.- Parameters:
info- contains information about the assertion.actual- the "actual"Date.date- the date to compare actual time to- Throws:
AssertionError- ifactualisnull.AssertionError- if the actualDatetime is not equal to the given date time.NullPointerException- if otherDateisnull.
-