1

i try to test my SpringBoot application with Mockito. Is it possible to check if a restTemplate.exchange() method is called n times?

For example:

verify(restTemplate, times(1))
    .exchange(myURL, method, requestEntity, responseType)
ab22
  • 27
  • 5
  • i would bet on it (it is possible)! what is the problem? (overload (+var args) methods (as `exchange` is) are little/more tricky to match/verify) – xerx593 Feb 08 '22 at 16:57
  • what causes you think that it cannot when compared to other class ? – Ken Chan Feb 08 '22 at 17:10

1 Answers1

0

Try this:

verify(restTemplate, times(1))
    .exchange(
        ArgumentMatchers.anyString(),
        ArgumentMatchers.any(HttpMethod.class),
        ArgumentMatchers.any(HttpEntity.class),
        ArgumentMatchers.<Class<Object>>any()
    );

More on this topic: How do I mock a REST template exchange?