I ran into a well-known InvalidUseOfMatchersException even though I was using all matchers.

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
3 matchers expected, 2 recorded:
-> at com.spotify.adaccountservice.utils.RoleUtilsTest.test_addOrRemoveRole_AddUserToAdAccount(RoleUtilsTest.java:179)
-> at com.spotify.adaccountservice.utils.RoleUtilsTest.test_addOrRemoveRole_AddUserToAdAccount(RoleUtilsTest.java:180)

I know we don't like screenshots of code here, but I want to convince that it's indeed happening at these line numbers:

enter image description here

And here's the actual method:

enter image description here

So it was kind of strange. Why is it expecting 3 matchers, when the method has 4 parameters? And why is it only "recording" 2 of them, when I'm using eq() for all of them?

Self-answering, as the error misdirected me. (Or, maybe someone can explain why it was actually accurate.)

1

There are 1 best solutions below

0
On BEST ANSWER

Turns out it was because one of the variables in my 3rd argument, portcullisUtils, was a mock object that I forgot to stub for getAdAccountRoleId(...).

I suppose the program can't really tell that of course I didn't mean to match against such an abstraction, and did something weird.

Will accept whoever's answer can explain why these particular error messages.