Mockito argument matchers and Scala
Attempting to use Mockito argument matchers in your Scala tests and getting a frustrating
Invalid use of argument matchers!
for no obvious reason?
Check that the function you're matching arguments on doesn't have any default values! All arguments need to be matchers, even if the values are provided by defaults:
def doCoolStuff(thing: Thing, message: String = "") = { ... }
Then the following will throw an InvalidUseOfMatchersException:
when(mock.doCoolStuff(eq(myThing)).thenReturn(anAwesomeResult)
But using a matcher for the defaulted parameters will work:
when(mock.doCoolStuff(eq(myThing),any[String])).thenReturn(anAwesomeResult)
Written by Jim Kinsey
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Scala
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#