/** * Schedules the saving of game preview screenshot. * * @param saveDirPath to save folder */ public void takeGamePreview(final Path saveDirPath) { this.savingGamePreview = true; this.savedGamePath = GamePreviewImageProvider.getNextGamePreviewImagePath(saveDirPath); this.saveScreenshot(); } }
@Test public void getNextGamePreviewImagePathNotEmptyFolderTest() throws IOException { Files.createDirectories(TMP_PREVIEWS_FOLDER); Files.createFile(TMP_PREVIEWS_FOLDER.resolve(DEFAULT_IMAGE_NAME)); final Path imagePath = GamePreviewImageProvider.getNextGamePreviewImagePath(TMP_FOLDER); Assert.assertNotNull(imagePath); Assert.assertEquals(TMP_PREVIEWS_FOLDER.resolve("2.jpg"), imagePath); }
@Test public void getNextGamePreviewImagePathOldestFileTest() throws IOException, InterruptedException { Files.createDirectories(TMP_PREVIEWS_FOLDER); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("1.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("2.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("3.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("4.jpg")); Files.createFile(TMP_PREVIEWS_FOLDER.resolve("5.jpg")); final Path expectedOldestFile = TMP_PREVIEWS_FOLDER.resolve("3.jpg"); Files.setLastModifiedTime(expectedOldestFile, FileTime.fromMillis(0)); final Path imagePath = GamePreviewImageProvider.getNextGamePreviewImagePath(TMP_FOLDER); Assert.assertNotNull(imagePath); Assert.assertEquals(expectedOldestFile, imagePath); } }
@Test public void getNextGamePreviewImagePathEmptyFolderTest() { final Path imagePath = GamePreviewImageProvider.getNextGamePreviewImagePath(TMP_FOLDER); Assert.assertNotNull(imagePath); Assert.assertEquals(TMP_PREVIEWS_FOLDER.resolve(DEFAULT_IMAGE_NAME), imagePath); }