-
Notifications
You must be signed in to change notification settings - Fork 263
Open
Description
参数匹配器那一节的demo代码和官方有出入
官方demo代码
//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(true);
//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(mockedList).add(argThat(someString -> someString.length() > 5));
中文版demo代码
//stubbing using built-in anyInt() argument matcher
// 使用内置的anyInt()参数匹配器
when(mockedList.get(anyInt())).thenReturn("element");
//stubbing using custom matcher (let's say isValid() returns your own matcher implementation):
// 使用自定义的参数匹配器( 在isValid()函数中返回你自己的匹配器实现 )
when(mockedList.contains(argThat(isValid()))).thenReturn("element");
//following prints "element"
// 输出element
System.out.println(mockedList.get(999));
//you can also verify using an argument matcher
// 你也可以验证参数匹配器
verify(mockedList).get(anyInt());
Metadata
Metadata
Assignees
Labels
No labels