title: Null Pointer Exception while mocking Optional Parameters
body: <p>My code is of the form:</p>
  
  <pre><code>public String getDeliveryDestinations(final RequestContext requestContext {
      final Accessor accessor = requestContext.getAccessor().get();
  
      final GroupAccessor groupAccessor = accessor.getGroupAccessor();
  
      final String groupId = groupAccessor.getGroupId();
  
  
      if(groupId.equals("s1") return "Type1";
      else return "type 2";
  
  
  }
  </code></pre>
  
  <p>For testing this, i wrote the following:</p>
  
  <pre><code>@Test
  public void getDestinationsDestinations_empty() throws Exception {
  
  
      Accessor accessor = mock(Accessor.class);
      GroupAccessor groupAccessor = mock(GroupAccessor.class);
      //*mockRequestContent is Mocked*
      when(mockRequestContext.getAccessor().get()).thenReturn(accessor);
      when(accessor.getGroupAccessor()).thenReturn(groupAccessor);
      when(groupAccessor.getGroupId()).thenReturn("s1");
  
      String destinationResult = provider.getDeliveryDestinations(mockRequestContext);
      assertEquals(destinationResult,"Type1");
  
  }
  </code></pre>
  
  <p>I get a NPE at, 
   when(mockRequestContext.getAccessor().get()).thenReturn(accessor);
  I don't know why! </p>
  
  <p>Any leads would be very helpful :)</p>