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

public abstract Class AbstractCompletableFutureAssert<SELF extends AbstractCompletableFutureAssert<SELF, RESULT>, RESULT>

extends AbstractAssert<SELF extends AbstractCompletableFutureAssert<SELF, RESULT>, CompletableFuture<RESULT>>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.CompletableFutureAssert
Type Parameters
<RESULT>
type of the value contained in the CompletableFuture.
Static Imports
org.assertj.core.api.AssertionsForClassTypes.assertThat, org.assertj.core.error.ShouldBeEqual.shouldBeEqual, .ShouldMatch.shouldMatch, org.assertj.core.error.future.ShouldBeCancelled.shouldBeCancelled, .ShouldBeCompleted.shouldBeCompleted, .ShouldBeCompletedExceptionally.shouldHaveCompletedExceptionally, .ShouldBeDone.shouldBeDone, .ShouldHaveFailed.shouldHaveFailed, .ShouldNotBeCancelled.shouldNotBeCancelled, .ShouldNotBeCompleted.shouldNotBeCompleted, .ShouldNotBeCompletedExceptionally.shouldNotHaveCompletedExceptionally, .ShouldNotBeDone.shouldNotBeDone, .ShouldNotHaveFailed.shouldNotHaveFailed

Assertions for CompletableFuture.

Field Summary

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

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public WithThrowable

Returns:

a new assertion instance on the future's exception.
failsWithin
(Duration
the maximum time to wait
timeout
)

Checks that the future does not complete within the given time (by calling Future#get(long, TimeUnit)) and returns the exception that caused the failure for further (exception) assertions, the exception can be any of InterruptedException, ExecutionException, TimeoutException or CancellationException.

public WithThrowable

Returns:

a new assertion instance on the future's exception.
failsWithin
(long
the maximum time to wait
timeout
,
TimeUnit
the time unit
unit
)

Checks that the future does not complete within the given time (by calling Future#get(long, TimeUnit)) and returns the exception that caused the failure for further (exception) assertions, the exception can be any of InterruptedException, ExecutionException, TimeoutException or CancellationException.

public SELF

Returns:

this assertion object.
hasFailed
()

Deprecated

Combine isCompletedExceptionally with isNotCancelled instead:

 assertThat(future).isCompletedExceptionally()
                  .isNotCancelled();
public AbstractThrowableAssert<?, ? extends Throwable>

Returns:

an exception assertion object.
hasFailedWithThrowableThat
()

Deprecated

Although not 100% the same, consider using failsWithin(Duration) or failsWithin(long, TimeUnit) instead:

 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException("boom!"));

assertThat(future).failsWithin(1, TimeUnit.SECONDS)
                  .withThrowableOfType(RuntimeException.class)
                  .withMessage("boom!"); 
public SELF

Returns:

this assertion object.
hasNotFailed
()

Deprecated

Use matches with the following combination instead:

 assertThat(future).matches (f -> f.isNotCompletedExceptionally() || f.isCancelled());
private WithThrowable
private WithThrowable
internalFailsWithin(long timeout, TimeUnit unit)

private ObjectAssert<RESULT>
private ObjectAssert<RESULT>
internalSucceedsWithin(long timeout, TimeUnit unit)

public SELF

Returns:

this assertion object.
isCancelled
()

Verifies that the CompletableFuture is cancelled.

public SELF

Returns:

this assertion object.
isCompleted
()

Verifies that the CompletableFuture is completed normally (i.e.done but not completed exceptionally) or cancelled.

public SELF

Returns:

this assertion object.
isCompletedExceptionally
()

Verifies that the CompletableFuture is completed exceptionally.

public SELF

Returns:

this assertion object.
isCompletedWithValue
(RESULT
the expected result value of the CompletableFuture.
expected
)

Verifies that the CompletableFuture is completed normally with the expected result.

public SELF

Returns:

this assertion object.
isCompletedWithValueMatching
(Predicate<? super RESULT>
the Predicate to apply.
predicate
)

Verifies that the CompletableFuture is completed normally with a result matching the predicate.

public SELF

Returns:

this assertion object.
isCompletedWithValueMatching
(Predicate<? super RESULT>
the Predicate to apply on the resulting value.
predicate
,
String
the Predicate description.
description
)

Verifies that the CompletableFuture is completed normally with a result matching the predicate, the String parameter is used in the error message.

private SELF
isCompletedWithValueMatching(Predicate<? super RESULT> predicate, PredicateDescription description)

public SELF

Returns:

this assertion object.
isDone
()

Verifies that the CompletableFuture is done i.e. completed normally, exceptionally, or via cancellation.

public SELF

Returns:

this assertion object.
isNotCancelled
()

Verifies that the CompletableFuture is not cancelled.

public SELF

Returns:

this assertion object.
isNotCompleted
()

Verifies that the CompletableFuture is not completed normally (i.e. incomplete, failed or cancelled).

public SELF

Returns:

this assertion object.
isNotCompletedExceptionally
()

Verifies that the CompletableFuture is not completed exceptionally.

public SELF

Returns:

this assertion object.
isNotDone
()

Verifies that the CompletableFuture is not done.

protected ObjectAssert<RESULT>
newObjectAssert(RESULT objectUnderTest)

public ObjectAssert<RESULT>

Returns:

a new assertion object on the future's result.
succeedsWithin
(Duration
the maximum time to wait
timeout
)

Waits if necessary for at most the given time for this future to complete, and then returns its result for further assertions.

public ObjectAssert<RESULT>

Returns:

a new assertion object on the future's result.
succeedsWithin
(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Waits if necessary for at most the given time for this future to complete, and then returns its result for further assertions.

public <
the type of the resulting Assert
ASSERT extends AbstractAssert<?, ?>
>
ASSERT

Returns:

a new narrowed Assert instance for assertions chaining on the value of the CompletableFuture
succeedsWithin
(Duration
the maximum time to wait
timeout
,
InstanceOfAssertFactory<RESULT, ASSERT>
the factory which verifies the type and creates the new Assert
assertFactory
)

Waits if necessary for at most the given time for this future to complete, the InstanceOfAssertFactory parameter is used to return assertions specific to the future's result type.

public <
the type of the resulting Assert
ASSERT extends AbstractAssert<?, ?>
>
ASSERT

Returns:

a new narrowed Assert instance for assertions chaining on the value of the CompletableFuture
succeedsWithin
(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
,
InstanceOfAssertFactory<RESULT, ASSERT>
the factory which verifies the type and creates the new Assert
assertFactory
)

Waits if necessary for at most the given time for this future to complete, the InstanceOfAssertFactory parameter is used to return assertions specific to the future's result type.

Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingComparatorusingComparatorusingDefaultComparatorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError

Field Detail

futuresback to summary
pack-priv Futures futures
Annotations
@VisibleForTesting

Constructor Detail

AbstractCompletableFutureAssertback to summary
protected AbstractCompletableFutureAssert(CompletableFuture<RESULT> actual, Class<?> selfType)

Method Detail

failsWithinback to summary
public WithThrowable failsWithin(Duration timeout)

Checks that the future does not complete within the given time (by calling Future#get(long, TimeUnit)) and returns the exception that caused the failure for further (exception) assertions, the exception can be any of InterruptedException, ExecutionException, TimeoutException or CancellationException.

WARNING

failsWithin does not fully integrate with soft assertions, if the future completes the test will fail immediately (the error is not collected as a soft assertion error), if the assertion succeeds the chained assertions are executed and any errors will be collected as a soft assertion errors.
The rationale is that if we collect failsWithin error as a soft assertion error, the chained assertions would be executed but that does not make sense since there is no exception to check as the future has completed.

Examples:

 CompletableFuture<?> future = futureCompletingAfterMs(100);

// assertion succeeds as the future is not completed after 50ms
assertThat(future).failsWithin(Duration.ofMillis(50))
                  .withThrowableOfType(TimeoutException.class)
                  .withMessage(null);

// fails as the future is completed after within 200ms
assertThat(future).failsWithin(Duration.ofMillis(200));
Parameters
timeout:Duration

the maximum time to wait

Returns:WithThrowable

a new assertion instance on the future's exception.

Exceptions
AssertionError:
  • if the actual CompletableFuture is null.
  • if the actual CompletableFuture succeeds within the given timeout.
Since
3.18.0
failsWithinback to summary
public WithThrowable failsWithin(long timeout, TimeUnit unit)

Checks that the future does not complete within the given time (by calling Future#get(long, TimeUnit)) and returns the exception that caused the failure for further (exception) assertions, the exception can be any of InterruptedException, ExecutionException, TimeoutException or CancellationException.

WARNING

failsWithin does not fully integrate with soft assertions, if the future completes the test will fail immediately (the error is not collected as a soft assertion error), if the assertion succeeds the chained assertions are executed and any errors will be collected as a soft assertion errors.
The rationale is that if we collect failsWithin error as a soft assertion error, the chained assertions would be executed but that does not make sense since there is no exception to check as the future has completed.

Examples:

 CompletableFuture<?> future = futureCompletingAfterMs(100);

// assertion succeeds as the future is not completed after 50ms
assertThat(future).failsWithin(50, TimeUnit.MILLISECONDS)
                  .withThrowableOfType(TimeoutException.class)
                  .withMessage(null);

// fails as the future is completed after within 200ms
assertThat(future).failsWithin(200, TimeUnit.MILLISECONDS);
Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit

Returns:WithThrowable

a new assertion instance on the future's exception.

Exceptions
AssertionError:
  • if the actual CompletableFuture is null.
  • if the actual CompletableFuture succeeds within the given timeout.
Since
3.18.0
hasFailedback to summary
public SELF hasFailed()

Deprecated

Combine isCompletedExceptionally with isNotCancelled instead:

 assertThat(future).isCompletedExceptionally()
                  .isNotCancelled();
This assertion is deprecated to change the semantics of failed to correspond to CompletableFuture#get() failing.

Original javadoc

Verifies that the CompletableFuture has completed exceptionally but has not been cancelled, this assertion is equivalent to:

 assertThat(future).isCompletedExceptionally()
                  .isNotCancelled();

Assertion will pass :

 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException());
assertThat(future).hasFailed();
Assertion will fail :
 CompletableFuture future = new CompletableFuture();
future.cancel(true);
assertThat(future).hasFailed();
Returns:SELF

this assertion object.

Annotations
@Deprecated
hasFailedWithThrowableThatback to summary
public AbstractThrowableAssert<?, ? extends Throwable> hasFailedWithThrowableThat()

Deprecated

Although not 100% the same, consider using failsWithin(Duration) or failsWithin(long, TimeUnit) instead:

 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException("boom!"));

assertThat(future).failsWithin(1, TimeUnit.SECONDS)
                  .withThrowableOfType(RuntimeException.class)
                  .withMessage("boom!"); 
This assertion is deprecated because it relies on hasFailed() semantics which we want to move away from (they are not clear!) and to use failure semantics corresponding to CompletableFuture#get() failing.

Original javadoc

Verifies that the CompletableFuture has completed exceptionally and returns a Throwable assertion object allowing to check the Throwable that has caused the future to fail.

Assertion will pass :

 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException("boom!"));

assertThat(future).hasFailedWithThrowableThat().isInstanceOf(RuntimeException.class);
                                               .hasMessage("boom!"); 
Assertion will fail :
 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException());

assertThat(future).hasFailedWithThrowableThat().isInstanceOf(IllegalArgumentException.class);
Returns:AbstractThrowableAssert<?, ? extends Throwable>

an exception assertion object.

Annotations
@Deprecated
hasNotFailedback to summary
public SELF hasNotFailed()

Deprecated

Use matches with the following combination instead:

 assertThat(future).matches (f -> f.isNotCompletedExceptionally() || f.isCancelled());
This assertion is deprecated because its semantic is not obvious.

Original javadoc

Verifies that the CompletableFuture has not failed i.e: incomplete, completed or cancelled.
This is different from isNotCompletedExceptionally() as a cancelled future has not failed but is completed exceptionally.

Assertion will pass :

 CompletableFuture future = new CompletableFuture();
future.cancel(true);
assertThat(future).hasNotFailed();
Assertion will fail :
 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException());
assertThat(future).hasNotFailed();
Returns:SELF

this assertion object.

Annotations
@Deprecated
internalFailsWithinback to summary
private WithThrowable internalFailsWithin(Duration timeout)
internalFailsWithinback to summary
private WithThrowable internalFailsWithin(long timeout, TimeUnit unit)
internalSucceedsWithinback to summary
private ObjectAssert<RESULT> internalSucceedsWithin(Duration timeout)
internalSucceedsWithinback to summary
private ObjectAssert<RESULT> internalSucceedsWithin(long timeout, TimeUnit unit)
isCancelledback to summary
public SELF isCancelled()

Verifies that the CompletableFuture is cancelled.

Assertion will pass :

 CompletableFuture future = new CompletableFuture();
future.cancel(true);
assertThat(future).isCancelled();
Assertion will fail :
 assertThat(new CompletableFuture()).isCancelled();
Returns:SELF

this assertion object.

See Also
CompletableFuture#isCancelled()
isCompletedback to summary
public SELF isCompleted()

Verifies that the CompletableFuture is completed normally (i.e.done but not completed exceptionally) or cancelled.

Assertion will pass :

 assertThat(CompletableFuture.completedFuture("something")).isCompleted();
Assertion will fail :
 assertThat(new CompletableFuture()).isCompleted();
Returns:SELF

this assertion object.

isCompletedExceptionallyback to summary
public SELF isCompletedExceptionally()

Verifies that the CompletableFuture is completed exceptionally.

Possible causes include cancellation, explicit invocation of completeExceptionally, and abrupt termination of a CompletionStage action.

Assertion will pass :

 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException());
assertThat(future).isCompletedExceptionally();
Assertion will fail :
 assertThat(CompletableFuture.completedFuture("something")).isCompletedExceptionally();
Returns:SELF

this assertion object.

See Also
CompletableFuture#isCompletedExceptionally()
isCompletedWithValueback to summary
public SELF isCompletedWithValue(RESULT expected)

Verifies that the CompletableFuture is completed normally with the expected result.

Assertion will pass :

 assertThat(CompletableFuture.completedFuture("something"))
          .isCompletedWithValue("something");
Assertion will fail :
 assertThat(CompletableFuture.completedFuture("something"))
          .isCompletedWithValue("something else");
Parameters
expected:RESULT

the expected result value of the CompletableFuture.

Returns:SELF

this assertion object.

isCompletedWithValueMatchingback to summary
public SELF isCompletedWithValueMatching(Predicate<? super RESULT> predicate)

Verifies that the CompletableFuture is completed normally with a result matching the predicate.

Assertion will pass :

 assertThat(CompletableFuture.completedFuture("something"))
          .isCompletedWithValueMatching(result -> result.equals("something"));
Assertion will fail :
 assertThat(CompletableFuture.completedFuture("something"))
          .isCompletedWithValueMatching(result -> result.equals("something else"));
Parameters
predicate:Predicate<? super RESULT>

the Predicate to apply.

Returns:SELF

this assertion object.

isCompletedWithValueMatchingback to summary
public SELF isCompletedWithValueMatching(Predicate<? super RESULT> predicate, String description)

Verifies that the CompletableFuture is completed normally with a result matching the predicate, the String parameter is used in the error message.

Assertion will pass :

 assertThat(CompletableFuture.completedFuture("something"))
          .isCompletedWithValueMatching(result -> result != null, "expected not null");
Assertion will fail :
 assertThat(CompletableFuture.completedFuture("something"))
          .isCompletedWithValueMatching(result -> result == null, "expected null");
Error message is:
 Expecting:
  <"something">
to match 'expected null' predicate.
Parameters
predicate:Predicate<? super RESULT>

the Predicate to apply on the resulting value.

description:String

the Predicate description.

Returns:SELF

this assertion object.

isCompletedWithValueMatchingback to summary
private SELF isCompletedWithValueMatching(Predicate<? super RESULT> predicate, PredicateDescription description)
isDoneback to summary
public SELF isDone()

Verifies that the CompletableFuture is done i.e. completed normally, exceptionally, or via cancellation.

Assertion will pass :

 assertThat(CompletableFuture.completedFuture("something")).isDone();
Assertion will fail :
 assertThat(new CompletableFuture()).isDone();
Returns:SELF

this assertion object.

See Also
CompletableFuture#isDone()
isNotCancelledback to summary
public SELF isNotCancelled()

Verifies that the CompletableFuture is not cancelled.

Assertion will pass :

 assertThat(new CompletableFuture()).isNotCancelled();
Assertion will fail :
 CompletableFuture future = new CompletableFuture();
future.cancel(true);
assertThat(future).isNotCancelled();
Returns:SELF

this assertion object.

See Also
CompletableFuture#isCancelled()
isNotCompletedback to summary
public SELF isNotCompleted()

Verifies that the CompletableFuture is not completed normally (i.e. incomplete, failed or cancelled).

Assertion will pass :

 assertThat(new CompletableFuture()).isNotCompleted();
Assertion will fail :
 assertThat(CompletableFuture.completedFuture("something")).isNotCompleted();
Returns:SELF

this assertion object.

isNotCompletedExceptionallyback to summary
public SELF isNotCompletedExceptionally()

Verifies that the CompletableFuture is not completed exceptionally.

Assertion will pass :

 assertThat(CompletableFuture.completedFuture("something")).isNotCompletedExceptionally();
Assertion will fail :
 CompletableFuture future = new CompletableFuture();
future.completeExceptionally(new RuntimeException());
assertThat(future).isNotCompletedExceptionally();
Returns:SELF

this assertion object.

See Also
CompletableFuture#isCompletedExceptionally()
isNotDoneback to summary
public SELF isNotDone()

Verifies that the CompletableFuture is not done.

Assertion will pass :

 assertThat(new CompletableFuture()).isNotDone();
Assertion will fail :
 assertThat(CompletableFuture.completedFuture("something")).isNotDone();
Returns:SELF

this assertion object.

See Also
CompletableFuture#isDone()
newObjectAssertback to summary
protected ObjectAssert<RESULT> newObjectAssert(RESULT objectUnderTest)
succeedsWithinback to summary
public ObjectAssert<RESULT> succeedsWithin(Duration timeout)

Waits if necessary for at most the given time for this future to complete, and then returns its result for further assertions.

If the future's result is not available for any reason an assertion error is thrown.

To get assertions for the future result's type use succeedsWithin(Duration, InstanceOfAssertFactory) instead.

Examples:

 CompletableFuture<String> future = CompletableFuture.completedFuture("ook!");
Duration timeout = Duration.ofMillis(100);

// assertion succeeds
assertThat(future).succeedsWithin(timeout)
                  .isEqualTo("ook!");

// fails assuming the future is not done after the given timeout
CompletableFuture<String> future = ... ; // future too long to complete
assertThat(future).succeedsWithin(timeout);

// fails as the future is cancelled
CompletableFuture future = new CompletableFuture();
future.cancel(false);
assertThat(future).succeedsWithin(timeout);
Parameters
timeout:Duration

the maximum time to wait

Returns:ObjectAssert<RESULT>

a new assertion object on the future's result.

Exceptions
AssertionError:
  • if the actual CompletableFuture is null.
  • if the actual CompletableFuture does not succeed within the given timeout.
succeedsWithinback to summary
public ObjectAssert<RESULT> succeedsWithin(long timeout, TimeUnit unit)

Waits if necessary for at most the given time for this future to complete, and then returns its result for further assertions.

If the future's result is not available for any reason an assertion error is thrown.

To get assertions for the future result's type use succeedsWithin(long, TimeUnit, InstanceOfAssertFactory) instead.

Examples:

 CompletableFuture<String> future = CompletableFuture.completedFuture("ook!");

// assertion succeeds
assertThat(future).succeedsWithin(100, TimeUnit.MILLISECONDS)
                  .isEqualTo("ook!");

// fails assuming the future is not done after the given timeout
CompletableFuture<String> future = ... ; // future too long to complete
assertThat(future).succeedsWithin(100, TimeUnit.MILLISECONDS);

// fails as the future is cancelled
CompletableFuture future = new CompletableFuture();
future.cancel(false);
assertThat(future).succeedsWithin(100, TimeUnit.MILLISECONDS);
Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:ObjectAssert<RESULT>

a new assertion object on the future's result.

Exceptions
AssertionError:
  • if the actual CompletableFuture is null.
  • if the actual CompletableFuture does not succeed within the given timeout.
succeedsWithinback to summary
public <ASSERT extends AbstractAssert<?, ?>> ASSERT succeedsWithin(Duration timeout, InstanceOfAssertFactory<RESULT, ASSERT> assertFactory)

Waits if necessary for at most the given time for this future to complete, the InstanceOfAssertFactory parameter is used to return assertions specific to the future's result type.

If the future's result is not available for any reason an assertion error is thrown.

Examples:

 CompletableFuture<String> future = CompletableFuture.completedFuture("ook!");
Duration timeout = Duration.ofMillis(100);

// assertion succeeds
// using asInstanceOf is recommended to get assertions for the future result's type
assertThat(future).succeedsWithin(timeout, InstanceOfAssertFactories.STRING)
                  .contains("ok");

// assertion fails if the narrowed type for assertions is incompatible with the future's result type.
assertThat(future).succeedsWithin(timeout, InstanceOfAssertFactories.DATE)
                  .isToday();
Parameters
<ASSERT>
the type of the resulting Assert
timeout:Duration

the maximum time to wait

assertFactory:InstanceOfAssertFactory<RESULT, ASSERT>

the factory which verifies the type and creates the new Assert

Returns:ASSERT

a new narrowed Assert instance for assertions chaining on the value of the CompletableFuture

Exceptions
AssertionError:
if the actual CompletableFuture is null.
IllegalStateException:
if the actual CompletableFuture does not succeed within the given timeout.
succeedsWithinback to summary
public <ASSERT extends AbstractAssert<?, ?>> ASSERT succeedsWithin(long timeout, TimeUnit unit, InstanceOfAssertFactory<RESULT, ASSERT> assertFactory)

Waits if necessary for at most the given time for this future to complete, the InstanceOfAssertFactory parameter is used to return assertions specific to the future's result type.

If the future's result is not available for any reason an assertion error is thrown.

Examples:

 CompletableFuture<String> future = CompletableFuture.completedFuture("ook!");

// assertion succeeds
// using asInstanceOf is recommended to get assertions for the future result's type
assertThat(future).succeedsWithin(100, TimeUnit.MILLISECONDS, InstanceOfAssertFactories.STRING)
                  .contains("ok");

// assertion  fails if the narrowed type for assertions is incompatible with the future's result type.
assertThat(future).succeedsWithin(100, TimeUnit.MILLISECONDS, InstanceOfAssertFactories.DATE)
                  .isToday();
Parameters
<ASSERT>
the type of the resulting Assert
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

assertFactory:InstanceOfAssertFactory<RESULT, ASSERT>

the factory which verifies the type and creates the new Assert

Returns:ASSERT

a new narrowed Assert instance for assertions chaining on the value of the CompletableFuture

Exceptions
AssertionError:
  • if the actual CompletableFuture is null.
  • if the actual CompletableFuture does not succeed within the given timeout.