Is there a clean method of mocking a class with generic parameters? Say I have to mock a class Foo which I need to pass into a method that expects a <
Here is an interesting case: method receieves generic collection and returns generic collection of same base type. For example:
Collection extends Assertion> map(Collection extends Assertion> assertions);
This method can be mocked with combination of Mockito anyCollectionOf matcher and the Answer.
when(mockedObject.map(anyCollectionOf(Assertion.class))).thenAnswer(
new Answer>() {
@Override
public Collection answer(InvocationOnMock invocation) throws Throwable {
return new ArrayList();
}
});