1

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 Answer 1

3

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.