Class VertxTestContext
java.lang.Object
io.vertx.junit5.VertxTestContext
A test context to wait on the outcomes of asynchronous operations.
- Author:
- Julien Ponge
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for an executable block of assertion code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Future<T> assertComplete(Future<T> fut) This method allows you to check if a future is completed.<T> Future<T> assertFailure(Future<T> fut) This method allows you to check if a future is failed.booleanawaitCompletion(long timeout, TimeUnit unit) Wait for the completion of the test context.Give the cause of failure.Create a strict checkpoint.checkpoint(int requiredNumberOfPasses) Deprecated.booleanCheck if the context has completed.voidComplete the test context immediately, making the corresponding test pass.<T> Handler<AsyncResult<T>> Deprecated.UsesucceedingThenComplete()instead.booleanfailed()Check if the context has been marked has failed or not.<T> Handler<AsyncResult<T>> failing()Deprecated.UsefailingThenComplete()orfailing(Handler), for examplefailing(e -> checkpoint.flag()),failing(e -> { more testing code }), orfailing(e -> {}).<T> Handler<AsyncResult<T>> Create an asynchronous result handler that expects a failure, and passes the exception to another handler.<T> Handler<AsyncResult<T>> Create an asynchronous result handler that expects a failure to then complete the test context.voidCallsfailNow(Throwable)with themessage.voidMake the test context fail immediately, making the corresponding test fail.Create a lax checkpoint.laxCheckpoint(int requiredNumberOfPasses) Deprecated.instead create a regular checkpoint and useCheckpoint.asLatch(int)to create a latch succeeding this checkpoint<T> Handler<AsyncResult<T>> succeeding(Handler<T> nextHandler) Create an asynchronous result handler that expects a success, and passes the value to another handler.<T> Handler<AsyncResult<T>> Create an asynchronous result handler that expects a success to then complete the test context.Gives the call sites of all unsatisfied checkpoints.Allow verifications and assertions to be made.
-
Constructor Details
-
VertxTestContext
public VertxTestContext()
-
-
Method Details
-
failed
public boolean failed()Check if the context has been marked has failed or not.- Returns:
trueif the context has failed,falseotherwise.
-
causeOfFailure
Give the cause of failure.- Returns:
- the cause of failure, or
nullif the test context hasn't failed.
-
completed
public boolean completed()Check if the context has completed.- Returns:
trueif the context has completed,falseotherwise.
-
unsatisfiedCheckpointCallSites
Gives the call sites of all unsatisfied checkpoints.- Returns:
- a set of
StackTraceElementreferences pointing to the unsatisfied checkpoint call sites.
-
completeNow
public void completeNow()Complete the test context immediately, making the corresponding test pass. -
failNow
Make the test context fail immediately, making the corresponding test fail.- Parameters:
t- the cause of failure.
-
failNow
CallsfailNow(Throwable)with themessage.- Parameters:
message- the cause of failure
-
laxCheckpoint
Create a lax checkpoint.- Returns:
- a checkpoint that requires 1 pass; more passes are allowed and ignored.
-
laxCheckpoint
Deprecated.instead create a regular checkpoint and useCheckpoint.asLatch(int)to create a latch succeeding this checkpointCreate a lax checkpoint.- Parameters:
requiredNumberOfPasses- the required number of passes to validate the checkpoint.- Returns:
- a checkpoint that requires several passes; more passes than the required number are allowed and ignored.
-
checkpoint
Create a strict checkpoint.- Returns:
- a checkpoint that requires 1 pass, and makes the context fail if it is called more than once.
-
checkpoint
Deprecated.instead create a regular checkpoint and useCheckpoint.asLatch(int)to create a latch succeeding this checkpointCreate a strict checkpoint.- Parameters:
requiredNumberOfPasses- the required number of passes to validate the checkpoint.- Returns:
- a checkpoint that requires several passes, but no more, or it fails the context.
-
succeeding
Create an asynchronous result handler that expects a success, and passes the value to another handler.- Type Parameters:
T- the asynchronous result type.- Parameters:
nextHandler- the value handler to call on success that is expected not to throw aThrowable.- Returns:
- the handler.
-
failing
Deprecated.UsefailingThenComplete()orfailing(Handler), for examplefailing(e -> checkpoint.flag()),failing(e -> { more testing code }), orfailing(e -> {}).Create an asynchronous result handler that expects a failure.- Type Parameters:
T- the asynchronous result type.- Returns:
- the handler.
-
failing
Create an asynchronous result handler that expects a failure, and passes the exception to another handler.- Type Parameters:
T- the asynchronous result type.- Parameters:
nextHandler- the exception handler to call on failure that is expected not to throw aThrowable.- Returns:
- the handler.
-
succeedingThenComplete
Create an asynchronous result handler that expects a success to then complete the test context.- Type Parameters:
T- the asynchronous result type.- Returns:
- the handler.
-
completing
Deprecated.UsesucceedingThenComplete()instead.Create an asynchronous result handler that expects a success to then complete the test context.- Type Parameters:
T- the asynchronous result type.- Returns:
- the handler.
- See Also:
-
failingThenComplete
Create an asynchronous result handler that expects a failure to then complete the test context.- Type Parameters:
T- the asynchronous result type.- Returns:
- the handler.
-
assertComplete
-
assertFailure
-
verify
Allow verifications and assertions to be made.This method allows any assertion API to be used. The semantic is that the verification is successful when no exception is being thrown upon calling
block, otherwise the context fails with that exception.- Parameters:
block- a block of code to execute.- Returns:
- this context.
-
awaitCompletion
Wait for the completion of the test context.This method is automatically called by the
VertxExtensionwhen using parameter injection ofVertxTestContext. You should only call it when you instantiate this class manually.- Parameters:
timeout- the timeout.unit- the timeout unit.- Returns:
trueif the completion or failure happens before the timeout has been reached,falseotherwise.- Throws:
InterruptedException- when the thread has been interrupted.
-
Checkpoint.asLatch(int)to create a latch succeeding this checkpoint