### Question:
BatikSVGRasterizer implements SVGRasterizer { @Override public TemporaryResourceReference rasterizeToTemporaryResource(String content, int width, int height) throws IOException { return rasterizeToTemporaryResource(content, width, height, getCurrentDocument()); }  @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 rasterizeToTemporaryResourceUsesContextDocument() throws Exception { TemporaryResourceReference tref = this.mocker.getComponentUnderTest().rasterizeToTemporaryResource(VALID_SVG, 100, 200); Assert.assertEquals("svg", tref.getModuleId()); Assert.assertTrue(tref.getParameters().isEmpty()); Assert.assertEquals(this.dref, tref.getOwningEntityReference()); Assert.assertEquals(RASTER_FILE_NAME, tref.getResourceName()); }
@Test public void rasterizeToTemporaryResourceReusesFile() throws Exception { writeTestFile(this.rasterFile); TemporaryResourceReference tref = this.mocker.getComponentUnderTest().rasterizeToTemporaryResource(VALID_SVG, 100, 200); Assert.assertEquals("svg", tref.getModuleId()); Assert.assertTrue(tref.getParameters().isEmpty()); Assert.assertEquals(this.dref, tref.getOwningEntityReference()); Assert.assertEquals(Math.abs(VALID_SVG.hashCode()) + ".png", tref.getResourceName()); Assert.assertTrue(isTestFile(this.rasterFile)); }
@Test public void rasterizeToTemporaryResourceReturnsNullOnExceptions() throws Exception { TemporaryResourceReference tref = this.mocker.getComponentUnderTest().rasterizeToTemporaryResource(INVALID_SVG, 0, 0); Assert.assertNull(tref); }
@Test public void rasterizeToTemporaryResourceReturnsNullWhenBaseTempDirCannotBeCreated() throws Exception { this.baseDirectory.getRoot().mkdirs(); writeTestFile(new File(this.baseDirectory.getRoot(), "temp")); TemporaryResourceReference tref = this.mocker.getComponentUnderTest().rasterizeToTemporaryResource(VALID_SVG, 100, 200); Assert.assertNull(tref); }
@Test public void rasterizeToTemporaryResourceReturnsNullWhenContextTempDirCannotBeCreated() throws Exception { this.baseDirectory.getRoot().mkdirs(); writeTestFile( new File(new File(new File(new File(this.baseDirectory.getRoot(), "temp"), "svg"), "wiki"), "Space")); TemporaryResourceReference tref = this.mocker.getComponentUnderTest().rasterizeToTemporaryResource(VALID_SVG, 100, 200); Assert.assertNull(tref); }