HdfsUtils { public static String getLastComponent(String path) { if (Strings.isNullOrEmpty(path)) { return ""; } String[] folderLayers = path.split("/"); return folderLayers[folderLayers.length - 1]; } 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 testGetJobIdTypicalCase() { Path filePath1 = new Path(Constants.TONY_CORE_SRC + "test/resources/job1"); Path filePath2 = new Path(Constants.TONY_CORE_SRC + "test/resources/app2/"); assertEquals("job1", HdfsUtils.getLastComponent(filePath1.toString())); assertEquals("app2", HdfsUtils.getLastComponent(filePath2.toString())); }
@Test public void testGetJobIdEmptyPath() { Path filePath = mock(Path.class); when(filePath.toString()).thenReturn(""); assertEquals(HdfsUtils.getLastComponent(filePath.toString()), ""); }