title: Mocking a List and attempting to iterate over it
body: <p>Currently using Mockito to Test a method from one of my classes. My class contains a List, and the method takes in an object of the same class. The issue is when I attempt to iterate over the List from the object. I'm getting a null pointer to the list. Below you will see the code snippets.</p>
  
  <pre><code>private Shipment shipment;
  private Shipment shipment2;
  @Mock
  private Order mockOrder1;
  @Mock
  private Order mockOrder2;
  @Mock
  private Order mockOrder3;
  @Mock
  private ArrayList&lt;Order&gt; mockShipmentOrders;
  @Mock
  private ArrayList&lt;Order&gt; mockShipmentOrders2;
  
  @Before
  public void setUp(){
      MockitoAnnotations.initMocks(this);
      mockShipmentOrders.add(mockOrder1);
      mockShipmentOrders.add(mockOrder2);
      mockShipmentOrders2.add(mockOrder3);
      shipment = new Shipment(1, mockShipmentOrders);
      shipment2 = new Shipment(2, mockShipmentOrders2);
  }
  
  @Test
  public void test_mergeShipments_increasesByOneWhenAShipmentOfOneAddedToAShipmentORderSizeOfTwo(){
      shipment.mergeShipments(shipment2);
      assertEquals(3, shipment.getShipmentOrders().size());
  }
  </code></pre>
  
  <p>above you can see my mockito test and below is my Class with the method:</p>
  
  <p>public class Shipment {</p>
  
  <pre><code>private long shipmentID;
  private List&lt;Order&gt; shipmentOrders;
  
  public Shipment(long shipmentID, List&lt;Order&gt; shipmentOrders){
      this.shipmentID = shipmentID;
      this.shipmentOrders = shipmentOrders;
  }
  
  public List&lt;Order&gt; getShipmentOrders(){
      return shipmentOrders;
  }
  
  public void mergeShipments(Shipment shipment2){     
      List&lt;Order&gt; existingShipment = shipment2.getShipmentOrders();
      for (Order order : existingShipment){
          shipmentOrders.add(order);
      }
  }
  </code></pre>
  
  <p>When I run the test I am getting a java.lang.NullPointerException for the line: for (Order order : existingShipment){
  in mergeShipemts();</p>
  
  <p>The question is; Is it possible to mock a list, call that list and then run a foreach over that mocked list?</p>