我正在编写单元测试,并通过junit框架验证其中的方法调用。我实现的方法在我的代码库中说明如下:
AtlasBaseClient.API api = new AtlasBaseClient.API("api/atlas/v2/types/typedefs","PUT",Response.Status.OK);
1. client.callAPI(api, (Class<?>) null, (Object) objectMapper.writeValueAsString(type), null);
2. client.callAPI(api, (Class<?>) null, object, null);
以上方法的库声明为:
public <T> T callAPI(AtlasBaseClient.API api, Class<T> responseType, Object requestObject, String... params) throws AtlasServiceException {
return this.callAPIWithResource(api, this.getResource(api, params), requestObject, responseType);
}
现在,我正在编写单元测试,并希望验证是否调用了这些方法,以及我正在尝试的代码段的外观
verify(client, times(1)).callAPI(any(AtlasBaseClient.API.class), (Class<?>) null, any(Object.class), any());
但按照junit框架,如果其中一个参数通过matcher,那么其他参数也应该通过matcher,这使得测试失败。
2条答案
按热度按时间qeeaahzv1#
n9vozmp42#
如果你用匹配器
verify
测试所有参数都需要匹配,这是什么InvalidUseOfMatchersException
手段。您正在显式测试的第二个参数
null
,应该是Mockito.isNull()
或者类似的东西。即