title: How can I test a method that initaiates a download as stream using Arquillian?
body: <p>I need to write a bunch of integration tests (Arquillian framework) and right now I'm struggling in a few areas. Here is an example of a method in a Controller, that initiates the creation of a Jasper Report, which is subsequently streamed to the client:</p>
  
  <pre><code>public void executeFibuAuswertung(){
      Report report = reportService.find(99913L);
      reportParameterForm.setReport(report);
      List&lt;ReportParameter&gt; reportParameters = Collections.emptyList();
      createExcelReport(reportParameters);
      reportExecutionController.streamReportResult();
  }
  
  public void streamReportResult(){
      EnumReportFormat format = reportParameterForm.getSelectedFormat();
  
      ServletUtils.streamToClient(reportParameterForm.getReportResult()
                  , reportParameterForm.getReport().getTitle() + format.getFileExtention()
                  , format.getContentType()
                  , false);
      facesContext.responseComplete();
  }
  </code></pre>
  
  <p>How can I write a test for this using the Arquillian framework?</p>
  
  <p>At this time, my test Looks like this:</p>
  
  <pre><code>@Before
  public void before() {
      FacesContext context = ContextMocker.mockFacesContext();
      ContextMocker.mockPostback(context, false);
      ContextMocker.mockFacesMessages(context);
      ContextMocker.mockFindComponent(UIComponent.getCurrentComponent(context), context);
  }
  
  @Test(expected = NullPointerException.class)
  @WindowScopeRequired
  public void testExecuteAuswertung1() throws Exception {
      fibuController.executeAuswertung();
      byte[] content = reportParameterForm.getReportResult();
      Assert.assertNotNull(content);
  }
  </code></pre>
  
  <p>Obviously, this doesn't make much sense. It is the following line of code that throws the NullPointerException:</p>
  
  <pre><code>    HttpServletResponse resp = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
  </code></pre>