MakeDirectory { public boolean converge(TaskContext context) { boolean systemModified = false; Optional<FileAttributes> attributes = attributesCache.forceGet(); if (attributes.isPresent()) { if (!attributes.get().isDirectory()) { throw new UncheckedIOException(new NotDirectoryException(path.toString())); } } else { if (createParents) { path.createParents(); } context.recordSystemModification(logger, "Creating directory " + path); systemModified = true; Optional<String> permissions = attributeSync.getPermissions(); if (permissions.isPresent()) { path.createDirectory(permissions.get()); } else { path.createDirectory(); } } systemModified |= attributeSync.converge(context, attributesCache); return systemModified; } MakeDirectory(Path path); MakeDirectory createParents(); MakeDirectory withOwner(String owner); MakeDirectory withGroup(String group); MakeDirectory withPermissions(String permissions); boolean converge(TaskContext context);  }
@Test public void exceptionIfMissingParent() { String path = "/parent/dir"; MakeDirectory makeDirectory = new MakeDirectory(fileSystem.getPath(path)); try { makeDirectory.converge(context); } catch (UncheckedIOException e) { if (e.getCause() instanceof NoSuchFileException) { return; } throw e; } fail(); }
@Test public void okIfParentExists() { String path = "/dir"; MakeDirectory makeDirectory = new MakeDirectory(fileSystem.getPath(path)); assertTrue(makeDirectory.converge(context)); assertTrue(Files.isDirectory(fileSystem.getPath(path))); MakeDirectory makeDirectory2 = new MakeDirectory(fileSystem.getPath(path)); assertFalse(makeDirectory2.converge(context)); }