I have the following code:
@Component
public class Wrapper
{
@Resource
private List strategies;
public String getName(String
Why not just mock out your call to toStream()
?
@InjectMocks
private Wrapper testedObject = new Wrapper();
private List mockedStrategies;
@Mock
StrategyA strategyA;
@Mock
StrategyB strategyB;
@Before
public void setup() {
when(strategies.stream()).thenReturn(Stream.of(strategyA, strategyB));
}
To me this is far more elegant as it doesn't require you to add a helper method that is only relevant to testing to your code.