Mockito Matches any card

How can I use any card in mockito? I have tried with the 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.

      

Only works when I put any(String.class)

:

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

      

But I want to be able to put actual values ​​instead of any string

+3


source to share


1 answer


You cannot mix matches and mismatches. "1"

Use instead Matchers.eq("1")

. This creates a match that matches any string equal to "1" that suits your needs (equal to "1") and Mockito (both arguments are collations).



+8


source







All Articles