Class AbstractLocalDateTimeAssert<SELF extends 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
LocalDateTime type from new Date & Time API introduced in Java 8.- Author:
- Paweł Stawicki, Joel Costigliola, Marcin Zajączkowski, Nikolaos Georgiou
-
Field Summary
FieldsFields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractLocalDateTimeAssert(LocalDateTime actual, Class<?> selfType) Creates a new.AbstractLocalDateTimeAssert -
Method Summary
Modifier and TypeMethodDescriptionhasDayOfMonth(int dayOfMonth) Verifies that actualLocalDateTimeis in the given day of month.hasHour(int hour) Verifies that actualLocalDateTimeis in the given hour.hasMinute(int minute) Verifies that actualLocalDateTimeis in the given minute.Verifies that actualLocalDateTimeis in the givenMonth.hasMonthValue(int monthVal) Verifies that actualLocalDateTimehas same month value.hasNano(int nano) Verifies that actualLocalDateTimeis in the given nanosecond.hasSecond(int second) Verifies that actualLocalDateTimeis in the given second.hasYear(int year) Verifies that actualLocalDateTimeis in the given year.Same assertion asisAfter(LocalDateTime)but theLocalDateTimeis built from given a String that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.isAfter(LocalDateTime other) Verifies that the actualLocalDateTimeis strictly after the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime).isAfterOrEqualTo(String localDateTimeAsString) Same assertion asisAfterOrEqualTo(LocalDateTime)but theLocalDateTimeis built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.isAfterOrEqualTo(LocalDateTime other) Verifies that the actualLocalDateTimeis after or equals to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime).Same assertion asisBefore(LocalDateTime)but theLocalDateTimeis built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.isBefore(LocalDateTime other) Verifies that the actualLocalDateTimeis strictly before the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime).isBeforeOrEqualTo(String localDateTimeAsString) Same assertion asisBeforeOrEqualTo(LocalDateTime)but theLocalDateTimeis built from given String, which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.isBeforeOrEqualTo(LocalDateTime other) Verifies that the actualLocalDateTimeis before or equals to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime).Same assertion asisBetween(LocalDateTime, LocalDateTime)but here you passLocalDateTimeString representations which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.isBetween(LocalDateTime startInclusive, LocalDateTime endInclusive) Verifies that the actualLocalDateTimeis in the [start, end] period (start and end included) according to theChronoLocalDateTime.timeLineOrder()comparator.isCloseTo(LocalDateTime other, TemporalOffset<? super LocalDateTime> offset) Verifies that the actualLocalDateTimeis close to the other according to the givenTemporalOffset.isCloseToUtcNow(TemporalUnitOffset offset) Verifies that the actualLocalDateTimeis close to the current date and time on the UTC timezone, according to the givenTemporalUnitOffset.Verifies that the actualLocalDateTimeis equal to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime).Same assertion asisEqualTo(Object)(where Object is expected to beLocalDateTime) but here you passLocalDateTimeString representation that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.Deprecated.Deprecated.UseisCloseTo(LocalDateTime, TemporalOffset)instead, although not exactly the same semantics, this is the right way to compare with a given precision.Verifies that actual and givenLocalDateTimehave same year, month, day, hour, minute and second fields, (nanosecond fields are ignored in comparison).Deprecated.UseisCloseTo(LocalDateTime, TemporalOffset)instead, although not exactly the same semantics, this is the right way to compare with a given precision.Same assertion asAbstractAssert.isIn(Object...)(where Objects are expected to beLocalDateTime) but here you passLocalDateTimeString representations that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.Verifies that the actualLocalDateTimeis strictly in the future.Verifies that the actualLocalDateTimeis strictly in the past.isNotEqualTo(Object other) Verifies that the actualLocalDateTimeis not equal to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime).isNotEqualTo(String dateTimeAsString) Same assertion asisNotEqualTo(Object)(where Object is expected to beLocalDateTime) but here you passLocalDateTimeString representation that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.Same assertion asAbstractAssert.isNotIn(Object...)(where Objects are expected to beLocalDateTime) but here you passLocalDateTimeString representations that must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.isStrictlyBetween(String startExclusive, String endExclusive) Same assertion asisStrictlyBetween(LocalDateTime, LocalDateTime)but here you passLocalDateTimeString representations which must follow ISO LocalDateTime format to allow callingLocalDateTime.parse(CharSequence)method.isStrictlyBetween(LocalDateTime startExclusive, LocalDateTime endExclusive) Verifies that the actualLocalDateTimeis in the ]start, end[ period (start and end excluded) according to theChronoLocalDateTime.timeLineOrder()comparator.protected LocalDateTimeObtains an instance ofTEMPORALfrom a string representation in ISO date format.Revert to standard comparison for the incoming assertion checks.Methods inherited from class org.assertj.core.api.AbstractTemporalAssert
isCloseTo, usingComparator, usingComparatorMethods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, 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, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Field Details
-
NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE
- See Also:
-
-
Constructor Details
-
AbstractLocalDateTimeAssert
Creates a new.AbstractLocalDateTimeAssert- Parameters:
actual- the actual value to verifyselfType- the "self type"
-
-
Method Details
-
isBefore
Verifies that the actualLocalDateTimeis strictly before the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime).ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not strictly before the given one.
-
isBefore
Same assertion asisBefore(LocalDateTime)but theLocalDateTimeis 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 actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis not strictly before theLocalDateTimebuilt from given String.
-
isBeforeOrEqualTo
Verifies that the actualLocalDateTimeis before or equals to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isBefore(ChronoLocalDateTime).ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not before or equals to the given one.
-
isBeforeOrEqualTo
Same assertion asisBeforeOrEqualTo(LocalDateTime)but theLocalDateTimeis 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 actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis not before or equals to theLocalDateTimebuilt from given String.
-
isAfterOrEqualTo
Verifies that the actualLocalDateTimeis after or equals to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime).ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not after or equals to the given one.
-
isAfterOrEqualTo
Same assertion asisAfterOrEqualTo(LocalDateTime)but theLocalDateTimeis 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 actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis not after or equals to theLocalDateTimebuilt from given String.
-
isAfter
Verifies that the actualLocalDateTimeis strictly after the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isAfter(ChronoLocalDateTime).ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not strictly after the given one.
-
isAfter
Same assertion asisAfter(LocalDateTime)but theLocalDateTimeis 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 actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis not strictly after theLocalDateTimebuilt from given String.
-
isEqualTo
Verifies that the actualLocalDateTimeis equal to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime).ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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:
isEqualToin interfaceAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime> - Overrides:
isEqualToin classAbstractAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime> - Parameters:
other- the givenLocalDateTime.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimediffers from the givenLocalDateTimeaccording to the comparator in use.
-
isEqualTo
Same assertion asisEqualTo(Object)(where Object is expected to beLocalDateTime) but here you passLocalDateTimeString 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 actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis not equal to theLocalDateTimebuilt from given String.
-
isNotEqualTo
Verifies that the actualLocalDateTimeis not equal to the given one according to theChronoLocalDateTime.timeLineOrder()comparator which is consistent withLocalDateTime.isEqual(ChronoLocalDateTime).ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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:
isNotEqualToin interfaceAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime> - Overrides:
isNotEqualToin 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 actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeequals to the givenLocalDateTimeaccording to the comparator in use.
-
isNotEqualTo
Same assertion asisNotEqualTo(Object)(where Object is expected to beLocalDateTime) but here you passLocalDateTimeString 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 actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis equal to theLocalDateTimebuilt from given String.
-
isIn
Same assertion asAbstractAssert.isIn(Object...)(where Objects are expected to beLocalDateTime) but here you passLocalDateTimeString 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 representingLocalDateTimes.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis not in theLocalDateTimes built from given Strings.
-
isNotIn
Same assertion asAbstractAssert.isNotIn(Object...)(where Objects are expected to beLocalDateTime) but here you passLocalDateTimeString 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 actualLocalDateTimeisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDateTime.AssertionError- if the actualLocalDateTimeis in theLocalDateTimes built from given Strings.
-
isCloseToUtcNow
Verifies that the actualLocalDateTimeis 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- ifoffsetparameter isnull.AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not close to the current time by less than the given offset.
-
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 AbstractLocalDateTimeAssert<SELF>,LocalDateTime> - Overrides:
usingDefaultComparatorin classAbstractTemporalAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime> - Returns:
thisassertion object.
-
isEqualToIgnoringNanos
Verifies that actual and givenLocalDateTimehave 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis are not equal with nanoseconds ignored.
-
isEqualToIgnoringSeconds
Deprecated.UseisCloseTo(LocalDateTime, TemporalOffset)instead, although not exactly the same semantics, this is the right way to compare with a given precision.Verifies that actual and givenLocalDateTimehave 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis are not equal with second and nanosecond fields ignored.
-
isEqualToIgnoringMinutes
Deprecated.UseisCloseTo(LocalDateTime, TemporalOffset)instead, although not exactly the same semantics, this is the right way to compare with a given precision.Verifies that actual and givenLocalDateTimehave 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis are not equal ignoring minute, second and nanosecond fields.
-
isEqualToIgnoringHours
Deprecated.UseisCloseTo(LocalDateTime, TemporalOffset)instead, although not exactly the same semantics, this is the right way to compare with a given precision.Verifies that actual and givenLocalDateTimehave 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 actualLocalDateTimeisnull.IllegalArgumentException- if otherLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis are not equal with second and nanosecond fields ignored.
-
isInThePast
Verifies that the actualLocalDateTimeis strictly in the past.Example:
// assertion succeeds: assertThat(LocalDateTime.now().minusMinutes(1)).isInThePast();- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the past.- Since:
- 3.25.0
-
isInTheFuture
Verifies that the actualLocalDateTimeis strictly in the future.Example:
// assertion succeeds: assertThat(LocalDateTime.now().plusMinutes(1)).isInTheFuture();- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the future.- Since:
- 3.25.0
-
isBetween
Verifies that the actualLocalDateTimeis in the [start, end] period (start and end included) according to theChronoLocalDateTime.timeLineOrder()comparator.ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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
Same assertion asisBetween(LocalDateTime, LocalDateTime)but here you passLocalDateTimeString 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
Verifies that the actualLocalDateTimeis in the ]start, end[ period (start and end excluded) according to theChronoLocalDateTime.timeLineOrder()comparator.ChronoLocalDateTime.timeLineOrder()comparesLocalDateTimein 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
Same assertion asisStrictlyBetween(LocalDateTime, LocalDateTime)but here you passLocalDateTimeString 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
-
hasYear
Verifies that actualLocalDateTimeis in the given year.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2002, 1, 1, 0, 0, 0)).hasYear(2002); // Assertion fails: assertThat(LocalDate.of(2002, 1, 1, 0, 0, 0)).hasYear(2001);- Parameters:
year- the given year.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the given year.- Since:
- 3.23.0
-
hasMonth
Verifies that actualLocalDateTimeis in the givenMonth.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2022, Month.APRIL, 16, 20, 18, 59)).hasMonth(Month.APRIL); // Assertion fails: assertThat(LocalDateTime.of(2022, Month.APRIL, 16, 20, 18, 59)).hasMonth(Month.MAY);- Parameters:
month- the givenMonth.- Returns:
- this assertion object.
- Throws:
IllegalArgumentException- if the given Month is null.AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the givenMonth.- Since:
- 3.23.0
-
hasMonthValue
Verifies that actualLocalDateTimehas same month value.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2000, 12, 31, 23, 59, 59)).hasMonthValue(12); // Assertion fails: assertThat(LocalDateTime.of(2000, 12, 31, 23, 59, 59)).hasMonthValue(3);- Parameters:
monthVal- the given month value between 1 and 12 inclusive.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not equal with month field.- Since:
- 3.23.0
-
hasDayOfMonth
Verifies that actualLocalDateTimeis in the given day of month.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2002, 1, 1, 0, 0, 0)).hasDayOfMonth(1); // Assertion fails: assertThat(LocalDate.of(2002, 1, 1, 0, 0, 0)).hasDayOfMonth(2);- Parameters:
dayOfMonth- the given numeric day.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the given day of month.- Since:
- 3.23.0
-
hasHour
Verifies that actualLocalDateTimeis in the given hour.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 59)).hasHour(23); // Assertion fails: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 59)).hasHour(22);- Parameters:
hour- the given hour.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the given hour.- Since:
- 3.23.0
-
hasMinute
Verifies that actualLocalDateTimeis in the given minute.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 00)).hasMinute(59); // Assertion fails: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 00)).hasMinute(58);- Parameters:
minute- the given minute.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the given minute.- Since:
- 3.23.0
-
hasSecond
Verifies that actualLocalDateTimeis in the given second.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 00)).hasSecond(00); // Assertion fails: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 00)).hasSecond(17);- Parameters:
second- the given second.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the given second.- Since:
- 3.23.0
-
hasNano
Verifies that actualLocalDateTimeis in the given nanosecond.Example:
// Assertion succeeds: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 15)).hasNano(15); // Assertion fails: assertThat(LocalDateTime.of(2021, 12, 31, 23, 59, 00)).hasNano(15);- Parameters:
nano- the given second.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not in the given nanosecond.- Since:
- 3.23.0
-
isCloseTo
Verifies that the actualLocalDateTimeis close to the other according to the givenTemporalOffset.You can build the offset parameter using
Assertions.within(long, TemporalUnit)orAssertions.byLessThan(long, TemporalUnit).Example:
LocalDateTime localDateTime = LocalDateTime.now(); // assertion succeeds: assertThat(localDateTime).isCloseTo(localDateTime.plusHours(1), within(32, ChronoUnit.MINUTES)); // assertion fails: assertThat(localDateTime).isCloseTo(localDateTime.plusHours(1), within(10, ChronoUnit.SECONDS));- Overrides:
isCloseToin classAbstractTemporalAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime> - Parameters:
other- the localDateTime to compare actual tooffset- the offset used for comparison- Returns:
- this assertion object
- Throws:
NullPointerException- ifLocalDateTimeorTemporalOffsetparameter isnull.AssertionError- if the actualLocalDateTimeisnull.AssertionError- if the actualLocalDateTimeis not close to the given one for a provided offset.
-
parse
Obtains an instance ofTEMPORALfrom a string representation in ISO date format.- Specified by:
parsein classAbstractTemporalAssert<SELF extends AbstractLocalDateTimeAssert<SELF>,LocalDateTime> - Parameters:
localDateTimeAsString- the string to parse, not null- Returns:
- the parsed
TEMPORAL, not null
-
isCloseTo(LocalDateTime, TemporalOffset)instead, although not exactly the same semantics, this is the right way to compare with a given precision.