T
- type of the value contained in the CompletableFuture
.public abstract class AbstractCompletableFutureAssert<S extends AbstractCompletableFutureAssert<S,T>,T> extends AbstractAssert<S,CompletableFuture<T>>
CompletableFuture
.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
AbstractCompletableFutureAssert(CompletableFuture<T> actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
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 allowng to check the Throwable that has caused the future to fail. |
S |
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. |
S |
isCancelled()
Verifies that the
CompletableFuture is cancelled. |
S |
isCompleted()
Verifies that the
CompletableFuture is completed normally (i.e.done
but not completed exceptionally ). |
S |
isCompletedExceptionally()
Verifies that the
CompletableFuture is completed exceptionally. |
S |
isCompletedWithValue(T expected)
Verifies that the
CompletableFuture is completed normally with the expected result. |
S |
isCompletedWithValueMatching(Predicate<? super T> predicate)
Verifies that the
CompletableFuture is completed normally with a result matching the predicate . |
S |
isCompletedWithValueMatching(Predicate<? super T> 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. |
S |
isDone()
Verifies that the
CompletableFuture is done i.e. |
S |
isNotCancelled()
Verifies that the
CompletableFuture is not cancelled. |
S |
isNotCompleted()
Verifies that the
CompletableFuture is not completed normally (i.e. |
S |
isNotCompletedExceptionally()
Verifies that the
CompletableFuture is not completed exceptionally. |
S |
isNotDone()
Verifies that the
CompletableFuture is not done. |
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
protected AbstractCompletableFutureAssert(CompletableFuture<T> actual, Class<?> selfType)
public S 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 S isNotDone()
CompletableFuture
is not done.
Assertion will pass :
assertThat(new CompletableFuture()).isNotDone();
Assertion will fail :
assertThat(CompletableFuture.completedFuture("something")).isNotDone();
CompletableFuture.isDone()
public S 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 exceptionnaly 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 S 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 S 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 S 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 S 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 S 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 S isCompletedWithValue(T 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");
public S isCompletedWithValueMatching(Predicate<? super T> 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"));
public S isCompletedWithValueMatching(Predicate<? super T> 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 S 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 S 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 allowng 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–2016 AssertJ. All rights reserved.