Mockito 2 参数匹配器
Mockito 通过使用 equals() 这种自然的 Java 样式来校验参数值。有时候,当需要有其他一些灵活性的时候,你可能会要求使用参数匹配(argument matchers)。 请参考下面的代码: //stubbing using built-in anyInt() argument matcher when(mockedList.get(anyInt())).thenReturn( "element" ); //stubbing using custom matcher (let's say isValid() returns your own matcher implementation): when(mockedList.contains(argThat(isValid()))).thenReturn( "element" ); //following prints "element" System.out.println(mockedList.get( 999 )); //you can also verify using an argument matcher verify(mockedList).get(anyInt()); //argument matchers can also be written as Java 8 Lambdas verify