【问题标题】:Resttemplate JUNIT Exchange method not solvingResttemplate JUNIT Exchange方法无法解决
【发布时间】:2020-04-10 22:32:18
【问题描述】:

我正在尝试为 restemplate 调用编写一个 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】:

    此方法的第四个参数是Class.class,而不是SalesOrderDocument.class。你需要修复它(到any(Class.class),f.e.)。

    Docs 用于 exchange 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-08
      • 2012-10-11
      • 1970-01-01
      • 2018-06-01
      • 2014-03-17
      • 1970-01-01
      • 2021-12-21
      • 2017-09-30
      相关资源
      最近更新 更多