Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mocking getResourceClass of ResourceInfo

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.

like image 950
Trying Avatar asked Sep 11 '25 21:09

Trying


1 Answers

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);
like image 167
Paul Samsotha Avatar answered Sep 14 '25 10:09

Paul Samsotha