public class DateAssert extends AbstractAssert<DateAssert,Date>
Date
s.
To create a new instance of this class invoke
.
Assertions.assertThat(Date)
Date
and the other is a String
representing a Date.withDateFormat(DateFormat)
.withIsoDateFormat()
.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
DateAssert(Date actual)
Creates a new
DateAssert . |
Modifier and Type | Method and Description |
---|---|
DateAssert |
hasTime(long timestamp)
Verifies that the actual
Date has the same time as the given timestamp. |
DateAssert |
isAfter(Date other)
Verifies that the actual
Date is strictly after the given one. |
DateAssert |
isAfter(String dateAsString)
Same assertion as
isAfter(Date) but given Date is represented as String either with ISO date format (yyyy-MM-dd) or
user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isAfterOrEqualsTo(Date other)
Verifies that the actual
Date is after or equals to the given one. |
DateAssert |
isAfterOrEqualsTo(String dateAsString)
Same assertion as
isAfterOrEqualsTo(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isAfterYear(int year)
Verifies that the actual
Date is strictly after the given year. |
DateAssert |
isBefore(Date other)
Verifies that the actual
Date is strictly before the given one. |
DateAssert |
isBefore(String dateAsString)
Same assertion as
isBefore(Date) but given Date is represented as String either with ISO date format (yyyy-MM-dd) or
user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isBeforeOrEqualsTo(Date other)
Verifies that the actual
Date is before or equals to the given one. |
DateAssert |
isBeforeOrEqualsTo(String dateAsString)
Same assertion as
isBeforeOrEqualsTo(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isBeforeYear(int year)
Verifies that the actual
Date is strictly before the given year. |
DateAssert |
isBetween(Date start,
Date end)
Verifies that the actual
Date is in [start, end[ period (start included, end excluded). |
DateAssert |
isBetween(Date start,
Date end,
boolean inclusiveStart,
boolean inclusiveEnd)
Verifies that the actual
Date is in the given period defined by start and end dates.To include start in the period set inclusiveStart parameter to true .To include end in the period set inclusiveEnd parameter to true . |
DateAssert |
isBetween(String start,
String end)
Same assertion as
isBetween(Date, Date) but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isBetween(String start,
String end,
boolean inclusiveStart,
boolean inclusiveEnd)
Same assertion as
isBetween(Date, Date, boolean, boolean) but given Dates are represented as String either with ISO
date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isCloseTo(Date other,
long deltaInMilliseconds)
Verifies that the actual
Date is close to the other date by less than delta (expressed in milliseconds), if
difference is equals to delta it's ok. |
DateAssert |
isCloseTo(String dateAsString,
long deltaInMilliseconds)
Same assertion as
isCloseTo(Date, long) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isEqualTo(String dateAsString)
Same assertion as
isEqualTo(Date date) but given Date is represented as String
either with ISO date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isIn(String... datesAsString)
Same assertion as
Assert.isIn(Object...) but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isInSameDayAs(Date other)
Verifies that actual and given
Date are chronologically in the same day of month (and thus in the same month and
year). |
DateAssert |
isInSameDayAs(String dateAsString)
Same assertion as
isInSameDayAs(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isInSameHourAs(Date other)
Verifies that actual and given
Date are chronologically in the same hour (and thus in the same day, month and year). |
DateAssert |
isInSameHourAs(String dateAsString)
Same assertion as
isInSameHourAs(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isInSameMinuteAs(Date other)
Verifies that actual and given
Date are chronologically in the same minute (and thus in the same hour, day, month and
year). |
DateAssert |
isInSameMinuteAs(String dateAsString)
Same assertion as
isInSameMinuteAs(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isInSameMonthAs(Date other)
Verifies that actual and given
Date are chronologically in the same month (and thus in the same year). |
DateAssert |
isInSameMonthAs(String dateAsString)
Same assertion as
isInSameMonthAs(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isInSameSecondAs(Date other)
Verifies that actual and given
Date are chronologically in the same second (and thus in the same minute, hour, day,
month and year). |
DateAssert |
isInSameSecondAs(String dateAsString)
Same assertion as
isInSameSecondAs(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isInSameYearAs(Date other)
Verifies that actual and given
Date are in the same year. |
DateAssert |
isInSameYearAs(String dateAsString)
Same assertion as
isInSameYearAs(Date) but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isInTheFuture()
Verifies that the actual
Date is strictly in the future. |
DateAssert |
isInThePast()
Verifies that the actual
Date is strictly in the past. |
DateAssert |
isInWithStringDateCollection(Collection<String> datesAsString)
Same assertion as
Assert.isIn(Iterable) but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ).Method signature could not be isIn(Collection<String>) because it would be same signature as
isIn(Collection<Date>) since java collection type are erased at runtime. |
DateAssert |
isNotBetween(Date start,
Date end)
Verifies that the actual
Date is not in [start, end[ period |
DateAssert |
isNotBetween(Date start,
Date end,
boolean inclusiveStart,
boolean inclusiveEnd)
Verifies that the actual
Date is not in the given period defined by start and end dates.To include start in the period set inclusiveStart parameter to true .To include end in the period set inclusiveEnd parameter to true . |
DateAssert |
isNotBetween(String start,
String end)
Same assertion as
isNotBetween(Date, Date) but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isNotBetween(String start,
String end,
boolean inclusiveStart,
boolean inclusiveEnd)
Same assertion as
isNotBetween(Date, Date, boolean, boolean) but given Dates are represented as String either with
ISO date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isNotEqualTo(String dateAsString)
Same assertion as
isNotEqualTo(Date date) but given Date is represented as String
either with ISO date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isNotIn(String... datesAsString)
Same assertion as
Assert.isNotIn(Object...) but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ). |
DateAssert |
isNotInWithStringDateCollection(Collection<String> datesAsString)
Same assertion as
Assert.isNotIn(Iterable) but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat) ).Method signature could not be isNotIn(Collection<String>) because it would be same signature as
isNotIn(Collection<Date>) since java collection type are erased at runtime. |
DateAssert |
isToday()
Verifies that the actual
Date is today, that is matching current year, month and day (no check on hour, minute,
second, milliseconds). |
DateAssert |
isWithinDayOfMonth(int dayOfMonth)
Verifies that the actual
Date day of month is equal to the given day of month. |
DateAssert |
isWithinDayOfWeek(int dayOfWeek)
Verifies that the actual
Date day of week is equal to the given day of week (see Calendar.DAY_OF_WEEK for
valid values). |
DateAssert |
isWithinHourOfDay(int hourOfDay)
Verifies that the actual
Date hour od day is equal to the given hour of day (24-hour clock). |
DateAssert |
isWithinMillisecond(int millisecond)
Verifies that the actual
Date millisecond is equal to the given millisecond. |
DateAssert |
isWithinMinute(int minute)
Verifies that the actual
Date minute is equal to the given minute. |
DateAssert |
isWithinMonth(int month)
Verifies that the actual
Date month is equal to the given month, month value starting at 1 (January=1,
February=2, ...). |
DateAssert |
isWithinSecond(int second)
Verifies that the actual
Date second is equal to the given second. |
DateAssert |
isWithinYear(int year)
Verifies that the actual
Date year is equal to the given year. |
static void |
useDateFormat(DateFormat userCustomDateFormat)
For String based Date assertions like
isBefore(String) , given String is expected to follow the default Date format,
that is ISO 8601 format : "yyyy-MM-dd". |
static void |
useIsoDateFormat()
Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.
|
DateAssert |
usingComparator(Comparator<? super Date> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
DateAssert |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
DateAssert |
withDateFormat(DateFormat userCustomDateFormat)
For String based Date assertions like
isBefore(String) , given String is expected to follow the default Date format,
that is ISO 8601 format : "yyyy-MM-dd". |
DateAssert |
withIsoDateFormat()
Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.
|
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage
protected DateAssert(Date actual)
DateAssert
.actual
- the target to verify.public DateAssert isEqualTo(String dateAsString)
isEqualTo(Date date)
but given Date is represented as String
either with ISO date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.AssertionError
- if actual and given Date represented as String are not equal.AssertionError
- if the given date as String could not be converted to a Date.public DateAssert isNotEqualTo(String dateAsString)
isNotEqualTo(Date date)
but given Date is represented as String
either with ISO date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.AssertionError
- if actual and given Date represented as String are equal.AssertionError
- if the given date as String could not be converted to a Date.public DateAssert isIn(String... datesAsString)
Assert.isIn(Object...)
but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).datesAsString
- the given Dates represented as String in default or custom date format.AssertionError
- if actual is not in given Dates represented as String.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isInWithStringDateCollection(Collection<String> datesAsString)
Assert.isIn(Iterable)
but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).isIn(Collection<String>)
because it would be same signature as
isIn(Collection<Date>)
since java collection type are erased at runtime.datesAsString
- the given Dates represented as String in default or custom date format.AssertionError
- if actual is not in given Dates represented as String.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isNotIn(String... datesAsString)
Assert.isNotIn(Object...)
but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).datesAsString
- the given Dates represented as String in default or custom date format.AssertionError
- if actual is in given Dates represented as String.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isNotInWithStringDateCollection(Collection<String> datesAsString)
Assert.isNotIn(Iterable)
but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).isNotIn(Collection<String>)
because it would be same signature as
isNotIn(Collection<Date>)
since java collection type are erased at runtime.datesAsString
- the given Dates represented as String in default or custom date format.AssertionError
- if actual is in given Dates represented as String.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isBefore(Date other)
Date
is strictly before the given one.other
- the given Date.AssertionError
- if the actual Date
is null
.NullPointerException
- if other Date
is null
.AssertionError
- if the actual Date
is not strictly before the given one.public DateAssert isBefore(String dateAsString)
isBefore(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or
user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.AssertionError
- if the actual Date
is null
.NullPointerException
- if given date as String is null
.AssertionError
- if the actual Date
is not strictly before the given Date represented as String.AssertionError
- if the given date as String could not be converted to a Date.public DateAssert isBeforeOrEqualsTo(Date other)
Date
is before or equals to the given one.other
- the given Date.AssertionError
- if the actual Date
is null
.NullPointerException
- if other Date
is null
.AssertionError
- if the actual Date
is not before or equals to the given one.public DateAssert isBeforeOrEqualsTo(String dateAsString)
isBeforeOrEqualsTo(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.AssertionError
- if the actual Date
is null
.NullPointerException
- if given date as String is null
.AssertionError
- if the actual Date
is not before or equals to the given Date represented as String.AssertionError
- if the given date as String could not be converted to a Date.public DateAssert isAfter(Date other)
Date
is strictly after the given one.other
- the given Date.AssertionError
- if the actual Date
is null
.NullPointerException
- if other Date
is null
.AssertionError
- if the actual Date
is not strictly after the given one.public DateAssert isAfter(String dateAsString)
isAfter(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or
user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.AssertionError
- if the actual Date
is null
.NullPointerException
- if given date as String is null
.AssertionError
- if the actual Date
is not strictly after the given Date represented as String.AssertionError
- if the given date as String could not be converted to a Date.public DateAssert isAfterOrEqualsTo(Date other)
Date
is after or equals to the given one.other
- the given Date.AssertionError
- if the actual Date
is null
.NullPointerException
- if other Date
is null
.AssertionError
- if the actual Date
is not after or equals to the given one.public DateAssert isAfterOrEqualsTo(String dateAsString)
isAfterOrEqualsTo(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.AssertionError
- if the actual Date
is null
.NullPointerException
- if given date as String is null
.AssertionError
- if the actual Date
is not after or equals to the given Date represented as String.AssertionError
- if the given date as String could not be converted to a Date.public DateAssert isBetween(Date start, Date end)
Date
is in [start, end[ period (start included, end excluded).start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.AssertionError
- if the actual Date
is null
.NullPointerException
- if start Date
is null
.NullPointerException
- if end Date
is null
.AssertionError
- if the actual Date
is not in [start, end[ period.public DateAssert isBetween(String start, String end)
isBetween(Date, Date)
but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.AssertionError
- if the actual Date
is null
.NullPointerException
- if start Date as String is null
.NullPointerException
- if end Date as String is null
.AssertionError
- if the actual Date
is not in [start, end[ period.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
Date
is in the given period defined by start and end dates.true
.true
.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.AssertionError
- if actual
is null
.NullPointerException
- if start Date
is null
.NullPointerException
- if end Date
is null
.AssertionError
- if the actual Date
is not in (start, end) period.public DateAssert isBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd)
isBetween(Date, Date, boolean, boolean)
but given Dates are represented as String either with ISO
date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).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.AssertionError
- if actual
is null
.NullPointerException
- if start Date as String is null
.NullPointerException
- if end Date as String is null
.AssertionError
- if the actual Date
is not in (start, end) period.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isNotBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
Date
is not in the given period defined by start and end dates.true
.true
.start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.inclusiveStart
- wether to include start date in period.inclusiveEnd
- wether to include end date in period.AssertionError
- if actual
is null
.NullPointerException
- if start Date
is null
.NullPointerException
- if end Date
is null
.AssertionError
- if the actual Date
is not in (start, end) period.public DateAssert isNotBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd)
isNotBetween(Date, Date, boolean, boolean)
but given Dates are represented as String either with
ISO date format (yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.inclusiveStart
- wether to include start date in period.inclusiveEnd
- wether to include end date in period.AssertionError
- if actual
is null
.NullPointerException
- if start Date as String is null
.NullPointerException
- if end Date as String is null
.AssertionError
- if the actual Date
is not in (start, end) period.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isNotBetween(Date start, Date end)
Date
is not in [start, end[ periodstart
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.AssertionError
- if the actual Date
is null
.NullPointerException
- if start Date
is null
.NullPointerException
- if end Date
is null
.AssertionError
- if the actual Date
is in [start, end[ period.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isNotBetween(String start, String end)
isNotBetween(Date, Date)
but given Dates are represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.AssertionError
- if the actual Date
is null
.NullPointerException
- if start Date as String is null
.NullPointerException
- if end Date as String is null
.AssertionError
- if the actual Date
is in [start, end[ period.AssertionError
- if one of the given date as String could not be converted to a Date.public DateAssert isInThePast()
Date
is strictly in the past.AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
is not in the past.public DateAssert isToday()
Date
is today, that is matching current year, month and day (no check on hour, minute,
second, milliseconds).AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
is not today.public DateAssert isInTheFuture()
Date
is strictly in the future.AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
is not in the future.public DateAssert isBeforeYear(int year)
Date
is strictly before the given year.year
- the year to compare actual year toAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
year is after or equals to the given year.public DateAssert isAfterYear(int year)
Date
is strictly after the given year.year
- the year to compare actual year toAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
year is before or equals to the given year.public DateAssert isWithinYear(int year)
Date
year is equal to the given year.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
year
- the year to compare actual year toAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
year is not equal to the given year.public DateAssert isWithinMonth(int month)
Date
month is equal to the given month, month value starting at 1 (January=1,
February=2, ...).
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
month
- the month to compare actual month to, month value starting at 1 (January=1, February=2, ...).AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
month is not equal to the given month.public DateAssert isWithinDayOfMonth(int dayOfMonth)
Date
day of month is equal to the given day of month.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
dayOfMonth
- the day of month to compare actual day of month toAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
month is not equal to the given day of month.public DateAssert isWithinDayOfWeek(int dayOfWeek)
Date
day of week is equal to the given day of week (see Calendar.DAY_OF_WEEK
for
valid values).
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
dayOfWeek
- the day of week to compare actual day of week to, see Calendar.DAY_OF_WEEK
for valid valuesAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
week is not equal to the given day of week.public DateAssert isWithinHourOfDay(int hourOfDay)
Date
hour od day is equal to the given hour of day (24-hour clock).
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
hourOfDay
- the hour of day to compare actual hour of day to (24-hour clock)AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
hour is not equal to the given hour.public DateAssert isWithinMinute(int minute)
Date
minute is equal to the given minute.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
minute
- the minute to compare actual minute toAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
minute is not equal to the given minute.public DateAssert isWithinSecond(int second)
Date
second is equal to the given second.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
second
- the second to compare actual second toAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
second is not equal to the given second.public DateAssert isWithinMillisecond(int millisecond)
Date
millisecond is equal to the given millisecond.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
millisecond
- the millisecond to compare actual millisecond toAssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
millisecond is not equal to the given millisecond.public DateAssert isInSameYearAs(Date other)
Date
are in the same year.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
other
- the given Date
to compare actual Date
to.NullPointerException
- if Date
parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same year.public DateAssert isInSameYearAs(String dateAsString)
isInSameYearAs(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.NullPointerException
- if dateAsString parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date represented as String are not in the same year.AssertionError
- if the given date as String could not be converted to a Date.public DateAssert isInSameMonthAs(Date other)
Date
are chronologically in the same month (and thus in the same year).
If you want to compare month only (without year), use : assertThat(myDate).isWithinMonth(monthOf(otherDate))
See Dates.monthOf(Date)
to get the month of a given Date.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
other
- the given Date
to compare actual Date
to.NullPointerException
- if Date
parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same month.public DateAssert isInSameMonthAs(String dateAsString)
isInSameMonthAs(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.NullPointerException
- if dateAsString parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same month.public DateAssert isInSameDayAs(Date other)
Date
are chronologically in the same day of month (and thus in the same month and
year).
If you want to compare day of month only (without month and year), you could write :
assertThat(myDate).isWithinDayOfMonth(dayOfMonthOf(otherDate))
see Dates.dayOfMonthOf(Date)
to get the day of month of a given Date.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
other
- the given Date
to compare actual Date
to.NullPointerException
- if Date
parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same day of month.public DateAssert isInSameDayAs(String dateAsString)
isInSameDayAs(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.NullPointerException
- if dateAsString parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same day of month.public DateAssert isInSameHourAs(Date other)
Date
are chronologically in the same hour (and thus in the same day, month and year).
If you want to compare hour only (without day, month and year), you could write :
assertThat(myDate).isWithinHour(hourOfDayOf(otherDate))
see Dates.hourOfDay(Date)
to get the hour of a given Date.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
other
- the given Date
to compare actual Date
to.NullPointerException
- if Date
parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same hour.public DateAssert isInSameHourAs(String dateAsString)
isInSameHourAs(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.NullPointerException
- if dateAsString parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same hour.public DateAssert isInSameMinuteAs(Date other)
Date
are chronologically in the same minute (and thus in the same hour, day, month and
year).
If you want to compare minute only (without hour, day, month and year), you could write :
assertThat(myDate).isWithinMinute(minuteOf(otherDate))
see Dates.minuteOf(Date)
to get the minute of a given Date.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
other
- the given Date
to compare actual Date
to.NullPointerException
- if Date
parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same minute.public DateAssert isInSameMinuteAs(String dateAsString)
isInSameMinuteAs(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.NullPointerException
- if dateAsString parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same minute.public DateAssert isInSameSecondAs(Date other)
Date
are chronologically in the same second (and thus in the same minute, hour, day,
month and year).
If you want to compare second only (without minute, hour, day, month and year), you could write :
assertThat(myDate).isWithinSecond(secondOf(otherDate))
see Dates.secondOf(Date)
to get the second of a given Date.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
other
- the given Date
to compare actual Date
to.NullPointerException
- if Date
parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same second.public DateAssert isInSameSecondAs(String dateAsString)
isInSameSecondAs(Date)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.NullPointerException
- if dateAsString parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if actual and given Date
are not in the same second.public DateAssert isCloseTo(Date other, long deltaInMilliseconds)
Date
is close to the other date by less than delta (expressed in milliseconds), if
difference is equals to delta it's ok.
One can use handy TimeUnit
to convert a duration in milliseconds, for example you can express a delta of 5 seconds
with TimeUnit.SECONDS.toMillis(5)
.
Note that using a custom comparator has no effect on this assertion (see usingComparator(Comparator)
.
other
- the date to compare actual todeltaInMilliseconds
- the delta used for date comparison, expressed in millisecondsNullPointerException
- if Date
parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
week is not close to the given date by less than delta.public DateAssert isCloseTo(String dateAsString, long deltaInMilliseconds)
isCloseTo(Date, long)
but given Date is represented as String either with ISO date format
(yyyy-MM-dd) or user custom date format (set with method withDateFormat(DateFormat)
).dateAsString
- the given Date represented as String in default or custom date format.deltaInMilliseconds
- the delta used for date comparison, expressed in millisecondsNullPointerException
- if dateAsString parameter is null
.AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
week is not close to the given date by less than delta.public DateAssert hasTime(long timestamp)
Date
has the same time as the given timestamp.
Both time or timestamp express a number of milliseconds since January 1, 1970, 00:00:00 GMT.
timestamp
- the timestamp to compare actual time to.AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
time is not equal to the given timestamp.Date.getTime()
public DateAssert withDateFormat(DateFormat userCustomDateFormat)
isBefore(String)
, given String is expected to follow the default Date format,
that is ISO 8601 format : "yyyy-MM-dd".
With this method, user can specify its own date format, replacing the current date format for all future Date assertions in the test suite (i.e. not only the current assertions) since custom DateFormat is stored in a static field.
To revert to default format simply call withIsoDateFormat()
.
userCustomDateFormat
- the new Date format used for String based Date assertions.public static void useDateFormat(DateFormat userCustomDateFormat)
isBefore(String)
, given String is expected to follow the default Date format,
that is ISO 8601 format : "yyyy-MM-dd".
With this method, user can specify its own date format, replacing the current date format for all future Date assertions in the test suite (i.e. not only the current assertions) since custom DateFormat is stored in a static field.
To revert to default format simply call useIsoDateFormat()
(static method) or withIsoDateFormat()
.
userCustomDateFormat
- the new Date format used for String based Date assertions.public DateAssert withIsoDateFormat()
public static void useIsoDateFormat()
public DateAssert usingComparator(Comparator<? super Date> customComparator)
AbstractAssert
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
usingComparator
in interface Assert<DateAssert,Date>
usingComparator
in class AbstractAssert<DateAssert,Date>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public DateAssert usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling Assert.usingComparator(Comparator)
.
usingDefaultComparator
in interface Assert<DateAssert,Date>
usingDefaultComparator
in class AbstractAssert<DateAssert,Date>
this
assertion object.Copyright © 2013 AssertJ. All Rights Reserved.