title: EasyMock chained method call producing null pointer exception
body: <p>I am using EasyMock to try and mock iteration through a list of items that are two levels deep.  My unit test code is below</p>
  
  <pre><code>    EventContext ctx = EasyMock.createMock(EventContext.class);
      Order order = EasyMock.createMock(Order.class);
      Item oli = new Item();
      oli.setProduct(370);
      List&lt;Item&gt; lineItems = new ArrayList&lt;Item&gt;();
      lineItems.add(oli);
      EasyMock.expect(ctx.getOrder()).andReturn(order).times(2);
      EasyMock.expect(order.getTopLevelLineItems()).andReturn(lineItems);
  </code></pre>
  
  <p>and the code it is attempting to test is</p>
  
  <pre><code>    for(Item item : (List&lt;Item&gt;) ctx.getOrder().getTopLevelLineItems()) {
              if(370 == item.getProduct()) {
                  result = true;
              }
  </code></pre>
  
  <p>But when the unit test runs I get a NullPointerException on the line below:</p>
  
  <pre><code>for(Item item : (List&lt;Item&gt;) ctx.getOrder().getTopLevelLineItems()) 
  </code></pre>
  
  <p>It seems like I have set up the chained call correctly does anyone have any suggestions of what might be going wrong here?</p>
  
  <p>Edit: I want to add I split out the chain into different lines in the class being tested and it appears that the ctx.getOrder() is not null but the lineItems returned are</p>