HdfsUtils { public static boolean pathExists(FileSystem fs, Path filePath) { try { return fs.exists(filePath); } catch (IOException e) { LOG.error("Error when reading " + filePath.toString(), e); return false; } } private  HdfsUtils(); static boolean pathExists(FileSystem fs, Path filePath); static String contentOfHdfsFile(FileSystem fs, Path filePath); static String getLastComponent(String path); @VisibleForTesting static boolean isJobFolder(Path p, String regex); static List<FileStatus> getDirectories(FileSystem fs, Path path); static Path getJobDirPath(FileSystem fs, Path curr, String applicationId); static List<Path> getJobDirs(FileSystem fs, Path curr, String regex); static void copySrcToDest(Path src, Path dst, Configuration conf);  }
@Test public void testPathExistsTrue() { Path exists = new Path(Constants.TONY_CORE_SRC + "test/resources/file.txt"); assertTrue(HdfsUtils.pathExists(fs, exists)); }
@Test public void testPathExistsFalse() { Path invalidPath = new Path("/invalid/path"); assertFalse(HdfsUtils.pathExists(fs, invalidPath)); }
@Test public void testPathExistsThrowsException() throws IOException { FileSystem mockFs = mock(FileSystem.class); Path invalidPath = new Path("/invalid/path"); when(mockFs.exists(invalidPath)).thenThrow(new IOException("IO Excpt")); assertFalse(HdfsUtils.pathExists(mockFs, invalidPath)); }