I am trying to test a overridden method that takes in a parameter of type Class<? extends HttpMessageConverter<?>>
Class<? extends HttpMessageConverter<?>>
as an input. As this parameter is not being used in my implementation, I want to mock it (or in worst case I can go ahead with actual initialization of the instance).
@Mock
Class<? extends HttpMessageConverter<?>> selectedConverterType;
This is how I am mocking it (although I have tried using Mockito.mock()
, but even that did not work)
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {.....}
This is the method I am trying to test.
Some observation:
It fails when MockCreationValidator
try to validate the type of mock in MockSettingsImpl
. This happens only for Class
type, other objects are being mocked as expected.
As the concerned instance is not being used in implementation, passing it as null
did the job for me. It is not a good idea to do so, but I am running out of time and I want to reach code coverage limit.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.