I am trying to mock the getResourceClass
of javax.ws.rs.container.ResourceInfo
. So what i have done is:
ResourceInfo resourceInfo = mock(ResourceInfo.class);
Now when i am trying below:
when(resourceInfo.getResourceClass()).thenReturn(Class.forName("com.p.q.ClassName"));
It throws the below compilation error:
The method thenReturn(Class<capture#1-of ?>) in the type OngoingStubbing<Class<capture#1-of ?>> is not applicable for the arguments (Class<capture#2-of ?>)
Can anybody help me resolving this. Thanks.
Not a big Mockito user, so I can't really explain why it doesn't work. But after a little playing around, I found this works
ResourceInfo resourceInfo = Mockito.mock(ResourceInfo.class);
Mockito.doReturn(YouResourceClass.class).when(resourceInfo).getResourceClass();
Another option
Mockito.<Class<?>>when(resourceInfo.getResourceClass()).thenReturn(YourResource.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With