Package org.fest.assertions.internal
Class Dates
java.lang.Object
org.fest.assertions.internal.Dates
Reusable assertions for
Date
s.- Author:
- Joel Costigliola
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
assertHasTime
(AssertionInfo info, Date actual, long timestamp) Verifies that the actualDate
time is equal to the given timestamp.void
assertIsAfter
(AssertionInfo info, Date actual, Date other) Verifies that the actualDate
is strictly after the given one.void
assertIsAfterOrEqualsTo
(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
assertIsBeforeOrEqualsTo
(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
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 chronologically in the same hour (and thus in the same day of month, month and year).void
assertIsInSameMinuteAs
(AssertionInfo info, Date actual, Date other) Verifies that actual and givenDate
are chronologically in the same minute (and thus in the same hour, day of month, month and year).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 chronologically in the same second (and thus in the same minute, hour, day of month, month and year).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.void
assertIsWithinDayOfMonth
(AssertionInfo info, Date actual, int dayOfMonth) Verifies that the actualDate
day of month is equal to the given day of month.void
assertIsWithinDayOfWeek
(AssertionInfo info, Date actual, int dayOfWeek) Verifies that the actualDate
day of week is equal to the given day of week.void
assertIsWithinHourOfDay
(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
assertIsWithinMillisecond
(AssertionInfo info, Date actual, int millisecond) Verifies that the actualDate
millisecond is equal to the given millisecond.void
assertIsWithinMinute
(AssertionInfo info, Date actual, int minute) Verifies that the actualDate
minute is equal to the given minute.void
assertIsWithinMonth
(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
assertIsWithinSecond
(AssertionInfo info, Date actual, int second) Verifies that the actualDate
second is equal to the given second.void
assertIsWithinYear
(AssertionInfo info, Date actual, int year) Verifies that the actualDate
year is equal to the given year.Comparator<?>
static Dates
instance()
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 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.
-
assertIsBeforeOrEqualsTo
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
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.
-
assertIsAfterOrEqualsTo
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.
-
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
- wether to include start date in period.inclusiveEnd
- wether 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.
-
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
- wether to include start date in period.inclusiveEnd
- wether 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
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
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
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
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
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.
-
assertIsWithinYear
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.
-
assertIsWithinMonth
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.
-
assertIsWithinDayOfMonth
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.
-
assertIsWithinDayOfWeek
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.
-
assertIsWithinHourOfDay
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.
-
assertIsWithinMinute
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.
-
assertIsWithinSecond
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.
-
assertIsWithinMillisecond
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
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.
-
assertIsInSameMonthAs
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.
-
assertIsInSameDayAs
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.
-
assertIsInSameHourAs
Verifies that actual and givenDate
are chronologically 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.
-
assertIsInSameMinuteAs
Verifies that actual and givenDate
are chronologically in the same minute (and thus 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 minute.
-
assertIsInSameSecondAs
Verifies that actual and givenDate
are chronologically in the same second (and thus 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 second.
-
assertIsCloseTo
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
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.
-