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;
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.