FilepathUtils { public static String getCanonicalForm(final String path) { final String[] fragments = getCanonicalFragments(path); if (0 == fragments.length) { if (path.startsWith(DIRECTORY_SEPARATOR)) { return DIRECTORY_SEPARATOR; } else { return path; } } final StringBuilder builder = new StringBuilder(); if (path.startsWith(DIRECTORY_SEPARATOR)) { builder.append(DIRECTORY_SEPARATOR); } for (int i = 0; i < fragments.length; ++i) { if (0 != i) { builder.append(DIRECTORY_SEPARATOR); } builder.append(fragments[i]); } return builder.toString(); }  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 testGetCanonicalForm() { final Object[][] testParameters = new Object[][] { {"/Users/tester", "/Users/tester"}, {"/Users/admin/systems", "/Users/admin/systems"}, {"./tests/./subtest1", "tests/subtest1"}, {"././tests/../subtest2", "subtest2"}}; for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[1]; String path = (String) testParameter[0]; assertEquals(expected, FilepathUtils.getCanonicalForm(path)); } }