@Test public void ensureCreatedDirectoryExists() throws IOException { FileSystem fsMock = mock(FileSystem.class); Path path = new Path("existing"); when(fsMock.exists(any(Path.class))).thenReturn(false); when(fsMock.mkdirs(any(Path.class))).thenReturn(true); FileSystemUtils.ensureDirectoriesExist(Collections.singleton(new Path("existing")), fsMock); verify(fsMock, times(1)).exists(path); verify(fsMock, times(1)).mkdirs(path); }
public static boolean ensureDirectoriesExist(Collection<Path> dirs, FileSystem fs) throws IOException { boolean created = false; for (Path dir : dirs) { if (!fs.exists(dir)) { created = fs.mkdirs(dir); if (!created) throw new IOException(String.format("Couldn't create %s (no specific reason)", dir.toUri())); } } return created; }
FileSystemUtils { public static boolean ensureDirectoriesExist(Collection<Path> dirs, FileSystem fs) throws IOException { boolean created = false; for (Path dir : dirs) { if (!fs.exists(dir)) { created = fs.mkdirs(dir); if (!created) throw new IOException(String.format("Couldn't create %s (no specific reason)", dir.toUri())); } } return created; } }
FileSystemUtils { public static boolean ensureDirectoriesExist(Collection<Path> dirs, FileSystem fs) throws IOException { boolean created = false; for (Path dir : dirs) { if (!fs.exists(dir)) { created = fs.mkdirs(dir); if (!created) throw new IOException(String.format("Couldn't create %s (no specific reason)", dir.toUri())); } } return created; } private  FileSystemUtils(); }
FileSystemUtils { public static boolean ensureDirectoriesExist(Collection<Path> dirs, FileSystem fs) throws IOException { boolean created = false; for (Path dir : dirs) { if (!fs.exists(dir)) { created = fs.mkdirs(dir); if (!created) throw new IOException(String.format("Couldn't create %s (no specific reason)", dir.toUri())); } } return created; } private  FileSystemUtils(); static boolean ensureDirectoriesExist(Collection<Path> dirs, FileSystem fs); }
FileSystemUtils { public static boolean ensureDirectoriesExist(Collection<Path> dirs, FileSystem fs) throws IOException { boolean created = false; for (Path dir : dirs) { if (!fs.exists(dir)) { created = fs.mkdirs(dir); if (!created) throw new IOException(String.format("Couldn't create %s (no specific reason)", dir.toUri())); } } return created; } private  FileSystemUtils(); static boolean ensureDirectoriesExist(Collection<Path> dirs, FileSystem fs);  }