RESULT
- type of the value contained in the CompletableFuture
.public abstract class AbstractCompletableFutureAssert<SELF extends AbstractCompletableFutureAssert<SELF,RESULT>,RESULT> extends AbstractAssert<SELF,CompletableFuture<RESULT>>
CompletableFuture
.actual, info, myself, throwUnsupportedExceptionOnEquals
Modifier | Constructor and Description |
---|---|
protected |
AbstractCompletableFutureAssert(CompletableFuture<RESULT> actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
SELF |
hasFailed()
Verifies that the
CompletableFuture has completed exceptionally but has not been cancelled,
this assertion is equivalent to: |
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. |
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. |
SELF |
isCancelled()
Verifies that the
CompletableFuture is cancelled. |
SELF |
isCompleted()
Verifies that the
CompletableFuture is completed normally (i.e.done
but not completed exceptionally ). |
SELF |
isCompletedExceptionally()
Verifies that the
CompletableFuture is completed exceptionally. |
SELF |
isCompletedWithValue(RESULT expected)
Verifies that the
CompletableFuture is completed normally with the expected result. |
SELF |
isCompletedWithValueMatching(Predicate<? super RESULT> predicate)
Verifies that the
CompletableFuture is completed normally with a result matching the predicate . |
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. |
SELF |
isDone()
Verifies that the
CompletableFuture is done i.e. |
SELF |
isNotCancelled()
Verifies that the
CompletableFuture is not cancelled. |
SELF |
isNotCompleted()
Verifies that the
CompletableFuture is not completed normally (i.e. |
SELF |
isNotCompletedExceptionally()
Verifies that the
CompletableFuture is not completed exceptionally. |
SELF |
isNotDone()
Verifies that the
CompletableFuture is not done. |
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, 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, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
protected AbstractCompletableFutureAssert(CompletableFuture<RESULT> actual, Class<?> selfType)
public SELF isDone()
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();
CompletableFuture.isDone()
public SELF isNotDone()
CompletableFuture
is not done.
Assertion will pass :
assertThat(new CompletableFuture()).isNotDone();
Assertion will fail :
assertThat(CompletableFuture.completedFuture("something")).isNotDone();
CompletableFuture.isDone()
public SELF isCompletedExceptionally()
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();
CompletableFuture.isCompletedExceptionally()
public SELF isNotCompletedExceptionally()
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();
CompletableFuture.isCompletedExceptionally()
public SELF isCancelled()
CompletableFuture
is cancelled.
Assertion will pass :
CompletableFuture future = new CompletableFuture();
future.cancel(true);
assertThat(future).isCancelled();
Assertion will fail :
assertThat(new CompletableFuture()).isCancelled();
CompletableFuture.isCancelled()
public SELF isNotCancelled()
CompletableFuture
is not cancelled.
Assertion will pass :
assertThat(new CompletableFuture()).isNotCancelled();
Assertion will fail :
CompletableFuture future = new CompletableFuture();
future.cancel(true);
assertThat(future).isNotCancelled();
CompletableFuture.isCancelled()
public SELF isCompleted()
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();
public SELF isNotCompleted()
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();
public SELF isCompletedWithValue(RESULT expected)
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");
expected
- the expected result value of the CompletableFuture
.public SELF isCompletedWithValueMatching(Predicate<? super RESULT> predicate)
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"));
predicate
- the Predicate
to apply.public SELF isCompletedWithValueMatching(Predicate<? super RESULT> predicate, String description)
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.
public SELF hasFailed()
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();
public SELF hasNotFailed()
CompletableFuture
has not failed i.e: incomplete, completed or cancelled.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();
public AbstractThrowableAssert<?,? extends Throwable> hasFailedWithThrowableThat()
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);
Copyright © 2014–2019 AssertJ. All rights reserved.