英文:
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
Class
英文:
I am trying to write a JUNIT(version 5 ) for a restemplate call.
My actual Implementation is like below .
ResponseEntity<OrderDocument> responseEntity = restTemplate.exchange(
URL,
HttpMethod.GET,
new HttpEntity<>(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<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
Class<T> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论