title: Mockito - Injecting a List of mocks
body: <p>I have the following code:</p>
  
  <pre><code>@Component 
  public class Wrapper
  { 
      @Resource 
      private List&lt;Strategy&gt; strategies;
  
      public String getName(String id)
      {
      // the revelant part of this statement is that I would like to iterate over "strategies"
          return strategies.stream()
              .filter(strategy -&gt; strategy.isApplicable(id))
              .findFirst().get().getAmount(id);
      } 
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Component 
  public class StrategyA implements Strategy{...}
  
  @Component 
  public class StrategyB implements Strategy{...}
  </code></pre>
  
  <p>I would like to create a Test for it using Mockito.
  I wrote the test as follows:</p>
  
  <pre><code>@InjectMocks
  private Wrapper testedObject = new Wrapper ();
  
  // I was hoping that this list will contain both strategies: strategyA and strategyB
  @Mock
  private List&lt;Strategy&gt; strategies;
  
  @Mock
  StrategyA strategyA;
  
  @Mock
  StrategyB strategyB;
  
  @Test
  public void shouldReturnNameForGivenId()
  {   // irrevelant code...
      //when
      testedObject.getName(ID);
  }
  </code></pre>
  
  <p>I am getting NullPointerException on line:  </p>
  
  <pre><code>filter(strategy -&gt; strategy.isApplicable(id))
  </code></pre>
  
  <p>, which states that the "strategies" list is initialized but is empty. 
  Is there any way Mohito will behave in the same wasy as Spring? Adding automatically all instances implementing interface "Strategy" to the list?</p>
  
  <p>Btw I do not have any setters in Wrapper class and I would like to leave it in that way if possible.</p>