PersistedScreenshotImage extends ScreenshotImage { protected InputStream getImageStream() { return persister.getImageStream(metadata); } PersistedScreenshotImage(Persister persister, PersistMetadata metadata);  PersistedScreenshotImage(Persister persister, PersistMetadata metadata, BufferedImage image); PersistMetadata getMetadata(); @Override BufferedImage get(); @Override InputStream getAsStream(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void testGetAsStream_image_exists() throws Exception { BufferedImage expected = getImage(); persister.saveScreenshot(metadata, expected); PersistedScreenshotImage image = new PersistedScreenshotImage(persister, metadata); InputStream in = null; try { in = image.getImageStream(); BufferedImage actual = ImageIO.read(in); assertThat(ImageUtils.imageEquals(expected, actual), is(true)); } finally { if (in != null) { in.close(); } } assertThat(image.isImageCached(), is(false)); }