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

public Class AbstractInstantAssert<SELF extends AbstractInstantAssert<SELF>>

extends AbstractTemporalAssert<SELF extends AbstractInstantAssert<SELF>, Instant>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.InstantAssert
Type Parameters
<SELF>
the "self" type of this assertion class.
Static Imports
org.assertj.core.error.ShouldBeAfter.shouldBeAfter, .ShouldBeAfterOrEqualTo.shouldBeAfterOrEqualTo, .ShouldBeBefore.shouldBeBefore, .ShouldBeBeforeOrEqualTo.shouldBeBeforeOrEqualTo, .ShouldBeInTheFuture.shouldBeInTheFuture, .ShouldBeInThePast.shouldBeInThePast, org.assertj.core.util.Preconditions.checkArgument

Assertions for Instant type from new Date & Time API introduced in Java 8.
Since
3.7.0

Field Summary

Inherited from org.assertj.core.api.AbstractTemporalAssert:
comparables

Constructor Summary

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

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

Method Summary

Modifier and TypeMethod and Description
private static void
assertInstantAsStringParameterIsNotNull(String
String representing the Instant to compare actual with
instantAsString
)

Check that the Instant string representation to compare actual Instant to is not null, otherwise throws a IllegalArgumentException with an explicit message

private static void
private static void
private void
private static Object[]
convertToInstantArray(String[] instantsAsString)

public SELF

Returns:

this assertion object.
isAfter
(Instant
the given Instant.
other
)

Verifies that the actual Instant is strictly after the given one.

public SELF

Returns:

this assertion object.
isAfter
(String
String representing a Instant.
instantAsString
)

Same assertion as isAfter(Instant) but the Instant is built from given a String that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isAfterOrEqualTo
(Instant
the given Instant.
other
)

Verifies that the actual Instant is after or equals to the given one.

public SELF

Returns:

this assertion object.
isAfterOrEqualTo
(String
String representing a Instant.
instantAsString
)

Same assertion as isAfterOrEqualTo(Instant) but the Instant is built from given String, which must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isBefore
(Instant
the given Instant.
other
)

Verifies that the actual Instant is strictly before the given one.

public SELF

Returns:

this assertion object.
isBefore
(String
String representing a Instant.
instantAsString
)

Same assertion as isBefore(Instant) but the Instant is built from given String, which must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isBeforeOrEqualTo
(Instant
the given Instant.
other
)

Verifies that the actual Instant is before or equals to the given one.

public SELF

Returns:

this assertion object.
isBeforeOrEqualTo
(String
String representing a Instant.
instantAsString
)

Same assertion as isBeforeOrEqualTo(Instant) but the Instant is built from given String, which must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isBetween
(Instant
the start value (inclusive), expected not to be null.
startInclusive
,
Instant
the end value (inclusive), expected not to be null.
endInclusive
)

Verifies that the actual Instant is in the [start, end] period (start and end included).

public SELF

Returns:

this assertion object.
isBetween
(String
the start value (inclusive), expected not to be null.
startInclusive
,
String
the end value (inclusive), expected not to be null.
endInclusive
)

Same assertion as isBetween(Instant, Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isEqualTo
(String
String representing a Instant.
instantAsString
)

Same assertion as isEqualTo(Object) (where Object is expected to be Instant) but here you pass Instant String representation that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isIn
(String...
String array representing Instants.
instantsAsString
)

Same assertion as isIn(Object...) (where Objects are expected to be Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isInTheFuture
()

Verifies that the actual Instant is strictly in the future.

public SELF

Returns:

this assertion object.
isInThePast
()

Verifies that the actual Instant is strictly in the past.

public SELF

Returns:

this assertion object.
isNotEqualTo
(String
String representing a Instant.
instantAsString
)

Same assertion as isNotEqualTo(Object) (where Object is expected to be Instant) but here you pass Instant String representation that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isNotIn
(String...
Array of String representing a Instant.
instantsAsString
)

Same assertion as isNotIn(Object...) (where Objects are expected to be Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isStrictlyBetween
(Instant
the start value (exclusive), expected not to be null.
startExclusive
,
Instant
the end value (exclusive), expected not to be null.
endExclusive
)

Verifies that the actual Instant is in the ]start, end[ period (start and end excluded).

public SELF

Returns:

this assertion object.
isStrictlyBetween
(String
the start value (exclusive), expected not to be null.
startExclusive
,
String
the end value (exclusive), expected not to be null.
endExclusive
)

Same assertion as isStrictlyBetween(Instant, Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

protected Instant
parse(String
the string to parse, not null
instantAsString
)

Implements abstract org.assertj.core.api.AbstractTemporalAssert.parse.

Obtains an instance of TEMPORAL from a string representation in ISO date format.
Inherited from org.assertj.core.api.AbstractTemporalAssert:
getActualisCloseToisCloseTousingComparatorusingComparatorusingDefaultComparator

Constructor Detail

AbstractInstantAssertback to summary
protected AbstractInstantAssert(Instant actual, Class<?> selfType)

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

Parameters
actual:Instant

the actual value to verify

selfType:Class<?>

the "self type"

Method Detail

assertInstantAsStringParameterIsNotNullback to summary
private static void assertInstantAsStringParameterIsNotNull(String instantAsString)

Check that the Instant string representation to compare actual Instant to is not null, otherwise throws a IllegalArgumentException with an explicit message

Parameters
instantAsString:String

String representing the Instant to compare actual with

Exceptions
IllegalArgumentException:
with an explicit message if the given String is null
assertInstantParameterIsNotNullback to summary
private static void assertInstantParameterIsNotNull(Instant instant)
assertNotNullback to summary
private static void assertNotNull(AssertionInfo info, Instant actual)
checkIsNotNullAndNotEmptyback to summary
private void checkIsNotNullAndNotEmpty(Object[] values)
convertToInstantArrayback to summary
private static Object[] convertToInstantArray(String[] instantsAsString)
isAfterback to summary
public SELF isAfter(Instant other)

Verifies that the actual Instant is strictly after the given one.

Example :

 assertThat(parse("2007-12-03T10:15:30.00Z").isAfter(parse("2007-12-03T10:15:27.00Z"));
Parameters
other:Instant

the given Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not strictly after the given one.
IllegalArgumentException:
if other Instant is null.
Since
3.7.0
isAfterback to summary
public SELF isAfter(String instantAsString)

Same assertion as isAfter(Instant) but the Instant is built from given a String that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use String in comparison to avoid conversion
assertThat(parse("2007-12-03T10:15:30.00Z")).isAfter("2007-12-03T10:15:27.00Z");
Parameters
instantAsString:String

String representing a Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not strictly after the Instant built from given String.
IllegalArgumentException:
if given String is null.
DateTimeParseException:
if given String can't be converted to a Instant.
Since
3.7.0
isAfterOrEqualToback to summary
public SELF isAfterOrEqualTo(Instant other)

Verifies that the actual Instant is after or equals to the given one.

Example :

 assertThat(parse("2007-12-03T10:15:30.00Z")).isAfterOrEqualTo(parse("2007-12-03T10:15:30.00Z"))
                               .isAfterOrEqualTo(parse("2007-12-03T10:15:27.00Z"));
Parameters
other:Instant

the given Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not after or equals to the given one.
IllegalArgumentException:
if other Instant is null.
Since
3.7.0
isAfterOrEqualToback to summary
public SELF isAfterOrEqualTo(String instantAsString)

Same assertion as isAfterOrEqualTo(Instant) but the Instant is built from given String, which must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use String in comparison to avoid conversion
assertThat(parse("2007-12-03T10:15:30.00Z")).isAfterOrEqualTo("2007-12-03T10:15:30.00Z")
                               .isAfterOrEqualTo("2007-12-03T10:15:27.00Z");
Parameters
instantAsString:String

String representing a Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not after or equals to the Instant built from given String.
IllegalArgumentException:
if given String is null.
DateTimeParseException:
if given String can't be converted to a Instant.
Since
3.7.0
isBeforeback to summary
public SELF isBefore(Instant other)

Verifies that the actual Instant is strictly before the given one.

Example :

 assertThat(parse("2007-12-03T10:15:30.00Z")).isBefore(parse("2007-12-03T10:15:31.00Z"));
Parameters
other:Instant

the given Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not strictly before the given one.
IllegalArgumentException:
if other Instant is null.
Since
3.7.0
isBeforeback to summary
public SELF isBefore(String instantAsString)

Same assertion as isBefore(Instant) but the Instant is built from given String, which must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use String in comparison to avoid writing the code to perform the conversion
assertThat(parse("2007-12-03T10:15:30.00Z").isBefore("2007-12-03T10:15:31.00Z");
Parameters
instantAsString:String

String representing a Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not strictly before the Instant built from given String.
IllegalArgumentException:
if given String is null.
DateTimeParseException:
if given String can't be converted to a Instant.
Since
3.7.0
isBeforeOrEqualToback to summary
public SELF isBeforeOrEqualTo(Instant other)

Verifies that the actual Instant is before or equals to the given one.

Example :

 assertThat(parse("2007-12-03T10:15:30.00Z")).isBeforeOrEqualTo(parse("2007-12-03T10:15:30.00Z"))
                               .isBeforeOrEqualTo(parse("2007-12-03T10:15:31.00Z"));
Parameters
other:Instant

the given Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not before or equals to the given one.
IllegalArgumentException:
if other Instant is null.
Since
3.7.0
isBeforeOrEqualToback to summary
public SELF isBeforeOrEqualTo(String instantAsString)

Same assertion as isBeforeOrEqualTo(Instant) but the Instant is built from given String, which must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use String in comparison to avoid conversion
assertThat(parse("2007-12-03T10:15:30.00Z")).isBeforeOrEqualTo("2007-12-03T10:15:30.00Z")
                               .isBeforeOrEqualTo("2007-12-03T10:15:31.00Z");
Parameters
instantAsString:String

String representing a Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not before or equals to the Instant built from given String.
IllegalArgumentException:
if given String is null.
DateTimeParseException:
if given String can't be converted to a Instant.
Since
3.7.0
isBetweenback to summary
public SELF isBetween(Instant startInclusive, Instant endInclusive)

Verifies that the actual Instant is in the [start, end] period (start and end included).

Example:

 Instant instant = Instant.now();

// assertions succeed:
assertThat(instant).isBetween(instant.minusSeconds(1), instant.plusSeconds(1))
                   .isBetween(instant, instant.plusSeconds(1))
                   .isBetween(instant.minusSeconds(1), instant)
                   .isBetween(instant, instant);

// assertions fail:
assertThat(instant).isBetween(instant.minusSeconds(10), instant.minusSeconds(1));
assertThat(instant).isBetween(instant.plusSeconds(1), instant.plusSeconds(10));
Parameters
startInclusive:Instant

the start value (inclusive), expected not to be null.

endInclusive:Instant

the end value (inclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in [start, end] range.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
3.7.1
isBetweenback to summary
public SELF isBetween(String startInclusive, String endInclusive)

Same assertion as isBetween(Instant, Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example:

 Instant firstOfJanuary2000 = Instant.parse("2000-01-01T00:00:00.00Z");

// assertions succeed:
assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z")
                              .isBetween("2000-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z")
                              .isBetween("1999-01-01T00:00:00.00Z", "2000-01-01T00:00:00.00Z")
                              .isBetween("2000-01-01T00:00:00.00Z", "2000-01-01T00:00:00.00Z");

// assertion fails:
assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:00.00Z", "1999-12-31T23:59:59.59Z");
Parameters
startInclusive:String

the start value (inclusive), expected not to be null.

endInclusive:String

the end value (inclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in [start, end] range.
NullPointerException:
  • if start value is null.
  • if end value is null.
DateTimeParseException:
if any of the given String can't be converted to a Instant.
Since
3.7.1
isEqualToback to summary
public SELF isEqualTo(String instantAsString)

Same assertion as isEqualTo(Object) (where Object is expected to be Instant) but here you pass Instant String representation that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use directly String in comparison to avoid writing the code to perform the conversion
assertThat(parse("2007-12-03T10:15:30.00Z")).isEqualTo("2007-12-03T10:15:30.00Z");
Parameters
instantAsString:String

String representing a Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not equal to the Instant built from given String.
IllegalArgumentException:
if given String is null.
DateTimeParseException:
if given String can't be converted to a Instant.
Since
3.7.0
isInback to summary
public SELF isIn(String... instantsAsString)

Same assertion as isIn(Object...) (where Objects are expected to be Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use String based representation of Instant
assertThat(parse("2007-12-03T10:15:30.00Z")).isIn("2007-12-03T10:15:30.00Z", "2007-12-03T10:15:35.00Z");
Parameters
instantsAsString:String[]

String array representing Instants.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not in the Instants built from given Strings.
IllegalArgumentException:
if given Strings are null or empty.
DateTimeParseException:
if one of the given String can't be converted to a Instant.
Since
3.7.0
isInTheFutureback to summary
public SELF isInTheFuture()

Verifies that the actual Instant is strictly in the future.

Example:

 // assertion succeeds:
assertThat(Instant.now().plusSeconds(60)).isInTheFuture();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not in the future.
Since
3.25.0
isInThePastback to summary
public SELF isInThePast()

Verifies that the actual Instant is strictly in the past.

Example:

 // assertion succeeds:
assertThat(Instant.now().minusSeconds(60)).isInThePast();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is not in the past.
Since
3.25.0
isNotEqualToback to summary
public SELF isNotEqualTo(String instantAsString)

Same assertion as isNotEqualTo(Object) (where Object is expected to be Instant) but here you pass Instant String representation that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use directly String in comparison to avoid writing the code to perform the conversion
assertThat(parse("2007-12-03T10:15:30.00Z")).isNotEqualTo("2007-12-03T10:15:00.00Z");
Parameters
instantAsString:String

String representing a Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is equal to the Instant built from given String.
IllegalArgumentException:
if given String is null.
DateTimeParseException:
if given String can't be converted to a Instant.
Since
3.7.0
isNotInback to summary
public SELF isNotIn(String... instantsAsString)

Same assertion as isNotIn(Object...) (where Objects are expected to be Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example :

 // use String based representation of Instant
assertThat(parse("2007-12-03T10:15:30.00Z")).isNotIn("2007-12-03T10:15:35.00Z", "2007-12-03T10:15:25.00Z");
Parameters
instantsAsString:String[]

Array of String representing a Instant.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual Instant is null.
  • if the actual Instant is in the Instants built from given Strings.
IllegalArgumentException:
if given Strings are null or empty.
DateTimeParseException:
if one of the given String can't be converted to a Instant.
Since
3.7.0
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(Instant startExclusive, Instant endExclusive)

Verifies that the actual Instant is in the ]start, end[ period (start and end excluded).

Example:

 Instant instant = Instant.now();

// assertion succeeds:
assertThat(instant).isStrictlyBetween(instant.minusSeconds(1), instant.plusSeconds(1));

// assertions fail:
assertThat(instant).isStrictlyBetween(instant.minusSeconds(10), instant.minusSeconds(1));
assertThat(instant).isStrictlyBetween(instant.plusSeconds(1), instant.plusSeconds(10));
assertThat(instant).isStrictlyBetween(instant, instant.plusSeconds(1));
assertThat(instant).isStrictlyBetween(instant.minusSeconds(1), instant);
Parameters
startExclusive:Instant

the start value (exclusive), expected not to be null.

endExclusive:Instant

the end value (exclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in ]start, end[ range.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
3.7.1
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(String startExclusive, String endExclusive)

Same assertion as isStrictlyBetween(Instant, Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant#parse(CharSequence) method.

Example:

 Instant firstOfJanuary2000 = Instant.parse("2000-01-01T00:00:00.00Z");

// assertion succeeds:
assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z");

// assertions fail:
assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:00.00Z", "1999-12-31T23:59:59.59Z");
assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z");
assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:00.00Z", "2000-01-01T00:00:00.00Z");
Parameters
startExclusive:String

the start value (exclusive), expected not to be null.

endExclusive:String

the end value (exclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in ]start, end[ range.
NullPointerException:
  • if start value is null.
  • if end value is null.
DateTimeParseException:
if any of the given String can't be converted to a Instant.
Since
3.7.1
parseback to summary
protected Instant parse(String instantAsString)

Implements abstract org.assertj.core.api.AbstractTemporalAssert.parse.

Doc from org.assertj.core.api.AbstractTemporalAssert.parse.

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

Parameters
instantAsString:String

the string to parse, not null

Returns:Instant

the parsed TEMPORAL, not null

Annotations
@Override