Argument matchers play a key role in mocking. Following are the rationale and examples of Argument matchers.
Mock objects return expected values. But when it needs to return different values for different arguments, argument matcher comes into play. Suppose we have a method that takes a player name as the input and returns the number of runs as the output. We want to stub it and return 100 for
Sachin and 10 for
xyz. We have to use argument matcher to stub this.
Mockito returns expected values when a method is stubbed. If the method takes arguments, the argument must match during the execution. For example, the
getValue(int someValue) method is stubbed in the following way: