RestTemplate的JUNIT Exchange方法未解决。

huangapple go评论82阅读模式
英文:

Resttemplate JUNIT Exchange method not solving

问题

我正在尝试为一个 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 exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity,
Class responseType, Object... uriVariables) throws RestClientException;

英文:

I am trying to write a JUNIT(version 5 ) for a restemplate call.

My actual Implementation is like below .

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

My Mock call is

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

I am getting compiler error Cannot resolve method 'exchange(java.lang.String, T, T, T, T)'
I believe my mock call matching with Implementation.Not sure why its not compiling.Please help.

 ResponseEntity&lt;T&gt; exchange(String url, HttpMethod method, @Nullable HttpEntity&lt;?&gt; requestEntity, 
 Class&lt;T&gt; responseType, Object... uriVariables) throws RestClientException;

答案1

得分: 3

这个方法的第四个参数是 Class.class,而不是 SalesOrderDocument.class。你需要修复它(改成 any(Class.class),例如)。

exchange 方法的文档

英文:

The 4th argument of this method is Class.class, not SalesOrderDocument.class. You need to fix it (to any(Class.class), f.e.).

Docs for exchange method.

huangapple
  • 本文由 发表于 2020年4月11日 06:32:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/61149611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定