Top Description Fields Constructors Methods
org.assertj.core.api

public abstract Class AbstractTemporalAssert<SELF extends AbstractTemporalAssert<SELF, TEMPORAL>, TEMPORAL extends Temporal>

extends AbstractAssert<SELF extends AbstractTemporalAssert<SELF, TEMPORAL>, TEMPORAL extends Temporal>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.AbstractYearMonthAssert, org.assertj.core.api.AbstractZonedDateTimeAssert, org.assertj.core.api.AbstractOffsetDateTimeAssert, org.assertj.core.api.AbstractOffsetTimeAssert, org.assertj.core.api.TemporalAssert, org.assertj.core.api.AbstractInstantAssert, org.assertj.core.api.AbstractLocalDateAssert, org.assertj.core.api.AbstractLocalDateTimeAssert, org.assertj.core.api.AbstractLocalTimeAssert
Static Imports
java.util.Objects.requireNonNull, org.assertj.core.error.ShouldBeCloseTo.shouldBeCloseTo

Base class for all implementations of assertions for Temporals.
Since
3.7.0

Field Summary

Modifier and TypeField and Description
pack-priv Comparables
Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected
AbstractTemporalAssert(TEMPORAL
the actual value to verify
actual
,
Class<?>
the "self type"
selfType
)

Creates a new org.assertj.core.api.AbstractTemporalAssert.

Method Summary

Modifier and TypeMethod and Description
protected TEMPORAL
public SELF

Returns:

this assertion object
isCloseTo
(TEMPORAL
the temporal to compare actual to
other
,
TemporalOffset<? super TEMPORAL>
the offset used for comparison
offset
)

Verifies that the actual Temporal is close to the other according to the given TemporalOffset.

public SELF

Returns:

this assertion object.
isCloseTo
(String
String representing a TEMPORAL.
otherAsString
,
TemporalOffset<? super TEMPORAL>
the offset used for comparison
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.

protected abstract TEMPORAL

Returns:

the parsed TEMPORAL, not null
parse
(String
the string to parse, not null
temporalAsString
)

Obtains an instance of TEMPORAL from a string representation in ISO date format.

public SELF
usingComparator(Comparator<? super TEMPORAL>
the comparator to use for the incoming assertion checks.
customComparator
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingComparator(Comparator<? super TEMPORAL>
the comparator to use for the incoming assertion checks.
customComparator
,
String
comparator description to be used in assertion error messages
customComparatorDescription
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingDefaultComparator()

Overrides org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Implements org.assertj.core.api.Assert.usingDefaultComparator.

Revert to standard comparison for the incoming assertion checks.
Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError

Field Detail

comparablesback to summary
pack-priv Comparables comparables
Annotations
@VisibleForTesting

Constructor Detail

AbstractTemporalAssertback to summary
protected AbstractTemporalAssert(TEMPORAL actual, Class<?> selfType)

Creates a new org.assertj.core.api.AbstractTemporalAssert.

Parameters
actual:TEMPORAL

the actual value to verify

selfType:Class<?>

the "self type"

Method Detail

getActualback to summary
protected TEMPORAL getActual()
Annotations
@VisibleForTesting
isCloseToback to summary
public SELF isCloseTo(TEMPORAL other, TemporalOffset<? super TEMPORAL> offset)

Verifies that the actual 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 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:TEMPORAL

the temporal to compare actual to

offset:TemporalOffset<? super TEMPORAL>

the offset used for comparison

Returns:SELF

this assertion object

Exceptions
NullPointerException:
if Temporal or TemporalOffset parameter is null.
AssertionError:
  • if the actual Temporal is null.
  • if the actual Temporal is not close to the given one for a provided offset.
isCloseToback to summary
public 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.

Example :

 assertThat(LocalTime.parse("07:10:30")).isCloseTo("07:12:11", within(5, ChronoUnit.MINUTES));
Parameters
otherAsString:String

String representing a TEMPORAL.

offset:TemporalOffset<? super TEMPORAL>

the offset used for comparison

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Temporal is null.
  • if the actual Temporal is null.
  • if the actual Temporal is not close to the given within the provided offset.
NullPointerException:
if temporal string representation or TemporalOffset parameter is null.
parseback to summary
protected abstract TEMPORAL parse(String temporalAsString)

Obtains an instance of TEMPORAL from a string representation in ISO date format.

Parameters
temporalAsString:String

the string to parse, not null

Returns:TEMPORAL

the parsed TEMPORAL, not null

usingComparatorback to summary
public SELF usingComparator(Comparator<? super TEMPORAL> customComparator)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Doc from org.assertj.core.api.AbstractAssert.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);
Parameters
customComparator:Comparator<? super TEMPORAL>

Doc from org.assertj.core.api.Assert.usingComparator.

the comparator to use for the incoming assertion checks.

Returns:SELF

Doc from org.assertj.core.api.Assert.usingComparator.

this assertion object.

Annotations
@Override
@CheckReturnValue
usingComparatorback to summary
public SELF usingComparator(Comparator<? super TEMPORAL> customComparator, String customComparatorDescription)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Doc from org.assertj.core.api.AbstractAssert.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, "Hobbit Race Comparator").isEqualTo(sam);
Parameters
customComparator:Comparator<? super TEMPORAL>

Doc from org.assertj.core.api.Assert.usingComparator.

the comparator to use for the incoming assertion checks.

customComparatorDescription:String

Doc from org.assertj.core.api.Assert.usingComparator.

comparator description to be used in assertion error messages

Returns:SELF

Doc from org.assertj.core.api.Assert.usingComparator.

this assertion object.

Annotations
@Override
@CheckReturnValue
usingDefaultComparatorback to summary
public SELF usingDefaultComparator()

Overrides org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Implements org.assertj.core.api.Assert.usingDefaultComparator.

Doc from org.assertj.core.api.AbstractAssert.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.

Returns:SELF

Doc from org.assertj.core.api.Assert.usingDefaultComparator.

this assertion object.

Annotations
@Override
@CheckReturnValue