Quantcast
Channel: Using Mockito to mock classes with generic parameters - Stack Overflow
Viewing all articles
Browse latest Browse all 13

Answer by Marek Kirejczyk for Using Mockito to mock classes with generic parameters

$
0
0

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<Bar> fooMock;    @Test    public void testFoo() {        when(fooMock.getValue()).thenReturn(new Bar());    }}

The MockitoJUnitRunner initializes the fields annotated with @Mock.


Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>