title: How to use ArgumentCaptor to verify bytes written to HttpServletResponse
body: <p>I have a controller that provides functionality to download the file.</p>
  
  <pre><code>@ResponseBody
  public void downloadRecycleResults(String batchName, HttpServletResponse response) throws Exception {
      File finalResultFile = null;
      // code here generates and initializes finalResultFile for batchName
      response.setContentType("application/octet-stream");
      response.setHeader("Content-Disposition", "attachment;filename=" + finalResultFile.getName());
      IOUtils.copy(new FileReader(finalResultFile), response.getOutputStream());
  }
  </code></pre>
  
  <p>I am not able to figure out how to write test where I can verify the contents which were written to <code>response</code>. I have used <code>ArgumentCaptor</code> lot but somehow it doesn't seem to fit here.</p>
  
  <pre><code>controller.downloadRecycleResults("batchName", mock(HttpServletResponse.class));
  verify(response).getOutputStream(); // but how to capture content?
  </code></pre>