RegistryPathUtils { public static String parentOf(String path) throws PathNotFoundException { List<String> elements = split(path); int size = elements.size(); if (size == 0) { throw new PathNotFoundException("No parent of " + path); } if (size == 1) { return "/"; } elements.remove(size - 1); StringBuilder parent = new StringBuilder(path.length()); for (String element : elements) { parent.append("/"); parent.append(element); } return parent.toString(); }  static String validateZKPath(String path); static String validateElementsAsDNS(String path); static String createFullPath(String base, String path); static String join(String base, String path); static List<String> split(String path); static String lastPathEntry(String path); static String parentOf(String path); static String encodeForRegistry(String element); static String encodeYarnID(String yarnId); static String getUsername(String recPath);  }
@Test public void testParentOf() throws Throwable { assertEquals("/", parentOf("/a")); assertEquals("/", parentOf("/a/")); assertEquals("/a", parentOf("/a/b")); assertEquals("/a/b", parentOf("/a/b/c")); }
@Test(expected = PathNotFoundException.class) public void testParentOfRoot() throws Throwable { parentOf("/"); }