Strings { public static String getParent(String path) { String result = path; if (!isNullOrEmpty(path)) { if (!"/".equals(path)) { int lastSlash = path.lastIndexOf('/', path.length()); if (lastSlash != INDEX_NOT_FOUND) { if (lastSlash == 0) { result = path.substring(0, 1); } else { result = path.substring(0, lastSlash); } } else { result = null; } } } return result; } private  Strings(); static String abbreviate(String str, int offset, int maxWidth); static String abbreviateMiddle(String string, int maxLength); static String abbreviateFqClassName(String fqcn); static String capitalize(String str); static String substringAfterLast(String str, String separator); static String strip(String str, String stripChars); static String stripStart(String str, String stripChars); static String stripEnd(String str, String stripChars); static String getParent(String path); static String getDomain(String url); static String sanitize(String str);  }
@Test public void getParent() throws Exception { assertNull(Strings.getParent(null)); assertEquals("", Strings.getParent("")); assertNull(Strings.getParent("a")); assertEquals("/", Strings.getParent("/")); assertEquals("/", Strings.getParent("/a")); assertEquals("/a", Strings.getParent("/a/b")); assertEquals("/a/b", Strings.getParent("/a/b/c")); assertEquals("/a", Strings.getParent(Strings.getParent("/a/b/c"))); assertEquals("a", Strings.getParent("a/b")); assertEquals("a/b", Strings.getParent("a/b/c")); assertEquals("a", Strings.getParent(Strings.getParent("a/b/c"))); }