How to EasyMock a call to a method that returns a wildcarded generic? How to EasyMock a call to a method that returns a wildcarded generic? spring spring

How to EasyMock a call to a method that returns a wildcarded generic?


I've run into a problem like this before, with Mockito. I'm not sure why it happens yet. You can cast the expect(..) argument to the non-generic Class type, ala

expect((Class) mockBeanFactory.getType(CLASS_NAME)).andReturn(SOME_CLASS);

Then you'll just have a warning, which you can suppress if you want. Not a very elegant solution; I'm going to spend a few more minutes looking at it.


The easiest thing to avoid any casting and warnings is to use expectLastCall() instead of expect(..) (see my answer to a similar question for details).

So in this case:

mockBeanFactory.getType(CLASS_NAME);expectLastCall().andReturn(SOME_CLASS);