title: Mocking an interface with Mockito
body: <p>Can someone please help me with the below Mock object.
  I want to write a mock test case for ServiceImpl class. 
  I want to mock OrderIF interface: </p>
  
  <pre><code>public interface OrderIF{
      List&lt;Order&gt; ordersFor(String type);
  }
  </code></pre>
  
  <p>The implementation of service is:  </p>
  
  <pre><code>public class ServiceImpl implements Service {
      private List &lt;Order&gt; orders ;
      private OrderIF orderif ; // this is 3rd party interface
  
      public int getval(String type) {
         //some code 
  
         // this returns a list of objects (orders)
         orders = orderif.ordersFor(type);
  
         // some code 
         return orders.get(0)
      }
  }
  </code></pre>
  
  <p>My code give NullPoinerException: </p>
  
  <pre><code>public class ServiceImplTest {
       private List &lt;Order&gt; ll ;
       private service reqService ; 
  
       @InjectMocks
       private orderIF order;
  
       @Before
       public void setUp() throws Exception {
           ll = new ArrayList&lt;Order&gt; ();
           ll.add(new Order("Buy"  ,  11 , "USD" ));
           ll.add(new Order("Sell" ,  22 , "USD" ));
           reqService = spy(new ServiceImpl());
       }
  
       @Test
       public void test() {
          String type= "USD" ; 
          when(order.ordersFor(type)).thenReturn(ll);
          q = reqService.getval(type);
          assertTrue(q.get().ask == 232.75);
      }
  }
  </code></pre>