Top Description Fields Constructors Methods
org.assertj.core.api

public abstract Class AbstractDateAssert<SELF extends AbstractDateAssert<SELF>>

extends AbstractAssert<SELF extends AbstractDateAssert<SELF>, Date>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.DateAssert
Type Parameters
<SELF>
the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
Static Imports
java.util.Objects.requireNonNull, java.util.concurrent.TimeUnit.HOURS, .TimeUnit.MILLISECONDS, .TimeUnit.MINUTES, .TimeUnit.SECONDS, java.util.stream.Collectors.toList, org.assertj.core.util.DateUtil.newIsoDateFormat, .DateUtil.newIsoDateTimeFormat, .DateUtil.newIsoDateTimeWithIsoTimeZoneFormat, .DateUtil.newIsoDateTimeWithMsAndIsoTimeZoneFormat, .DateUtil.newIsoDateTimeWithMsFormat, .DateUtil.newTimestampDateFormat, .Lists.list, .Lists.newArrayList

Base class for all implementations of assertions for Dates.

Note that assertions with date parameter come with two flavors, 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().

Authors
Tomasz Nurkiewicz (thanks for giving assertions idea), Joel Costigliola, Mikhail Mazursky, William Delanoue, Michal Kordas, Eddú Meléndez

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
pack-priv Dates
private static List<DateFormat>
DEFAULT_DATE_FORMATS

the default DateFormat used to parse any String date representation.

private static boolean
pack-priv static ThreadLocal<LinkedHashSet<DateFormat>>
userDateFormats

Used in String based Date assertions - like isAfter(String) - to convert input date represented as string to Date.

Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected
AbstractDateAssert(Date actual, Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
private List<DateFormat>
private Date
dateFrom(Instant instant)

private static boolean
pack-priv static List<DateFormat>
public SELF

Returns:

this assertion object.
hasDayOfMonth
(int
the day of month to compare actual day of month to
dayOfMonth
)

Verifies that the actual Date day of month is equal to the given day of month.

public SELF

Returns:

this assertion object.
hasDayOfWeek
(int
the day of week to compare actual day of week to, see Calendar#DAY_OF_WEEK for valid values
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).

public SELF

Returns:

this assertion object.
hasHourOfDay
(int
the hour of day to compare actual hour of day to (24-hour clock)
hourOfDay
)

Verifies that the actual Date hour of day is equal to the given hour of day (24-hour clock).

public SELF

Returns:

this assertion object.
hasMillisecond
(int
the millisecond to compare actual millisecond to
millisecond
)

Verifies that the actual Date millisecond is equal to the given millisecond.

public SELF

Returns:

this assertion object.
hasMinute
(int
the minute to compare actual minute to
minute
)

Verifies that the actual Date minute is equal to the given minute.

public SELF

Returns:

this assertion object.
hasMonth
(int
the month to compare actual month to, month value starting at 1 (January=1, February=2, ...).
month
)

Verifies that the actual Date month is equal to the given month, month value starting at 1 (January=1, February=2, ...).

public SELF

Returns:

this assertion object.
hasSameTimeAs
(Date
the date to compare actual time to.
date
)

Verifies that the actual Date has the same time as the given date, useful to compare Date and java.sql.Timestamp.

public SELF

Returns:

this assertion object.
hasSameTimeAs
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Verifies that the actual Date represents the same time as the given date in String format.

public SELF

Returns:

this assertion object.
hasSecond
(int
the second to compare actual second to
second
)

Verifies that the actual Date second is equal to the given second.

public SELF

Returns:

this assertion object.
hasTime
(long
the timestamp to compare actual time to.
timestamp
)

Verifies that the actual Date has the same time as the given timestamp.

public SELF

Returns:

this assertion object.
hasYear
(int
the year to compare actual year to
year
)

Verifies that the actual Date year is equal to the given year.

public SELF

Returns:

this assertion object.
isAfter
(Date
the given Date.
other
)

Verifies that the actual Date is strictly after the given one.

public SELF

Returns:

this assertion object.
isAfter
(Instant
the given Instant.
other
)

Verifies that the actual Date is strictly after the given Instant.

public SELF

Returns:

this assertion object.
isAfter
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isAfter(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)).

public SELF

Returns:

this assertion object.
isAfterOrEqualsTo
(Date
the given Date.
other
)

Deprecated prefer calling isAfterOrEqualTo(Date)
Verifies that the actual Date is after or equals to the given one.
public SELF

Returns:

this assertion object.
isAfterOrEqualsTo
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated prefer calling isAfterOrEqualTo(String)
Same assertion as isAfterOrEqualsTo(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)).
public SELF

Returns:

this assertion object.
isAfterOrEqualTo
(Date
the given Date.
other
)

Verifies that the actual Date is after or equal to the given one.

public SELF

Returns:

this assertion object.
isAfterOrEqualTo
(Instant
the given Instant.
other
)

Verifies that the actual Date is after or equal to the given Instant.

public SELF

Returns:

this assertion object.
isAfterOrEqualTo
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isAfterOrEqualTo(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)).

public SELF

Returns:

this assertion object.
isAfterYear
(int
the year to compare actual year to
year
)

Verifies that the actual Date is strictly after the given year.

public SELF

Returns:

this assertion object.
isBefore
(Date
the given Date.
other
)

Verifies that the actual Date is strictly before the given one.

public SELF

Returns:

this assertion object.
isBefore
(Instant
the given Instant.
other
)

Verifies that the actual Date is strictly before the given Instant.

public SELF

Returns:

this assertion object.
isBefore
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isBefore(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)).

public SELF

Returns:

this assertion object.
isBeforeOrEqualsTo
(Date
the given Date.
other
)

Deprecated prefer calling isBeforeOrEqualTo(Date)
Verifies that the actual Date is before or equals to the given one.
public SELF

Returns:

this assertion object.
isBeforeOrEqualsTo
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated prefer calling isBeforeOrEqualTo(String)
Same assertion as isBeforeOrEqualsTo(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)).
public SELF

Returns:

this assertion object.
isBeforeOrEqualTo
(Date
the given Date.
other
)

Verifies that the actual Date is before or equal to the given one.

public SELF

Returns:

this assertion object.
isBeforeOrEqualTo
(Instant
the given Instant.
other
)

Verifies that the actual Date is before or equal to the given Instant.

public SELF

Returns:

this assertion object.
isBeforeOrEqualTo
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isBeforeOrEqualTo(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)).

public SELF

Returns:

this assertion object.
isBeforeYear
(int
the year to compare actual year to
year
)

Verifies that the actual Date is strictly before the given year.

public SELF

Returns:

this assertion object.
isBetween
(Date
the period start (inclusive), expected not to be null.
start
,
Date
the period end (exclusive), expected not to be null.
end
)

Verifies that the actual Date is in [start, end[ period (start included, end excluded).

public SELF

Returns:

this assertion object.
isBetween
(String
the period start (inclusive), expected not to be null.
start
,
String
the period end (exclusive), expected not to be null.
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)).

public SELF

Returns:

this assertion object.
isBetween
(Instant
the period start (inclusive), expected not to be null.
start
,
Instant
the period end (exclusive), expected not to be null.
end
)

Same assertion as isBetween(Date, Date) but given period is represented with java.time.Instant.

public SELF

Returns:

this assertion object.
isBetween
(Date
the period start, expected not to be null.
start
,
Date
the period end, expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Verifies that the actual Date is in the given period defined by start and end dates.

public SELF

Returns:

this assertion object.
isBetween
(String
the period start, expected not to be null.
start
,
String
the period end, expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Same assertion as isBetween(Date, Date, boolean, boolean) 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)).

public SELF

Returns:

this assertion object.
isBetween
(Instant
the period start, expected not to be null.
start
,
Instant
the period end, expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Same assertion as isBetween(Date, Date, boolean, boolean) but given period is represented with java.time.Instant.

public SELF

Returns:

this assertion object.
isCloseTo
(Date
the date to compare actual to
other
,
long
the delta used for date comparison, expressed in milliseconds
deltaInMilliseconds
)

Verifies that the actual Date is close to the other date by less than delta (expressed in milliseconds), if difference is equal to delta it's ok.

public SELF

Returns:

this assertion object.
isCloseTo
(Instant
the Instant to compare actual to
other
,
long
the delta used for date comparison, expressed in milliseconds
deltaInMilliseconds
)

Verifies that the actual Date is close to the given Instant by less than delta (expressed in milliseconds), if the difference is equal to delta the assertion succeeds.

public SELF

Returns:

this assertion object.
isCloseTo
(String
the given Date represented as String in default or custom date format.
dateAsString
,
long
the delta used for date comparison, expressed in milliseconds
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)).

public SELF

Returns:

this assertion object.
isEqualTo
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isEqualTo(Date date) but given date is represented as a String either with one of the supported default date formats or a user custom date format set with method withDateFormat(DateFormat).

public SELF

Returns:

this assertion object.
isEqualTo
(Instant
the given Instant to compare to actual.
instant
)

Calls isEqualTo(Date date) after converting the given Instant to a Date.

public SELF

Returns:

this assertion object.
isEqualToIgnoringHours
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#isEqualToIgnoringHours(Date) but given Date is represented as String either with one of the default supported date formats or user custom date format (set with method withDateFormat(DateFormat)).
public SELF

Returns:

this assertion object.
isEqualToIgnoringHours
(Instant
the given Instant.
instant
)

Deprecated Use isCloseTo(Instant, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#isEqualToIgnoringHours(Date) but given Date is represented as an java.time.Instant.
public SELF

Returns:

this assertion object.
isEqualToIgnoringHours
(Date
the given Date.
date
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractAssert#isEqualTo(Object) but the comparison ignores hours, minutes, seconds and milliseconds.
public SELF

Returns:

this assertion object.
isEqualToIgnoringMillis
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#isEqualToIgnoringMillis(Date) but given Date is represented as String either with one of the default supported date formats or user custom date format (set with method withDateFormat(DateFormat)).
public SELF

Returns:

this assertion object.
isEqualToIgnoringMillis
(Instant
the given Instant.
instant
)

Deprecated Use isCloseTo(Instant, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#isEqualToIgnoringMillis(Date) but given Date is represented as an java.time.Instant.
public SELF

Returns:

this assertion object.
isEqualToIgnoringMillis
(Date
the given Date represented as String in default or custom date format.
date
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractAssert#isEqualTo(Object) but given Date should not take care of milliseconds precision.
public SELF

Returns:

this assertion object.
isEqualToIgnoringMinutes
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#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)).
public SELF

Returns:

this assertion object.
isEqualToIgnoringMinutes
(Instant
the given Instant.
instant
)

Deprecated Use isCloseTo(Instant, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#isEqualToIgnoringMinutes(Date) but given Date is represented as an java.time.Instant.
public SELF

Returns:

this assertion object.
isEqualToIgnoringMinutes
(Date
the given Date.
date
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractAssert#isEqualTo(Object) but given Date should not take care of minutes, seconds and millisecond precision.
public SELF

Returns:

this assertion object.
isEqualToIgnoringSeconds
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#isEqualToIgnoringSeconds(Date) but given Date is represented as String either with one of the default supported date formats or user custom date format (set with method withDateFormat(DateFormat)).
public SELF

Returns:

this assertion object.
isEqualToIgnoringSeconds
(Instant
the given Instant.
instant
)

Deprecated Use isCloseTo(Instant, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractDateAssert#isEqualToIgnoringSeconds(Date) but given Date is represented as an java.time.Instant.
public SELF

Returns:

this assertion object.
isEqualToIgnoringSeconds
(Date
the given Date represented as String in default or custom date format.
date
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as AbstractAssert#isEqualTo(Object) but given Date should not take care of seconds and millisecond precision.
public SELF

Returns:

this assertion object.
isIn
(String...
the given Dates represented as String in default or custom date format.
datesAsString
)

Same assertion as Assert#isIn(Object...)but given dates are represented as String either with one of the supported default date formats or a user custom date format (set with method withDateFormat(DateFormat)).

public SELF

Returns:

this assertion object.
isIn
(Instant...
the given dates represented as Instant.
instants
)

Same assertion as Assert#isIn(Object...)but given dates are represented as an java.time.Instant.

public SELF

Returns:

this assertion object.
isInSameDayAs
(Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date have the same day of month, month and year fields values.

public SELF

Returns:

this assertion object.
isInSameDayAs
(Instant
the given Date to compare actual Date to.
other
)

Verifies that actual Date and given Instant have the same day of month, month and year fields values.

public SELF

Returns:

this assertion object.
isInSameDayAs
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isInSameDayAs(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)).

public SELF

Returns:

this assertion object.
isInSameHourAs
(Date
the given Date to compare actual Date to.
other
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Verifies that actual and given Date have same hour, day, month and year fields values.
public SELF

Returns:

this assertion object.
isInSameHourAs
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as isInSameHourAs(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)).
public SELF

Returns:

this assertion object.
isInSameHourWindowAs
(Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically in the same hour (i.e. their time difference < 1 hour).

public SELF

Returns:

this assertion object.
isInSameHourWindowAs
(Instant
the given Instant to compare actual Date to.
other
)

Verifies that actual Date and given Instant are chronologically in the same hour (i.e. their time difference < 1 hour).

public SELF

Returns:

this assertion object.
isInSameHourWindowAs
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isInSameHourWindowAs(java.util.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)).

public SELF

Returns:

this assertion object.
isInSameMinuteAs
(Date
the given Date to compare actual Date to.
other
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Verifies that actual and given Date have same minute, same hour, day, month and year fields values.
public SELF

Returns:

this assertion object.
isInSameMinuteAs
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Same assertion as isInSameMinuteAs(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)).
public SELF

Returns:

this assertion object.
isInSameMinuteWindowAs
(Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically in the same minute (i.e. their time difference < 1 minute).

public SELF

Returns:

this assertion object.
isInSameMinuteWindowAs
(Instant
the given Instant to compare actual Date to.
other
)

Verifies that actual Date and given Instant are chronologically in the same minute (i.e. their time difference < 1 minute).

public SELF

Returns:

this assertion object.
isInSameMinuteWindowAs
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isInSameMinuteWindowAs(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)).

public SELF

Returns:

this assertion object.
isInSameMonthAs
(Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date have same month and year fields.

public SELF

Returns:

this assertion object.
isInSameMonthAs
(Instant
the given Instant to compare actual Date to.
other
)

Verifies that actual Date and given Instant have same month and year fields.

public SELF

Returns:

this assertion object.
isInSameMonthAs
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isInSameMonthAs(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)).

public SELF

Returns:

this assertion object.
isInSameSecondAs
(Date
the given Date to compare actual Date to.
other
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Verifies that actual and given Date have same second, minute, hour, day, month and year fields values.
public SELF

Returns:

this assertion object.
isInSameSecondAs
(String
the given Date represented as String.
dateAsString
)

Deprecated Use isCloseTo(Date, long) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
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)).
public SELF

Returns:

this assertion object.
isInSameSecondWindowAs
(Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically strictly in the same second (i.e. their time difference < 1 second).

public SELF

Returns:

this assertion object.
isInSameSecondWindowAs
(Instant
the given Instant to compare actual Date to.
other
)

Verifies that actual Date and given Instant are chronologically strictly in the same second (i.e. their time difference < 1 second).

public SELF

Returns:

this assertion object.
isInSameSecondWindowAs
(String
the given Date represented as String.
dateAsString
)

Same assertion as isInSameSecondWindowAs(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)).

public SELF

Returns:

this assertion object.
isInSameYearAs
(Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are in the same year.

public SELF

Returns:

this assertion object.
isInSameYearAs
(Instant
the given Instant to compare actual Date to.
other
)

Verifies that actual Date and given Instant are in the same year.

public SELF

Returns:

this assertion object.
isInSameYearAs
(String
the given Date represented as String in default or custom date format.
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)).

public SELF

Returns:

this assertion object.
isInTheFuture
()

Verifies that the actual Date is strictly in the future.

public SELF

Returns:

this assertion object.
isInThePast
()

Verifies that the actual Date is strictly in the past.

public SELF

Returns:

this assertion object.
isInWithStringDateCollection
(Collection<String>
the given Dates represented as String in default or custom date format.
datesAsString
)

Same assertion as Assert#isIn(Iterable) but given dates are represented as String either with one of the supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)).

public SELF

Returns:

this assertion object.
isNotBetween
(Date
the period start (inclusive), expected not to be null.
start
,
Date
the period end (exclusive), expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Verifies that the actual Date is not in the given period defined by start and end dates.

public SELF

Returns:

this assertion object.
isNotBetween
(Instant
the period start (inclusive), expected not to be null.
start
,
Instant
the period end (exclusive), expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Verifies that the actual Date is not in the given period defined by start and end dates.

public SELF

Returns:

this assertion object.
isNotBetween
(String
the period start (inclusive), expected not to be null.
start
,
String
the period end (exclusive), expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Same assertion as isNotBetween(Date, Date, boolean, boolean) 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)).

public SELF

Returns:

this assertion object.
isNotBetween
(Date
the period start (inclusive), expected not to be null.
start
,
Date
the period end (exclusive), expected not to be null.
end
)

Verifies that the actual 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"));
public SELF

Returns:

this assertion object.
isNotBetween
(Instant
the period start (inclusive), expected not to be null.
start
,
Instant
the period end (exclusive), expected not to be null.
end
)

Verifies that the actual 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(Instant.parse("2000-01-01T00:00:00Z"), Instant.parse("2100-12-01T00:00:00Z"));
assertThat(format.parse("2200-01-01")).isNotBetween(Instant.parse("2000-01-01T00:00:00Z"), Instant.parse("2100-12-01T00:00:00Z"));
assertThat(format.parse("2000-01-01")).isNotBetween(Instant.parse("1900-01-01T00:00:00Z"), Instant.parse("2000-01-01T00:00:00Z"));

// assertions will fail
assertThat(format.parse("2001-12-24")).isNotBetween(Instant.parse("2000-01-01T00:00:00Z"), Instant.parse("2100-01-01T00:00:00Z"));
assertThat(format.parse("1900-01-01")).isNotBetween(Instant.parse("1900-01-01T00:00:00Z"), Instant.parse("2000-01-01T00:00:00Z"));
public SELF

Returns:

this assertion object.
isNotBetween
(String
the period start (inclusive), expected not to be null.
start
,
String
the period end (exclusive), expected not to be null.
end
)

Same assertion as isNotBetween(Date, 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)).

public SELF

Returns:

this assertion object.
isNotEqualTo
(String
the given Date represented as String in default or custom date format.
dateAsString
)

Same assertion as isNotEqualTo(Date 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)).

public SELF

Returns:

this assertion object.
isNotEqualTo
(Instant
the given Instant.
instant
)

Same assertion as isNotEqualTo(Date date) but given date is represented as an java.time.Instant.

public SELF

Returns:

this assertion object.
isNotIn
(String...
the given Dates represented as String in default or custom date format.
datesAsString
)

Same assertion as Assert#isNotIn(Object...) but given dates are represented as String either with one of the supported defaults date format or a user custom date format (set with method withDateFormat(DateFormat)).

public SELF

Returns:

this assertion object.
isNotIn
(Instant...
the given dates represented as Instant.
instants
)

Same assertion as Assert#isNotIn(Object...) but given dates are represented as java.time.Instant.

public SELF

Returns:

this assertion object.
isNotInWithStringDateCollection
(Collection<String>
the given Dates represented as String in default or custom date format.
datesAsString
)

Same assertion as Assert#isNotIn(Iterable) 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)).

public SELF

Returns:

this assertion object.
isToday
()

Verifies that the actual Date is today, that is matching current year, month and day (no check on hour, minute, second, milliseconds).

public SELF

Returns:

this assertion object.
isWithinDayOfMonth
(int
the day of month to compare actual day of month to
dayOfMonth
)

Deprecated use hasDayOfMonth(int) instead.
public SELF

Returns:

this assertion object.
isWithinDayOfWeek
(int
the day of week to compare actual day of week to, see Calendar#DAY_OF_WEEK for valid values
dayOfWeek
)

Deprecated use hasDayOfWeek(int) instead.
public SELF

Returns:

this assertion object.
isWithinHourOfDay
(int
the hour of day to compare actual hour of day to (24-hour clock)
hourOfDay
)

Deprecated use hasHourOfDay(int) instead.
public SELF

Returns:

this assertion object.
isWithinMillisecond
(int
the millisecond to compare actual millisecond to
millisecond
)

Deprecated use hasMillisecond(int) instead.
public SELF

Returns:

this assertion object.
isWithinMinute
(int
the minute to compare actual minute to
minute
)

Deprecated use hasMinute(int) instead.
public SELF

Returns:

this assertion object.
isWithinMonth
(int
the month to compare actual month to, month value starting at 1 (January=1, February=2, ...).
month
)

Deprecated use hasMonth(int) instead.
public SELF

Returns:

this assertion object.
isWithinSecond
(int
the second to compare actual second to
second
)

Deprecated use hasSecond(int) instead.
public SELF

Returns:

this assertion object.
isWithinYear
(int
the year to compare actual year to
year
)

Deprecated use hasYear(int) instead.
pack-priv Date

Returns:

the corresponding Date, null if dateAsString parameter is null.
parse
(String
the string to parse as a Date with userDateFormats
dateAsString
)

Thread safe utility method to parse a Date with userDateFormats first, then defaultDateFormats().

private Date
parseDateWith(final String dateAsString, final Collection<DateFormat> dateFormats)

private synchronized Date
public static void
registerCustomDateFormat(DateFormat
the new Date format used for String based Date assertions.
userCustomDateFormat
)

Add the given date format to the ones used to parse date String in String based Date assertions like isEqualTo(String).

public static void
registerCustomDateFormat(String
the new Date format pattern used for String based Date assertions.
userCustomDateFormatPattern
)

Add the given date format to the ones used to parse date String in String based Date assertions like isEqualTo(String).

public static void
setLenientDateParsing(boolean
whether lenient parsing mode should be enabled or not
lenientDateParsing
)

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).

private static <T> Date[]
toDateArray(T[] values, Function<T, Date> converter)

public static void
useDefaultDateFormatsOnly()

Remove all registered custom date formats => use only the defaults date formats to parse string as date.

public SELF
usingComparator(Comparator<? super Date>
the comparator to use for the incoming assertion checks.
customComparator
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingComparator(Comparator<? super Date>
the comparator to use for the incoming assertion checks.
customComparator
,
String
comparator description to be used in assertion error messages
customComparatorDescription
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingDefaultComparator()

Overrides org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Implements org.assertj.core.api.Assert.usingDefaultComparator.

Revert to standard comparison for the incoming assertion checks.
public SELF

Returns:

this assertion object.
withDateFormat
(DateFormat
the new Date format used for String based Date assertions.
userCustomDateFormat
)

Instead of using default date formats for the date String based Date assertions like isEqualTo(String), AssertJ is going to use any date formats registered with one of these methods :

public SELF

Returns:

this assertion object.
withDateFormat
(String
the new Date format string pattern used for String based Date assertions.
userCustomDateFormatPattern
)

Instead of using default date formats for the date String based Date assertions like isEqualTo(String), AssertJ is going to use any date formats registered with one of these methods :

public SELF

Returns:

this assertion
withDefaultDateFormatsOnly
()

Remove all registered custom date formats => use only the default date formats to parse string as date.

Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError