Transforms a future of any type into a Future[T]
, where T
is a given
expected exception type, which succeeds if the given future
completes with a Failure
containing the specified exception type.
Transforms a future of any type into a Future[T]
, where T
is a given
expected exception type, which succeeds if the given future
completes with a Failure
containing the specified exception type.
See the main documentation for this trait for more detail and examples.
A future of any type, which you expect to fail with an exception of the specified type T
a Future[T] containing on success the expected exception, or containing on failure
a TestFailedException
Transforms a future of any type into a Future[Assertion]
that succeeds if the future
completes with a Failure
containing the specified exception type.
Transforms a future of any type into a Future[Assertion]
that succeeds if the future
completes with a Failure
containing the specified exception type.
See the main documentation for this trait for more detail and examples.
A future of any type, which you expect to fail with an exception of the specified type T
a Future[Assertion] containing on success the Succeeded
singleton, or containing on failure
a TestFailedException
Offers two methods for transforming futures when exceptions are expected.
This trait offers two methods for testing for expected exceptions in the context of futures:
recoverToSucceededIf
andrecoverToExceptionIf
. Because this trait is mixed into traitAsyncTestSuite
, both of its methods are available by default in any async-style suite.If you just want to ensure that a future fails with a particular exception type, and do not need to inspect the exception further, use
recoverToSucceededIf
:The
recoverToSucceededIf
method performs a job similar toassertThrows
, except in the context of a future. It transforms aFuture
of any type into aFuture[Assertion]
that succeeds only if the original future fails with the specified exception. Here's an example in the REPL:Otherwise it fails with an error message similar to those given by
assertThrows
:The
recoverToExceptionIf
method differs from therecoverToSucceededIf
in its behavior when the assertion succeeds:recoverToSucceededIf
yields aFuture[Assertion]
, whereasrecoverToExceptionIf
yields aFuture[T]
, whereT
is the expected exception type.In other words,
recoverToExpectionIf
is tointercept
asrecovertToSucceededIf
is toassertThrows
. The first one allows you to perform further assertions on the expected exception. The second one gives you a result type that will satisfy the type checker at the end of the test body. Here's an example showingrecoverToExceptionIf
in the REPL: