FilepathUtils { public static String getParentPath(final String path) { if (null == path) { return null; } if (EMPTY_STRING.equals(path) || DIRECTORY_SEPARATOR.equals(path)) { return null; } final int index = path.lastIndexOf(DIRECTORY_SEPARATOR); if (0 == index) { return DIRECTORY_SEPARATOR; } else if (index < 0) { return null; } return path.substring(0, index); }  static String[] getCanonicalFragments(final String path); static String getCanonicalForm(final String path); static String[] split(final String path); static String getParentPath(final String path); static String getFilename(final String path); static String concat(final String... fragments); static String append(final String... fragments); static String append(final String[] fragments, final int start, final int end);  }
@Test public void testGetParentPath() { final Object[][] testParameters = new Object[][] {{"/tester", "/"}, {"/Users/tester", "/Users"}, {"/Users/admin/systems", "/Users/admin"}}; assertNull(FilepathUtils.getParentPath(null)); assertNull(FilepathUtils.getParentPath("")); assertNull(FilepathUtils.getParentPath("/")); assertNull(FilepathUtils.getParentPath(" ")); for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[1]; String path = (String) testParameter[0]; assertEquals(expected, FilepathUtils.getParentPath(path)); } }