### Question:
ScreenshotActions { public Path resolveTakeScreenshotPath(String filename) { Path path = Paths.get(filename); if (path.isAbsolute()) { return path; } TestCase currentTestCase = baseActionLoader.getCurrentTestCase(); Path folderPath = currentTestCase != null ? currentTestCase.getTcFile().getParent() : null; if (folderPath == null || !Files.exists(folderPath)) { LOGGER.warn("The test case folder could not be found => Fallback: Use test suite folder!"); folderPath = baseActionLoader.getTestSuite().getTestSuiteFolder(); } return folderPath.resolve(filename); } @Autowired  ScreenshotActions(Screen screen, ActionProperties props, @Qualifier("baseLoader") BaseActionLoader baseActionLoader); Path takeScreenshot(Path picturePath); Path takeScreenshot(String filename, Rectangle rectangle); Path takeScreenshot(Path picturePath, Rectangle rectangle); Path takeScreenshotWithTimestamp(final String filenamePostfix, final String optFolderPath, final String optFormat, Rectangle optRectangle); Path takeScreenshotWithTimestamp(String message, Path folderPath); Path takeScreenshotWithTimestamp(String message, Path folderPath, String format, Rectangle rectangle); Path takeScreenshotWithTimestampThrowIOException(String message, Path folderPath, String format, Rectangle rectangle); Path resolveTakeScreenshotPath(String filename);  }### Answer:
@Test public void testResolveTakeScreenshotFolder() throws Exception { TestCase tc = mock(TestCase.class); Path examplePath = Paths.get(BaseTest.TEST_FOLDER_PATH + File.separator + "case" + File.separator + "tc.js"); when(tc.getTcFile()).thenReturn(examplePath); when(loader.getCurrentTestCase()).thenReturn(tc); Path result = testling.resolveTakeScreenshotPath("screenshot.png"); assertEquals(result.toString(), BaseTest.TEST_FOLDER_PATH + File.separator + "case" + File.separator + "screenshot.png"); verify(loader, never()).getTestSuite(); verify(loader).getCurrentTestCase(); }
@Test public void testResolveTakeScreenshotFolderFallback() throws Exception { TestCase tc = mock(TestCase.class); Path examplePath = Paths.get(BaseTest.TEST_FOLDER_PATH + File.separator + "NO_FOLDER" + File.separator + "tc.js"); when(tc.getTcFile()).thenReturn(examplePath); when(loader.getCurrentTestCase()).thenReturn(tc); TestSuite ts = mock(TestSuite.class); when(ts.getTestSuiteFolder()).thenReturn(Paths.get(BaseTest.TEST_FOLDER_PATH)); when(loader.getTestSuite()).thenReturn(ts); Path result = testling.resolveTakeScreenshotPath("test"); assertEquals(result.toString(), Paths.get(BaseTest.TEST_FOLDER_PATH) + File.separator + "test"); verify(loader).getTestSuite(); verify(loader).getCurrentTestCase(); }
@Test public void testResolveTakeScreenshotFolderAbsolutPath() throws Exception { String filename = Settings.isWindows() ? "C:\\test" : "/home/test"; Path result = testling.resolveTakeScreenshotPath(filename); assertEquals(result.toString(), filename); verify(loader, never()).getTestSuite(); verify(loader, never()).getCurrentTestCase(); }