### Question:
Packr { void verifyEmptyOrCreateOutputFolder (PackrOutput output) throws IOException { Path outputPath = output.executableFolder.toPath(); if (Files.exists(outputPath)) { if (!Files.isDirectory(outputPath)) { System.err.println("Output directory \"" + outputPath + "\" must be a directory."); throw new IOException("Output directory \"" + outputPath + "\" is not a directory."); } try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(outputPath)) { if (dirStream.iterator().hasNext()) { System.err.println("Output directory \"" + outputPath + "\" must be empty."); throw new IOException("Output directory \"" + outputPath + "\" is not empty."); } } } Files.createDirectories(outputPath); }  static void main(String[] args); @SuppressWarnings("unused") Packr setRemovePlatformLibsFileFilter(Predicate<File> filter); @SuppressWarnings("WeakerAccess") void pack(PackrConfig config); static final String JRE_RELATIVE_PATH_NAME; }### Answer:
@Test void verifyEmptyOrCreateOutputFolderCreated (@TempDir Path tempDirectoryPath) throws IOException { Packr packr = new Packr(); Path outputPath = tempDirectoryPath.resolve("output"); PackrOutput packrOutput = new PackrOutput(outputPath.toFile(), outputPath.toFile()); packr.verifyEmptyOrCreateOutputFolder(packrOutput); assertTrue(Files.exists(outputPath)); }
@Test void verifyEmptyOrCreateOutputFolderEmpty (@TempDir Path tempDirectoryPath) throws IOException { Packr packr = new Packr(); Path outputPath = tempDirectoryPath.resolve("output"); Files.createDirectories(outputPath); PackrOutput packrOutput = new PackrOutput(outputPath.toFile(), outputPath.toFile()); packr.verifyEmptyOrCreateOutputFolder(packrOutput); assertTrue(Files.exists(outputPath)); try (Stream<Path> walk = Files.walk(outputPath, 1)) { assertEquals(walk.count(), 1); } }
@Test void verifyEmptyOrCreateOutputFolderThrowsNotEmpty (@TempDir Path tempDirectoryPath) throws IOException { Packr packr = new Packr(); Path outputPath = tempDirectoryPath.resolve("output"); Files.createDirectories(outputPath); Path someFileThatIsInOutputDir = outputPath.resolve("someFile.txt"); Files.write(someFileThatIsInOutputDir, "Hello world!".getBytes(StandardCharsets.UTF_8)); PackrOutput packrOutput = new PackrOutput(outputPath.toFile(), outputPath.toFile()); try { packr.verifyEmptyOrCreateOutputFolder(packrOutput); } catch (IOException exception) { assertTrue(exception.getMessage().contains("is not empty")); return; } fail("Should have thrown a not empty exception"); }
@Test void verifyEmptyOrCreateOutputFolderThrowsIsFile (@TempDir Path tempDirectoryPath) throws IOException { Packr packr = new Packr(); Path outputPath = tempDirectoryPath.resolve("output"); Files.write(outputPath, "Hello world!".getBytes(StandardCharsets.UTF_8)); PackrOutput packrOutput = new PackrOutput(outputPath.toFile(), outputPath.toFile()); try { packr.verifyEmptyOrCreateOutputFolder(packrOutput); } catch (IOException exception) { assertTrue(exception.getMessage().contains("is not a directory")); return; } fail("Should have thrown a not empty exception"); }