这是我的选拔赛
java
when(restTemplate.exchange(
Mockito.<String>eq("http://some.api.asmx"),
Mockito.<HttpMethod>eq(HttpMethod.POST),
Mockito.<HttpEntity<List<Object>>>any(),
Mockito.<ParameterizedTypeReference<SuchenResponse>>any())).thenReturn(Mockito.<ResponseEntity>any());
这总是会失败
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
1 matchers expected, 2 recorded:
-> at com.myapp.sst.base.app.service.ServiceTest.shouldDo(ServiceTest.java:62)
-> at com.myapp.sst.base.app.service.ServiceTest.shouldDo(ServiceTest.java:63)
然而,我对每个参数都使用了eq
或any
,所以不应该发生这个错误,对吗?
1条答案
按热度按时间fnx2tebb1#
您正在使用
thenReturn
中的Mockito.<ResponseEntity>any()
在这里,您应该指定当restTemplate调用发生时mockito应该返回什么,例如
ResponseEntityBuilder.builderOK().build()
也许与其模仿RestTemplate,不如尝试使用类似的
MockRestServiceServer