How to capture the Class argument of a method with Argument Capture For the following method
public <T> T response(RequestContent requestContent, Class<T> returnType) throws Exception
{
var response = getResponse(requestContent);
var type = objectMapper.getTypeFactory().constructType(returnType);
return objectMapper.readValue(response, type);
}
The method is used in the caller class as
var res = response(requestContent, Account.class);
I do not know how to use doReturn
and Argument Capture
in the following situations:
doReturn(Account).when(stub).response(isA(RequestContent.class), ???);
and
verify(stub).getResponseClass(requestCaptor.capture(), ???);
I get the following error
No argument value was captured!
You might have forgotten to use argument.capture() in verify()...
...or you used capture() in stubbing but stubbed method was not called.
Be aware that it is recommended to use capture() only with verify()