### Question:
ProcessErrorReportExcelServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { ManagedProcess report = request.getResource().adaptTo(ManagedProcess.class); if (report != null) { String title = report.getName(); String fileName = JcrUtil.createValidName(title) + ".xlsx"; Workbook workbook = createSpreadsheet(report); response.setContentType("application/vnd.ms-excel"); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); try (ServletOutputStream out = response.getOutputStream()) { workbook.write(out); out.flush(); } catch (Exception ex) { LOG.error("Error generating excel export for " + request.getResource().getPath(), ex); throw ex; } } else { String msg = String.format("Unable to process report stored at %s", request.getResource().getPath()); throw new ServletException(msg); } }    }### Answer:
@Test public void testDoGet() throws Exception { this.context.create().resource(RESOURCE_PATH, "prop", "resourceval"); this.context.registerAdapter(Resource.class, ManagedProcess.class, process); this.context.currentResource(RESOURCE_PATH); servlet.doGet(this.context.request(), this.context.response()); }
@Test(expected = IllegalStateException.class) public void testDoGet_innerThrow() throws Exception { this.context.create().resource(RESOURCE_PATH, "prop", "resourceval"); this.context.registerAdapter(Resource.class, ManagedProcess.class, process); this.context.currentResource(RESOURCE_PATH); SlingHttpServletResponse response = mock(SlingHttpServletResponse.class); doThrow(IllegalStateException.class).when(response).getOutputStream(); servlet.doGet(this.context.request(), response); }
@Test(expected = ServletException.class) public void testDoGet_outerThrow() throws Exception { this.context.create().resource(RESOURCE_PATH, "prop", "resourceval"); this.context.currentResource(RESOURCE_PATH); servlet.doGet(this.context.request(), this.context.response()); }