Class AbstractOffsetDateTimeAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,TEMPORAL>
-
- org.assertj.core.api.AbstractTemporalAssert<SELF,OffsetDateTime>
-
- org.assertj.core.api.AbstractOffsetDateTimeAssert<SELF>
-
- Type Parameters:
SELF- the "self" type of this assertion class.
- All Implemented Interfaces:
Assert<SELF,OffsetDateTime>,Descriptable<SELF>,ExtensionPoints<SELF,OffsetDateTime>
- Direct Known Subclasses:
OffsetDateTimeAssert
public abstract class AbstractOffsetDateTimeAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>> extends AbstractTemporalAssert<SELF,OffsetDateTime>
Assertions forOffsetDateTimetype from new Date & Time API introduced in Java 8.- Author:
- Paweł Stawicki, Joel Costigliola, Marcin Zajączkowski, Nikolaos Georgiou
-
-
Field Summary
Fields Modifier and Type Field Description static StringNULL_OFFSET_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 protectedAbstractOffsetDateTimeAssert(OffsetDateTime actual, Class<?> selfType)Creates a new.AbstractOffsetDateTimeAssert
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static booleanareEqualIgnoringMinutes(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same year, month, day of month and hour, false otherwise.private static booleanareEqualIgnoringNanos(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same year, month and day of month, hour, minute and second, false otherwise.private static booleanareEqualIgnoringSeconds(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same year, month, day of month, hour and minute, false otherwise.private static booleanareEqualIgnoringTimezone(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same hour, minute, second and nanosecond false otherwise.private static voidassertOffsetDateTimeAsStringParameterIsNotNull(String offsetDateTimeAsString)Check that theOffsetDateTimestring representation to compare actualOffsetDateTimeto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit messageprivate static voidassertOffsetDateTimeParameterIsNotNull(OffsetDateTime other)Check that theOffsetDateTimeto compare actualOffsetDateTimeto is not null, in that case throws aIllegalArgumentExceptionwith an explicit messageprivate ComparablesbuildDefaultComparables()private voidcheckIsNotNullAndNotEmpty(Object[] values)private static Object[]convertToOffsetDateTimeArray(String... dateTimesAsString)private static booleanhaveSameNano(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.private static booleanhaveSameYear(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same year, false otherwise.private static booleanhaveSameYearAndMonth(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same year and month, false otherwise.private static booleanhaveSameYearMonthAndDayOfMonth(OffsetDateTime actual, OffsetDateTime other)Returns true if both OffsetDateTime are in the same year, month and day of month, false otherwise.SELFisAfter(String offsetDateTimeAsString)Same assertion asisAfter(java.time.OffsetDateTime)but theOffsetDateTimeis built from given a String that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisAfter(OffsetDateTime other)Verifies that the actualOffsetDateTimeis strictly after the given one according to the comparator in use.SELFisAfterOrEqualTo(String offsetDateTimeAsString)Same assertion asisAfterOrEqualTo(java.time.OffsetDateTime)but theOffsetDateTimeis built from given String, which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisAfterOrEqualTo(OffsetDateTime other)Verifies that the actualOffsetDateTimeis after or equals to the given one according to the comparator in use.SELFisAtSameInstantAs(OffsetDateTime other)Verifies that actual and givenOffsetDateTimeare at the sameInstant.SELFisBefore(String offsetDateTimeAsString)Same assertion asisBefore(java.time.OffsetDateTime)but theOffsetDateTimeis built from given String, which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisBefore(OffsetDateTime other)Verifies that the actualOffsetDateTimeis strictly before the given one according to the comparator in use.SELFisBeforeOrEqualTo(String offsetDateTimeAsString)Same assertion asisBeforeOrEqualTo(java.time.OffsetDateTime)but theOffsetDateTimeis built from given String, which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisBeforeOrEqualTo(OffsetDateTime other)Verifies that the actualOffsetDateTimeis before or equals to the given one according to the comparator in use.SELFisBetween(String startExclusive, String endExclusive)Same assertion asisBetween(OffsetDateTime, OffsetDateTime)but here you passOffsetDateTimeString representations which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisBetween(OffsetDateTime startExclusive, OffsetDateTime endExclusive)Verifies that the actualOffsetDateTimeis in the [start, end] period (start and end included) according to the comparator in use.SELFisCloseToUtcNow(TemporalUnitOffset offset)Verifies that the actualOffsetDateTimeis close to the current date and time on the UTC timezone, according to the givenTemporalUnitOffset.SELFisEqualTo(Object other)Verifies that the actualOffsetDateTimeis equal to the given one according to the comparator in use.SELFisEqualTo(String dateTimeAsString)Same assertion asisEqualTo(Object)(where Object is expected to beOffsetDateTime) but here you passOffsetDateTimeString representation that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisEqualToIgnoringHours(OffsetDateTime other)Verifies that actual and givenOffsetDateTimehave same year, month and day fields (hour, minute, second and nanosecond fields are ignored in comparison).SELFisEqualToIgnoringMinutes(OffsetDateTime other)Verifies that actual and givenOffsetDateTimehave same year, month, day and hour fields (minute, second and nanosecond fields are ignored in comparison).SELFisEqualToIgnoringNanos(OffsetDateTime other)Verifies that actual and givenOffsetDateTimehave same year, month, day, hour, minute and second fields, (nanosecond fields are ignored in comparison).SELFisEqualToIgnoringSeconds(OffsetDateTime other)Verifies that actual and givenOffsetDateTimehave same year, month, day, hour and minute fields (second and nanosecond fields are ignored in comparison).SELFisEqualToIgnoringTimezone(OffsetDateTime other)Verifies that actual and givenOffsetDateTimehave same year, month, day, hour, minute, second and nanosecond fields, (timezone fields are ignored in comparison).SELFisIn(String... dateTimesAsString)Same assertion asAbstractAssert.isIn(Object...)(where Objects are expected to beOffsetDateTime) but here you passOffsetDateTimeString representations that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisNotEqualTo(Object other)Verifies that the actualOffsetDateTimeis not equal to the given value according to the comparator in use.SELFisNotEqualTo(String dateTimeAsString)Same assertion asisNotEqualTo(Object)(where Object is expected to beOffsetDateTime) but here you passOffsetDateTimeString representation that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisNotIn(String... dateTimesAsString)Same assertion asAbstractAssert.isNotIn(Object...)(where Objects are expected to beOffsetDateTime) but here you passOffsetDateTimeString representations that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisStrictlyBetween(String startExclusive, String endExclusive)Same assertion asisStrictlyBetween(OffsetDateTime, OffsetDateTime)but here you passOffsetDateTimeString representations which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.SELFisStrictlyBetween(OffsetDateTime startExclusive, OffsetDateTime endExclusive)Verifies that the actualOffsetDateTimeis in the ]start, end[ period (start and end excluded) according to the comparator in use.protected OffsetDateTimeparse(String offsetDateTimeAsString)Obtains an instance ofTEMPORALfrom a string representation in ISO date format.SELFusingDefaultComparator()Revert to standard comparison for the incoming assertion checks.-
Methods inherited from class org.assertj.core.api.AbstractTemporalAssert
getActual, isCloseTo, isCloseTo, usingComparator, usingComparator
-
Methods inherited from class org.assertj.core.api.AbstractAssert
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, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingRecursiveComparison, usingRecursiveComparison, withAssertionState, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs
-
-
-
-
Field Detail
-
NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE
public static final String NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractOffsetDateTimeAssert
protected AbstractOffsetDateTimeAssert(OffsetDateTime actual, Class<?> selfType)
Creates a new.AbstractOffsetDateTimeAssert- Parameters:
selfType- the "self type"actual- the actual value to verify
-
-
Method Detail
-
isBefore
public SELF isBefore(OffsetDateTime other)
Verifies that the actualOffsetDateTimeis strictly before the given one according to the comparator in use.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime 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 OffsetDateTime refer to the same instant and OffsetDateTime natural comparator is used. assertThat(parse("2000-01-02T00:00:00Z")).usingComparator(OffsetDateTime::compareTo) .isBefore(parse("2000-01-02T01:00:00+01:00"));- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis not strictly before the given one according to the comparator in use.
-
isBefore
public SELF isBefore(String offsetDateTimeAsString)
Same assertion asisBefore(java.time.OffsetDateTime)but theOffsetDateTimeis built from given String, which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime 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 OffsetDateTime refer to the same instant and OffsetDateTime natural comparator is used. assertThat(parse("2000-01-02T00:00:00Z")).usingComparator(OffsetDateTime::compareTo) .isBefore("2000-01-02T01:00:00+01:00");- Parameters:
offsetDateTimeAsString- String representing aOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis not strictly before theOffsetDateTimebuilt from given String.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(OffsetDateTime other)
Verifies that the actualOffsetDateTimeis before or equals to the given one according to the comparator in use.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime natural comparator is used and OffsetDateTime are on different offsets assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(OffsetDateTime::compareTo) .isBeforeOrEqualTo(parse("2000-01-01T00:00:00-01:00"));- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis not before or equals to the given one according to the comparator in use.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(String offsetDateTimeAsString)
Same assertion asisBeforeOrEqualTo(java.time.OffsetDateTime)but theOffsetDateTimeis built from given String, which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime natural comparator is used and OffsetDateTime are on different offsets assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(OffsetDateTime::compareTo) .isBeforeOrEqualTo("2000-01-01T00:00:00-01:00");- Parameters:
offsetDateTimeAsString- String representing aOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis not before or equals to theOffsetDateTimebuilt from given String.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(OffsetDateTime other)
Verifies that the actualOffsetDateTimeis after or equals to the given one according to the comparator in use.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime natural comparator assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo) .isAfterOrEqualTo(parse("2000-01-01T01:00:00+01:00"));- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis not after or equals to the given one according to the comparator in use.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(String offsetDateTimeAsString)
Same assertion asisAfterOrEqualTo(java.time.OffsetDateTime)but theOffsetDateTimeis built from given String, which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 .isAfterOrEqualTo("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 OffsetDateTime natural comparator assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo) .isAfterOrEqualTo("2000-01-01T01:00:00+01:00");- Parameters:
offsetDateTimeAsString- String representing aOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis not after or equals to theOffsetDateTimebuilt from given String.
-
isAfter
public SELF isAfter(OffsetDateTime other)
Verifies that the actualOffsetDateTimeis strictly after the given one according to the comparator in use.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.usingComparator(Comparator).Example :
// assertions succeed: assertThat(parse("2000-01-01T00:00:00Z")).isAfter(parse("1999-12-31T23:59:59Z")); // 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 OffsetDateTime 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(OffsetDateTime::compareTo) .isAfter(parse("2000-01-01T00:00:00-01:00"));- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis not strictly after the given one according to the comparator in use.
-
isAfter
public SELF isAfter(String offsetDateTimeAsString)
Same assertion asisAfter(java.time.OffsetDateTime)but theOffsetDateTimeis built from given a String that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime 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(OffsetDateTime::compareTo) .isAfter("2000-01-01T00:00:00-01:00");- Parameters:
offsetDateTimeAsString- String representing aOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis not strictly after theOffsetDateTimebuilt from given String.
-
isEqualTo
public SELF isEqualTo(Object other)
Verifies that the actualOffsetDateTimeis equal to the given one according to the comparator in use.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.usingComparator(Comparator).Example :
OffsetDateTime firstOfJanuary2000InUTC = OffsetDateTime.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(OffsetDateTime::compareTo) .isEqualTo(parse("2000-01-01T01:00:00+01:00"));- Specified by:
isEqualToin interfaceAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>,OffsetDateTime>- Overrides:
isEqualToin classAbstractAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>,OffsetDateTime>- Parameters:
other- the given value to compare the actual value to.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeis not equal to the given one according to the comparator in use.
-
isCloseToUtcNow
public SELF isCloseToUtcNow(TemporalUnitOffset offset)
Verifies that the actualOffsetDateTimeis close to the current date and time on the UTC timezone, according to the givenTemporalUnitOffset. You can build the offset parameter usingAssertions.within(long, TemporalUnit)orAssertions.byLessThan(long, TemporalUnit).If the difference is equal to the offset, the assertion succeeds.
Example:
OffsetDateTime actual = OffsetDateTime.now(Clock.systemUTC()); // assertion will pass as if executed less than one second after actual was built assertThat(actual).isCloseToUtcNow(within(1, ChronoUnit.SECONDS)); // assertion will fail assertThat(actual.plusSeconds(2)).isCloseToUtcNow(within(1, ChronoUnit.SECONDS));- Parameters:
offset- The offset used for comparison- Returns:
- this assertion object
- Throws:
NullPointerException- ifoffsetparameter isnull.AssertionError- if the actualOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis not close to the current time by less than the given offset.
-
isEqualTo
public SELF isEqualTo(String dateTimeAsString)
Same assertion asisEqualTo(Object)(where Object is expected to beOffsetDateTime) but here you passOffsetDateTimeString representation that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.usingComparator(Comparator).Example :
OffsetDateTime firstOfJanuary2000InUTC = OffsetDateTime.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(OffsetDateTime::compareTo) .isEqualTo("2000-01-01T01:00:00+01:00");- Parameters:
dateTimeAsString- String representing aOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis not equal to theOffsetDateTimebuilt from given String.
-
isNotEqualTo
public SELF isNotEqualTo(Object other)
Verifies that the actualOffsetDateTimeis not equal to the given value according to the comparator in use.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime comparator checks the offsets assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::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"));- Specified by:
isNotEqualToin interfaceAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>,OffsetDateTime>- Overrides:
isNotEqualToin classAbstractAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>,OffsetDateTime>- Parameters:
other- the given value to compare the actual value to.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeis equal to the given one according to the comparator in use.
-
isNotEqualTo
public SELF isNotEqualTo(String dateTimeAsString)
Same assertion asisNotEqualTo(Object)(where Object is expected to beOffsetDateTime) but here you passOffsetDateTimeString representation that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.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 OffsetDateTime comparator checks the offsets assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::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");- Parameters:
dateTimeAsString- String representing aOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis equal to theOffsetDateTimebuilt from given String.
-
isIn
public SELF isIn(String... dateTimesAsString)
Same assertion asAbstractAssert.isIn(Object...)(where Objects are expected to beOffsetDateTime) but here you passOffsetDateTimeString representations that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Example :
// use String based representation of OffsetDateTime assertThat(parse("2000-01-01T00:00:00Z")).isIn("1999-12-31T00:00:00Z", "2000-01-01T00:00:00Z");- Parameters:
dateTimesAsString- String array representingOffsetDateTimes.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis not in theOffsetDateTimes built from given Strings.
-
isNotIn
public SELF isNotIn(String... dateTimesAsString)
Same assertion asAbstractAssert.isNotIn(Object...)(where Objects are expected to beOffsetDateTime) but here you passOffsetDateTimeString representations that must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Example :
// use String based representation of OffsetDateTime assertThat(parse("2000-01-01T00:00:00Z")).isNotIn("1999-12-31T00:00:00Z", "2000-01-02T00:00:00Z");- Parameters:
dateTimesAsString- Array of String representing aOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aOffsetDateTime.AssertionError- if the actualOffsetDateTimeis in theOffsetDateTimes built from given Strings.
-
isEqualToIgnoringNanos
public SELF isEqualToIgnoringNanos(OffsetDateTime other)
Verifies that actual and givenOffsetDateTimehave same year, month, day, hour, minute and second fields, (nanosecond fields are ignored in comparison).Assertion can fail with OffsetDateTimes in same chronological nanosecond time window, e.g :
2000-01-01T00:00:01.000000000+01:00 and 2000-01-01T00:00:00.999999999+01:00.
Assertion fails as second fields differ even if time difference is only 1ns.
Code example :
// successful assertions OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC); OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 456, ZoneOffset.UTC); assertThat(OffsetDateTime1).isEqualToIgnoringNanos(OffsetDateTime2);// failing assertions (even if time difference is only 1ns) OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC); OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC); assertThat(OffsetDateTimeA).isEqualToIgnoringNanos(OffsetDateTimeB);- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis are not equal with nanoseconds ignored.
-
isEqualToIgnoringTimezone
public SELF isEqualToIgnoringTimezone(OffsetDateTime other)
Verifies that actual and givenOffsetDateTimehave same year, month, day, hour, minute, second and nanosecond fields, (timezone fields are ignored in comparison).Code example :
// successful assertions OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC); OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.MAX); assertThat(OffsetDateTime1).isEqualToIgnoringTimezone(OffsetDateTime2); // failing assertions OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC); OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC); assertThat(OffsetDateTimeA).isEqualToIgnoringTimezone(OffsetDateTimeB);- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis are not equal with timezone ignored.
-
isEqualToIgnoringSeconds
public SELF isEqualToIgnoringSeconds(OffsetDateTime other)
Verifies that actual and givenOffsetDateTimehave same year, month, day, hour and minute fields (second and nanosecond fields are ignored in comparison).Assertion can fail with OffsetDateTimes in same chronological second time window, e.g :
2000-01-01T00:01:00.000+01:00 and 2000-01-01T00:00:59.000+01:00.
Assertion fails as minute fields differ even if time difference is only 1s.
Code example :
// successful assertions OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC); OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 50, 10, 456, ZoneOffset.UTC); assertThat(OffsetDateTime1).isEqualToIgnoringSeconds(OffsetDateTime2); // failing assertions (even if time difference is only 1ms) OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 23, 50, 00, 000, ZoneOffset.UTC); OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 49, 59, 999, ZoneOffset.UTC); assertThat(OffsetDateTimeA).isEqualToIgnoringSeconds(OffsetDateTimeB);- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis are not equal with second and nanosecond fields ignored.
-
isEqualToIgnoringMinutes
public SELF isEqualToIgnoringMinutes(OffsetDateTime other)
Verifies that actual and givenOffsetDateTimehave same year, month, day and hour fields (minute, second and nanosecond fields are ignored in comparison).Assertion can fail with OffsetDateTimes in same chronological second time window, e.g :
2000-01-01T01:00:00.000+01:00 and 2000-01-01T00:59:59.000+01:00.
Time difference is only 1s but hour fields differ.
Code example :
// successful assertions OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC); OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 00, 2, 7, ZoneOffset.UTC); assertThat(OffsetDateTime1).isEqualToIgnoringMinutes(OffsetDateTime2); // failing assertions (even if time difference is only 1ms) OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 01, 00, 00, 000, ZoneOffset.UTC); OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 00, 59, 59, 999, ZoneOffset.UTC); assertThat(OffsetDateTimeA).isEqualToIgnoringMinutes(OffsetDateTimeB);- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis are not equal ignoring minute, second and nanosecond fields.
-
isEqualToIgnoringHours
public SELF isEqualToIgnoringHours(OffsetDateTime other)
Verifies that actual and givenOffsetDateTimehave same year, month and day fields (hour, minute, second and nanosecond fields are ignored in comparison).Assertion can fail with OffsetDateTimes in same chronological minute time window, e.g :
2000-01-01T23:59:00.000+01:00 and 2000-01-02T00:00:00.000+01:00.
Time difference is only 1min but day fields differ.
Code example :
// successful assertions OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC); OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 00, 00, 00, 000, ZoneOffset.UTC); assertThat(OffsetDateTime1).isEqualToIgnoringHours(OffsetDateTime2); // failing assertions (even if time difference is only 1ms) OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 2, 00, 00, 00, 000, ZoneOffset.UTC); OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC); assertThat(OffsetDateTimeA).isEqualToIgnoringHours(OffsetDateTimeB);- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis are not equal with second and nanosecond fields ignored.
-
isBetween
public SELF isBetween(OffsetDateTime startExclusive, OffsetDateTime endExclusive)
Verifies that the actualOffsetDateTimeis 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
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.usingComparator(Comparator).Example:
OffsetDateTime offsetDateTime = OffsetDateTime.now(); // assertions succeed: assertThat(offsetDateTime).isBetween(offsetDateTime.minusSeconds(1), offsetDateTime.plusSeconds(1)) .isBetween(offsetDateTime, offsetDateTime.plusSeconds(1)) .isBetween(offsetDateTime.minusSeconds(1), offsetDateTime) .isBetween(offsetDateTime, offsetDateTime); // 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(offsetDateTime).isBetween(offsetDateTime.minusSeconds(10), offsetDateTime.minusSeconds(1)); assertThat(offsetDateTime).isBetween(offsetDateTime.plusSeconds(1), offsetDateTime.plusSeconds(10)); // succeeds with default comparator assertThat(parse("2010-01-01T00:00:00Z")).isBetween(parse("2010-01-01T01:00:00+01:00"), parse("2010-01-01T01:00:00+01:00")); // fails with a comparator which checks the offset, too assertThat(parse("2010-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo) .isBetween(parse("2010-01-01T01:00:00+01:00"), parse("2010-01-01T01:00:00+01:00"));- 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 according to the comparator in use.- Since:
- 3.7.1
-
isBetween
public SELF isBetween(String startExclusive, String endExclusive)
Same assertion asisBetween(OffsetDateTime, OffsetDateTime)but here you passOffsetDateTimeString representations which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.usingComparator(Comparator).Example:
OffsetDateTime firstOfJanuary2000 = OffsetDateTime.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");- 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 aOffsetDateTime.AssertionError- if the actual value is not in [start, end] period.- Since:
- 3.7.1
-
isStrictlyBetween
public SELF isStrictlyBetween(OffsetDateTime startExclusive, OffsetDateTime endExclusive)
Verifies that the actualOffsetDateTimeis 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
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.usingComparator(Comparator).Example:
OffsetDateTime offsetDateTime = OffsetDateTime.now(); // assertions succeed: assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.minusSeconds(1), offsetDateTime.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(OffsetDateTime::compareTo) .isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"), parse("2010-01-01T13:00:00+01:00")); // assertions fail: assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.minusSeconds(10), offsetDateTime.minusSeconds(1)); assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.plusSeconds(1), offsetDateTime.plusSeconds(10)); assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime, offsetDateTime.plusSeconds(1)); assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.minusSeconds(1), offsetDateTime); // 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"));- 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 according to the comparator in use.- Since:
- 3.7.1
-
isStrictlyBetween
public SELF isStrictlyBetween(String startExclusive, String endExclusive)
Same assertion asisStrictlyBetween(OffsetDateTime, OffsetDateTime)but here you passOffsetDateTimeString representations which must follow ISO OffsetDateTime format to allow callingOffsetDateTime.parse(CharSequence)method.Breaking change since 3.15.0 The default comparator uses
OffsetDateTime.timeLineOrder()which only compares the underlying instant and ignores different timezones / offsets / chronologies.
This behaviour can be overridden byAbstractTemporalAssert.usingComparator(Comparator).Example:
OffsetDateTime firstOfJanuary2000 = OffsetDateTime.parse("2000-01-01T00:00:00Z"); // assertion succeeds: 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(OffsetDateTime::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");- 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 aOffsetDateTime.AssertionError- if the actual value is not in ]start, end[ period.- Since:
- 3.7.1
-
usingDefaultComparator
public SELF usingDefaultComparator()
Revert to standard comparison for the incoming assertion checks.This method should be used to disable a custom comparison strategy set by calling
usingComparator.- Specified by:
usingDefaultComparatorin interfaceAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>,OffsetDateTime>- Overrides:
usingDefaultComparatorin classAbstractTemporalAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>,OffsetDateTime>- Returns:
thisassertion object.
-
buildDefaultComparables
private Comparables buildDefaultComparables()
-
isAtSameInstantAs
public SELF isAtSameInstantAs(OffsetDateTime other)
Verifies that actual and givenOffsetDateTimeare at the sameInstant.Example:
OffsetDateTime offsetDateTime1 = OffsetDateTime.of(2000, 12, 12, 3, 0, 0, 0, ZoneOffset.ofHours(3)); OffsetDateTime offsetDateTime2 = OffsetDateTime.of(2000, 12, 12, 0, 0, 0, 0, ZoneOffset.ofHours(0)); // assertion succeeds assertThat(offsetDateTime1).isAtSameInstantAs(offsetDateTime2); offsetDateTime2 = OffsetDateTime.of(2000, 12, 12, 2, 0, 0, 0, ZoneOffset.ofHours(0)); // assertion fails assertThat(offsetDateTime1).isAtSameInstantAs(offsetDateTime2);- Parameters:
other- the givenOffsetDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualOffsetDateTimeisnull.IllegalArgumentException- if otherOffsetDateTimeisnull.AssertionError- if the actualOffsetDateTimeis not at the sameInstantas the other.
-
parse
protected OffsetDateTime parse(String offsetDateTimeAsString)
Obtains an instance ofTEMPORALfrom a string representation in ISO date format.- Specified by:
parsein classAbstractTemporalAssert<SELF extends AbstractOffsetDateTimeAssert<SELF>,OffsetDateTime>- Parameters:
offsetDateTimeAsString- the string to parse, not null- Returns:
- the parsed
TEMPORAL, not null
-
areEqualIgnoringNanos
private static boolean areEqualIgnoringNanos(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same year, month and day of month, hour, minute and second, false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same year, month and day of month, hour, minute and second, false otherwise.
-
areEqualIgnoringSeconds
private static boolean areEqualIgnoringSeconds(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same year, month, day of month, hour and minute, false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same year, month, day of month, hour and minute, false otherwise.
-
areEqualIgnoringMinutes
private static boolean areEqualIgnoringMinutes(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same year, month, day of month and hour, false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same year, month, day of month and hour, false otherwise.
-
haveSameYearMonthAndDayOfMonth
private static boolean haveSameYearMonthAndDayOfMonth(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same year, month and day of month, false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same year, month and day of month, false otherwise
-
haveSameYearAndMonth
private static boolean haveSameYearAndMonth(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same year and month, false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same year and month, false otherwise
-
haveSameYear
private static boolean haveSameYear(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same year, false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same year, false otherwise
-
areEqualIgnoringTimezone
private static boolean areEqualIgnoringTimezone(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same hour, minute, second and nanosecond false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same hour, minute, second and nanosecond false otherwise.
-
haveSameNano
private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other)
Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.- Parameters:
actual- the actual OffsetDateTime. expected not be nullother- the other OffsetDateTime. expected not be null- Returns:
- true if both OffsetDateTime are in the same year, false otherwise
-
convertToOffsetDateTimeArray
private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString)
-
checkIsNotNullAndNotEmpty
private void checkIsNotNullAndNotEmpty(Object[] values)
-
assertOffsetDateTimeAsStringParameterIsNotNull
private static void assertOffsetDateTimeAsStringParameterIsNotNull(String offsetDateTimeAsString)
Check that theOffsetDateTimestring representation to compare actualOffsetDateTimeto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit message- Parameters:
offsetDateTimeAsString- String representing theOffsetDateTimeto compare actual with- Throws:
IllegalArgumentException- with an explicit message if the givenStringis null
-
assertOffsetDateTimeParameterIsNotNull
private static void assertOffsetDateTimeParameterIsNotNull(OffsetDateTime other)
Check that theOffsetDateTimeto compare actualOffsetDateTimeto is not null, in that case throws aIllegalArgumentExceptionwith an explicit message- Parameters:
other- theOffsetDateTimeto check- Throws:
IllegalArgumentException- with an explicit message if the givenOffsetDateTimeis null
-
-