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

java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,CompletableFuture<RESULT>>
org.assertj.core.api.AbstractCompletableFutureAssert<SELF,RESULT>
Type Parameters:
RESULT - type of the value contained in the CompletableFuture.
All Implemented Interfaces:
Assert<SELF,CompletableFuture<RESULT>>, Descriptable<SELF>, ExtensionPoints<SELF,CompletableFuture<RESULT>>
Direct Known Subclasses:
CompletableFutureAssert

public abstract class AbstractCompletableFutureAssert<SELF extends AbstractCompletableFutureAssert<SELF,RESULT>,RESULT> extends AbstractAssert<SELF,CompletableFuture<RESULT>>
Assertions for CompletableFuture.
  • Constructor Details

  • Method Details

    • isDone

      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:
      this assertion object.
      See Also:
    • isNotDone

      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:
      this assertion object.
      See Also:
    • isCompletedExceptionally

      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.

      If you only want to check that actual future is completed exceptionally but not cancelled, use hasFailed() or hasFailedWithThrowableThat().

      Assertion will pass :

       CompletableFuture future = new CompletableFuture();
       future.completeExceptionally(new RuntimeException());
       assertThat(future).isCompletedExceptionally();
      Assertion will fail :
       assertThat(CompletableFuture.completedFuture("something")).isCompletedExceptionally();
      Returns:
      this assertion object.
      See Also:
    • isNotCompletedExceptionally

      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:
      this assertion object.
      See Also:
    • isCancelled

      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:
      this assertion object.
      See Also:
    • isNotCancelled

      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:
      this assertion object.
      See Also:
    • isCompleted

      public SELF isCompleted()
      Verifies that the CompletableFuture is completed normally (i.e.done but not completed exceptionally).

      Assertion will pass :

       assertThat(CompletableFuture.completedFuture("something")).isCompleted();
      Assertion will fail :
       assertThat(new CompletableFuture()).isCompleted();
      Returns:
      this assertion object.
    • isNotCompleted

      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:
      this assertion object.
    • isCompletedWithValue

      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");
      Returns:
      this assertion object.
    • isCompletedWithValueMatching

      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"));
      Returns:
      this assertion object.
    • isCompletedWithValueMatching

      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:
         invalid input: '<'"something">
       to match 'expected null' predicate.
      Returns:
      this assertion object.
    • isCompletedWithValueMatching

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

      public SELF hasFailed()
      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:
      this assertion object.
    • hasNotFailed

      public SELF hasNotFailed()
      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:
      this assertion object.
    • hasFailedWithThrowableThat

      public AbstractThrowableAssert<?,? extends Throwable> hasFailedWithThrowableThat()
      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:
      an exception assertion object.