title: Mockito: parameter's mocked service throws null pointer exception
body: <p>Having this controller method to test</p>
  
  <pre><code>@RequestMapping("/search/{q}")
  public String getWeatherForSearchTerm(@PathVariable String q, Model model) {
      GeocodingResult geocodingResult = geocodingService.findBySearchTerm(q);
      Weather weather = weatherService.findByLocation(geocodingResult.getGeometry().getLocation());
      model.addAttribute("geocodingResult",geocodingResult);
      model.addAttribute("weather",weather);
      return "weather/detail";
  }
  </code></pre>
  
  <p>trying to run this test</p>
  
  <pre><code>@Test
  public void getWeatherForSearchTermTest() throws Exception{
      GeocodingResult geocodingResult = new GeocodingResult();
  
      Weather weather = new Weather();
  
      Mockito.when(geocodingService.findBySearchTerm("13")).thenReturn(geocodingResult);
  
      Mockito.when(weatherService.findByLocation(any(Location.class))).thenReturn(weather);
      mockMvc.perform(get("/search/13"))
              .andExpect(MockMvcResultMatchers.view()
              .name("weather/detail"));
      Mockito.verify(geocodingService).findBySearchTerm(any(String.class));
  }
  </code></pre>
  
  <p>I am getting a NullPointerException while trying to do this code line  inside the Controller </p>
  
  <pre><code>Weather weather = weatherService.findByLocation(geocodingResult.getGeometry().getLocation());
  </code></pre>
  
  <p>Even if </p>
  
  <pre><code>        Mockito.when(weatherService.findByLocation(any(Location.class))).thenReturn(weather);
  </code></pre>
  
  <p>is defined.</p>
  
  <p>After debugging I realized that this is the part which is throwing the exception.</p>
  
  <pre><code>    geocodingResult.getGeometry().getLocation()
  </code></pre>
  
  <p>I dont understand why is this happening if I mocked the response as shown above on the snippet code.</p>
  
  <p>My class is annotated with</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  </code></pre>
  
  <p>and the memeber class are defined:</p>
  
  <pre><code> private MockMvc mockMvc;
  
  @InjectMocks
  private WeatherController controller;
  
  @Mock
  private WeatherService weatherService;
  
  @Mock
  private GeocodingService geocodingService;
  </code></pre>