public abstract class AbstractTemporalAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal> extends AbstractAssert<SELF,TEMPORAL>
Temporals.actual, info, myself, objects, throwUnsupportedExceptionOnEquals| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTemporalAssert(TEMPORAL actual,
Class<?> selfType)
Creates a new
. |
| Modifier and Type | Method and Description |
|---|---|
protected TEMPORAL |
getActual() |
SELF |
isCloseTo(String otherAsString,
TemporalOffset<? super TEMPORAL> offset)
Same assertion as
isCloseTo(Temporal, TemporalOffset) but the TEMPORAL is built from a given String that
follows predefined ISO date format Predefined Formatters to allow calling parse(String))} method. |
SELF |
isCloseTo(TEMPORAL other,
TemporalOffset<? super TEMPORAL> offset)
Verifies that the actual
Temporal is close to the other according to the given TemporalOffset. |
protected abstract TEMPORAL |
parse(String temporalAsString)
Obtains an instance of
TEMPORAL from a string representation in ISO date format. |
SELF |
usingComparator(Comparator<? super TEMPORAL> customComparator)
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingComparator(Comparator<? super TEMPORAL> customComparator,
String customComparatorDescription)
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingDefaultComparator()
Revert to standard comparison for the incoming assertion checks.
|
areEqual, 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, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitas, as, as, describedAsprotected AbstractTemporalAssert(TEMPORAL actual, Class<?> selfType)
AbstractTemporalAssert.selfType - the "self type"actual - the actual value to verifyprotected TEMPORAL getActual()
public SELF isCloseTo(TEMPORAL other, TemporalOffset<? super TEMPORAL> offset)
Temporal is close to the other according to the given TemporalOffset.
You can build the offset parameter using Assertions.within(long, TemporalUnit) or Assertions.byLessThan(long, TemporalUnit).
Example:
LocalTime _07_10 = LocalTime.of(7, 10);
LocalTime _07_42 = LocalTime.of(7, 42);
// assertions will pass
assertThat(_07_10).isCloseTo(_07_42, within(1, ChronoUnit.HOURS));
assertThat(_07_10).isCloseTo(_07_42, within(32, ChronoUnit.MINUTES));
// assertions will fail
assertThat(_07_10).isCloseTo(_07_42, byLessThan(32, ChronoUnit.MINUTES));
assertThat(_07_10).isCloseTo(_07_42, within(10, ChronoUnit.SECONDS));other - the temporal to compare actual tooffset - the offset used for comparisonNullPointerException - if Temporal or TemporalOffset parameter is null.AssertionError - if the actual Temporal is null.AssertionError - if the actual Temporal is not close to the given for a provided offset.public SELF isCloseTo(String otherAsString, TemporalOffset<? super TEMPORAL> offset)
isCloseTo(Temporal, TemporalOffset) but the TEMPORAL is built from a given String that
follows predefined ISO date format Predefined Formatters to allow calling parse(String))} method.
Example :
assertThat(LocalTime.parse("07:10:30")).isCloseTo("07:12:11", within(5, ChronoUnit.MINUTES));otherAsString - String representing a TEMPORAL.offset - the offset used for comparisonAssertionError - if the actual Temporal is null.NullPointerException - if temporal string representation or TemporalOffset parameter is null.AssertionError - if the actual Temporal is null.AssertionError - if the actual Temporal is not close to the given for a provided offset.protected abstract TEMPORAL parse(String temporalAsString)
TEMPORAL from a string representation in ISO date format.temporalAsString - the string to parse, not nullTEMPORAL, not nullpublic SELF usingComparator(Comparator<? super TEMPORAL> customComparator)
The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);usingComparator in interface Assert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>usingComparator in class AbstractAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>customComparator - the comparator to use for the incoming assertion checks.this assertion object.public SELF usingComparator(Comparator<? super TEMPORAL> customComparator, String customComparatorDescription)
The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator, "Hobbit Race Comparator").isEqualTo(sam);usingComparator in interface Assert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>usingComparator in class AbstractAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>customComparator - the comparator to use for the incoming assertion checks.customComparatorDescription - comparator description to be used in assertion error messagesthis assertion object.public SELF usingDefaultComparator()
This method should be used to disable a custom comparison strategy set by calling usingComparator.
usingDefaultComparator in interface Assert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>usingDefaultComparator in class AbstractAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>this assertion object.Copyright © 2025. All rights reserved.