Resttemplate JUNIT交换方法未解决

问题描述 投票:0回答:1

我正在尝试为retemplate调用编写JUNIT(第5版)。

我的实际实现如下。

ResponseEntity<OrderDocument> responseEntity = restTemplate.exchange(
URL,
HttpMethod.GET,
new HttpEntity<>(headers),
OrderDocument.class, message.getPayload().toString());

我的模拟电话是

when(restTemplate.exchange(anyString() ,
any(HttpMethod.class)   , 
any(HttpEntity.class) ,
any(OrderDocument.class) ,
any(String.class) )
.thenReturn(responseEntity));

我遇到编译器错误,无法解决方法'exchange(java.lang.String,T,T,T,T)'我相信我的模拟通话与实现匹配。不确定为什么不进行编译。请帮助。

 ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, 
 Class<T> responseType, Object... uriVariables) throws RestClientException;
java mockito resttemplate junit5
1个回答
1
投票

此方法的第四个参数是Class.class,而不是SalesOrderDocument.class。您需要对其进行修复(至any(Class.class),例如)。

© www.soinside.com 2019 - 2024. All rights reserved.