XXLUser
XXLUser

Reputation: 173

Mockito Matchers any Map

How can I use any map in mockito? I tried with following codes

when(mockedService.patch("1", Matchers.<Map<String, Object>>any())).thenReturn(object);

and with:

when(mockedService.patch("1", anyMap())).thenReturn(object);

But it returns:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
2 matchers expected, 1 recorded.

It works only when I put any(String.class):

when(mockedService.patch(any(String.class), Matchers.<Map<String, Object>>any())).thenReturn(object);

But I want to have option of puting actual values instead of any String

Upvotes: 3

Views: 13457

Answers (1)

yshavit
yshavit

Reputation: 43391

You can't mix matchers and non-matchers. Instead of "1", use Matchers.eq("1"). This creates a matcher that matches any string equal to "1", which satisfies both your needs (equal to "1") and Mockito's (both arguments are matchers).

Upvotes: 9

Related Questions