Argument Matcher : anyInt() anyString()



anyInt() : Argument Matcher
@Test
public void test_AnyInt(){
ArrayList<String> list =  Mockito.mock(ArrayList.class);
Mockito.when(list.get(Mockito.anyInt())).thenReturn("Hello");
System.out.println(list.get(1000));
}
Here whenever any integer value passed in the get() method of the list object it will return hello all the time for all the index values.

anyString() : Argument Matcher
@Test
public void test_anyString(){
HashMap<String,String> hashMap = Mockito.mock(HashMap.class);
Mockito.when(hashMap.get(Mockito.anyString())).thenReturn("This");
System.out.println(hashMap.get("1"));
}
Here whatever type string value you pass in the get() method of the hashMap object
it will return "This" as a value for that key string.