NOTE: I already tried some other solutions such as; Mockito: InvalidUseOfMatchersException
Mockito - Invalid use of argument matchers
Invalid use of argument matchers
I have the following unit test;
@Test(expectedExceptions = BadRequestException.class)
public void shouldThrowHttpClientErrorExceptionWhenHeadForHeaders()
{
final String command = "any/command";
final RoutingInfo routingInfo = new RoutingInfo(GET, "anyservice", command);
when(restTemplate.headForHeaders("https://anyservice/any/command"))
.thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST));
underTest.headers(routingInfo);
}
When I run it in Debug mode, my code passes the test, but when I run the test as normal (run mode) it does not pass. The exception thrown is:
Invalid use of argument matchers! 4 matchers expected, 2 recorded:
And here is my actual class;
public <T> ResponseEntity<T> forward(final RoutingInfo routingInfo, final HttpEntity<?> request, final Class<T> responseType)
{
final HttpMethod method = routingInfo.getMethod();
final String url = routingInfo.getURL(HTTPS_URI_SCHEME);
LOG.info("Routing request: {} {}", method, url);
try
{
return restTemplate.exchange(url, method, request, responseType);
}
catch (final HttpClientErrorException exc)
{
LOG.error("Failed to forward request: {}", exc.getMessage());
if (exc.getStatusCode().is4xxClientError())
{
throw new BadRequestException(exc.getMessage());
}
throw new InternalServerErrorException("Failed to forward request!");
}
}
I really stuck in these. request, responseType looks null when i debug this code. I am not really sure how to fix that, assuming I am right in my identification of the cause.