I was very surprised to find out that following simple code example doesn\'t work for all Mockito versions > 1.8.5
@RunWith(MockitoJUnitRunner.class)
public clas
This is documented in mockito as work around, if multiple mocks exists of the same type. It does not resolve the implementation based on the name provided (ie @Mock(name = "b2")
). The algorithm it uses to resolved the implementation is by field name of the injected dependency. So your code above will resolve correctly (b2
=> @Mock private B b2
and b3
=> @Mock private B b3
).
The other workaround is to use constructor injection which is the recommended way of injecting dependencies.