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 <
One other way around this is to use @Mock annotation instead.
Doesn't work in all cases, but looks much sexier :)
Here's an example:
@RunWith(MockitoJUnitRunner.class)
public class FooTests {
@Mock
public Foo fooMock;
@Test
public void testFoo() {
when(fooMock.getValue()).thenReturn(new Bar());
}
}
The MockitoJUnitRunner initializes the fields annotated with @Mock.