title: Mockito: mocking an arraylist that will be looped in a for loop
body: <p>I have a method under test that contains the following snippet:</p>
  
  <pre><code>private void buildChainCode(List&lt;TracedPath&gt; lines){
      for(TracedPath path : lines){
          /.../
      }
  }
  </code></pre>
  
  <p>My unit test code looks like this:</p>
  
  <pre><code>public class ChainCodeUnitTest extends TestCase {
  
      private @Mock List&lt;TracedPath&gt; listOfPaths;
      private @Mock TracedPath tracedPath;
  
      protected void setUp() throws Exception {
          super.setUp();
          MockitoAnnotations.initMocks(this);
      }
  
      public void testGetCode() {
          when(listOfPaths.get(anyInt())).thenReturn(tracedPath);
  
          ChainCode cc = new ChainCode();
          cc.getCode(listOfPaths);
  
          /.../
      }
  }
  </code></pre>
  
  <p>The problem is, that while running the test, the test code never enters the for loop. What when conditions should I specify, so that the for loop would be entered? Currently I have specified <code>when(listOfPaths.get(anyInt())).thenReturn(tracedPath)</code>, but I guess it is never used.</p>