### Question:
BatikSVGRasterizer implements SVGRasterizer { @Override public void rasterizeToResponse(String content, int width, int height) throws IOException { if (!(this.container.getResponse() instanceof ServletResponse)) { return; } HttpServletResponse response = ((ServletResponse) this.container.getResponse()).getHttpServletResponse(); File result = rasterizeToTemporaryFile(content, width, height); if (result == null) { return; } response.setContentLength((int) result.length()); response.setContentType("image/png"); OutputStream os = response.getOutputStream(); FileUtils.copyFile(result, os); os.flush(); }  @Override File rasterizeToTemporaryFile(String content, int width, int height); @Override TemporaryResourceReference rasterizeToTemporaryResource(String content, int width, int height); @Override TemporaryResourceReference rasterizeToTemporaryResource(String content, int width, int height,
        DocumentReference targetContext); @Override void rasterizeToResponse(String content, int width, int height);  }### Answer:
@Test public void rasterizeToResponseWritesImageToServletOutputStream() throws Exception { CapturingOutputStream out = new CapturingOutputStream(); when(this.hsresponse.getOutputStream()).thenReturn(out); this.mocker.getComponentUnderTest().rasterizeToResponse(VALID_SVG, 100, 200); Assert.assertTrue(out.out.size() > 0); Assert.assertArrayEquals("PNG".getBytes("UTF-8"), Arrays.copyOfRange(out.out.toByteArray(), 1, 4)); }
@Test public void rasterizeToResponseDoesNothingIfNotHttpResponse() throws Exception { Response r = Mockito.mock(Response.class); when(this.container.getResponse()).thenReturn(r); this.mocker.getComponentUnderTest().rasterizeToResponse(VALID_SVG, 100, 200); Mockito.verifyZeroInteractions(r); }
@Test public void rasterizeToResponseDoesNothingOnExceptions() throws Exception { CapturingOutputStream out = new CapturingOutputStream(); when(this.hsresponse.getOutputStream()).thenReturn(out); this.mocker.getComponentUnderTest().rasterizeToResponse(INVALID_SVG, 0, 0); Assert.assertEquals(0, out.out.size()); }