title: Capture an argument in Mockito
body: <p>I'm testing a certain class. This class is internally instantiating a "GetMethod" object that gets passed to a "HttpClient" object that gets injected into the tested class.</p>
  
  <p>I'm mocking the "HttpClient" class, but I would need to modify the behaviour of one method of the "GetMethod" class too. I'm playing with ArgumentCaptor but I don't seem to be able to get a hold of the instantiated object in the "when" call.</p>
  
  <p>Example:</p>
  
  <pre><code>HttpClient mockHttpClient = mock(HttpClient.class);
  ArgumentCaptor&lt;GetMethod&gt; getMethod = ArgumentCaptor.forClass(GetMethod.class);
  when(mockHttpClient.executeMethod(getMethod.capture())).thenReturn(HttpStatus.SC_OK);
  when(getMethod.getValue().getResponseBodyAsStream()).thenReturn(new FileInputStream(source));
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>org.mockito.exceptions.base.MockitoException: 
  No argument value was captured!
  You might have forgotten to use argument.capture() in verify()...
  ...or you used capture() in stubbing but stubbed method was not called.
  Be aware that it is recommended to use capture() only with verify()
  </code></pre>