I have two custom ArgumentMatchers and I'd like my mock to return a different value based on the argument value.
Example:
when(myMock.method(new ArgMatcher1()).thenReturn(false);
when(myMock.method(new ArgMatcher2()).thenReturn(true);
Unfortunately, the second call to when() results in an exception. This makes sense to me because, if the argument matches both ArgumentMatchers, Mockito wouldn't know whether to return true or false. Is there a way to do this in Mockito? It could even be something like:
when(myMock.method(new ArgMatcher2()).thenReturn(false).elseReturn(true);
I'm not sure how your matchers are coded, but having two different matchers is supported of course, maybe the method you are stubbing is not mockable via Mockito (final).
Also for the record it is possible to tell the stub to return different return values in different ways :