目前我使用 Mockito 编写 JUnit 测试。当列表中的一个 String
具有定义的值(例如 "00123"
)时,它应该通过:
Mockito.when(myMock.isContractAvailable("0815", Arrays.asList(new String[] {ANYVALUE, "00123", ANYVALUE})).thenReturn(Boolean.TRUE);
我该怎么做? 谢谢!
最佳答案
您可以提供自定义匹配器来进行参数匹配
when(myMock.isContractAvailable(eq("0815"), argThat(new ArgumentMatcher<List<String>>() {
@Override
public boolean matches(List<String> list) {
return "00123".equals(list.get(1)); // essentially ```list -> "00123".equals(list.get(1))``` in java 8
}
})).thenReturn(true);
关于java - Mockito:使用 List<String> 作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54250124/