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,AbstractZonedDateTimeAssert
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
FieldsFields inherited from class org.assertj.core.api.AbstractAssert
actual, conditions, info, myself, objects -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractTemporalAssert(TEMPORAL actual, Class<?> selfType) Creates a new.AbstractTemporalAssert -
Method Summary
Modifier and TypeMethodDescriptionprotected TEMPORALisCloseTo(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.Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
-
Field Details
-
comparables
Comparables comparables
-
-
Constructor Details
-
AbstractTemporalAssert
Creates a new.AbstractTemporalAssert- Parameters:
selfType- the "self type"actual- the actual value to verify
-
-
Method Details
-
getActual
-
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 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));- 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 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.- 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 for a 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
-