Package org.assertj.core.api
Class AbstractTemporalAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>
java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,TEMPORAL>
org.assertj.core.api.AbstractTemporalAssert<SELF,TEMPORAL>
- All Implemented Interfaces:
Assert<SELF,,TEMPORAL> Descriptable<SELF>,ExtensionPoints<SELF,TEMPORAL>
- Direct Known Subclasses:
AbstractInstantAssert,AbstractLocalDateAssert,AbstractLocalDateTimeAssert,AbstractLocalTimeAssert,AbstractOffsetDateTimeAssert,AbstractOffsetTimeAssert,AbstractYearMonthAssert,AbstractZonedDateTimeAssert,TemporalAssert
public abstract class AbstractTemporalAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>,TEMPORAL extends Temporal>
extends AbstractAssert<SELF,TEMPORAL>
Base class for all implementations of assertions for
Temporals.- Since:
- 3.7.0
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractTemporalAssert(TEMPORAL actual, Class<?> selfType) Creates a new.AbstractTemporalAssert -
Method Summary
Modifier and TypeMethodDescriptionisCloseTo(String otherAsString, TemporalOffset<? super TEMPORAL> offset) Same assertion asisCloseTo(Temporal, TemporalOffset)but theTEMPORALis built from a given String that follows predefined ISO date format Predefined Formatters to allow callingparse(String))} method.isCloseTo(TEMPORAL other, TemporalOffset<? super TEMPORAL> offset) Verifies that the actualTemporalis close to the other according to the givenTemporalOffset.protected abstract TEMPORALObtains an instance ofTEMPORALfrom a string representation in ISO date format.usingComparator(Comparator<? super TEMPORAL> customComparator) Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.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.Revert to standard comparison for the incoming assertion checks.Methods 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, 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, 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
-
Constructor Details
-
AbstractTemporalAssert
Creates a new.AbstractTemporalAssert- Parameters:
actual- the actual value to verifyselfType- the "self type"
-
-
Method Details
-
isCloseTo
Verifies that the actualTemporalis close to the other according to the givenTemporalOffset.You can build the offset parameter using
Assertions.within(long, TemporalUnit)orAssertions.byLessThan(long, TemporalUnit).Example:
LocalTime _07_10 = LocalTime.of(7, 10); LocalTime _07_42 = LocalTime.of(7, 42); // assertions succeed: assertThat(_07_10).isCloseTo(_07_42, within(1, ChronoUnit.HOURS)); assertThat(_07_10).isCloseTo(_07_42, within(32, ChronoUnit.MINUTES)); // assertions fail: assertThat(_07_10).isCloseTo(_07_42, byLessThan(32, ChronoUnit.MINUTES)); assertThat(_07_10).isCloseTo(_07_42, within(10, ChronoUnit.SECONDS));- Parameters:
other- the temporal to compare actual tooffset- the offset used for comparison- Returns:
- this assertion object
- Throws:
NullPointerException- ifTemporalorTemporalOffsetparameter isnull.AssertionError- if the actualTemporalisnull.AssertionError- if the actualTemporalis not close to the given one for a provided offset.
-
isCloseTo
Same assertion asisCloseTo(Temporal, TemporalOffset)but theTEMPORALis built from a given String that follows predefined ISO date format Predefined Formatters to allow callingparse(String))} method.Example :
assertThat(LocalTime.parse("07:10:30")).isCloseTo("07:12:11", within(5, ChronoUnit.MINUTES));- Parameters:
otherAsString- String representing aTEMPORAL.offset- the offset used for comparison- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualTemporalisnull.NullPointerException- if temporal string representation orTemporalOffsetparameter isnull.AssertionError- if the actualTemporalisnull.AssertionError- if the actualTemporalis not close to the given within the provided offset.
-
parse
Obtains an instance ofTEMPORALfrom a string representation in ISO date format.- Parameters:
temporalAsString- the string to parse, not null- Returns:
- the parsed
TEMPORAL, not null
-
usingComparator
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.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);- Specified by:
usingComparatorin interfaceAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>, TEMPORAL extends Temporal> - Overrides:
usingComparatorin classAbstractAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>, TEMPORAL extends Temporal> - Parameters:
customComparator- the comparator to use for the incoming assertion checks.- Returns:
thisassertion object.
-
usingComparator
public 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.The custom comparator is bound to the current assertion chain, 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);- Specified by:
usingComparatorin interfaceAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>, TEMPORAL extends Temporal> - Overrides:
usingComparatorin classAbstractAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>, TEMPORAL extends Temporal> - Parameters:
customComparator- the comparator to use for the incoming assertion checks.customComparatorDescription- comparator description to be used in assertion error messages- Returns:
thisassertion object.
-
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 AbstractTemporalAssert<SELF,TEMPORAL>, TEMPORAL extends Temporal> - Overrides:
usingDefaultComparatorin classAbstractAssert<SELF extends AbstractTemporalAssert<SELF,TEMPORAL>, TEMPORAL extends Temporal> - Returns:
thisassertion object.
-