VKP
VKP

Reputation: 658

Resttemplate JUNIT Exchange method not solving

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;

Upvotes: 1

Views: 2254

Answers (2)

Johnpeter J
Johnpeter J

Reputation: 1

Changing any(OrderDocument.class) to eq(OrderDocument.class) worked for me.

Upvotes: 0

amseager
amseager

Reputation: 6391

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.

Upvotes: 3

Related Questions