public abstract class AbstractZonedDateTimeAssert<SELF extends AbstractZonedDateTimeAssert<SELF>> extends AbstractTemporalAssert<SELF,ZonedDateTime>
| Modifier and Type | Field and Description |
|---|---|
static String |
NULL_DATE_TIME_PARAMETER_MESSAGE |
actual, info, myself, objects, throwUnsupportedExceptionOnEquals| Modifier | Constructor and Description |
|---|---|
protected |
AbstractZonedDateTimeAssert(ZonedDateTime actual,
Class<?> selfType) |
| Modifier and Type | Method and Description |
|---|---|
SELF |
isAfter(String dateTimeAsString)
Same assertion as
isAfter(ZonedDateTime) but the ZonedDateTime is built from given String, which
must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isAfter(ZonedDateTime other)
Verifies that the actual
ZonedDateTime is strictly after the given one according to the comparator in use. |
SELF |
isAfterOrEqualTo(String dateTimeAsString)
Same assertion as
isAfterOrEqualTo(ZonedDateTime) but the ZonedDateTime is built from given
String which must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isAfterOrEqualTo(ZonedDateTime other)
Verifies that the actual
ZonedDateTime is after or equals to the given one according to the comparator in use. |
SELF |
isBefore(String dateTimeAsString)
Same assertion as
isBefore(ZonedDateTime) but the ZonedDateTime is built from given String, which
must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isBefore(ZonedDateTime other)
Verifies that the actual
ZonedDateTime is strictly before the given one according to the comparator in use. |
SELF |
isBeforeOrEqualTo(String dateTimeAsString)
Same assertion as
isBeforeOrEqualTo(ZonedDateTime) but the ZonedDateTime is built from given
String which must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isBeforeOrEqualTo(ZonedDateTime other)
Verifies that the actual
ZonedDateTime is before or equals to the given one according to the comparator in use. |
SELF |
isBetween(String startInclusive,
String endInclusive)
Same assertion as
isBetween(ZonedDateTime, ZonedDateTime) but here you pass ZonedDateTime String representations
which must follow ISO ZonedDateTime format
to allow calling ZonedDateTime.parse(CharSequence) method. |
SELF |
isBetween(ZonedDateTime startInclusive,
ZonedDateTime endInclusive)
Verifies that the actual
ZonedDateTime is in the [start, end] period (start and end included) according to
the comparator in use. |
SELF |
isEqualTo(Object expected)
Verifies that the actual
ZonedDateTime is equal to the given one according to the comparator in use. |
SELF |
isEqualTo(String dateTimeAsString)
Same assertion as
isEqualTo(Object) but the ZonedDateTime is built from given String which must follow
ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isEqualToIgnoringHours(ZonedDateTime other)
Verifies that actual and given
ZonedDateTime have same year, month and day fields (hour, minute, second and
nanosecond fields are ignored in comparison). |
SELF |
isEqualToIgnoringMinutes(ZonedDateTime other)
Verifies that actual and given
ZonedDateTime have same year, month, day and hour fields (minute, second and
nanosecond fields are ignored in comparison). |
SELF |
isEqualToIgnoringNanos(ZonedDateTime other)
Verifies that actual and given
ZonedDateTime have same year, month, day, hour, minute and second fields,
(nanosecond fields are ignored in comparison). |
SELF |
isEqualToIgnoringSeconds(ZonedDateTime other)
Verifies that actual and given
ZonedDateTime have same year, month, day, hour and minute fields (second and
nanosecond fields are ignored in comparison). |
SELF |
isIn(String... dateTimesAsString)
Same assertion as
isIn(ZonedDateTime...) but the ZonedDateTime are built from given String, which
must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isIn(ZonedDateTime... expected)
Verifies that the actual
ZonedDateTime is equal to one of the given ZonedDateTime in the actual
ZonedDateTime's ZoneId. |
SELF |
isNotEqualTo(Object expected)
Verifies that the actual value is not equal to the given one according to the comparator in use.
|
SELF |
isNotEqualTo(String dateTimeAsString)
Same assertion as
#isNotEqualTo(Object) but the ZonedDateTime is built from given String which must follow
ISO date-time format
to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isNotIn(String... dateTimesAsString)
Same assertion as
isNotIn(ZonedDateTime...) but the ZonedDateTime is built from given String,
which must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method. |
SELF |
isNotIn(ZonedDateTime... expected)
Verifies that the actual
ZonedDateTime is equal to one of the given ZonedDateTime in the actual
ZonedDateTime's ZoneId. |
SELF |
isStrictlyBetween(String startExclusive,
String endExclusive)
Same assertion as
isStrictlyBetween(ZonedDateTime, ZonedDateTime) but here you pass ZonedDateTime String representations
which must follow ISO ZonedDateTime format
to allow calling ZonedDateTime.parse(CharSequence) method. |
SELF |
isStrictlyBetween(ZonedDateTime startExclusive,
ZonedDateTime endExclusive)
Verifies that the actual
ZonedDateTime is in the ]start, end[ period (start and end excluded) according to
the comparator in use. |
protected ZonedDateTime |
parse(String dateTimeAsString)
Obtains an instance of
ZonedDateTime from a string representation in ISO date format. |
SELF |
usingDefaultComparator()
Revert to standard comparison for the incoming assertion checks.
|
getActual, isCloseTo, isCloseTo, usingComparator, usingComparatorareEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitas, as, as, describedAspublic static final String NULL_DATE_TIME_PARAMETER_MESSAGE
protected AbstractZonedDateTimeAssert(ZonedDateTime actual, Class<?> selfType)
public SELF isBefore(ZonedDateTime other)
ZonedDateTime is strictly before the given one according to the comparator in use.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertion succeeds
assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("2020-01-01T01:00:00Z"));
// assertions fail
assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("1999-01-01T01:00:00Z"));
assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("2000-01-01T01:00:00Z"));
// fails because both ZonedDateTime refer to the same instant (on different offsets)
assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("2000-01-01T00:00:00-01:00"));
// succeeds because both ZonedDateTime refer to the same instant and ZonedDateTime natural comparator is used.
assertThat(parse("2000-01-02T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isBefore(parse("2000-01-02T01:00:00+01:00")); other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is not strictly before the given one.public SELF isBefore(String dateTimeAsString)
isBefore(ZonedDateTime) but the ZonedDateTime is built from given String, which
must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertion succeeds
assertThat(parse("2000-01-01T01:00:00Z")).isBefore("2020-01-01T01:00:00Z");
// assertions fail
assertThat(parse("2000-01-01T01:00:00Z")).isBefore("1999-01-01T01:00:00Z");
assertThat(parse("2000-01-01T01:00:00Z")).isBefore("2000-01-01T01:00:00Z");
// fails because both ZonedDateTime refer to the same instant (on different offsets)
assertThat(parse("2000-01-01T01:00:00Z")).isBefore("2000-01-01T00:00:00-01:00");
// succeeds because both ZonedDateTime refer to the same instant and ZonedDateTime natural comparator is used.
assertThat(parse("2000-01-02T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isBefore("2000-01-02T01:00:00+01:00"); dateTimeAsString - String representing a ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is not strictly before the ZonedDateTime built
from given String.public SELF isBeforeOrEqualTo(ZonedDateTime other)
ZonedDateTime is before or equals to the given one according to the comparator in use.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertions succeed
assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo(parse("2020-01-01T01:00:00Z"))
.isBeforeOrEqualTo(parse("2000-01-01T01:00:00Z"))
// same instant (on different offsets)
.isBeforeOrEqualTo(parse("2000-01-01T00:00:00-01:00"));
// assertions fail
assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo(parse("1999-01-01T01:00:00Z"));
// even though the same instant, fails because of ZonedDateTime natural comparator is used and ZonedDateTime are on different offsets
assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isBeforeOrEqualTo(parse("2000-01-01T00:00:00-01:00")); other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZoneDateTime is not before or equals to the given one.public SELF isBeforeOrEqualTo(String dateTimeAsString)
isBeforeOrEqualTo(ZonedDateTime) but the ZonedDateTime is built from given
String which must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertions succeed
assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo("2020-01-01T01:00:00Z")
.isBeforeOrEqualTo("2000-01-01T01:00:00Z")
// same instant (on different offsets)
.isBeforeOrEqualTo("2000-01-01T00:00:00-01:00");
// assertions fail
assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo("1999-01-01T01:00:00Z");
// even though the same instant, fails because of ZonedDateTime natural comparator is used and ZonedDateTime are on different offsets
assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isBeforeOrEqualTo("2000-01-01T00:00:00-01:00"); dateTimeAsString - String representing a ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is not before or equals to the ZonedDateTime
built from given String.public SELF isAfterOrEqualTo(ZonedDateTime other)
ZonedDateTime is after or equals to the given one according to the comparator in use.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertions succeed
assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2000-01-01T00:00:00Z"))
.isAfterOrEqualTo(parse("1999-12-31T23:59:59Z"))
// same instant in different offset
.isAfterOrEqualTo(parse("2000-01-01T00:00:00-01:00"));
// assertions fail
assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2001-01-01T00:00:00Z"));
// fails even though they refer to the same instant due to ZonedDateTime natural comparator
assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isAfterOrEqualTo(parse("2000-01-01T01:00:00+01:00"));other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is not after or equals to the given one.public SELF isAfterOrEqualTo(String dateTimeAsString)
isAfterOrEqualTo(ZonedDateTime) but the ZonedDateTime is built from given
String which must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertions succeed
assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2000-01-01T00:00:00Z")
.isAfterOrEqualTo("1999-12-31T23:59:59Z")
// same instant in different offset
.isAfter("2000-01-01T00:00:00-01:00");
// assertions fail
assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2001-01-01T00:00:00Z");
// fails even though they refer to the same instant due to ZonedDateTime natural comparator
assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isAfterOrEqualTo("2000-01-01T01:00:00+01:00");dateTimeAsString - String representing a ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is not after or equals to the ZonedDateTime
built from given String.public SELF isAfter(ZonedDateTime other)
ZonedDateTime is strictly after the given one according to the comparator in use.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertion succeeds
assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("1999-01-01T00:00:00Z"));
// assertions fail
assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2001-01-01T01:00:00Z"));
assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2000-01-01T01:00:00Z"));
// fails because both ZonedDateTime refer to the same instant (on different offsets)
assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2000-01-01T00:00:00-01:00"));
// even though they refer to the same instant assertion succeeds because of different offset
assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isAfter(parse("2000-01-01T00:00:00-01:00"));other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is not strictly after the given one.public SELF isAfter(String dateTimeAsString)
isAfter(ZonedDateTime) but the ZonedDateTime is built from given String, which
must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertion succeeds
assertThat(parse("2000-01-01T01:00:00Z")).isAfter("1999-01-01T00:00:00Z");
// assertions fail
assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2001-01-01T01:00:00Z");
assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2000-01-01T01:00:00Z");
// fails because both ZonedDateTime refer to the same instant (on different offsets)
assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2000-01-01T00:00:00-01:00");
// even though they refer to the same instant assertion succeeds because of different offset
assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isAfter("2000-01-01T00:00:00-01:00");dateTimeAsString - String representing a ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is not strictly after the ZonedDateTime built from the given String.public SELF isEqualToIgnoringNanos(ZonedDateTime other)
ZonedDateTime have same year, month, day, hour, minute and second fields,
(nanosecond fields are ignored in comparison).
Note that given ZonedDateTime is converted in the actual's ZoneId before comparison.
Assertion can fail with dateTimes in same chronological nanosecond time window, e.g :
2000-01-01T00:00:01.000000000 and 2000-01-01T00:00:00.999999999.
Assertion fails as second fields differ even if time difference is only 1ns.
Code example :
// successful assertions
ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 0, 0, 1, 0);
ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 0, 0, 1, 456);
assertThat(dateTime1).isEqualToIgnoringNanos(dateTime2);
// failing assertions (even if time difference is only 1ms)
ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 1, 0, 0, 1, 0);
ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 999999999);
assertThat(dateTimeA).isEqualToIgnoringNanos(dateTimeB);other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is are not equal with nanoseconds ignored.public SELF isEqualToIgnoringSeconds(ZonedDateTime other)
ZonedDateTime have same year, month, day, hour and minute fields (second and
nanosecond fields are ignored in comparison).
Note that given ZonedDateTime is converted in the actual's ZoneId before comparison.
Assertion can fail with ZonedDateTimes in same chronological second time window, e.g :
2000-01-01T00:01:00.000 and 2000-01-01T00:00:59.000.
Assertion fails as minute fields differ even if time difference is only 1ns.
Code example :
// successful assertions
ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 23, 50, 0, 0);
ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 23, 50, 10, 456);
assertThat(dateTime1).isEqualToIgnoringSeconds(dateTime2);
// failing assertions (even if time difference is only 1ns)
ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 1, 23, 50, 00, 0);
ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 23, 49, 59, 999999999);
assertThat(dateTimeA).isEqualToIgnoringSeconds(dateTimeB);other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is are not equal with second and nanosecond fields
ignored.public SELF isEqualToIgnoringMinutes(ZonedDateTime other)
ZonedDateTime have same year, month, day and hour fields (minute, second and
nanosecond fields are ignored in comparison).
Note that given ZonedDateTime is converted in the actual's ZoneId before comparison.
Assertion can fail with dateTimes in same chronological second time window, e.g :
2000-01-01T01:00:00.000 and 2000-01-01T00:59:59.000.
Time difference is only 1s but hour fields differ.
Code example :
// successful assertions
ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 23, 50, 0, 0);
ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 23, 00, 2, 7);
assertThat(dateTime1).isEqualToIgnoringMinutes(dateTime2);
// failing assertions (even if time difference is only 1ms)
ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 1, 01, 00, 00, 000);
ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 00, 59, 59, 999);
assertThat(dateTimeA).isEqualToIgnoringMinutes(dateTimeB);other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is are not equal ignoring minute, second and nanosecond
fields.public SELF isEqualToIgnoringHours(ZonedDateTime other)
ZonedDateTime have same year, month and day fields (hour, minute, second and
nanosecond fields are ignored in comparison).
Note that given ZonedDateTime is converted in the actual's ZoneId before comparison.
Assertion can fail with dateTimes in same chronological minute time window, e.g :
2000-01-01T23:59:00.000 and 2000-01-02T00:00:00.000.
Time difference is only 1min but day fields differ.
Code example :
// successful assertions
ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneId.systemDefault());
ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 00, 00, 00, 000, ZoneId.systemDefault());
assertThat(dateTime1).isEqualToIgnoringHours(dateTime2);
// failing assertions (even if time difference is only 1ms)
ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 2, 00, 00, 00, 000, ZoneId.systemDefault());
ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneId.systemDefault());
assertThat(dateTimeA).isEqualToIgnoringHours(dateTimeB);other - the given ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if other ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is are not equal with second and nanosecond fields
ignored.public SELF isEqualTo(Object expected)
ZonedDateTime is equal to the given one according to the comparator in use.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z");
// both assertions succeed, the second one because the comparison based on the instant they are referring to
// 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC
assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("2000-01-01T00:00:00Z"))
.isEqualTo(parse("2000-01-01T01:00:00+01:00"));
// assertions fail
assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("1999-01-01T01:00:00Z"));
// fails as the comparator compares the offsets
assertThat(firstOfJanuary2000InUTC).usingComparator(ZonedDateTime::compareTo)
.isEqualTo(parse("2000-01-01T01:00:00+01:00"));isEqualTo in interface Assert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>isEqualTo in class AbstractAssert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>expected - the given value to compare the actual value to.this assertion object.AssertionError - if the actual ZonedDateTime is not equal to the ZonedDateTime according
to the comparator in use.public SELF isEqualTo(String dateTimeAsString)
isEqualTo(Object) but the ZonedDateTime is built from given String which must follow
ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z");
// both assertions succeed, the second one because the comparison based on the instant they are referring to
// 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC
assertThat(firstOfJanuary2000InUTC).isEqualTo("2000-01-01T00:00:00Z")
.isEqualTo("2000-01-01T01:00:00+01:00");
// assertions fail
assertThat(firstOfJanuary2000InUTC).isEqualTo("1999-01-01T01:00:00Z");
// fails as the comparator compares the offsets
assertThat(firstOfJanuary2000InUTC).usingComparator(ZonedDateTime::compareTo)
.isEqualTo("2000-01-01T01:00:00+01:00");dateTimeAsString - String representing a ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is not equal to the ZonedDateTime built from the given String.public SELF isNotEqualTo(Object expected)
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertions succeed
assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2020-01-01T00:00:00Z"));
// even though they refer to the same instant, succeeds as the ZonedDateTime comparator checks the offsets
assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));
// assertions fail
assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T00:00:00Z"));
// fails because the default comparator only checks the instant and they refer to the same
assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));isNotEqualTo in interface Assert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>isNotEqualTo in class AbstractAssert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>expected - the given value to compare the actual value to.this assertion object.AssertionError - if the actual ZonedDateTime is equal to the ZonedDateTime according
to the comparator in use.public SELF isNotEqualTo(String dateTimeAsString)
#isNotEqualTo(Object) but the ZonedDateTime is built from given String which must follow
ISO date-time format
to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example :
// assertions succeed
assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2020-01-01T00:00:00Z");
// even though they refer to the same instant, succeeds as the ZonedDateTime comparator checks the offsets
assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isNotEqualTo("2000-01-01T02:00:00+02:00");
// assertions fail
assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T00:00:00Z");
// fails because the default comparator only checks the instant and they refer to the same
assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T02:00:00+02:00");dateTimeAsString - String representing a ZonedDateTime.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is equal to the ZonedDateTime built from given String.public SELF isIn(ZonedDateTime... expected)
ZonedDateTime is equal to one of the given ZonedDateTime in the actual
ZonedDateTime's ZoneId.
Example :
assertThat(parse("2000-01-01T00:00:00Z")).isIn(parse("1999-12-31T23:59:59Z"),
parse("2000-01-01T00:00:00Z"));expected - the given ZonedDateTimes to compare the actual value to.this assertion object.AssertionError - if the actual ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is not in the given ZonedDateTimes.public SELF isIn(String... dateTimesAsString)
isIn(ZonedDateTime...) but the ZonedDateTime are built from given String, which
must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Note that the ZonedDateTimes created from the given Strings are built in the ZoneId of
the ZonedDateTime to check..
Example :
// use String based representation of LocalDateTime
assertThat(parse("2000-01-01T00:00:00Z")).isIn("1999-12-31T23:59:59Z",
"2000-01-01T00:00:00Z");dateTimesAsString - String array representing ZonedDateTimes.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is not in the ZonedDateTimes built from given
Strings.public SELF isNotIn(ZonedDateTime... expected)
ZonedDateTime is equal to one of the given ZonedDateTime in the actual
ZonedDateTime's ZoneId.
Example :
assertThat(parse("2000-01-01T00:00:00Z")).isNotIn(parse("1999-12-31T23:59:59Z"),
parse("2000-01-02T00:00:00Z"));expected - the given ZonedDateTimes to compare the actual value to.this assertion object.AssertionError - if the actual ZonedDateTime is null.AssertionError - if the actual ZonedDateTime is not in the given ZonedDateTimes.public SELF isNotIn(String... dateTimesAsString)
isNotIn(ZonedDateTime...) but the ZonedDateTime is built from given String,
which must follow ISO date-time format to allow calling ZonedDateTime.parse(CharSequence, DateTimeFormatter) method.
Note that the ZonedDateTimes created from the given Strings are built in the ZoneId of
the ZonedDateTime to check..
Example :
// use String based representation of ZonedDateTime
assertThat(parse("2000-01-01T00:00:00Z")).isNotIn("1999-12-31T23:59:59Z",
"2000-01-02T00:00:00Z");dateTimesAsString - String array representing ZonedDateTimes.AssertionError - if the actual ZonedDateTime is null.IllegalArgumentException - if given String is null or can't be converted to a ZonedDateTime.AssertionError - if the actual ZonedDateTime is not equal to the ZonedDateTime built from
given String.public SELF isBetween(ZonedDateTime startInclusive, ZonedDateTime endInclusive)
ZonedDateTime is in the [start, end] period (start and end included) according to
the comparator in use.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example:
ZonedDateTime zonedDateTime = ZonedDateTime.now();
// assertions succeed:
assertThat(zonedDateTime).isBetween(zonedDateTime.minusSeconds(1), zonedDateTime.plusSeconds(1))
.isBetween(zonedDateTime, zonedDateTime.plusSeconds(1))
.isBetween(zonedDateTime.minusSeconds(1), zonedDateTime)
.isBetween(zonedDateTime, zonedDateTime);
// succeeds with default comparator which compares the point in time
assertThat(parse("2010-01-01T00:00:00Z")).isBetween(parse("2010-01-01T01:00:00+01:00"),
parse("2010-01-01T01:00:00+01:00"));
// assertions fail:
assertThat(zonedDateTime).isBetween(zonedDateTime.minusSeconds(10), zonedDateTime.minusSeconds(1));
assertThat(zonedDateTime).isBetween(zonedDateTime.plusSeconds(1), zonedDateTime.plusSeconds(10));
// fails because the comparator checks the offsets are the same
assertThat(parse("2010-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isBetween(parse("2010-01-01T01:00:00+01:00"),
parse("2010-01-01T01:00:00+01:00"));startInclusive - the start value (inclusive), expected not to be null.endInclusive - the end value (inclusive), expected not to be null.AssertionError - if the actual value is null.NullPointerException - if start value is null.NullPointerException - if end value is null.AssertionError - if the actual value is not in [start, end] period.public SELF isBetween(String startInclusive, String endInclusive)
isBetween(ZonedDateTime, ZonedDateTime) but here you pass ZonedDateTime String representations
which must follow ISO ZonedDateTime format
to allow calling ZonedDateTime.parse(CharSequence) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example:
ZonedDateTime firstOfJanuary2000 = ZonedDateTime.parse("2000-01-01T00:00:00Z");
// assertions succeed:
assertThat(firstOfJanuary2000).isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")
.isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z")
.isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z")
.isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:00Z")
// same instant as firstOfJanuary2000 but on a different offset
.isBetween("2000-01-01T01:00:00+01:00", "2000-01-01T01:00:00+01:00");
// assertion fails:
assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");startInclusive - the start value (inclusive), expected not to be null.endInclusive - the end value (inclusive), expected not to be null.AssertionError - if the actual value is null.NullPointerException - if start value is null.NullPointerException - if end value is null.DateTimeParseException - if any of the given String can't be converted to a ZonedDateTime.AssertionError - if the actual value is not in [start, end] period.public SELF isStrictlyBetween(ZonedDateTime startExclusive, ZonedDateTime endExclusive)
ZonedDateTime is in the ]start, end[ period (start and end excluded) according to
the comparator in use.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example:
ZonedDateTime zonedDateTime = ZonedDateTime.now();
// assertions succeed:
assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(1), zonedDateTime.plusSeconds(1));
// succeeds with a different comparator even though the end value refers to the same instant as the actual
assertThat(parse("2010-01-01T12:00:00Z")).usingComparator(ZonedDateTime::compareTo)
.isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),
parse("2010-01-01T13:00:00+01:00"));
// assertions fail:
assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(10), zonedDateTime.minusSeconds(1));
assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.plusSeconds(1), zonedDateTime.plusSeconds(10));
assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime, zonedDateTime.plusSeconds(1));
assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(1), zonedDateTime);
// fails with default comparator since the end value refers to the same instant as the actual
assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),
parse("2010-01-01T13:00:00+01:00"));startExclusive - the start value (exclusive), expected not to be null.endExclusive - the end value (exclusive), expected not to be null.AssertionError - if the actual value is null.NullPointerException - if start value is null.NullPointerException - if end value is null.AssertionError - if the actual value is not in ]start, end[ period.public SELF isStrictlyBetween(String startExclusive, String endExclusive)
isStrictlyBetween(ZonedDateTime, ZonedDateTime) but here you pass ZonedDateTime String representations
which must follow ISO ZonedDateTime format
to allow calling ZonedDateTime.parse(CharSequence) method.
Breaking change: since 3.15.0 the default comparator uses ChronoZonedDateTime.timeLineOrder() which only
compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.
This behaviour can be overridden by AbstractTemporalAssert.usingComparator(Comparator).
Example:
ZonedDateTime firstOfJanuary2000 = ZonedDateTime.parse("2000-01-01T00:00:00Z");
// assertions succeed:
assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")
// succeeds with a different comparator even though the end value refers to the same instant as the actual
.usingComparator(ZonedDateTime::compareTo)
.isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T01:00:00+01:00");
// assertions fail:
assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");
assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z");
assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z");
// fails with default comparator since the end value refers to the same instant as the actual
assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween("2010-01-01T12:59:59+01:00", "2010-01-01T13:00:00+01:00");startExclusive - the start value (exclusive), expected not to be null.endExclusive - the end value (exclusive), expected not to be null.AssertionError - if the actual value is null.NullPointerException - if start value is null.NullPointerException - if end value is null.DateTimeParseException - if any of the given String can't be converted to a ZonedDateTime.AssertionError - if the actual value is not in ]start, end[ period.public SELF usingDefaultComparator()
This method should be used to disable a custom comparison strategy set by calling usingComparator.
usingDefaultComparator in interface Assert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>usingDefaultComparator in class AbstractTemporalAssert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>this assertion object.protected ZonedDateTime parse(String dateTimeAsString)
ZonedDateTime from a string representation in ISO date format.parse in class AbstractTemporalAssert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>dateTimeAsString - the string to parseZonedDateTimeCopyright © 2025. All rights reserved.