Class AbstractZonedDateTimeAssert<SELF extends AbstractZonedDateTimeAssert<SELF>>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,TEMPORAL>
-
- org.assertj.core.api.AbstractTemporalAssert<SELF,ZonedDateTime>
-
- org.assertj.core.api.AbstractZonedDateTimeAssert<SELF>
-
- All Implemented Interfaces:
Assert<SELF,ZonedDateTime>,Descriptable<SELF>,ExtensionPoints<SELF,ZonedDateTime>
- Direct Known Subclasses:
ZonedDateTimeAssert
public abstract class AbstractZonedDateTimeAssert<SELF extends AbstractZonedDateTimeAssert<SELF>> extends AbstractTemporalAssert<SELF,ZonedDateTime>
-
-
Field Summary
Fields Modifier and Type Field Description static StringNULL_DATE_TIME_PARAMETER_MESSAGE-
Fields inherited from class org.assertj.core.api.AbstractTemporalAssert
comparables
-
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, assertionErrorCreator, conditions, info, myself, objects, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractZonedDateTimeAssert(ZonedDateTime actual, Class<?> selfType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static booleanareEqualIgnoringMinutes(ZonedDateTime actual, ZonedDateTime other)Returns true if both datetime are in the same year, month, day of month and hour, false otherwise.private static booleanareEqualIgnoringNanos(ZonedDateTime actual, ZonedDateTime other)Returns true if both datetime are in the same year, month and day of month, hour, minute and second, false otherwise.private static booleanareEqualIgnoringSeconds(ZonedDateTime actual, ZonedDateTime other)Returns true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.private static voidassertDateTimeAsStringParameterIsNotNull(String dateTimeAsString)Check that theZonedDateTimestring representation to compare actualZonedDateTimeto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit messageprivate static voidassertDateTimeParameterIsNotNull(ZonedDateTime dateTime)Check that theZonedDateTimeto compare actualZonedDateTimeto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit messageprivate ZonedDateTime[]changeToActualTimeZone(ZonedDateTime... dateTimes)private voidcheckIsNotNullAndNotEmpty(Object[] values)private ZonedDateTime[]convertToDateTimeArray(String... dateTimesAsString)private static booleanhaveSameYear(ZonedDateTime actual, ZonedDateTime other)Returns true if both datetime are in the same year, false otherwise.private static booleanhaveSameYearAndMonth(ZonedDateTime actual, ZonedDateTime other)Returns true if both datetime are in the same year and month, false otherwise.private static booleanhaveSameYearMonthAndDayOfMonth(ZonedDateTime actual, ZonedDateTime other)Returns true if both datetime are in the same year, month and day of month, false otherwise.SELFisAfter(String dateTimeAsString)Same assertion asisAfter(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisAfter(ZonedDateTime other)Verifies that the actualZonedDateTimeis strictly after the given one.SELFisAfterOrEqualTo(String dateTimeAsString)Same assertion asisAfterOrEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisAfterOrEqualTo(ZonedDateTime other)Verifies that the actualZonedDateTimeis after or equals to the given one.SELFisBefore(String dateTimeAsString)Same assertion asisBefore(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisBefore(ZonedDateTime other)Verifies that the actualZonedDateTimeis strictly before the given one.SELFisBeforeOrEqualTo(String dateTimeAsString)Same assertion asisBeforeOrEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisBeforeOrEqualTo(ZonedDateTime other)Verifies that the actualZonedDateTimeis before or equals to the given one.SELFisBetween(String startInclusive, String endInclusive)Same assertion asisBetween(ZonedDateTime, ZonedDateTime)but here you passZonedDateTimeString representations which must follow ISO ZonedDateTime format to allow callingZonedDateTime.parse(CharSequence)method.SELFisBetween(ZonedDateTime startInclusive, ZonedDateTime endInclusive)Verifies that the actualZonedDateTimeis in the [start, end] period (start and end included).SELFisEqualTo(String dateTimeAsString)Same assertion asisEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisEqualTo(ZonedDateTime expected)Verifies that the actualZonedDateTimeis equal to the given one in the actual'sZoneId.SELFisEqualToIgnoringHours(ZonedDateTime other)Verifies that actual and givenZonedDateTimehave same year, month and day fields (hour, minute, second and nanosecond fields are ignored in comparison).SELFisEqualToIgnoringMinutes(ZonedDateTime other)Verifies that actual and givenZonedDateTimehave same year, month, day and hour fields (minute, second and nanosecond fields are ignored in comparison).SELFisEqualToIgnoringNanos(ZonedDateTime other)Verifies that actual and givenZonedDateTimehave same year, month, day, hour, minute and second fields, (nanosecond fields are ignored in comparison).SELFisEqualToIgnoringSeconds(ZonedDateTime other)Verifies that actual and givenZonedDateTimehave same year, month, day, hour and minute fields (second and nanosecond fields are ignored in comparison).SELFisIn(String... dateTimesAsString)Same assertion asisIn(ZonedDateTime...)but theZonedDateTimeare built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisIn(ZonedDateTime... expected)Verifies that the actualZonedDateTimeis equal to one of the givenZonedDateTimein the actual ZonedDateTime'sZoneId.SELFisNotEqualTo(String dateTimeAsString)Same assertion asisNotEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisNotEqualTo(ZonedDateTime expected)Verifies that the actual value is not equal to the given one in the actual ZonedDateTime's java.time.ZoneId.SELFisNotIn(String... dateTimesAsString)Same assertion asisNotIn(ZonedDateTime...)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.SELFisNotIn(ZonedDateTime... expected)Verifies that the actualZonedDateTimeis equal to one of the givenZonedDateTimein the actual ZonedDateTime'sZoneId.SELFisStrictlyBetween(String startExclusive, String endExclusive)Same assertion asisStrictlyBetween(ZonedDateTime, ZonedDateTime)but here you passZonedDateTimeString representations which must follow ISO ZonedDateTime format to allow callingZonedDateTime.parse(CharSequence)method.SELFisStrictlyBetween(ZonedDateTime startExclusive, ZonedDateTime endExclusive)Verifies that the actualZonedDateTimeis in the ]start, end[ period (start and end excluded).protected ZonedDateTimeparse(String dateTimeAsString)Obtains an instance ofZonedDateTimefrom a string representation in ISO date format.private ZonedDateTimesameInstantInActualTimeZone(ZonedDateTime zonedDateTime)-
Methods inherited from class org.assertj.core.api.AbstractTemporalAssert
getActual, isCloseTo, isCloseTo
-
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, asInstanceOf, 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, usingComparator, usingComparator, usingDefaultComparator, withAssertionState, withFailMessage, withRepresentation, withThreadDumpOnError
-
-
-
-
Field Detail
-
NULL_DATE_TIME_PARAMETER_MESSAGE
public static final String NULL_DATE_TIME_PARAMETER_MESSAGE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractZonedDateTimeAssert
protected AbstractZonedDateTimeAssert(ZonedDateTime actual, Class<?> selfType)
-
-
Method Detail
-
assertDateTimeParameterIsNotNull
private static void assertDateTimeParameterIsNotNull(ZonedDateTime dateTime)
Check that theZonedDateTimeto compare actualZonedDateTimeto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit message- Parameters:
dateTime- theZonedDateTimeto check- Throws:
IllegalArgumentException- with an explicit message if the givenZonedDateTimeis null
-
isBefore
public SELF isBefore(ZonedDateTime other)
Verifies that the actualZonedDateTimeis strictly before the given one.Comparison is done on
ZonedDateTime's instant (i.e.ChronoZonedDateTime.toEpochSecond())Example :
assertThat(parse("2000-01-01T23:59:59Z")).isBefore(parse("2000-01-02T00:00:00Z"));- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis not strictly before the given one.
-
isBefore
public SELF isBefore(String dateTimeAsString)
Same assertion asisBefore(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimecreated from the given String is built in theZoneIdof theZonedDateTimeto check..Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01T23:59:59Z")).isBefore("2000-01-02T00:00:00Z");- Parameters:
dateTimeAsString- String representing aZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis not strictly before theZonedDateTimebuilt from given String.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(ZonedDateTime other)
Verifies that the actualZonedDateTimeis before or equals to the given one.Comparison is done on
ZonedDateTime's instant (i.e.ChronoZonedDateTime.toEpochSecond())Example :
assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo(parse("2000-01-01T23:59:59Z")) .isBeforeOrEqualTo(parse("2000-01-02T00:00:00Z"));- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZoneDateTimeis not before or equals to the given one.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(String dateTimeAsString)
Same assertion asisBeforeOrEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimecreated from the given String is built in theZoneIdof theZonedDateTimeto check..Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo("2000-01-01T23:59:59Z") .isBeforeOrEqualTo("2000-01-02T00:00:00Z");- Parameters:
dateTimeAsString- String representing aZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis not before or equals to theZonedDateTimebuilt from given String.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(ZonedDateTime other)
Verifies that the actualZonedDateTimeis after or equals to the given one.Comparison is done on
ZonedDateTime's instant (i.e.ChronoZonedDateTime.toEpochSecond())Example :
assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2000-01-01T00:00:00Z")) .isAfterOrEqualTo(parse("1999-12-31T23:59:59Z"));- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis not after or equals to the given one.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(String dateTimeAsString)
Same assertion asisAfterOrEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimecreated from the given String is built in theZoneIdof theZonedDateTimeto check.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2000-01-01T00:00:00Z") .isAfterOrEqualTo("1999-12-31T23:59:59Z");- Parameters:
dateTimeAsString- String representing aZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis not after or equals to theZonedDateTimebuilt from given String.
-
isAfter
public SELF isAfter(ZonedDateTime other)
Verifies that the actualZonedDateTimeis strictly after the given one.Comparison is done on
ZonedDateTime's instant (i.e.ChronoZonedDateTime.toEpochSecond())Example :
assertThat(parse("2000-01-01T00:00:00Z")).isAfter(parse("1999-12-31T23:59:59Z"));- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis not strictly after the given one.
-
isAfter
public SELF isAfter(String dateTimeAsString)
Same assertion asisAfter(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimecreated from the given String is built in theZoneIdof theZonedDateTimeto check.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01T00:00:00Z")).isAfter("1999-12-31T23:59:59Z");- Parameters:
dateTimeAsString- String representing aZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis not strictly after theZonedDateTimebuilt from given String.
-
isEqualToIgnoringNanos
public SELF isEqualToIgnoringNanos(ZonedDateTime other)
Verifies that actual and givenZonedDateTimehave same year, month, day, hour, minute and second fields, (nanosecond fields are ignored in comparison).Note that given
ZonedDateTimeis converted in the actual'sZoneIdbefore 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);- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis are not equal with nanoseconds ignored.
-
isEqualToIgnoringSeconds
public SELF isEqualToIgnoringSeconds(ZonedDateTime other)
Verifies that actual and givenZonedDateTimehave same year, month, day, hour and minute fields (second and nanosecond fields are ignored in comparison).Note that given
ZonedDateTimeis converted in the actual'sZoneIdbefore 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);- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis are not equal with second and nanosecond fields ignored.
-
isEqualToIgnoringMinutes
public SELF isEqualToIgnoringMinutes(ZonedDateTime other)
Verifies that actual and givenZonedDateTimehave same year, month, day and hour fields (minute, second and nanosecond fields are ignored in comparison).Note that given
ZonedDateTimeis converted in the actual'sZoneIdbefore 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);- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis are not equal ignoring minute, second and nanosecond fields.
-
isEqualToIgnoringHours
public SELF isEqualToIgnoringHours(ZonedDateTime other)
Verifies that actual and givenZonedDateTimehave same year, month and day fields (hour, minute, second and nanosecond fields are ignored in comparison).Note that given
ZonedDateTimeis converted in the actual'sZoneIdbefore 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);- Parameters:
other- the givenZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if otherZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis are not equal with second and nanosecond fields ignored.
-
isEqualTo
public SELF isEqualTo(ZonedDateTime expected)
Verifies that the actualZonedDateTimeis equal to the given one in the actual'sZoneId.Example :
ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z"); assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("2000-01-01T00:00:00Z")); // the following assertion succeeds as ZonedDateTime are compared in actual's time zone // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("2000-01-01T01:00:00+01:00"));- Parameters:
expected- the given value to compare the actual value to.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualZonedDateTimeis not equal to theZonedDateTimein the actual ZonedDateTime's java.time.ZoneId.
-
isEqualTo
public SELF isEqualTo(String dateTimeAsString)
Same assertion asisEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimecreated from the given String is built in theZoneIdof theZonedDateTimeto check.Example :
// use String in comparison to avoid writing the code to perform the conversion ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z"); assertThat(firstOfJanuary2000InUTC).isEqualTo("2000-01-01T00:00:00Z"); // the following assertion succeeds as ZonedDateTime are compared in actual's time zone // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC assertThat(firstOfJanuary2000InUTC).isEqualTo("2000-01-01T01:00:00+01:00");- Parameters:
dateTimeAsString- String representing aZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis not equal to theZonedDateTimebuilt from given String.
-
isNotEqualTo
public SELF isNotEqualTo(ZonedDateTime expected)
Verifies that the actual value is not equal to the given one in the actual ZonedDateTime's java.time.ZoneId.Example :
assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-15T00:00:00Z"));- Parameters:
expected- the given value to compare the actual value to.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualZonedDateTimeis equal to theZonedDateTimein the actual ZonedDateTime's java.time.ZoneId.
-
isNotEqualTo
public SELF isNotEqualTo(String dateTimeAsString)
Same assertion asisNotEqualTo(ZonedDateTime)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimecreated from the given String is built in theZoneIdof theZonedDateTimeto check..ZonedDateTime.Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-15T00:00:00Z");- Parameters:
dateTimeAsString- String representing aZonedDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis equal to theZonedDateTimebuilt from given String.
-
isIn
public SELF isIn(ZonedDateTime... expected)
Verifies that the actualZonedDateTimeis equal to one of the givenZonedDateTimein the actual ZonedDateTime'sZoneId.Example :
assertThat(parse("2000-01-01T00:00:00Z")).isIn(parse("1999-12-31T23:59:59Z"), parse("2000-01-01T00:00:00Z"));- Parameters:
expected- the givenZonedDateTimes to compare the actual value to.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis not in the givenZonedDateTimes.
-
isIn
public SELF isIn(String... dateTimesAsString)
Same assertion asisIn(ZonedDateTime...)but theZonedDateTimeare built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimes created from the given Strings are built in theZoneIdof theZonedDateTimeto 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");- Parameters:
dateTimesAsString- String array representingZonedDateTimes.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis not in theZonedDateTimes built from given Strings.
-
isNotIn
public SELF isNotIn(ZonedDateTime... expected)
Verifies that the actualZonedDateTimeis equal to one of the givenZonedDateTimein the actual ZonedDateTime'sZoneId.Example :
assertThat(parse("2000-01-01T00:00:00Z")).isNotIn(parse("1999-12-31T23:59:59Z"), parse("2000-01-02T00:00:00Z"));- Parameters:
expected- the givenZonedDateTimes to compare the actual value to.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualZonedDateTimeisnull.AssertionError- if the actualZonedDateTimeis not in the givenZonedDateTimes.
-
isNotIn
public SELF isNotIn(String... dateTimesAsString)
Same assertion asisNotIn(ZonedDateTime...)but theZonedDateTimeis built from given String, which must follow ISO date-time format to allow callingZonedDateTime.parse(CharSequence, DateTimeFormatter)method.Note that the
ZonedDateTimes created from the given Strings are built in theZoneIdof theZonedDateTimeto 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");- Parameters:
dateTimesAsString- String array representingZonedDateTimes.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualZonedDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aZonedDateTime.AssertionError- if the actualZonedDateTimeis not equal to theZonedDateTimebuilt from given String.
-
isBetween
public SELF isBetween(ZonedDateTime startInclusive, ZonedDateTime endInclusive)
Verifies that the actualZonedDateTimeis in the [start, end] period (start and end included).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); // assertions fail: assertThat(zonedDateTime).isBetween(zonedDateTime.minusSeconds(10), zonedDateTime.minusSeconds(1)); assertThat(zonedDateTime).isBetween(zonedDateTime.plusSeconds(1), zonedDateTime.plusSeconds(10));- Parameters:
startInclusive- the start value (inclusive), expected not to be null.endInclusive- the end value (inclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.AssertionError- if the actual value is not in [start, end] period.- Since:
- 3.7.1
-
isBetween
public SELF isBetween(String startInclusive, String endInclusive)
Same assertion asisBetween(ZonedDateTime, ZonedDateTime)but here you passZonedDateTimeString representations which must follow ISO ZonedDateTime format to allow callingZonedDateTime.parse(CharSequence)method.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"); // assertion fails: assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");- Parameters:
startInclusive- the start value (inclusive), expected not to be null.endInclusive- the end value (inclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.DateTimeParseException- if any of the given String can't be converted to aZonedDateTime.AssertionError- if the actual value is not in [start, end] period.- Since:
- 3.7.1
-
isStrictlyBetween
public SELF isStrictlyBetween(ZonedDateTime startExclusive, ZonedDateTime endExclusive)
Verifies that the actualZonedDateTimeis in the ]start, end[ period (start and end excluded).Example:
ZonedDateTime zonedDateTime = ZonedDateTime.now(); // assertion succeeds: assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(1), zonedDateTime.plusSeconds(1)); // 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);- Parameters:
startExclusive- the start value (exclusive), expected not to be null.endExclusive- the end value (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.AssertionError- if the actual value is not in ]start, end[ period.- Since:
- 3.7.1
-
isStrictlyBetween
public SELF isStrictlyBetween(String startExclusive, String endExclusive)
Same assertion asisStrictlyBetween(ZonedDateTime, ZonedDateTime)but here you passZonedDateTimeString representations which must follow ISO ZonedDateTime format to allow callingZonedDateTime.parse(CharSequence)method.Example:
ZonedDateTime firstOfJanuary2000 = ZonedDateTime.parse("2000-01-01T00:00:00Z"); // assertion succeeds: assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z"); // 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");- Parameters:
startExclusive- the start value (exclusive), expected not to be null.endExclusive- the end value (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.DateTimeParseException- if any of the given String can't be converted to aZonedDateTime.AssertionError- if the actual value is not in ]start, end[ period.- Since:
- 3.7.1
-
convertToDateTimeArray
private ZonedDateTime[] convertToDateTimeArray(String... dateTimesAsString)
-
changeToActualTimeZone
private ZonedDateTime[] changeToActualTimeZone(ZonedDateTime... dateTimes)
-
checkIsNotNullAndNotEmpty
private void checkIsNotNullAndNotEmpty(Object[] values)
-
parse
protected ZonedDateTime parse(String dateTimeAsString)
Obtains an instance ofZonedDateTimefrom a string representation in ISO date format. Note that theZonedDateTimecreated from the given String is built in theZoneIdof the actualZonedDateTime.- Specified by:
parsein classAbstractTemporalAssert<SELF extends AbstractZonedDateTimeAssert<SELF>,ZonedDateTime>- Parameters:
dateTimeAsString- the string to parse- Returns:
- the parsed
ZonedDateTime
-
sameInstantInActualTimeZone
private ZonedDateTime sameInstantInActualTimeZone(ZonedDateTime zonedDateTime)
-
assertDateTimeAsStringParameterIsNotNull
private static void assertDateTimeAsStringParameterIsNotNull(String dateTimeAsString)
Check that theZonedDateTimestring representation to compare actualZonedDateTimeto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit message- Parameters:
dateTimeAsString- String representing the ZonedDateTime to compare actual with- Throws:
IllegalArgumentException- with an explicit message if the givenStringis null
-
areEqualIgnoringNanos
private static boolean areEqualIgnoringNanos(ZonedDateTime actual, ZonedDateTime other)
Returns true if both datetime are in the same year, month and day of month, hour, minute and second, false otherwise.- Parameters:
actual- the actual datetime. expected not be nullother- the other datetime. expected not be null- Returns:
- true if both datetime are in the same year, month and day of month, hour, minute and second, false otherwise.
-
areEqualIgnoringSeconds
private static boolean areEqualIgnoringSeconds(ZonedDateTime actual, ZonedDateTime other)
Returns true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.- Parameters:
actual- the actual datetime. expected not be nullother- the other datetime. expected not be null- Returns:
- true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.
-
areEqualIgnoringMinutes
private static boolean areEqualIgnoringMinutes(ZonedDateTime actual, ZonedDateTime other)
Returns true if both datetime are in the same year, month, day of month and hour, false otherwise.- Parameters:
actual- the actual datetime. expected not be nullother- the other datetime. expected not be null- Returns:
- true if both datetime are in the same year, month, day of month and hour, false otherwise.
-
haveSameYearMonthAndDayOfMonth
private static boolean haveSameYearMonthAndDayOfMonth(ZonedDateTime actual, ZonedDateTime other)
Returns true if both datetime are in the same year, month and day of month, false otherwise.- Parameters:
actual- the actual datetime. expected not be nullother- the other datetime. expected not be null- Returns:
- true if both datetime are in the same year, month and day of month, false otherwise
-
haveSameYearAndMonth
private static boolean haveSameYearAndMonth(ZonedDateTime actual, ZonedDateTime other)
Returns true if both datetime are in the same year and month, false otherwise.- Parameters:
actual- the actual datetime. expected not be nullother- the other datetime. expected not be null- Returns:
- true if both datetime are in the same year and month, false otherwise
-
haveSameYear
private static boolean haveSameYear(ZonedDateTime actual, ZonedDateTime other)
Returns true if both datetime are in the same year, false otherwise.- Parameters:
actual- the actual datetime. expected not be nullother- the other datetime. expected not be null- Returns:
- true if both datetime are in the same year, false otherwise
-
-