Java单元测试验证RestOperations交换方法

时间:2019-03-27 11:46:28

标签: java spring rest junit mockito

我正在编写一个单元测试,我在其中模拟用来调用另一个服务的RestOperations,问题是当我尝试验证交换方法的调用时说它不匹配:

Wanted but not invoked:
org.springframework.web.client.RestOperations#0 bean.exchange(
    <any>,
    <any>,
    <any>,
    <any>
);

However, there was exactly 1 interaction with this mock:
org.springframework.web.client.RestOperations#0 bean.exchange(
    null,
    POST,
    <com.mypackage.MyCommand@285f09de,[]>,
    class com.mypackage.MyResponse
);

我的验证方法如下:

verify(restOperations, times(1)).exchange(Mockito.any(), Mockito.any(), Mockito.any(), Mockito<Class<MyResponse>>any());

我在验证中做错了吗?因为所有匹配器都是any(),所以它应该捕获所有参数?

0 个答案:

没有答案