SELF
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for
more details.public abstract class AbstractDateAssert<SELF extends AbstractDateAssert<SELF>> extends AbstractAssert<SELF,Date>
Date
s.
Note that assertions with date parameter comes with two flavor, one is obviously a Date
and the other is a
String
representing a Date.
For the latter, the default format follows ISO 8901 : "yyyy-MM-dd", user can override it with a custom format by
calling withDateFormat(DateFormat)
.
The user custom format will then be used for all next Date assertions (i.e not limited to the current assertion) in
the test suite.
To turn back to default format, simply call withDefaultDateFormatsOnly()
.
actual, info, myself, throwUnsupportedExceptionOnEquals
Constructor and Description |
---|
AbstractDateAssert(Date actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
SELF |
hasDayOfMonth(int dayOfMonth)
Verifies that the actual
Date day of month is equal to the given day of month. |
SELF |
hasDayOfWeek(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). |
SELF |
hasHourOfDay(int hourOfDay)
Verifies that the actual
Date hour of day is equal to the given hour of day (24-hour clock). |
SELF |
hasMillisecond(int millisecond)
Verifies that the actual
Date millisecond is equal to the given millisecond. |
SELF |
hasMinute(int minute)
Verifies that the actual
Date minute is equal to the given minute. |
SELF |
hasMonth(int month)
Verifies that the actual
Date month is equal to the given month, month value starting at 1
(January=1, February=2, ...). |
SELF |
hasSameTimeAs(Date date)
|
SELF |
hasSameTimeAs(String dateAsString)
Verifies that the actual
Date represents the same time as the given date in String format. |
SELF |
hasSecond(int second)
Verifies that the actual
Date second is equal to the given second. |
SELF |
hasTime(long timestamp)
Verifies that the actual
Date has the same time as the given timestamp. |
SELF |
hasYear(int year)
Verifies that the actual
Date year is equal to the given year. |
SELF |
isAfter(Date other)
Verifies that the actual
Date is strictly after the given one. |
SELF |
isAfter(String dateAsString)
Same assertion as
isAfter(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isAfterOrEqualsTo(Date other)
Verifies that the actual
Date is after or equals to the given one. |
SELF |
isAfterOrEqualsTo(String dateAsString)
Same assertion as
isAfterOrEqualsTo(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isAfterYear(int year)
Verifies that the actual
Date is strictly after the given year. |
SELF |
isBefore(Date other)
Verifies that the actual
Date is strictly before the given one. |
SELF |
isBefore(String dateAsString)
Same assertion as
isBefore(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isBeforeOrEqualsTo(Date other)
Verifies that the actual
Date is before or equals to the given one. |
SELF |
isBeforeOrEqualsTo(String dateAsString)
Same assertion as
isBeforeOrEqualsTo(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isBeforeYear(int year)
Verifies that the actual
Date is strictly before the given year. |
SELF |
isBetween(Date start,
Date end)
Verifies that the actual
Date is in [start, end[ period (start included, end excluded). |
SELF |
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 . |
SELF |
isBetween(String start,
String end)
Same assertion as
isBetween(Date, Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isBetween(String start,
String end,
boolean inclusiveStart,
boolean inclusiveEnd)
Same assertion as
isBetween(Date, Date, boolean, boolean) but given date is represented as String either
with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
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. |
SELF |
isCloseTo(String dateAsString,
long deltaInMilliseconds)
Same assertion as
isCloseTo(Date, long) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isEqualTo(String dateAsString)
Same assertion as
isEqualTo(Date date) but given date is represented as
String either with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isEqualToIgnoringHours(Date date)
Same assertion as
AbstractAssert.isEqualTo(Object) but given Date is represented as String either with
one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isEqualToIgnoringHours(String dateAsString)
Same assertion as
isEqualToIgnoringHours(Date) but given Date is represented as String
either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isEqualToIgnoringMillis(Date date)
Same assertion as
AbstractAssert.isEqualTo(Object) but given Date should not take care of milliseconds
precision. |
SELF |
isEqualToIgnoringMillis(String dateAsString)
Same assertion as
isEqualToIgnoringMillis(Date) but given Date is represented as String
either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isEqualToIgnoringMinutes(Date date)
Same assertion as
AbstractAssert.isEqualTo(Object) but given Date should not take care of minutes,
seconds and milliseconds precision. |
SELF |
isEqualToIgnoringMinutes(String dateAsString)
Same assertion as
isEqualToIgnoringMinutes(Date) but given Date is represented as
String either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isEqualToIgnoringSeconds(Date date)
Same assertion as
AbstractAssert.isEqualTo(Object) but given Date should not take care of seconds and
milliseconds precision. |
SELF |
isEqualToIgnoringSeconds(String dateAsString)
Same assertion as
isEqualToIgnoringSeconds(Date) but given Date is represented as
String
either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isIn(String... datesAsString)
Same assertion as
Assert.isIn(Object...) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isInSameDayAs(Date other)
Verifies that actual and given
Date have the same day of month, month and year fields values. |
SELF |
isInSameDayAs(String dateAsString)
Same assertion as
isInSameDayAs(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isInSameHourAs(Date other)
Verifies that actual and given
Date have same hour, day, month and year fields values. |
SELF |
isInSameHourAs(String dateAsString)
Same assertion as
isInSameHourAs(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isInSameHourWindowAs(Date other)
Verifies that actual and given
Date are chronologically in the same hour (i.e. |
SELF |
isInSameHourWindowAs(String dateAsString)
Same assertion as
isInSameHourWindowAs(java.util.Date) but given date is represented as String either
with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isInSameMinuteAs(Date other)
Verifies that actual and given
Date have same minute, same hour, day, month and year fields values. |
SELF |
isInSameMinuteAs(String dateAsString)
Same assertion as
isInSameMinuteAs(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isInSameMinuteWindowAs(Date other)
Verifies that actual and given
Date are chronologically in the same minute (i.e. |
SELF |
isInSameMinuteWindowAs(String dateAsString)
Same assertion as
isInSameMinuteWindowAs(Date) but given date is represented as String either with one of
the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isInSameMonthAs(Date other)
Verifies that actual and given
Date have same month and year fields. |
SELF |
isInSameMonthAs(String dateAsString)
Same assertion as
isInSameMonthAs(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isInSameSecondAs(Date other)
Verifies that actual and given
Date have same second, minute, hour, day, month and year fields values. |
SELF |
isInSameSecondAs(String dateAsString)
Same assertion as
isInSameSecondAs(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isInSameSecondWindowAs(Date other)
Verifies that actual and given
Date are chronologically strictly in the same second (i.e. |
SELF |
isInSameSecondWindowAs(String dateAsString)
Same assertion as
isInSameSecondWindowAs(Date) but given date is represented as String either with one of
the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isInSameYearAs(Date other)
Verifies that actual and given
Date are in the same year. |
SELF |
isInSameYearAs(String dateAsString)
Same assertion as
isInSameYearAs(Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isInTheFuture()
Verifies that the actual
Date is strictly in the future. |
SELF |
isInThePast()
Verifies that the actual
Date is strictly in the past. |
SELF |
isInWithStringDateCollection(Collection<String> datesAsString)
Same assertion as
Assert.isIn(Iterable) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isNotBetween(Date start,
Date end)
Verifies that the actual
Date is not in [start, end[ period |
SELF |
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 . |
SELF |
isNotBetween(String start,
String end)
Same assertion as
isNotBetween(Date, Date) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isNotBetween(String start,
String end,
boolean inclusiveStart,
boolean inclusiveEnd)
Same assertion as
isNotBetween(Date, Date, boolean, boolean) but given date is represented as String
either with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat) ). |
SELF |
isNotEqualTo(String dateAsString)
Same assertion as
isNotEqualTo(Date date) but given date is
represented as String either with one of the supported defaults date format or a user custom date format (set with
method withDateFormat(DateFormat) ). |
SELF |
isNotIn(String... datesAsString)
Same assertion as
Assert.isNotIn(Object...) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isNotInWithStringDateCollection(Collection<String> datesAsString)
Same assertion as
Assert.isNotIn(Iterable) but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat) ). |
SELF |
isToday()
Verifies that the actual
Date is today, that is matching current year, month and day (no check on hour,
minute, second, milliseconds). |
SELF |
isWithinDayOfMonth(int dayOfMonth)
Deprecated.
use
hasDayOfMonth(int) instead. |
SELF |
isWithinDayOfWeek(int dayOfWeek)
Deprecated.
use
hasDayOfWeek(int) instead. |
SELF |
isWithinHourOfDay(int hourOfDay)
Deprecated.
use
hasHourOfDay(int) instead. |
SELF |
isWithinMillisecond(int millisecond)
Deprecated.
use
hasMillisecond(int) instead. |
SELF |
isWithinMinute(int minute)
Deprecated.
use
hasMinute(int) instead. |
SELF |
isWithinMonth(int month)
Deprecated.
use
hasMonth(int) instead. |
SELF |
isWithinSecond(int second)
Deprecated.
use
hasSecond(int) instead. |
SELF |
isWithinYear(int year)
Deprecated.
use
hasYear(int) instead. |
static void |
registerCustomDateFormat(DateFormat userCustomDateFormat)
Add the given date format to the ones used to parse date String in String based Date assertions like
isEqualTo(String) . |
static void |
registerCustomDateFormat(String userCustomDateFormatPattern)
Add the given date format to the ones used to parse date String in String based Date assertions like
isEqualTo(String) . |
static void |
setLenientDateParsing(boolean value)
Instead of using default strict date/time parsing, it is possible to use lenient parsing mode for default date
formats parser to interpret inputs that do not precisely match supported date formats (lenient parsing).
|
static void |
useDefaultDateFormatsOnly()
Remove all registered custom date formats => use only the defaults date formats to parse string as date.
|
SELF |
usingComparator(Comparator<? super Date> customComparator)
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingComparator(Comparator<? super Date> customComparator,
String customComparatorDescription)
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingDefaultComparator()
Revert to standard comparison for the incoming assertion checks.
|
SELF |
withDateFormat(DateFormat userCustomDateFormat)
Instead of using default date formats for the date String based Date assertions like
isEqualTo(String) ,
AssertJ is gonna use any date formats registered with one of these methods :
withDateFormat(String)
this method
registerCustomDateFormat(java.text.DateFormat)
registerCustomDateFormat(String)
|
SELF |
withDateFormat(String userCustomDateFormatPattern)
Instead of using default date formats for the date String based Date assertions like
isEqualTo(String) ,
AssertJ is gonna use any date formats registered with one of these methods :
this method
withDateFormat(java.text.DateFormat)
registerCustomDateFormat(java.text.DateFormat)
registerCustomDateFormat(String)
|
SELF |
withDefaultDateFormatsOnly()
Remove all registered custom date formats => use only the defaults date formats to parse string as date.
|
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, withFailMessage, withRepresentation, withThreadDumpOnError
public SELF isEqualTo(String dateAsString)
isEqualTo(Date date)
but given date is represented as
String either with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isEqualTo("2002-12-18");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isEqualTo("2002-12-19");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isEqualToIgnoringHours(String dateAsString)
isEqualToIgnoringHours(Date)
but given Date is represented as String
either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// OK : all dates fields are the same up to minutes excluded
assertThat("2003-04-26T13:01:35").isEqualToIgnoringHours("2003-04-26T14:02:35");
// KO : fail as day fields differ
assertThat("2003-04-26T14:01:35").isEqualToIgnoringHours("2003-04-27T13:02:35");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 ignoring hours, minutes,
seconds and milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isEqualToIgnoringHours(Date date)
AbstractAssert.isEqualTo(Object)
but given Date is represented as String either with
one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
Date date1 = parseDatetime("2003-04-26T13:01:35");
Date date2 = parseDatetime("2003-04-26T14:01:00");
Date date3 = parseDatetime("2003-04-27T13:01:35");
// OK : all dates fields are the same up to hours excluded
assertThat(date1).isEqualToIgnoringHours(date2);
// KO : fail as day fields differ
assertThat(date1).isEqualToIgnoringHours(date3);
date
- the given Date.AssertionError
- if actual and given Date represented as String are not equal ignoring hours, minutes,
seconds and milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isEqualToIgnoringMinutes(String dateAsString)
isEqualToIgnoringMinutes(Date)
but given Date is represented as
String either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
withDateFormat("yyyy-MM-dd'T'HH:mm:ss");
// OK : all dates fields are the same up to minutes excluded
assertThat("2003-04-26T13:01:35").isEqualToIgnoringMinutes("2003-04-26T13:02:35");
// KO : fail as hour fields differ
assertThat("2003-04-26T14:01:35").isEqualToIgnoringMinutes("2003-04-26T13:02:35");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 ignoring minutes, seconds and
milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isEqualToIgnoringMinutes(Date date)
AbstractAssert.isEqualTo(Object)
but given Date should not take care of minutes,
seconds and milliseconds precision.
Example:
Date date1 = parseDatetime("2003-04-26T13:01:35");
Date date2 = parseDatetime("2003-04-26T13:02:00");
Date date3 = parseDatetime("2003-04-26T14:02:00");
// OK : all dates fields are the same up to minutes excluded
assertThat(date1).isEqualToIgnoringMinutes(date2);
// KO : fail as hour fields differ
assertThat(date1).isEqualToIgnoringMinutes(date3);
date
- the given Date.AssertionError
- if actual and given Date represented as String are not equal ignoring minutes, seconds and
milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isEqualToIgnoringSeconds(String dateAsString)
isEqualToIgnoringSeconds(Date)
but given Date is represented as
String
either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
Date date1 = parseDatetime("2003-04-26T13:01:35");
// OK : all dates fields are the same up to seconds excluded
assertThat(date1).isEqualToIgnoringSeconds("2003-04-26T13:01:57");
// KO : fail as minute fields differ
assertThat(date1).isEqualToIgnoringMinutes("2003-04-26T13:02:00");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 ignoring seconds and
milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isEqualToIgnoringSeconds(Date date)
AbstractAssert.isEqualTo(Object)
but given Date should not take care of seconds and
milliseconds precision.
Example:
Date date1 = parseDatetime("2003-04-26T13:01:35");
Date date2 = parseDatetime("2003-04-26T13:01:36");
Date date3 = parseDatetime("2003-04-26T14:02:00");
// OK : all dates fields are the same up to seconds excluded
assertThat(date1).isEqualToIgnoringSeconds(date2);
// KO : fail as minute fields differ
assertThat(date1).isEqualToIgnoringSeconds(date3);
date
- the given Date represented as String in default or custom date format.AssertionError
- if actual and given Date represented as String are not equal ignoring seconds and
milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isEqualToIgnoringMillis(String dateAsString)
isEqualToIgnoringMillis(Date)
but given Date is represented as String
either with one of the default supported date format or user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
Date date1 = parseDatetimeWithMs("2003-04-26T13:01:35.998");
// OK : all dates fields are the same up to milliseconds excluded
assertThat().isEqualToIgnoringMillis("2003-04-26T13:01:35.997");
// KO : fail as seconds fields differ
assertThat("2003-04-26T13:01:35.998").isEqualToIgnoringMinutes("2003-04-26T13:01:36.998");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 ignoring milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isEqualToIgnoringMillis(Date date)
AbstractAssert.isEqualTo(Object)
but given Date should not take care of milliseconds
precision.
Example:
Date date1 = parseDatetimeAndMs("2003-04-26T13:01:35.001");
Date date2 = parseDatetimeAndMs("2003-04-26T13:01:35.002");
Date date3 = parseDatetimeAndMs("2003-04-26T14:01:36.001");
// OK : all dates fields are the same up to milliseconds excluded
assertThat(date1).isEqualToIgnoringMillis(date2);
// KO : fail as second fields differ
assertThat(date1).isEqualToIgnoringMillis(date3);
date
- the given Date represented as String in default or custom date format.AssertionError
- if actual and given Date represented as String are not equal ignoring milliseconds.AssertionError
- if the given date as String could not be converted to a Date.public SELF isNotEqualTo(String dateAsString)
isNotEqualTo(Date date)
but given date is
represented as String either with one of the supported defaults date format or a user custom date format (set with
method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isNotEqualTo("2002-12-19");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isNotEqualTo("2002-12-18");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isIn(String... datesAsString)
Assert.isIn(Object...)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isIn("2002-12-17", "2002-12-18", "2002-12-19");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isIn("2002-12-17", "2002-12-19", "2002-12-20");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInWithStringDateCollection(Collection<String> datesAsString)
Assert.isIn(Iterable)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isInWithStringDateCollection(asList("2002-12-17", "2002-12-18", "2002-12-19"));
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isInWithStringDateCollection(asList("2002-12-17", "2002-12-19", "2002-12-20"));
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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.
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 SELF isNotIn(String... datesAsString)
Assert.isNotIn(Object...)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isNotIn("2002-12-17", "2002-12-19");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isNotIn("2002-12-17", "2002-12-18");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isNotInWithStringDateCollection(Collection<String> datesAsString)
Assert.isNotIn(Iterable)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isNotInWithStringDateCollection(Arrays.asList("2002-12-17", "2002-12-19"));
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isNotInWithStringDateCollection(Arrays.asList("2002-12-17", "2002-12-18"));
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isBefore(Date other)
Date
is strictly before the given one.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isBefore(theReturnOfTheKing.getReleaseDate());
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isBefore(theFellowshipOfTheRing.getReleaseDate());
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 SELF isBefore(String dateAsString)
isBefore(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isBefore("2002-12-19");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isBefore("2002-12-17");
assertThat(theTwoTowers.getReleaseDate()).isBefore("2002-12-18");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isBeforeOrEqualsTo(Date other)
Date
is before or equals to the given one.
Example:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// assertions will pass
assertThat(dateFormat.parse("1990-12-01")).isBeforeOrEqualsTo(dateFormat.parse("2000-12-01"));
assertThat(dateFormat.parse("2000-12-01")).isBeforeOrEqualsTo(dateFormat.parse("2000-12-01"));
// assertion will fail
assertThat(dateFormat.parse("2000-12-01")).isBeforeOrEqualsTo(dateFormat.parse("1990-12-01"));
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 SELF isBeforeOrEqualsTo(String dateAsString)
isBeforeOrEqualsTo(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualsTo("2002-12-19");
assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualsTo("2002-12-18");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualsTo("2002-12-17");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isAfter(Date other)
Date
is strictly after the given one.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isAfter(theFellowshipOfTheRing.getReleaseDate());
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isAfter(theReturnOfTheKing.getReleaseDate());
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 SELF isAfter(String dateAsString)
isAfter(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isAfter("2002-12-17");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isAfter("2002-12-18");
assertThat(theTwoTowers.getReleaseDate()).isAfter("2002-12-19");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isAfterOrEqualsTo(Date other)
Date
is after or equals to the given one.
Example:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// assertions will pass
assertThat(dateFormat.parse("2000-12-01")).isAfterOrEqualsTo(dateFormat.parse("1990-12-01"));
assertThat(dateFormat.parse("2000-12-01")).isAfterOrEqualsTo(dateFormat.parse("2000-12-01"));
// assertion will fail
assertThat(dateFormat.parse("1990-12-01")).isAfterOrEqualsTo(dateFormat.parse("2000-12-01"));
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 SELF isAfterOrEqualsTo(String dateAsString)
isAfterOrEqualsTo(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualsTo("2002-12-17");
assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualsTo("2002-12-18");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualsTo("2002-12-19");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isBetween(Date start, Date end)
Date
is in [start, end[ period (start included, end excluded).
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isBetween(theFellowshipOfTheRing.getReleaseDate(), theReturnOfTheKing.getReleaseDate());
// assertion will fail
assertThat(theFellowshipOfTheRing.getReleaseDate()).isBetween(theTwoTowers.getReleaseDate(), theReturnOfTheKing.getReleaseDate());
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 SELF isBetween(String start, String end)
isBetween(Date, Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-17", "2002-12-19");
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-15", "2002-12-17");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
Date
is in the given period defined by start and end dates.true
.true
.Example:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// assertions will pass
assertThat(format.parse("2000-01-01")).isBetween(format.parse("2000-01-01"), format.parse("2100-12-01"), true, true);
assertThat(format.parse("2000-01-01")).isBetween(format.parse("1900-01-01"), format.parse("2000-01-01"), true, true);
assertThat(format.parse("2000-01-01")).isBetween(format.parse("1900-01-01"), format.parse("2100-01-01"), false, false);
// assertions will fail
assertThat(format.parse("2000-01-01")).isBetween(format.parse("2000-01-01"), format.parse("2100-12-01"), false, true);
assertThat(format.parse("2000-01-01")).isBetween(format.parse("1900-01-01"), format.parse("2000-01-01"), true, false);
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.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 SELF isBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd)
isBetween(Date, Date, boolean, boolean)
but given date is represented as String either
with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-17", "2002-12-18", false, true);
assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-18", "2002-12-19", true, false);
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-17", "2002-12-18", false, false);
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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.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 SELF isNotBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)
Date
is not in the given period defined by start and end dates.true
.true
.Example:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// assertions will pass
assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("2000-01-01"), format.parse("2100-12-01"), false, true);
assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2000-01-01"), true, false);
// assertions will fail
assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("2000-01-01"), format.parse("2100-12-01"), true, true);
assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2000-01-01"), true, true);
assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2100-01-01"), false, false);
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.inclusiveStart
- whether to include start date in period.inclusiveEnd
- whether 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 SELF isNotBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd)
isNotBetween(Date, Date, boolean, boolean)
but given date is represented as String
either with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isNotBetween("2002-12-17", "2002-12-18", false, false);
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isNotBetween("2002-12-17", "2002-12-18", false, true);
assertThat(theTwoTowers.getReleaseDate()).isNotBetween("2002-12-18", "2002-12-19", true, false);
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.inclusiveStart
- whether to include start date in period.inclusiveEnd
- whether 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 SELF isNotBetween(Date start, Date end)
Date
is not in [start, end[ period
Example:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// assertions will pass
assertThat(format.parse("1900-01-01")).isNotBetween(format.parse("2000-01-01"), format.parse("2100-12-01"));
assertThat(format.parse("2200-01-01")).isNotBetween(format.parse("2000-01-01"), format.parse("2100-12-01"));
assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2000-01-01"));
// assertions will fail
assertThat(format.parse("2001-12-24")).isNotBetween(format.parse("2000-01-01"), format.parse("2100-01-01"));
assertThat(format.parse("1900-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2000-01-01"));
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 in [start, end[ period.AssertionError
- if one of the given date as String could not be converted to a Date.public SELF isNotBetween(String start, String end)
isNotBetween(Date, Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
// assertion will pass
assertThat(theFellowshipOfTheRing.getReleaseDate()).isNotBetween("2002-12-01", "2002-12-10");
// assertion will fail
assertThat(theFellowshipOfTheRing.getReleaseDate()).isNotBetween("2002-12-01", "2002-12-19");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInThePast()
Date
is strictly in the past.
Example:
// assertion will pass
assertThat(theTwoTowers.getReleaseDate()).isInThePast();
AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
is not in the past.public SELF isToday()
Date
is today, that is matching current year, month and day (no check on hour,
minute, second, milliseconds).
Example:
// assertion will pass
assertThat(new Date()).isToday();
// assertion will fail
assertThat(theFellowshipOfTheRing.getReleaseDate()).isToday();
AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
is not today.public SELF isInTheFuture()
Date
is strictly in the future.
Example:
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isInTheFuture();
AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
is not in the future.public SELF isBeforeYear(int year)
Date
is strictly before the given year.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isBeforeYear(2004);
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isBeforeYear(2002);
assertThat(theTwoTowers.getReleaseDate()).isBeforeYear(2000);
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 SELF isAfterYear(int year)
Date
is strictly after the given year.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).isAfterYear(2001);
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).isAfterYear(2002);
assertThat(theTwoTowers.getReleaseDate()).isAfterYear(2004);
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 SELF hasYear(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)
.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).hasYear(2002);
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).hasYear(2004);
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.@Deprecated public SELF isWithinYear(int year)
hasYear(int)
instead.year
- the year to compare actual year topublic SELF hasMonth(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)
.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).hasMonth(12);
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).hasMonth(10);
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.@Deprecated public SELF isWithinMonth(int month)
hasMonth(int)
instead.month
- the month to compare actual month to, month value starting at 1 (January=1, February=2, ...).public SELF hasDayOfMonth(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)
.
Example:
// assertion will pass
// theTwoTowers release date : 2002-12-18
assertThat(theTwoTowers.getReleaseDate()).hasDayOfMonth(18);
// assertion will fail
assertThat(theTwoTowers.getReleaseDate()).hasDayOfMonth(20);
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.@Deprecated public SELF isWithinDayOfMonth(int dayOfMonth)
hasDayOfMonth(int)
instead.dayOfMonth
- the day of month to compare actual day of month topublic SELF hasDayOfWeek(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)
.
Example:
// assertion will pass
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasDayOfWeek(Calendar.SATURDAY);
// assertion will fail
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasDayOfWeek(Calendar.MONDAY);
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.@Deprecated public SELF isWithinDayOfWeek(int dayOfWeek)
hasDayOfWeek(int)
instead.dayOfWeek
- the day of week to compare actual day of week to, see Calendar.DAY_OF_WEEK
for valid
valuespublic SELF hasHourOfDay(int hourOfDay)
Date
hour of 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)
.
Example:
// assertion will pass
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasHourOfDay(13);
// assertion will fail
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasHourOfDay(22);
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.@Deprecated public SELF isWithinHourOfDay(int hourOfDay)
hasHourOfDay(int)
instead.hourOfDay
- the hour of day to compare actual hour of day to (24-hour clock)public SELF hasMinute(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)
.
Example:
// assertion will pass
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasMinute(20);
// assertion will fail
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasMinute(17);
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.@Deprecated public SELF isWithinMinute(int minute)
hasMinute(int)
instead.minute
- the minute to compare actual minute topublic SELF hasSecond(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)
.
Example:
// assertion will pass
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasSecond(35);
// assertion will fail
assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasSecond(11);
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.@Deprecated public SELF isWithinSecond(int second)
hasSecond(int)
instead.second
- the second to compare actual second topublic SELF hasMillisecond(int millisecond)
Date
millisecond is equal to the given millisecond.
Examples:
// assertion will pass
assertThat(parseDatetimeWithMs("2003-04-26T13:20:35.017")).hasMillisecond(17);
// assertion will fail
assertThat(parseDatetimeWithMs("2003-04-26T13:20:35.017")).hasMillisecond(25);
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.@Deprecated public SELF isWithinMillisecond(int millisecond)
hasMillisecond(int)
instead.millisecond
- the millisecond to compare actual millisecond topublic SELF isInSameYearAs(Date other)
Date
are in the same year.
Example:
Date date1 = parse("2003-04-26");
Date date2 = parse("2003-05-27");
assertThat(date1).isInSameYearAs(date2);
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 SELF isInSameYearAs(String dateAsString)
isInSameYearAs(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
Date date1 = parse("2003-04-26");
assertThat(date1).isInSameYearAs("2003-05-27");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInSameMonthAs(Date other)
Date
have same month and year fields.
Example:
Date date1 = parse("2003-04-26");
Date date2 = parse("2003-04-27");
assertThat(date1).isInSameMonthAs(date2);
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 SELF isInSameMonthAs(String dateAsString)
isInSameMonthAs(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
Date date1 = parse("2003-04-26");
assertThat(date1).isInSameMonthAs("2003-04-27");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInSameDayAs(Date other)
Date
have the same day of month, month and year fields values.
Example:
Date date1 = parseDatetime("2003-04-26T23:17:00");
Date date2 = parseDatetime("2003-04-26T12:30:00");
assertThat(date1).isInSameDayAs(date2);
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 SELF isInSameDayAs(String dateAsString)
isInSameDayAs(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Example:
Date date1 = parseDatetime("2003-04-26T23:17:00");
assertThat(date1).isInSameDayAs("2003-04-26");
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInSameHourWindowAs(Date other)
Date
are chronologically in the same hour (i.e. their time difference <= 1
hour).
This assertion succeeds as time difference is exactly = 1h:
Date date1 = parseDatetime("2003-04-26T13:00:00");
Date date2 = parseDatetime("2003-04-26T14:00:00");
assertThat(date1).isInSameHourWindowAs(date2);
Two dates can have different hour fields and yet be in the same chronological hour, example:
Date date1 = parseDatetime("2003-04-26T13:00:00");
Date date2 = parseDatetime("2003-04-26T12:59:59");
// succeeds as time difference == 1s
assertThat(date1).isInSameHourWindowAs(date2);
This assertion fails as time difference is more than one hour:
Date date1 = parseDatetime("2003-04-26T13:00:00");
Date date2 = parseDatetime("2003-04-26T14:00:01");
assertThat(date1).isInSameHourWindowAs(date2);
To compare date's hour fields only (without day, month and year), you can write :
assertThat(myDate).isWithinHour(hourOfDayOf(otherDate));
see hourOfDayOf
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 SELF isInSameHourWindowAs(String dateAsString)
isInSameHourWindowAs(java.util.Date)
but given date is represented as String either
with one of the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInSameHourAs(Date other)
Date
have same hour, day, month and year fields values.
Example:
Date date1 = parseDatetime("2003-01-01T12:00:00");
Date date2 = parseDatetime("2003-01-01T12:30:00");
// succeeds
assertThat(date1).isInSameHourAs(date2);
This assertion does not make a true chronological comparison since two dates can have different hour fields
and yet be in the same chronological hour, e.g:
// dates in the same hour time window but with different hour fields
Date date1 = parseDatetime("2003-01-01T12:00:00");
Date date2 = parseDatetime("2003-01-01T11:59:00");
If you want to assert that two dates are chronologically in the same hour time window use
isInSameHourWindowAs
assertion (note that if
isInSameHourAs
succeeds then isInSameHourWindowAs
will succeed too).
If you want to compare hour only (without day, month and year), you could write :
assertThat(myDate).isWithinHour(hourOfDayOf(otherDate))
see DateUtil.hourOfDayOf(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 SELF isInSameHourAs(String dateAsString)
isInSameHourAs(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInSameMinuteWindowAs(Date other)
Date
are chronologically in the same minute (i.e. their time difference <= 1
minute).
Example:
Date date1 = parseDatetime("2003-01-01T12:01:00");
Date date2 = parseDatetime("2003-01-01T12:01:30");
// succeeds because date time difference < 1 min
assertThat(date1).isInSameMinuteWindowAs(date2);
Two dates can have different minute fields and yet be in the same chronological minute, example:
Date date1 = parseDatetime("2003-01-01T12:01:00");
Date date3 = parseDatetime("2003-01-01T12:00:59");
// succeeds as time difference == 1s even though minutes fields differ
assertThat(date1).isInSameMinuteWindowAs(date3);
This assertion fails as time difference is >= one minute:
Date date1 = parseDatetime("2003-01-01T12:01:00");
Date date2 = parseDatetime("2003-01-01T12:02:00");
// fails, time difference should hae been < 1 min
assertThat(date1).isInSameMinuteWindowAs(date2); // ERROR
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 SELF isInSameMinuteWindowAs(String dateAsString)
isInSameMinuteWindowAs(Date)
but given date is represented as String either with one of
the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInSameMinuteAs(Date other)
Date
have same minute, same hour, day, month and year fields values.
Example:
Date date1 = parseDatetime("2003-01-01T12:01:00");
Date date2 = parseDatetime("2003-01-01T12:01:30");
// succeeds because the all the fields up to minutes are the same
assertThat(date1).isInSameMinuteAs(date2);
It does not make a true chronological comparison since two dates can have different minute fields and yet be
in the same chronological minute, e.g:
// dates in the same minute time window but with different minute fields
Date date1 = parseDatetime("2003-01-01T12:01:00");
Date date3 = parseDatetime("2003-01-01T12:00:59");
// fails because minutes fields differ even though time difference is only 1s !
assertThat(date1).isInSameMinuteAs(date3); // ERROR
If you want to assert that two dates are in the same minute time window use
isInSameMinuteWindowAs
assertion (note that if
isInSameMinuteAs
succeeds then isInSameMinuteWindowAs
will succeed too).
If you want to compare minute field only (without hour, day, month and year), you could write :
assertThat(myDate).hasMinute(minuteOf(otherDate))
using DateUtil.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 SELF isInSameMinuteAs(String dateAsString)
isInSameMinuteAs(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF isInSameSecondWindowAs(Date other)
Date
are chronologically strictly in the same second (i.e. their time
difference < 1 second).
Example:
Date date1 = parseDatetimeWithMs("2003-04-26T13:01:02.123");
Date date2 = parseDatetimeWithMs("2003-04-26T13:01:02.456");
// succeeds as time difference is < 1s
assertThat(date1).isInSameSecondWindowAs(date2);
Two dates can have different second fields and yet be in the same chronological second, example:
Date date1 = parseDatetimeWithMs("2003-04-26T13:01:02.999");
Date date2 = parseDatetimeWithMs("2003-04-26T13:01:03.000");
// succeeds as time difference is 1ms < 1s
assertThat(date1).isInSameSecondWindowAs(date2);
Those assertions fail as time difference is greater or equal to one second:
Date date1 = parseDatetimeWithMs("2003-04-26T13:01:01.000");
Date date2 = parseDatetimeWithMs("2003-04-26T13:01:02.000");
// fails as time difference = 1s
assertThat(date1).isInSameSecondWindowAs(date2); // ERROR
Date date3 = parseDatetimeWithMs("2003-04-26T13:01:02.001");
// fails as time difference > 1s
assertThat(date1).isInSameSecondWindowAs(date3); // ERROR
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 SELF isInSameSecondWindowAs(String dateAsString)
isInSameSecondWindowAs(Date)
but given date is represented as String either with one of
the supported defaults date format or a user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
dateAsString
- the given Date represented as String.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 SELF isInSameSecondAs(Date other)
Date
have same second, minute, hour, day, month and year fields values.
Date date1 = parseDatetimeWithMs("2003-01-01T12:00:01.000");
Date date2 = parseDatetimeWithMs("2003-01-01T12:00:01.250");
// succeeds because the all the time fields up to seconds are the same
assertThat(date1).isInSameSecondAs(date2);
It does not make a true chronological comparison since two dates can have different second fields and yet
be
in the same chronological second, e.g:
Date date1 = parseDatetimeWithMs("2003-01-01T12:00:01.000");
Date date3 = parseDatetimeWithMs("2003-01-01T12:00:00.999");
// fails because seconds fields differ even though time difference is only 1ms !
assertThat(date1).isInSameSecondAs(date3); // ERROR
If you want to assert that two dates are in the same second time window use
isInSameSecondWindowAs
assertion.
If you want to compare second fields only (without minute, hour, day, month and year), you could write :
assertThat(myDate).hasSecond(secondOf(otherDate))
using DateUtil.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 SELF isInSameSecondAs(String dateAsString)
isInSameSecondAs(Date)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
dateAsString
- the given Date represented as String.public SELF 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)
.
Example:
Date date1 = new Date();
Date date2 = new Date(date1.getTime() + 100);
// assertion will pass
assertThat(date1).isCloseTo(date2, 80);
assertThat(date1).isCloseTo(date2, 100);
// assertion will fail
assertThat(date1).isCloseTo(date2, 101);
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 SELF isCloseTo(String dateAsString, long deltaInMilliseconds)
isCloseTo(Date, long)
but given date is represented as String either with one of the
supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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 SELF 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.
Example:
assertThat(new Date(42)).hasTime(42);
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 SELF hasSameTimeAs(Date date)
Date
has the same time as the given date, useful to compare Date
and
Timestamp
.
Example:
Date date = new Date();
Timestamp timestamp = new Timestamp(date.getTime());
// Fail as date is not an instance of Timestamp
assertThat(date).isEqualTo(timestamp);
// Succeed as we compare date and timestamp time.
assertThat(date).hasSameTimeAs(timestamp);
date
- the date to compare actual time to.AssertionError
- if the actual Date
is null
.AssertionError
- if the actual Date
time is not equal to the given date time.NullPointerException
- if Date
parameter is null
.Date.getTime()
public SELF hasSameTimeAs(String dateAsString)
Date
represents the same time as the given date in String
format.
It is the same assertion as hasSameTimeAs(Date)
but given date is represented as String either with one of
the supported default date formats or a user custom date format (set with method
withDateFormat(DateFormat)
).
Beware that the default formats are expressed in the current local time zone.
Example:
Date date = parseDatetime("2003-04-26T12:00:00");
// assertion will pass
assertThat(date).hasSameTimeAs("2003-04-26T12:00:00");
// assertion will fail
assertThat(date).hasSameTimeAs("2003-04-26T12:00:01");
assertThat(date).hasSameTimeAs("2003-04-27T12:00:00");
Default date formats (expressed in the local time zone) are:
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
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
time is not equal to the time from date represented as
String.AssertionError
- if the given date as String could not be converted to a Date.public SELF withDateFormat(DateFormat userCustomDateFormat)
isEqualTo(String)
,
AssertJ is gonna use any date formats registered with one of these methods :
withDateFormat(String)
registerCustomDateFormat(java.text.DateFormat)
registerCustomDateFormat(String)
Beware that :
To revert to default format, call useDefaultDateFormatsOnly()
or withDefaultDateFormatsOnly()
.
userCustomDateFormat
- the new Date format used for String based Date assertions.public SELF withDateFormat(String userCustomDateFormatPattern)
isEqualTo(String)
,
AssertJ is gonna use any date formats registered with one of these methods :
withDateFormat(java.text.DateFormat)
registerCustomDateFormat(java.text.DateFormat)
registerCustomDateFormat(String)
Beware that :
To revert to default format, call useDefaultDateFormatsOnly()
or withDefaultDateFormatsOnly()
.
userCustomDateFormatPattern
- the new Date format string pattern used for String based Date assertions.public static void setLenientDateParsing(boolean value)
With strict parsing, inputs must match exactly date/time format.
Example:
final Date date = Dates.parse("2001-02-03");
final Date dateTime = parseDatetime("2001-02-03T04:05:06");
final Date dateTimeWithMs = parseDatetimeWithMs("2001-02-03T04:05:06.700");
AbstractDateAssert.setLenientDateParsing(true);
// assertions will pass
assertThat(date).isEqualTo("2001-01-34");
assertThat(date).isEqualTo("2001-02-02T24:00:00");
assertThat(date).isEqualTo("2001-02-04T-24:00:00.000");
assertThat(dateTime).isEqualTo("2001-02-03T04:05:05.1000");
assertThat(dateTime).isEqualTo("2001-02-03T04:04:66");
assertThat(dateTimeWithMs).isEqualTo("2001-02-03T04:05:07.-300");
// assertions will fail
assertThat(date).hasSameTimeAs("2001-02-04"); // different date
assertThat(dateTime).hasSameTimeAs("2001-02-03 04:05:06"); // leniency does not help here
To revert to default strict date parsing, call setLenientDateParsing(false)
.value
- whether lenient parsing mode should be enabled or notpublic static void registerCustomDateFormat(DateFormat userCustomDateFormat)
isEqualTo(String)
.
User date formats are used before default ones in the order they have been registered (first registered, first used).
AssertJ is gonna use any date formats registered with one of these methods :
withDateFormat(String)
withDateFormat(java.text.DateFormat)
registerCustomDateFormat(String)
Beware that AssertJ will use the newly registered format for all remaining Date assertions in the test suite
To revert to default formats only, call useDefaultDateFormatsOnly()
or
withDefaultDateFormatsOnly()
.
Code examples:
Date date = ... // set to 2003 April the 26th
assertThat(date).isEqualTo("2003-04-26");
try {
// date with a custom format : failure since the default formats don't match.
assertThat(date).isEqualTo("2003/04/26");
} catch (AssertionError e) {
assertThat(e).hasMessage("Failed to parse 2003/04/26 with any of these date formats: " +
"[yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd]");
}
// registering a custom date format to make the assertion pass
registerCustomDateFormat(new SimpleDateFormat("yyyy/MM/dd")); // registerCustomDateFormat("yyyy/MM/dd") would work to.
assertThat(date).isEqualTo("2003/04/26");
// the default formats are still available and should work
assertThat(date).isEqualTo("2003-04-26");
userCustomDateFormat
- the new Date format used for String based Date assertions.public static void registerCustomDateFormat(String userCustomDateFormatPattern)
isEqualTo(String)
.
User date formats are used before default ones in the order they have been registered (first registered, first used).
AssertJ is gonna use any date formats registered with one of these methods :
withDateFormat(String)
withDateFormat(java.text.DateFormat)
registerCustomDateFormat(java.text.DateFormat)
Beware that AssertJ will use the newly registered format for all remaining Date assertions in the test suite
To revert to default formats only, call useDefaultDateFormatsOnly()
or
withDefaultDateFormatsOnly()
.
Code examples:
Date date = ... // set to 2003 April the 26th
assertThat(date).isEqualTo("2003-04-26");
try {
// date with a custom format : failure since the default formats don't match.
assertThat(date).isEqualTo("2003/04/26");
} catch (AssertionError e) {
assertThat(e).hasMessage("Failed to parse 2003/04/26 with any of these date formats: " +
"[yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd]");
}
// registering a custom date format to make the assertion pass
registerCustomDateFormat("yyyy/MM/dd");
assertThat(date).isEqualTo("2003/04/26");
// the default formats are still available and should work
assertThat(date).isEqualTo("2003-04-26");
userCustomDateFormatPattern
- the new Date format pattern used for String based Date assertions.public static void useDefaultDateFormatsOnly()
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
public SELF withDefaultDateFormatsOnly()
Beware that the default formats are expressed in the current local timezone.
Defaults date format (expressed in the local time zone) are :
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
public SELF usingComparator(Comparator<? super Date> customComparator)
AbstractAssert
The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
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<SELF extends AbstractDateAssert<SELF>,Date>
usingComparator
in class AbstractAssert<SELF extends AbstractDateAssert<SELF>,Date>
customComparator
- the comparator to use for the incoming assertion checks.this
assertion object.public SELF usingComparator(Comparator<? super Date> customComparator, String customComparatorDescription)
AbstractAssert
The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator, "Hobbit Race Comparator").isEqualTo(sam);
usingComparator
in interface Assert<SELF extends AbstractDateAssert<SELF>,Date>
usingComparator
in class AbstractAssert<SELF extends AbstractDateAssert<SELF>,Date>
customComparator
- the comparator to use for the incoming assertion checks.customComparatorDescription
- comparator description to be used in assertion error messagesthis
assertion object.public SELF usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling usingComparator
.
usingDefaultComparator
in interface Assert<SELF extends AbstractDateAssert<SELF>,Date>
usingDefaultComparator
in class AbstractAssert<SELF extends AbstractDateAssert<SELF>,Date>
this
assertion object.Copyright © 2014–2019 AssertJ. All rights reserved.