title: Not getting Response in Test Class in java
body: <p>I am writing test case for servlets using mockito.</p>
  
  <p>In servlet response is set using servletoutputstream.</p>
  
  <p>i send request the servlet is working properly also giving output in console but in testclass i am not getting class.
  below is the code for setting response :</p>
  
  <pre><code>protected void commitResponseBuffer(String buffer, ServletResponse response) throws IOException 
  {
      response.setContentType("text/plain");
      System.out.println("Uncompressed Response Buffer : Size = " + buffer.length());
      // write to ZipOutputStream
      ByteArrayOutputStream bos = new ByteArrayOutputStream ();
      ZipOutputStream out = new ZipOutputStream(bos);
      out.putNextEntry(new ZipEntry("response.txt"));
      out.write(buffer.getBytes("UTF-8"));
      //out.flush();
      out.closeEntry();
      out.close ();
      bos.close();
      // encode to Base64 string
      String b64String = Base64.encodeBase64String(bos.toByteArray());
      // set the response
      ServletOutputStream servletOut = response.getOutputStream();
      response.setContentLength(b64String.length());
      System.out.println("Compressed Response Buffer : Size = " + b64String.length());
      servletOut.print(b64String);
      System.out.println(b64String);
      servletOut.close();
  }
  </code></pre>
  
  <p>and in test class </p>
  
  <pre><code>    when(response.getOutputStream()).thenReturn(servletOut);
      new xlCollaborationService().service(request, response);        
      System.out.println("Response Buffer in mock :"+response.getContentType());
  </code></pre>
  
  <p>can anyone suggest me how to read the response in test class  ???
  Thanks in Advance.</p>