Reputation: 880
I'm trying to mock a RestTemplate exchange() call with the following code:
Test method
given(restTemplate.exchange(any(UriComponents.class), any(HttpMethod.class), any(HttpEntity.class), any(StatusResponse.class)))
.willReturn(new ResponseEntity<>(HttpStatus.BAD_GATEWAY));
The code does not compile because:
cannot resolve method willReturn(new ResponseEntity<>(HttpStatus.BAD_GATEWAY))
cannot resolve method exchange(T, T, T, T)
How should I change the signature to make it work? Thanks.
Upvotes: 1
Views: 928
Reputation: 6391
The 1st argument of exchange
(url) should be eq("url")
or anyString()
(assumning that "url" is the value you're using in your test).
The 4th argument (response class) should be eq(StatusResponse.class)
or any(Class.class)
.
Upvotes: 1