I have the following code:
@Component
public class Wrapper
{
@Resource
private List strategies;
public String getName(String
Annotate it with @Spy instead of @Mock. As Mockito cannot spy on an interface, use a concrete implementation, for example ArrayList. During test setup add the mocks to the List spy. This way you do not need to alter your test subject solely for test purposes.
@InjectMocks
private Wrapper testedObject = new Wrapper();
@Spy
private ArrayList mockedStrategies;
@Mock
private StrategyA strategyA;
@Mock
private StrategyB strategyB;
@Before
public void setup() throws Exception {
mockedStrategies.add(strategyA);
mockedStrategies.add(strategyB);
}