Package org.assertj.core.api
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 theCompletableFuture
.
- 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
.-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, conditions, info, myself, objects
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractCompletableFutureAssert
(CompletableFuture<RESULT> actual, Class<?> selfType) -
Method Summary
Modifier and TypeMethodDescriptionVerifies that theCompletableFuture
has completed exceptionally but has not been cancelled, this assertion is equivalent to:AbstractThrowableAssert<?,
? extends Throwable> Verifies that theCompletableFuture
has completed exceptionally and returns a Throwable assertion object allowing to check the Throwable that has caused the future to fail.Verifies that theCompletableFuture
has not failed i.e: incomplete, completed or cancelled.
This is different fromisNotCompletedExceptionally()
as a cancelled future has not failed but is completed exceptionally.Verifies that theCompletableFuture
is cancelled.Verifies that theCompletableFuture
is completed normally (i.e.done
but notcompleted exceptionally
).Verifies that theCompletableFuture
is completed exceptionally.isCompletedWithValue
(RESULT expected) Verifies that theCompletableFuture
is completed normally with theexpected
result.isCompletedWithValueMatching
(Predicate<? super RESULT> predicate) Verifies that theCompletableFuture
is completed normally with a result matching thepredicate
.isCompletedWithValueMatching
(Predicate<? super RESULT> predicate, String description) Verifies that theCompletableFuture
is completed normally with a result matching thepredicate
, the String parameter is used in the error message.private SELF
isCompletedWithValueMatching
(Predicate<? super RESULT> predicate, PredicateDescription description) isDone()
Verifies that theCompletableFuture
is done i.e.Verifies that theCompletableFuture
is not cancelled.Verifies that theCompletableFuture
is not completed normally (i.e.Verifies that theCompletableFuture
is not completed exceptionally.Verifies that theCompletableFuture
is not done.Methods inherited from class org.assertj.core.api.AbstractAssert
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, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
-
Constructor Details
-
AbstractCompletableFutureAssert
-
-
Method Details
-
isDone
Verifies that theCompletableFuture
is done i.e. completed normally, exceptionally, or via cancellation.Assertion will pass :
Assertion will fail :assertThat(CompletableFuture.completedFuture("something")).isDone();
assertThat(new CompletableFuture()).isDone();
- Returns:
- this assertion object.
- See Also:
-
isNotDone
Verifies that theCompletableFuture
is not done.Assertion will pass :
Assertion will fail :assertThat(new CompletableFuture()).isNotDone();
assertThat(CompletableFuture.completedFuture("something")).isNotDone();
- Returns:
- this assertion object.
- See Also:
-
isCompletedExceptionally
Verifies that theCompletableFuture
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()
orhasFailedWithThrowableThat()
.Assertion will pass :
Assertion will fail :CompletableFuture future = new CompletableFuture(); future.completeExceptionally(new RuntimeException()); assertThat(future).isCompletedExceptionally();
assertThat(CompletableFuture.completedFuture("something")).isCompletedExceptionally();
- Returns:
- this assertion object.
- See Also:
-
isNotCompletedExceptionally
Verifies that theCompletableFuture
is not completed exceptionally.Assertion will pass :
Assertion will fail :assertThat(CompletableFuture.completedFuture("something")).isNotCompletedExceptionally();
CompletableFuture future = new CompletableFuture(); future.completeExceptionally(new RuntimeException()); assertThat(future).isNotCompletedExceptionally();
- Returns:
- this assertion object.
- See Also:
-
isCancelled
Verifies that theCompletableFuture
is cancelled.Assertion will pass :
Assertion will fail :CompletableFuture future = new CompletableFuture(); future.cancel(true); assertThat(future).isCancelled();
assertThat(new CompletableFuture()).isCancelled();
- Returns:
- this assertion object.
- See Also:
-
isNotCancelled
Verifies that theCompletableFuture
is not cancelled.Assertion will pass :
Assertion will fail :assertThat(new CompletableFuture()).isNotCancelled();
CompletableFuture future = new CompletableFuture(); future.cancel(true); assertThat(future).isNotCancelled();
- Returns:
- this assertion object.
- See Also:
-
isCompleted
Verifies that theCompletableFuture
is completed normally (i.e.done
but notcompleted exceptionally
).Assertion will pass :
Assertion will fail :assertThat(CompletableFuture.completedFuture("something")).isCompleted();
assertThat(new CompletableFuture()).isCompleted();
- Returns:
- this assertion object.
-
isNotCompleted
Verifies that theCompletableFuture
is not completed normally (i.e. incomplete, failed or cancelled).Assertion will pass :
Assertion will fail :assertThat(new CompletableFuture()).isNotCompleted();
assertThat(CompletableFuture.completedFuture("something")).isNotCompleted();
- Returns:
- this assertion object.
-
isCompletedWithValue
Verifies that theCompletableFuture
is completed normally with theexpected
result.Assertion will pass :
Assertion will fail :assertThat(CompletableFuture.completedFuture("something")) .isCompletedWithValue("something");
assertThat(CompletableFuture.completedFuture("something")) .isCompletedWithValue("something else");
- Returns:
- this assertion object.
-
isCompletedWithValueMatching
Verifies that theCompletableFuture
is completed normally with a result matching thepredicate
.Assertion will pass :
Assertion will fail :assertThat(CompletableFuture.completedFuture("something")) .isCompletedWithValueMatching(result -> result.equals("something"));
assertThat(CompletableFuture.completedFuture("something")) .isCompletedWithValueMatching(result -> result.equals("something else"));
- Returns:
- this assertion object.
-
isCompletedWithValueMatching
Verifies that theCompletableFuture
is completed normally with a result matching thepredicate
, the String parameter is used in the error message.Assertion will pass :
Assertion will fail :assertThat(CompletableFuture.completedFuture("something")) .isCompletedWithValueMatching(result -> result != null, "expected not null");
Error message is:assertThat(CompletableFuture.completedFuture("something")) .isCompletedWithValueMatching(result -> result == null, "expected null");
Expecting: <"something"> to match 'expected null' predicate.
- Returns:
- this assertion object.
-
isCompletedWithValueMatching
private SELF isCompletedWithValueMatching(Predicate<? super RESULT> predicate, PredicateDescription description) -
hasFailed
Verifies that theCompletableFuture
has completed exceptionally but has not been cancelled, this assertion is equivalent to:assertThat(future).isCompletedExceptionally() .isNotCancelled();
Assertion will pass :
Assertion will fail :CompletableFuture future = new CompletableFuture(); future.completeExceptionally(new RuntimeException()); assertThat(future).hasFailed();
CompletableFuture future = new CompletableFuture(); future.cancel(true); assertThat(future).hasFailed();
- Returns:
- this assertion object.
-
hasNotFailed
Verifies that theCompletableFuture
has not failed i.e: incomplete, completed or cancelled.
This is different fromisNotCompletedExceptionally()
as a cancelled future has not failed but is completed exceptionally.Assertion will pass :
Assertion will fail :CompletableFuture future = new CompletableFuture(); future.cancel(true); assertThat(future).hasNotFailed();
CompletableFuture future = new CompletableFuture(); future.completeExceptionally(new RuntimeException()); assertThat(future).hasNotFailed();
- Returns:
- this assertion object.
-
hasFailedWithThrowableThat
Verifies that theCompletableFuture
has completed exceptionally and returns a Throwable assertion object allowing to check the Throwable that has caused the future to fail.Assertion will pass :
Assertion will fail :CompletableFuture future = new CompletableFuture(); future.completeExceptionally(new RuntimeException("boom!")); assertThat(future).hasFailedWithThrowableThat().isInstanceOf(RuntimeException.class); .hasMessage("boom!");
CompletableFuture future = new CompletableFuture(); future.completeExceptionally(new RuntimeException()); assertThat(future).hasFailedWithThrowableThat().isInstanceOf(IllegalArgumentException.class);
- Returns:
- an exception assertion object.
-