PersistedScreenshotImage extends ScreenshotImage { @Override public BufferedImage get() { if (image != null) { return image; } InputStream in = null; try { in = getImageStream(); image = ImageIO.read(in); } catch (IOException e) { throw new TestRuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { LOG.error("", e); } } } return image; } 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 testGet_image_not_exist() throws Exception { ScreenshotImage image = new PersistedScreenshotImage(persister, metadata); expectedException.expect(ResourceUnavailableException.class); image.get(); }
@Test public void testGet_image_exists() throws Exception { BufferedImage expected = getImage(); persister.saveScreenshot(metadata, expected); ScreenshotImage image = new PersistedScreenshotImage(persister, metadata); assertThat(image.isImageCached(), is(false)); BufferedImage actual = image.get(); assertThat(ImageUtils.imageEquals(expected, actual), is(true)); assertThat(image.isImageCached(), is(true)); BufferedImage i = image.get(); assertThat(i, is(sameInstance(actual))); }
@Test public void testGet() throws Exception { BufferedImage i = getImage(); ScreenshotImage image = new PersistedScreenshotImage(persister, metadata, i); assertThat(image.get(), is(sameInstance(i))); }