Package org.assertj.core.internal
Class Dates
- java.lang.Object
-
- org.assertj.core.internal.Dates
-
-
Field Summary
Fields Modifier and Type Field Description private ComparisonStrategy
comparisonStrategy
(package private) Failures
failures
private static Dates
INSTANCE
-
Constructor Summary
Constructors Constructor Description Dates()
Dates(ComparisonStrategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
actualIsBetweenGivenPeriod(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
private boolean
areEqual(Date actual, Date other)
Returns true if the actualDate
is equal to the given one according to underlyingcomparisonStrategy
, false otherwise.private static boolean
areInSameDayOfMonth(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, false otherwise.private static boolean
areInSameHour(Date actual, Date other)
Returns true if both date are in the same year, month, day of month and hour, false otherwise.private static boolean
areInSameHourWindow(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.private static boolean
areInSameMinute(Date actual, Date other)
Returns true if both date are in the same year, month, day of month, hour and minute, false otherwise.private static boolean
areInSameMinuteWindow(Date actual, Date other)
private static boolean
areInSameMonth(Date actual, Date other)
Returns true if both date are in the same year and month, false otherwise.private static boolean
areInSameSecond(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.private static boolean
areInSameSecondWindow(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.private static boolean
areInSameYear(Date actual, Date other)
Returns true if both date are in the same year, false otherwise.void
assertHasDayOfMonth(AssertionInfo info, Date actual, int dayOfMonth)
Verifies that the actualDate
day of month is equal to the given day of month.void
assertHasDayOfWeek(AssertionInfo info, Date actual, int dayOfWeek)
Verifies that the actualDate
day of week is equal to the given day of week.void
assertHasHourOfDay(AssertionInfo info, Date actual, int hourOfDay)
Verifies that the actualDate
hour od day is equal to the given hour of day (24-hour clock).void
assertHasMillisecond(AssertionInfo info, Date actual, int millisecond)
Verifies that the actualDate
millisecond is equal to the given millisecond.void
assertHasMinute(AssertionInfo info, Date actual, int minute)
Verifies that the actualDate
minute is equal to the given minute.void
assertHasMonth(AssertionInfo info, Date actual, int month)
Verifies that the actualDate
month is equal to the given month, month value starting at 1 (January=1, February=2, ...).void
assertHasSameTime(AssertionInfo info, Date actual, Date expected)
Verifies that the actualDate
has same time as the givenDate
.void
assertHasSecond(AssertionInfo info, Date actual, int second)
Verifies that the actualDate
second is equal to the given second.void
assertHasTime(AssertionInfo info, Date actual, long timestamp)
Verifies that the actualDate
time is equal to the given timestamp.void
assertHasYear(AssertionInfo info, Date actual, int year)
Verifies that the actualDate
year is equal to the given year.void
assertIsAfter(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is strictly after the given one.void
assertIsAfterOrEqualTo(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is after or equal to the given one.void
assertIsAfterYear(AssertionInfo info, Date actual, int year)
Verifies that the actualDate
is strictly after the given year.void
assertIsBefore(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is strictly before the given one.void
assertIsBeforeOrEqualTo(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is before or equal to the given one.void
assertIsBeforeYear(AssertionInfo info, Date actual, int year)
Verifies that the actualDate
is strictly before the given year.void
assertIsBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
Verifies that the actualDate
is in start:end period.
start date belongs to the period if inclusiveStart is true.
end date belongs to the period if inclusiveEnd is true.void
assertIsCloseTo(AssertionInfo info, Date actual, Date other, long deltaInMilliseconds)
Verifies that the actualDate
is 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)
.void
assertIsEqualWithPrecision(AssertionInfo info, Date actual, Date other, TimeUnit precision)
Verifies that the actualDate
is equal to the given one with precision.void
assertIsInSameDayAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same day of month (and thus in the same month and year).void
assertIsInSameHourAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are in the same hour (and thus in the same day of month, month and year).void
assertIsInSameHourWindowAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same hour, day of month, month and year.void
assertIsInSameMinuteAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are in the same minute, hour, day of month, month and year.void
assertIsInSameMinuteWindowAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same minute.void
assertIsInSameMonthAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same month (and thus in the same year).void
assertIsInSameSecondAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are in the same second, minute, hour, day of month, month and year.void
assertIsInSameSecondWindowAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same second.void
assertIsInSameYearAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are in the same year.void
assertIsInTheFuture(AssertionInfo info, Date actual)
Verifies that the actualDate
is strictly in the future.void
assertIsInThePast(AssertionInfo info, Date actual)
Verifies that the actualDate
is strictly in the past.void
assertIsNotBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
Verifies that the actualDate
is 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.void
assertIsToday(AssertionInfo info, Date actual)
Verifies that the actualDate
is today, by comparing only year, month and day of actual to today (ie.private void
assertNotNull(AssertionInfo info, Date actual)
private static void
dateParameterIsNotNull(Date date)
used to check that the date to compare actual date to is not null, in that case throws aNullPointerException
with an explicit messageprivate static void
endDateParameterIsNotNull(Date end)
used to check that the end of period date to compare actual date to is not null, in that case throws aNullPointerException
with an explicit messageComparator<?>
getComparator()
void
hasSameTimeAs(AssertionInfo info, Date actual, Date date)
Verifies that the actualDate
is equal to the given date by comparing their time.static Dates
instance()
Returns the singleton instance of this class.private boolean
isAfter(Date actual, Date other)
Returns true if actual is after other according to underlyingcomparisonStrategy
, false otherwise.private boolean
isAfterOrEqualTo(Date actual, Date other)
Returnstrue
if the actualDate
is after or equal to the given one according to underlyingcomparisonStrategy
, false otherwise.private boolean
isBefore(Date actual, Date other)
Returns true if actual is before other according to underlyingcomparisonStrategy
, false otherwise.private boolean
isBeforeOrEqualTo(Date actual, Date other)
Returnstrue
if the actualDate
is before or equal to the given one according to underlyingcomparisonStrategy
, false otherwise.private static void
startDateParameterIsNotNull(Date start)
used to check that the start of period date to compare actual date to is not null, in that case throws aNullPointerException
with an explicit message
-
-
-
Field Detail
-
INSTANCE
private static final Dates INSTANCE
-
failures
Failures failures
-
comparisonStrategy
private final ComparisonStrategy comparisonStrategy
-
-
Constructor Detail
-
Dates
Dates()
-
Dates
public Dates(ComparisonStrategy comparisonStrategy)
-
-
Method Detail
-
instance
public static Dates instance()
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
getComparator
public Comparator<?> getComparator()
-
assertIsBefore
public void assertIsBefore(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is 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
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if the actualDate
is not strictly before the given one.
-
assertIsBeforeOrEqualTo
public void assertIsBeforeOrEqualTo(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is 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
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if the actualDate
is not before or equal to the given one.
-
assertIsAfter
public void assertIsAfter(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is strictly after the given one.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the given Date.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if the actualDate
is not strictly after the given one.
-
assertIsAfterOrEqualTo
public void assertIsAfterOrEqualTo(AssertionInfo info, Date actual, Date other)
Verifies that the actualDate
is after or equal to the given one.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the given Date.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if the actualDate
is not after or equal to the given one.
-
assertIsEqualWithPrecision
public void assertIsEqualWithPrecision(AssertionInfo info, Date actual, Date other, TimeUnit precision)
Verifies that the actualDate
is 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
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if the actualDate
is 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 actualDate
is 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
- ifactual
isnull
.NullPointerException
- if startDate
isnull
.NullPointerException
- if endDate
isnull
.AssertionError
- if the actualDate
is not in start:end period.
-
actualIsBetweenGivenPeriod
private boolean actualIsBetweenGivenPeriod(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
-
assertIsNotBetween
public void assertIsNotBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
Verifies that the actualDate
is 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
- ifactual
isnull
.NullPointerException
- if startDate
isnull
.NullPointerException
- if endDate
isnull
.AssertionError
- if the actualDate
is in start:end period.
-
assertIsInThePast
public void assertIsInThePast(AssertionInfo info, Date actual)
Verifies that the actualDate
is strictly in the past.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualDate
is not in the past.
-
assertIsToday
public void assertIsToday(AssertionInfo info, Date actual)
Verifies that the actualDate
is 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
- ifactual
isnull
.AssertionError
- if the actualDate
is not today.
-
assertIsInTheFuture
public void assertIsInTheFuture(AssertionInfo info, Date actual)
Verifies that the actualDate
is strictly in the future.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualDate
is not in the future.
-
assertIsBeforeYear
public void assertIsBeforeYear(AssertionInfo info, Date actual, int year)
Verifies that the actualDate
is 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
- ifactual
isnull
.AssertionError
- if the actualDate
year is after or equal to the given year.
-
assertIsAfterYear
public void assertIsAfterYear(AssertionInfo info, Date actual, int year)
Verifies that the actualDate
is 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
- ifactual
isnull
.AssertionError
- if the actualDate
year is before or equal to the given year.
-
assertHasYear
public void assertHasYear(AssertionInfo info, Date actual, int year)
Verifies that the actualDate
year is equal to the given year.- Parameters:
year
- the year to compare actual year toinfo
- contains information about the assertion.actual
- the "actual"Date
.- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualDate
year is not equal to the given year.
-
assertHasMonth
public void assertHasMonth(AssertionInfo info, Date actual, int month)
Verifies that the actualDate
month 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.MONTH
for valid values- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualDate
month is not equal to the given month.
-
assertHasDayOfMonth
public void assertHasDayOfMonth(AssertionInfo info, Date actual, int dayOfMonth)
Verifies that the actualDate
day 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
- ifactual
isnull
.AssertionError
- if the actualDate
month is not equal to the given day of month.
-
assertHasDayOfWeek
public void assertHasDayOfWeek(AssertionInfo info, Date actual, int dayOfWeek)
Verifies that the actualDate
day 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_WEEK
for valid values- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- if the actualDate
week is not equal to the given day of week.
-
assertHasHourOfDay
public void assertHasHourOfDay(AssertionInfo info, Date actual, int hourOfDay)
Verifies that the actualDate
hour 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
- ifactual
isnull
.AssertionError
- if the actualDate
hour is not equal to the given hour.
-
assertHasMinute
public void assertHasMinute(AssertionInfo info, Date actual, int minute)
Verifies that the actualDate
minute 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
- ifactual
isnull
.AssertionError
- if the actualDate
minute is not equal to the given minute.
-
assertHasSecond
public void assertHasSecond(AssertionInfo info, Date actual, int second)
Verifies that the actualDate
second 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
- ifactual
isnull
.AssertionError
- if the actualDate
second is not equal to the given second.
-
assertHasMillisecond
public void assertHasMillisecond(AssertionInfo info, Date actual, int millisecond)
Verifies that the actualDate
millisecond 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
- ifactual
isnull
.AssertionError
- if the actualDate
millisecond is not equal to the given millisecond.
-
assertIsInSameYearAs
public void assertIsInSameYearAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are in the same year.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not in the same year.
-
areInSameYear
private static boolean areInSameYear(Date actual, Date other)
Returns true if both date are in the same year, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year, false otherwise
-
assertIsInSameMonthAs
public void assertIsInSameMonthAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same month (and thus in the same year).- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same month.
-
areInSameMonth
private static boolean areInSameMonth(Date actual, Date other)
Returns true if both date are in the same year and month, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year and month, false otherwise
-
assertIsInSameDayAs
public void assertIsInSameDayAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are 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 givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same day of month.
-
areInSameDayOfMonth
private static boolean areInSameDayOfMonth(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year, month and day of month, false otherwise
-
assertIsInSameHourAs
public void assertIsInSameHourAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are 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 givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same hour.
-
assertIsInSameHourWindowAs
public void assertIsInSameHourWindowAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same hour, day of month, month and year.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same hour.
-
areInSameHourWindow
private static boolean areInSameHourWindow(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.
-
areInSameHour
private static boolean areInSameHour(Date actual, Date other)
Returns true if both date are in the same year, month, day of month and hour, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year, month, day of month and hour, false otherwise.
-
assertIsInSameMinuteAs
public void assertIsInSameMinuteAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are in the same minute, hour, day of month, month and year.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same minute.
-
assertIsInSameMinuteWindowAs
public void assertIsInSameMinuteWindowAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same minute.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same minute.
-
areInSameMinute
private static boolean areInSameMinute(Date actual, Date other)
Returns true if both date are in the same year, month, day of month, hour and minute, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year, month, day of month, hour and minute, false otherwise.
-
assertIsInSameSecondAs
public void assertIsInSameSecondAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are 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 givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same second.
-
assertIsInSameSecondWindowAs
public void assertIsInSameSecondWindowAs(AssertionInfo info, Date actual, Date other)
Verifies that actual and givenDate
are chronologically in the same second.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.other
- the givenDate
to compare actualDate
to.- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if actual and givenDate
are not chronologically speaking in the same second.
-
areInSameSecondWindow
private static boolean areInSameSecondWindow(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.
-
areInSameSecond
private static boolean areInSameSecond(Date actual, Date other)
Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.- Parameters:
actual
- the actual date. expected not be nullother
- the other date. expected not be null- Returns:
- true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.
-
assertIsCloseTo
public void assertIsCloseTo(AssertionInfo info, Date actual, Date other, long deltaInMilliseconds)
Verifies that the actualDate
is 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 givenDate
to compare actualDate
to.deltaInMilliseconds
- the delta used for date comparison, expressed in milliseconds- Throws:
AssertionError
- ifactual
isnull
.NullPointerException
- if otherDate
isnull
.AssertionError
- if the actualDate
week is not close to the given date by less than delta.
-
assertHasTime
public void assertHasTime(AssertionInfo info, Date actual, long timestamp)
Verifies that the actualDate
time 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
- ifactual
isnull
.AssertionError
- if the actualDate
time is not equal to the given timestamp.
-
assertHasSameTime
public void assertHasSameTime(AssertionInfo info, Date actual, Date expected)
Verifies that the actualDate
has same time as the givenDate
.- Parameters:
info
- contains information about the assertion.actual
- the "actual"Date
.expected
- the "expected"Date
to compare actual time to- Throws:
AssertionError
- ifactual
isnull
.AssertionError
- ifexpected
isnull
.AssertionError
- if the actualDate
time is not equal to the givenDate
.
-
hasSameTimeAs
public void hasSameTimeAs(AssertionInfo info, Date actual, Date date)
Verifies that the actualDate
is 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
- ifactual
isnull
.AssertionError
- if the actualDate
time is not equal to the given date time.NullPointerException
- if otherDate
isnull
.
-
dateParameterIsNotNull
private static void dateParameterIsNotNull(Date date)
used to check that the date to compare actual date to is not null, in that case throws aNullPointerException
with an explicit message- Parameters:
date
- the date to check- Throws:
NullPointerException
- with an explicit message if the given date is null
-
startDateParameterIsNotNull
private static void startDateParameterIsNotNull(Date start)
used to check that the start of period date to compare actual date to is not null, in that case throws aNullPointerException
with an explicit message- Parameters:
start
- the start date to check- Throws:
NullPointerException
- with an explicit message if the given start date is null
-
endDateParameterIsNotNull
private static void endDateParameterIsNotNull(Date end)
used to check that the end of period date to compare actual date to is not null, in that case throws aNullPointerException
with an explicit message- Parameters:
end
- the end date to check- Throws:
NullPointerException
- with an explicit message if the given end date is null
-
assertNotNull
private void assertNotNull(AssertionInfo info, Date actual)
-
isBeforeOrEqualTo
private boolean isBeforeOrEqualTo(Date actual, Date other)
Returnstrue
if the actualDate
is before or equal to the given one according to underlyingcomparisonStrategy
, false otherwise.- Parameters:
actual
- the actual date - must not be null.other
- the given Date.- Returns:
true
if the actualDate
is before or equal to the given one according to underlyingcomparisonStrategy
, false otherwise.- Throws:
NullPointerException
- ifactual
isnull
.
-
areEqual
private boolean areEqual(Date actual, Date other)
Returns true if the actualDate
is equal to the given one according to underlyingcomparisonStrategy
, false otherwise.- Parameters:
actual
- the actual date - must not be null.other
- the given Date.- Returns:
true
if the actualDate
is equal to the given one according to underlyingcomparisonStrategy
, false otherwise.
-
isAfterOrEqualTo
private boolean isAfterOrEqualTo(Date actual, Date other)
Returnstrue
if the actualDate
is after or equal to the given one according to underlyingcomparisonStrategy
, false otherwise.- Parameters:
actual
- the actual date - must not be null.other
- the given Date.- Returns:
true
if the actualDate
is after or equal to the given one according to underlyingcomparisonStrategy
, false otherwise.- Throws:
NullPointerException
- ifactual
isnull
.
-
isBefore
private boolean isBefore(Date actual, Date other)
Returns true if actual is before other according to underlyingcomparisonStrategy
, false otherwise.- Parameters:
actual
- theDate
to compare to otherother
- theDate
to compare to actual- Returns:
- true if actual is before other according to underlying
comparisonStrategy
, false otherwise.
-
isAfter
private boolean isAfter(Date actual, Date other)
Returns true if actual is after other according to underlyingcomparisonStrategy
, false otherwise.- Parameters:
actual
- theDate
to compare to otherother
- theDate
to compare to actual- Returns:
- true if actual is after other according to underlying
comparisonStrategy
, false otherwise.
-
-