### Question:
StorageStrategy { public Path createPathAndApply(FileSystem fs, Path path) throws IOException { List<Path> locations = getNonExistentLocations(fs, path); if (locations.isEmpty()) { return null; } fs.mkdirs(path); for (Path location : locations) { applyStrategy(fs, location, getFolderPermission(), deleteOnExit); } return locations.get(locations.size() - 1); } @JsonCreator  StorageStrategy(@JsonProperty("umask") String umask,
                         @JsonProperty("deleteOnExit") boolean deleteOnExit); String getUmask(); boolean isDeleteOnExit(); @JsonIgnore FsPermission getFolderPermission(); @JsonIgnore FsPermission getFilePermission(); Path createPathAndApply(FileSystem fs, Path path); Path createFileAndApply(FileSystem fs, Path file); void applyToFile(FileSystem fs, Path file); static final StorageStrategy DEFAULT; static final StorageStrategy TEMPORARY; }### Answer:
@Test public void testCreatePathAndDeleteOnExitFalse() throws Exception { Path initialPath = prepareStorageDirectory(); Path resultPath = addNLevelsAndFile(initialPath, 2, false); Path firstCreatedParentPath = addNLevelsAndFile(initialPath, 1, false); Path createdParentPath = PERSISTENT_STRATEGY.createPathAndApply(fs, resultPath); assertEquals("Path should match", firstCreatedParentPath, createdParentPath); checkPathAndPermission(initialPath, resultPath, false, 2, PERSISTENT_STRATEGY); checkDeleteOnExit(firstCreatedParentPath, false); }
@Test public void testCreatePathAndDeleteOnExitTrue() throws Exception { Path initialPath = prepareStorageDirectory(); Path resultPath = addNLevelsAndFile(initialPath, 2, false); Path firstCreatedParentPath = addNLevelsAndFile(initialPath, 1, false); Path createdParentPath = TEMPORARY_STRATEGY.createPathAndApply(fs, resultPath); assertEquals("Path should match", firstCreatedParentPath, createdParentPath); checkPathAndPermission(initialPath, resultPath, false, 2, TEMPORARY_STRATEGY); checkDeleteOnExit(firstCreatedParentPath, true); }
@Test public void testCreateNoPath() throws Exception { Path path = prepareStorageDirectory(); Path createdParentPath = TEMPORARY_STRATEGY.createPathAndApply(fs, path); assertNull("Path should be null", createdParentPath); assertEquals("Permission should match", FULL_PERMISSION, fs.getFileStatus(path).getPermission()); }