【发布时间】:2017-03-03 19:40:04
【问题描述】:
我在工作测试中有以下内容:
when(client.callApi(anyString(), isA(Office.class))).thenReturn(responseOne);
请注意,client 是 Client 类的 Mock。
我想更改“isA(Office.class)”以告诉它匹配 Office 实例的“id”属性为“123L”的位置。如何在模拟对象的方法中指定我想要一个特定的参数值?
编辑:不是重复的,因为我试图在“何时”使用它,并且链接的问题(以及我发现的其他资源)在“验证”和“断言”上使用 ArgumentCaptor 和 ArgumentMatcher。我在想我实际上不能做我正在尝试的事情,我会尝试另一种方式。当然,我愿意以其他方式展示。
【问题讨论】:
-
将其标记为受骗者:"How can I verify that a method is called with a parameter that contains a certain value, without verifying the whole parameter?"。简而言之,使用 ArgumentMatcher 或 Hamcrest Matcher 进行检查。