Synesso
Synesso

Reputation: 39018

Spec not failing on Mockito Matchers.any[FooException] matcher

In my spec, I expect the mock invocation msg.ctx.failWith(any[TimeoutException]).

Because failWith takes a Throwable, the type of the exception is not checked - even at runtime.

This nonsense passes:

there was one(msg.ctx).failWith(Matchers.any[ArrayIndexOfOutBoundsException])

Can I assert that the correct type of exception is passed?

I'm using Specs 2.3.13 (because it is a dependency of akka-test-kit)

Upvotes: 0

Views: 138

Answers (1)

Eric
Eric

Reputation: 15557

This is not pretty but it works:

there was one(m).failWith(beLike[Throwable] { case _: TimeoutException => ok })

Upvotes: 2

Related Questions