我已经使用Mockito模拟了restTemplate bean,如下所示。
@MockBean RestTemplate restTemplate;
when(this.restTemplate.exchange(
eq(url),
eq(HttpMethod.POST),
Mockito.<HttpEntity<?>> any(),
Mockito.<ParameterizedTypeReference<ResponseObject>> any()
)
).thenReturn(repsonsebasedonhttpEntity);
基于请求中发送的HttpEntity对象,我想返回适当的响应。有没有办法做到这一点?
最佳答案
对每个HttpEntity对象使用单独的when
并返回相应的响应,而不是对HttpEntity使用any
。
关于java - 从使用Mockito模拟的restTemplate.exchange()中检索httpEntity对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52354836/