Introduction
The article will stress the usage of argument matcher, method type and method name, and a brief description. Argument matchers are mostly utilised in Mockito to conduct flexible verification and stubbing. To access all of the matcher methods, it extends the ArgumentMatchers class. Equal() is a heritage method that Mockito uses to verify and match parameter values. In some circumstances, additional flexibility is required during the verification of argument values, hence argument matchers should be used instead of the equal() function. The org.mockito package contains the ArgumentMatchers class.
Methods in Argument Matcher class
There are several methods in the ArgumentMatchers class, some of which are given below:
Method type & Method name |
Description |
<T> any() |
It matches null values and varargs as well as all other values (everything). |
boolean anyBoolean() |
Any boolean or not-null boolean value matches it. |
byte anyByte() |
Any byte or not-null byte value matches it. |
char anyChar() |
Any char or not-null character value is matched. |
Collection <T> anyCollection |
It matches any collection that isn't null in the application. |
double anyDouble() |
Any double or not-null double value matches it. |
float anyFloat() |
It matches to any float or not-null float values. |
int anyInt() |
It matches any integer value that is an int or a not-null value. |
Iterable<T> anyIterable() |
It matches any iterable values that aren't null. |
List<T> anyList() |
It is equivalent to any not-null list. |
long anyLong() |
It is compatible with any long or not-null long value. |
Set<T> anySet() |
It is compatible with any not-null set. |
short anyShort() |
It may be used to match any short or not-null short value. |
String anyString() |
It matches any String that isn't null. |
<T>argThat(ArgumentMatcher<T>matcher) |
It allows you to make your own argument matchers. |
boolean booleanThat(ArgumentMatcher<Boolean> matcher) |
It allows you to make your own boolean argument matchers. |
byte byteThat(ArgumentMatcher<Byte> matcher) |
It allows you to make your own byte argument matchers. |
char charThat(ArgumentMatcher<Character> matcher) |
It allows you to make your own char argument matchers. |
String contains(String substring) |
It corresponds to the substring in the String argument. |
double doubleThat(ArgumentMatcher<Double> matcher) |
It allows you to make your own double argument matchers. |
String endsWith(String suffix) |
It corresponds to the String input that ends with the suffix specified. |
boolean eq(boolean value) |
It corresponds to the boolean argument that has the same value as the provided value. |
double eq(double value) |
It corresponds to the double argument, which has the same value as the provided value. |
long eq(long value) |
It corresponds to the long argument that has the same value as the provided value. |
<T> isNotNull() |
It is equivalent to the not null argument. |
<T> is Null() |
It matches the null argument. |
<T> same(T value) |
It's the same as the null argument. |






