Class VertxTestContext

java.lang.Object
io.vertx.junit5.VertxTestContext

public final class VertxTestContext extends Object
A test context to wait on the outcomes of asynchronous operations.
Author:
Julien Ponge
  • Constructor Details

    • VertxTestContext

      public VertxTestContext()
  • Method Details

    • failed

      public boolean failed()
      Check if the context has been marked has failed or not.
      Returns:
      true if the context has failed, false otherwise.
    • causeOfFailure

      public Throwable causeOfFailure()
      Give the cause of failure.
      Returns:
      the cause of failure, or null if the test context hasn't failed.
    • completed

      public boolean completed()
      Check if the context has completed.
      Returns:
      true if the context has completed, false otherwise.
    • unsatisfiedCheckpointCallSites

      public Set<StackTraceElement> unsatisfiedCheckpointCallSites()
      Gives the call sites of all unsatisfied checkpoints.
      Returns:
      a set of StackTraceElement references pointing to the unsatisfied checkpoint call sites.
    • completeNow

      public void completeNow()
      Complete the test context immediately, making the corresponding test pass.
    • failNow

      public void failNow(Throwable t)
      Make the test context fail immediately, making the corresponding test fail.
      Parameters:
      t - the cause of failure.
    • failNow

      public void failNow(String message)
      Calls failNow(Throwable) with the message.
      Parameters:
      message - the cause of failure
    • laxCheckpoint

      public Checkpoint laxCheckpoint()
      Create a lax checkpoint.
      Returns:
      a checkpoint that requires 1 pass; more passes are allowed and ignored.
    • laxCheckpoint

      @Deprecated public Checkpoint laxCheckpoint(int requiredNumberOfPasses)
      Deprecated.
      instead create a regular checkpoint and use Checkpoint.asLatch(int) to create a latch succeeding this checkpoint
      Create 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

      public Checkpoint 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 public Checkpoint checkpoint(int requiredNumberOfPasses)
      Deprecated.
      instead create a regular checkpoint and use Checkpoint.asLatch(int) to create a latch succeeding this checkpoint
      Create 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

      public <T> Handler<AsyncResult<T>> succeeding(Handler<T> nextHandler)
      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 a Throwable.
      Returns:
      the handler.
    • failing

      @Deprecated public <T> Handler<AsyncResult<T>> failing()
      Deprecated.
      Use failingThenComplete() or failing(Handler), for example failing(e -> checkpoint.flag()), failing(e -> { more testing code }), or failing(e -> {}).
      Create an asynchronous result handler that expects a failure.
      Type Parameters:
      T - the asynchronous result type.
      Returns:
      the handler.
    • failing

      public <T> Handler<AsyncResult<T>> failing(Handler<Throwable> nextHandler)
      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 a Throwable.
      Returns:
      the handler.
    • succeedingThenComplete

      public <T> Handler<AsyncResult<T>> 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 public <T> Handler<AsyncResult<T>> completing()
      Deprecated.
      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

      public <T> Handler<AsyncResult<T>> 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

      public <T> Future<T> assertComplete(Future<T> fut)
      This method allows you to check if a future is completed. It internally creates a checkpoint. You can use it in a chain of `Future`.
      Parameters:
      fut - The future to assert success
      Returns:
      a future with completion result
    • assertFailure

      public <T> Future<T> assertFailure(Future<T> fut)
      This method allows you to check if a future is failed. It internally creates a checkpoint. You can use it in a chain of `Future`.
      Parameters:
      fut - The future to assert failure
      Returns:
      a future with failure result
    • 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

      public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException
      Wait for the completion of the test context.

      This method is automatically called by the VertxExtension when using parameter injection of VertxTestContext. You should only call it when you instantiate this class manually.

      Parameters:
      timeout - the timeout.
      unit - the timeout unit.
      Returns:
      true if the completion or failure happens before the timeout has been reached, false otherwise.
      Throws:
      InterruptedException - when the thread has been interrupted.