ArgumentMatcher
Match arguments passed in a method of your mock
// example statement
final int addition = calculator.getAddition(2, 3);
// you have to match exact parameters, in this case (2,3)
Mockito.when(mckCalculator.getAddition(2, 3)).thenReturn(5);
// If you mock for (3,4), you mocked result will not be returned
Mockito.when(mckCalculator.getAddition(3, 4)).thenReturn(5);
// For cases, where you do not know exact parameter then you can use Mockito.anyInt()
Mockito.when(mckCalculator.getAddition(Mockito.anyInt(), Mockito.anyInt())).thenReturn(5);Last updated