FileUtil { public static void mkdirs(final Path dir) { if (!Files.isDirectory(dir)) { try { Files.createDirectories(dir); } catch (final IOException e) { throw new FileUtilException("Unable to make directory: " + FileUtil.getCanonicalPath(dir)); } } } private  FileUtil(); static boolean delete(final Path file); static void deleteFile(final Path file); static boolean deleteDir(final Path path); static boolean deleteContents(final Path path); static long count(final Path dir); static void touch(Path file); static void mkdirs(final Path dir); static void rename(final Path src, final Path dest); static void setLastModified(final Path file, final long time); static void addFilePermision(final Path path, final PosixFilePermission... posixFilePermission); static void removeFilePermision(final Path path, final PosixFilePermission... posixFilePermission); static String getCanonicalPath(final Path file); static final int MKDIR_RETRY_COUNT; static final int MKDIR_RETRY_SLEEP_MS; }
@Test void testMkdirs() throws InterruptedException { final Path rootDir = tempDir.resolve("TestFileUtil_" + System.currentTimeMillis()); final Path[] dirArray = new Path[10]; for (int i = 0; i < dirArray.length; i++) { dirArray[i] = buildDir(rootDir); } final AtomicBoolean exception = new AtomicBoolean(false); final SimpleExecutor simpleExecutor = new SimpleExecutor(4); for (int i = 0; i < 200; i++) { final int count = i; simpleExecutor.execute(() -> { try { final Path dir = dirArray[count % dirArray.length]; FileUtil.mkdirs(dir); } catch (final RuntimeException e) { e.printStackTrace(); exception.set(true); } }); } simpleExecutor.waitForComplete(); simpleExecutor.stop(false); assertThat(exception.get()).isFalse(); FileUtil.deleteDir(rootDir); }
@Test void testMkdirsUnableToCreate() { try { FileUtil.mkdirs(Paths.get("/dev/null")); fail("Not expecting that this directory can be created"); } catch (final RuntimeException e) { } }