【发布时间】:2014-08-25 23:41:03
【问题描述】:
我正在尝试为采用请求对象数组的方法设置模拟:
client.batchCall(Request[])
我试过这两种变体:
when(clientMock.batchCall(any(Request[].class))).thenReturn(result);
...
verify(clientMock).batchCall(any(Request[].class));
和
when(clientMock.batchCall((Request[])anyObject())).thenReturn(result);
...
verify(clientMock).batchCall((Request[])anyObject());
但我可以看出没有调用模拟。
它们都导致以下错误:
Argument(s) are different! Wanted:
clientMock.batchCall(
<any>
);
-> at com.my.pkg.MyUnitTest.call_test(MyUnitTest.java:95)
Actual invocation has different arguments:
clientMock.batchCall(
{Request id:123},
{Request id:456}
);
为什么匹配器不匹配数组?我需要使用特殊的匹配器来匹配对象数组吗?我能找到的最接近的东西是 AdditionalMatches.aryEq(),但这需要我指定数组的确切内容,我不想这样做。
【问题讨论】: