### Question:
FilePersister implements Persister { @Override public BufferedImage loadScreenshot(PersistMetadata metadata) { File file = checkFileAvailable(getScreenshotImageFile(metadata)); LOG.debug("[Load screenshot] ({})", file); LOG.trace("[Load screenshot] ({})", metadata); try { return ImageIO.read(file); } catch (IOException e) { LOG.debug("Failed to load screenshot.", e); throw new ResourceUnavailableException(e); } } FilePersister();  FilePersister(FilePersisterConfig config); @Override void saveDiffImage(PersistMetadata metadata, BufferedImage image); @Override BufferedImage loadDiffImage(PersistMetadata metadata); @Override void saveScreenshot(PersistMetadata metadata, BufferedImage image); @Override InputStream getImageStream(PersistMetadata metadata); @Override BufferedImage loadScreenshot(PersistMetadata metadata); @Override void saveTargetResults(PersistMetadata metadata, List<TargetResult> results); @Override List<TargetResult> loadTargetResults(final PersistMetadata metadata); @Override void saveTestResult(PersistMetadata metadata, TestResult result); @Override TestResult loadTestResult(PersistMetadata metadata); @Override void saveExpectedIds(Map<String, Map<String, String>> expectedIds); @Override Map<String, Map<String, String>> loadExpectedIds(); File getResultDirectoryFile(); File getExpectedIdsFile(); File getTestResultFile(PersistMetadata metadata); File getTargetResultsFile(PersistMetadata metadata); File getScreenshotImageFile(PersistMetadata metadata); File getDiffImageFile(PersistMetadata metadata); String getExpectedIdsFileName(); String getTestResultFileName(); String getTargetResultsFileName(PersistMetadata metadata); String getScreenshotImageFileName(PersistMetadata metadata); String getDiffImageFileName(PersistMetadata metadata); static final String DEFAULT_EXPECTED_IDS_FILE_NAME; static final String DEFAULT_TEST_RESULT_FILE_NAME; }### Answer:
@Test public void testLoadScreenshot_selector() throws Exception { File file = new File(BASE_DIRECTORY + "/testId/testClass/testMethod_scId_WINDOWS_firefox_38_CSS_SELECTOR_main_[0].png"); Map<String, Object> map = new HashMap<String, Object>(); map.put("platform", "WINDOWS"); map.put("browserName", "firefox"); map.put("version", "38"); PtlCapabilities capabilities = new PtlCapabilities(map); IndexDomSelector selector = new IndexDomSelector(SelectorType.CSS_SELECTOR, "main", 0); PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId", selector, null, capabilities); FileUtils.copyURLToFile(getClass().getResource("FilePersister_Image.png"), file); BufferedImage expected = ImageIO.read(getClass().getResource("FilePersister_Image.png")); BufferedImage actual = persister.loadScreenshot(metadata); assertArrayEquals(toRGB(expected), toRGB(actual)); }
@Test public void testLoadScreenshot_rectangle() throws Exception { File file = new File(BASE_DIRECTORY + "/testId/testClass/testMethod_scId_WINDOWS_firefox_38_rect_0_10_100_110.png"); Map<String, Object> map = new HashMap<String, Object>(); map.put("platform", "WINDOWS"); map.put("browserName", "firefox"); map.put("version", "38"); PtlCapabilities capabilities = new PtlCapabilities(map); RectangleArea rectangle = new RectangleArea(0d, 10d, 100d, 110d); PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId", null, rectangle, capabilities); FileUtils.copyURLToFile(getClass().getResource("FilePersister_Image.png"), file); BufferedImage expected = ImageIO.read(getClass().getResource("FilePersister_Image.png")); BufferedImage actual = persister.loadScreenshot(metadata); assertArrayEquals(toRGB(expected), toRGB(actual)); }