Class AbstractLocalDateTimeAssert<SELF extends AbstractLocalDateTimeAssert<SELF>>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,TEMPORAL>
-
- org.assertj.core.api.AbstractTemporalAssert<SELF,LocalDateTime>
-
- org.assertj.core.api.AbstractLocalDateTimeAssert<SELF>
-
- Type Parameters:
SELF
- the "self" type of this assertion class.
- All Implemented Interfaces:
Assert<SELF,LocalDateTime>
,Descriptable<SELF>
,ExtensionPoints<SELF,LocalDateTime>
- Direct Known Subclasses:
LocalDateTimeAssert
public abstract class AbstractLocalDateTimeAssert<SELF extends AbstractLocalDateTimeAssert<SELF>> extends AbstractTemporalAssert<SELF,LocalDateTime>
Assertions forLocalDateTime
type 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 String
NULL_LOCAL_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, customRepresentation, info, myself, objects, printAssertionsDescription, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractLocalDateTimeAssert(LocalDateTime actual, Class<?> selfType)
Creates a new
.AbstractLocalDateTimeAssert
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static boolean
areEqualIgnoringMinutes(LocalDateTime actual, LocalDateTime other)
Returns true if both datetime are in the same year, month, day of month and hour, false otherwise.private static boolean
areEqualIgnoringNanos(LocalDateTime actual, LocalDateTime other)
Returns true if both datetime are in the same year, month and day of month, hour, minute and second, false otherwise.private static boolean
areEqualIgnoringSeconds(LocalDateTime actual, LocalDateTime other)
Returns true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.private static void
assertLocalDateTimeAsStringParameterIsNotNull(String localDateTimeAsString)
Check that theLocalDateTime
string representation to compare actualLocalDateTime
to is not null, otherwise throws aIllegalArgumentException
with an explicit messageprivate static void
assertLocalDateTimeParameterIsNotNull(LocalDateTime other)
Check that theLocalDateTime
to compare actualLocalDateTime
to is not null, in that case throws aIllegalArgumentException
with an explicit messageprivate org.assertj.core.internal.Comparables
buildDefaultComparables()
private void
checkIsNotNullAndNotEmpty(Object[] values)
private static Object[]
convertToLocalDateTimeArray(String... dateTimesAsString)
private static boolean
haveSameYear(LocalDateTime actual, LocalDateTime other)
Returns true if both datetime are in the same year, false otherwise.private static boolean
haveSameYearAndMonth(LocalDateTime actual, LocalDateTime other)
Returns true if both datetime are in the same year and month, false otherwise.private static boolean
haveSameYearMonthAndDayOfMonth(LocalDateTime actual, LocalDateTime other)
Returns true if both datetime are in the same year, month and day of month, false otherwise.SELF
isAfter(String localDateTimeAsString)
Same assertion asisAfter(LocalDateTime)
but theLocalDateTime
is built from given a String that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isAfter(LocalDateTime other)
Verifies that the actualLocalDateTime
is strictly after the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime)
.SELF
isAfterOrEqualTo(String localDateTimeAsString)
Same assertion asisAfterOrEqualTo(LocalDateTime)
but theLocalDateTime
is built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isAfterOrEqualTo(LocalDateTime other)
Verifies that the actualLocalDateTime
is after or equals to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime)
.SELF
isBefore(String localDateTimeAsString)
Same assertion asisBefore(LocalDateTime)
but theLocalDateTime
is built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isBefore(LocalDateTime other)
Verifies that the actualLocalDateTime
is strictly before the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime)
.SELF
isBeforeOrEqualTo(String localDateTimeAsString)
Same assertion asisBeforeOrEqualTo(LocalDateTime)
but theLocalDateTime
is built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isBeforeOrEqualTo(LocalDateTime other)
Verifies that the actualLocalDateTime
is before or equals to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime)
.SELF
isBetween(String startInclusive, String endInclusive)
Same assertion asisBetween(LocalDateTime, LocalDateTime)
but here you passLocalDateTime
String representations which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isBetween(LocalDateTime startInclusive, LocalDateTime endInclusive)
Verifies that the actualLocalDateTime
is in the [start, end] period (start and end included) according to theChronoLocalDateTime.timeLineOrder()
comparator.SELF
isCloseToUtcNow(TemporalUnitOffset offset)
Verifies that the actualLocalDateTime
is close to the current date and time on the UTC timezone, according to the givenTemporalUnitOffset
.SELF
isEqualTo(Object other)
Verifies that the actualLocalDateTime
is equal to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime)
.SELF
isEqualTo(String dateTimeAsString)
Same assertion asisEqualTo(Object)
(where Object is expected to beLocalDateTime
) but here you passLocalDateTime
String representation that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isEqualToIgnoringHours(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month and day fields (hour, minute, second and nanosecond fields are ignored in comparison).SELF
isEqualToIgnoringMinutes(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month, day and hour fields (minute, second and nanosecond fields are ignored in comparison).SELF
isEqualToIgnoringNanos(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month, day, hour, minute and second fields, (nanosecond fields are ignored in comparison).SELF
isEqualToIgnoringSeconds(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month, day, hour and minute fields (second and nanosecond fields are ignored in comparison).SELF
isIn(String... dateTimesAsString)
Same assertion asAbstractAssert.isIn(Object...)
(where Objects are expected to beLocalDateTime
) but here you passLocalDateTime
String representations that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isNotEqualTo(Object other)
Verifies that the actualLocalDateTime
is not equal to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime)
.SELF
isNotEqualTo(String dateTimeAsString)
Same assertion asisNotEqualTo(Object)
(where Object is expected to beLocalDateTime
) but here you passLocalDateTime
String representation that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isNotIn(String... dateTimesAsString)
Same assertion asAbstractAssert.isNotIn(Object...)
(where Objects are expected to beLocalDateTime
) but here you passLocalDateTime
String representations that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isStrictlyBetween(String startExclusive, String endExclusive)
Same assertion asisStrictlyBetween(LocalDateTime, LocalDateTime)
but here you passLocalDateTime
String representations which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.SELF
isStrictlyBetween(LocalDateTime startExclusive, LocalDateTime endExclusive)
Verifies that the actualLocalDateTime
is in the ]start, end[ period (start and end excluded) according to theChronoLocalDateTime.timeLineOrder()
comparator.protected LocalDateTime
parse(String localDateTimeAsString)
Obtains an instance ofTEMPORAL
from a string representation in ISO date format.SELF
usingDefaultComparator()
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, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, 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_LOCAL_DATE_TIME_PARAMETER_MESSAGE
public static final String NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractLocalDateTimeAssert
protected AbstractLocalDateTimeAssert(LocalDateTime actual, Class<?> selfType)
Creates a new
.AbstractLocalDateTimeAssert
- Parameters:
selfType
- the "self type"actual
- the actual value to verify
-
-
Method Detail
-
isBefore
public SELF isBefore(LocalDateTime other)
Verifies that the actualLocalDateTime
is strictly before the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime)
.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example :
assertThat(parse("2000-01-01T23:59:59")).isBefore(parse("2000-01-02T00:00:00"));
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is not strictly before the given one.
-
isBefore
public SELF isBefore(String localDateTimeAsString)
Same assertion asisBefore(LocalDateTime)
but theLocalDateTime
is built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01T23:59:59")).isBefore("2000-01-02T00:00:00");
- Parameters:
localDateTimeAsString
- String representing aLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is not strictly before theLocalDateTime
built from given String.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(LocalDateTime other)
Verifies that the actualLocalDateTime
is before or equals to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime)
.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example :
assertThat(parse("2000-01-01T23:59:59")).isBeforeOrEqualTo(parse("2000-01-01T23:59:59")) .isBeforeOrEqualTo(parse("2000-01-02T00:00:00"));
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is not before or equals to the given one.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(String localDateTimeAsString)
Same assertion asisBeforeOrEqualTo(LocalDateTime)
but theLocalDateTime
is built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01T23:59:59")).isBeforeOrEqualTo("2000-01-01T23:59:59") .isBeforeOrEqualTo("2000-01-02T00:00:00");
- Parameters:
localDateTimeAsString
- String representing aLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is not before or equals to theLocalDateTime
built from given String.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(LocalDateTime other)
Verifies that the actualLocalDateTime
is after or equals to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime)
.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example :
assertThat(parse("2000-01-01T00:00:00")).isAfterOrEqualTo(parse("2000-01-01T00:00:00")) .isAfterOrEqualTo(parse("1999-12-31T23:59:59"));
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is not after or equals to the given one.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(String localDateTimeAsString)
Same assertion asisAfterOrEqualTo(LocalDateTime)
but theLocalDateTime
is built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01T00:00:00")).isAfterOrEqualTo("2000-01-01T00:00:00") .isAfterOrEqualTo("1999-12-31T23:59:59");
- Parameters:
localDateTimeAsString
- String representing aLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is not after or equals to theLocalDateTime
built from given String.
-
isAfter
public SELF isAfter(LocalDateTime other)
Verifies that the actualLocalDateTime
is strictly after the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime)
.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example :
assertThat(parse("2000-01-01T00:00:00")).isAfter(parse("1999-12-31T23:59:59"));
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is not strictly after the given one.
-
isAfter
public SELF isAfter(String localDateTimeAsString)
Same assertion asisAfter(LocalDateTime)
but theLocalDateTime
is built from given a String that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01T00:00:00")).isAfter("1999-12-31T23:59:59");
- Parameters:
localDateTimeAsString
- String representing aLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is not strictly after theLocalDateTime
built from given String.
-
isEqualTo
public SELF isEqualTo(Object other)
Verifies that the actualLocalDateTime
is equal to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime)
.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example :
assertThat(parse("2000-01-01T00:00:00")).isEqualTo(parse("2000-01-01T00:00:00"));
- Specified by:
isEqualTo
in interfaceAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime>
- Overrides:
isEqualTo
in classAbstractAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime>
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
differs from the givenLocalDateTime
according to the comparator in use.
-
isEqualTo
public SELF isEqualTo(String dateTimeAsString)
Same assertion asisEqualTo(Object)
(where Object is expected to beLocalDateTime
) but here you passLocalDateTime
String representation that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01T00:00:00")).isEqualTo("2000-01-01T00:00:00");
- Parameters:
dateTimeAsString
- String representing aLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is not equal to theLocalDateTime
built from given String.
-
isNotEqualTo
public SELF isNotEqualTo(Object other)
Verifies that the actualLocalDateTime
is not equal to the given one according to theChronoLocalDateTime.timeLineOrder()
comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime)
.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example :
assertThat(parse("2000-01-01T00:00:00")).isEqualTo(parse("2000-01-01T00:00:00"));
- Specified by:
isNotEqualTo
in interfaceAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime>
- Overrides:
isNotEqualTo
in classAbstractAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime>
- Parameters:
other
- the given value to compare the actual value to.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
equals to the givenLocalDateTime
according to the comparator in use.
-
isNotEqualTo
public SELF isNotEqualTo(String dateTimeAsString)
Same assertion asisNotEqualTo(Object)
(where Object is expected to beLocalDateTime
) but here you passLocalDateTime
String representation that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01T00:00:00")).isNotEqualTo("2000-01-15T00:00:00");
- Parameters:
dateTimeAsString
- String representing aLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is equal to theLocalDateTime
built from given String.
-
isIn
public SELF isIn(String... dateTimesAsString)
Same assertion asAbstractAssert.isIn(Object...)
(where Objects are expected to beLocalDateTime
) but here you passLocalDateTime
String representations that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String based representation of LocalDateTime assertThat(parse("2000-01-01T00:00:00")).isIn("1999-12-31T00:00:00", "2000-01-01T00:00:00");
- Parameters:
dateTimesAsString
- String array representingLocalDateTime
s.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is not in theLocalDateTime
s built from given Strings.
-
isNotIn
public SELF isNotIn(String... dateTimesAsString)
Same assertion asAbstractAssert.isNotIn(Object...)
(where Objects are expected to beLocalDateTime
) but here you passLocalDateTime
String representations that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example :
// use String based representation of LocalDateTime assertThat(parse("2000-01-01T00:00:00")).isNotIn("1999-12-31T00:00:00", "2000-01-02T00:00:00");
- Parameters:
dateTimesAsString
- Array of String representing aLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDateTime
.AssertionError
- if the actualLocalDateTime
is in theLocalDateTime
s built from given Strings.
-
isCloseToUtcNow
public SELF isCloseToUtcNow(TemporalUnitOffset offset)
Verifies that the actualLocalDateTime
is 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:
LocalDateTime actual = LocalDateTime.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
- ifoffset
parameter isnull
.AssertionError
- if the actualLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is not close to the current time by less than the given offset.
-
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:
usingDefaultComparator
in interfaceAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime>
- Overrides:
usingDefaultComparator
in classAbstractTemporalAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime>
- Returns:
this
assertion object.
-
buildDefaultComparables
private org.assertj.core.internal.Comparables buildDefaultComparables()
-
convertToLocalDateTimeArray
private static Object[] convertToLocalDateTimeArray(String... dateTimesAsString)
-
checkIsNotNullAndNotEmpty
private void checkIsNotNullAndNotEmpty(Object[] values)
-
assertLocalDateTimeAsStringParameterIsNotNull
private static void assertLocalDateTimeAsStringParameterIsNotNull(String localDateTimeAsString)
Check that theLocalDateTime
string representation to compare actualLocalDateTime
to is not null, otherwise throws aIllegalArgumentException
with an explicit message- Parameters:
localDateTimeAsString
- String representing theLocalDateTime
to compare actual with- Throws:
IllegalArgumentException
- with an explicit message if the givenString
is null
-
assertLocalDateTimeParameterIsNotNull
private static void assertLocalDateTimeParameterIsNotNull(LocalDateTime other)
Check that theLocalDateTime
to compare actualLocalDateTime
to is not null, in that case throws aIllegalArgumentException
with an explicit message- Parameters:
other
- theLocalDateTime
to check- Throws:
IllegalArgumentException
- with an explicit message if the givenLocalDateTime
is null
-
isEqualToIgnoringNanos
public SELF isEqualToIgnoringNanos(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month, day, hour, minute and second fields, (nanosecond fields are ignored in comparison).Assertion can fail with localDateTimes 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 LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 0, 0, 1, 0); LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 0, 0, 1, 456); assertThat(localDateTime1).isEqualToIgnoringNanos(localDateTime2); // failing assertions (even if time difference is only 1ms) LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 1, 0, 0, 1, 0); LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 0, 0, 0, 999999999); assertThat(localDateTimeA).isEqualToIgnoringNanos(localDateTimeB);
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is are not equal with nanoseconds ignored.
-
isEqualToIgnoringSeconds
public SELF isEqualToIgnoringSeconds(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month, day, hour and minute fields (second and nanosecond fields are ignored in comparison).Assertion can fail with LocalDateTimes 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 1s.
Code example :
// successful assertions LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 23, 50, 0, 0); LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 23, 50, 10, 456); assertThat(localDateTime1).isEqualToIgnoringSeconds(localDateTime2); // failing assertions (even if time difference is only 1ms) LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 1, 23, 50, 00, 000); LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 23, 49, 59, 999); assertThat(localDateTimeA).isEqualToIgnoringSeconds(localDateTimeB);
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is are not equal with second and nanosecond fields ignored.
-
isEqualToIgnoringMinutes
public SELF isEqualToIgnoringMinutes(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month, day and hour fields (minute, second and nanosecond fields are ignored in comparison).Assertion can fail with localDateTimes 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 LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 23, 50, 0, 0); LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 23, 00, 2, 7); assertThat(localDateTime1).isEqualToIgnoringMinutes(localDateTime2); // failing assertions (even if time difference is only 1ms) LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 1, 01, 00, 00, 000); LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 00, 59, 59, 999); assertThat(localDateTimeA).isEqualToIgnoringMinutes(localDateTimeB);
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is are not equal ignoring minute, second and nanosecond fields.
-
isEqualToIgnoringHours
public SELF isEqualToIgnoringHours(LocalDateTime other)
Verifies that actual and givenLocalDateTime
have same year, month and day fields (hour, minute, second and nanosecond fields are ignored in comparison).Assertion can fail with localDateTimes 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 LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 23, 59, 59, 999); LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 00, 00, 00, 000); assertThat(localDateTime1).isEqualToIgnoringHours(localDateTime2); // failing assertions (even if time difference is only 1ms) LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 2, 00, 00, 00, 000); LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 23, 59, 59, 999); assertThat(localDateTimeA).isEqualToIgnoringHours(localDateTimeB);
- Parameters:
other
- the givenLocalDateTime
.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDateTime
isnull
.IllegalArgumentException
- if otherLocalDateTime
isnull
.AssertionError
- if the actualLocalDateTime
is are not equal with second and nanosecond fields ignored.
-
isBetween
public SELF isBetween(LocalDateTime startInclusive, LocalDateTime endInclusive)
Verifies that the actualLocalDateTime
is in the [start, end] period (start and end included) according to theChronoLocalDateTime.timeLineOrder()
comparator.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example:
LocalDateTime localDateTime = LocalDateTime.now(); // assertions succeed: assertThat(localDateTime).isBetween(localDateTime.minusSeconds(1), localDateTime.plusSeconds(1)) .isBetween(localDateTime, localDateTime.plusSeconds(1)) .isBetween(localDateTime.minusSeconds(1), localDateTime) .isBetween(localDateTime, localDateTime); // assertions fail: assertThat(localDateTime).isBetween(localDateTime.minusSeconds(10), localDateTime.minusSeconds(1)); assertThat(localDateTime).isBetween(localDateTime.plusSeconds(1), localDateTime.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(LocalDateTime, LocalDateTime)
but here you passLocalDateTime
String representations which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example:
LocalDateTime firstOfJanuary2000 = LocalDateTime.parse("2000-01-01T00:00:00"); // assertions succeed: assertThat(firstOfJanuary2000).isBetween("1999-12-31T23:59:59", "2000-01-01T00:00:01") .isBetween("2000-01-01T00:00:00", "2000-01-01T00:00:01") .isBetween("1999-12-31T23:59:59", "2000-01-01T00:00:00") .isBetween("2000-01-01T00:00:00", "2000-01-01T00:00:00"); // assertion fails: assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:01", "1999-12-31T23:59:59");
- 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 aLocalDateTime
.AssertionError
- if the actual value is not in [start, end] period.- Since:
- 3.7.1
-
isStrictlyBetween
public SELF isStrictlyBetween(LocalDateTime startExclusive, LocalDateTime endExclusive)
Verifies that the actualLocalDateTime
is in the ]start, end[ period (start and end excluded) according to theChronoLocalDateTime.timeLineOrder()
comparator.ChronoLocalDateTime.timeLineOrder()
comparesLocalDateTime
in time-line order ignoring the chronology, this is equivalent to comparing the epoch-day and nano-of-day.This behaviour can be overridden by
AbstractTemporalAssert.usingComparator(Comparator)
.Example:
LocalDateTime localDateTime = LocalDateTime.now(); // assertion succeeds: assertThat(localDateTime).isStrictlyBetween(localDateTime.minusSeconds(1), localDateTime.plusSeconds(1)); // assertions fail: assertThat(localDateTime).isStrictlyBetween(localDateTime.minusSeconds(10), localDateTime.minusSeconds(1)); assertThat(localDateTime).isStrictlyBetween(localDateTime.plusSeconds(1), localDateTime.plusSeconds(10)); assertThat(localDateTime).isStrictlyBetween(localDateTime, localDateTime.plusSeconds(1)); assertThat(localDateTime).isStrictlyBetween(localDateTime.minusSeconds(1), localDateTime);
- 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(LocalDateTime, LocalDateTime)
but here you passLocalDateTime
String representations which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)
method.Example:
LocalDateTime firstOfJanuary2000 = LocalDateTime.parse("2000-01-01T00:00:00"); // assertion succeeds: assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59", "2000-01-01T00:00:01"); // assertions fail: assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:01", "1999-12-31T23:59:59"); assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01T00:00:00", "2000-01-01T00:00:01"); assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59", "2000-01-01T00:00: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 aLocalDateTime
.AssertionError
- if the actual value is not in ]start, end[ period.- Since:
- 3.7.1
-
parse
protected LocalDateTime parse(String localDateTimeAsString)
Obtains an instance ofTEMPORAL
from a string representation in ISO date format.- Specified by:
parse
in classAbstractTemporalAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime>
- Parameters:
localDateTimeAsString
- the string to parse, not null- Returns:
- the parsed
TEMPORAL
, not null
-
areEqualIgnoringNanos
private static boolean areEqualIgnoringNanos(LocalDateTime actual, LocalDateTime 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(LocalDateTime actual, LocalDateTime 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(LocalDateTime actual, LocalDateTime 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(LocalDateTime actual, LocalDateTime 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(LocalDateTime actual, LocalDateTime 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(LocalDateTime actual, LocalDateTime 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
-
-