Corner case:
If you're using Scala and you try to create an any
matcher on a value class, you'll get an unhelpful NPE.
So given case class ValueClass(value: Int) extends AnyVal
, what you want to do is ValueClass(anyInt)
instead of any[ValueClass]
when(mock.someMethod(ValueClass(anyInt))).thenAnswer {
...
val v = ValueClass(invocation.getArguments()(0).asInstanceOf[Int])
...
}
This other SO question is more specifically about that, but you'd miss it when you don't know the issue is with value classes.