PathHelper { public static String toAbsolute(String dirName, String path) throws InvalidRelativPathException { if (!isRelative(path)) return path; if (dirName.endsWith("/")) dirName = dirName.substring(0, dirName.length() - 1); if (!path.startsWith("../")) { if (path.startsWith("./")) path = path.substring(2); if (!path.startsWith("../")) { return dirName + "/" + path; } } assert path.startsWith("../"); final int lastSlash = dirName.lastIndexOf('/'); if (lastSlash <= 0) { if (path.startsWith("../../") || dirName.length() == 0) { throw new InvalidRelativPathException("Invalid relative path \"" + path + "\" for directory \"" + dirName + "\"."); } return (dirName.startsWith("/")) ? "/" + path.substring(3) : path .substring(3); } return toAbsolute(dirName.substring(0, lastSlash), "./" + path.substring(3)); } private  PathHelper(); static boolean isValid(final String path); static boolean isRelative(final String path); static String getParent(final String path); static String getFileName(final String path); static String getExtension(final String path); static String removeExtension(final String path); static String replaceExtension(final String path, String extension); static String toAbsolute(String dirName, String path); static String fullyQualifiedNameToDirName(
      final String fullyQualifiedName); static String packageNameToDirName(final String packageName); static String fullyQualifiedNameToAbsolute(
      final String fullyQualifiedName, final String path); static String packageNameToAbsolute(final String packageName,
      final String path); static String fullyQualifiedNameToPath(
      final String fullyQualifiedName, final String extension); static String fullyQualifiedNameToPath(
      final String fullyQualifiedName, final String suffix,
      final String extension); static final String PATH_REGEXP; }
@Test(groups = {"functional"}) public void testToAbsolute() throws Exception { assertEquals("foo/bar.txt", toAbsolute("foo", "./bar.txt")); assertEquals("foo/bar.txt", toAbsolute("foo", "bar.txt")); assertEquals("foo/bar.txt", toAbsolute("foo/", "./bar.txt")); assertEquals("foo/toto/bar.txt", toAbsolute("foo", "toto/bar.txt")); assertEquals("foo/toto/bar.txt", toAbsolute("foo", "./toto/bar.txt")); assertEquals("foo/toto/bar.txt", toAbsolute("foo/toto", "bar.txt")); assertEquals("foo/toto/bar.txt", toAbsolute("foo/toto", "./bar.txt")); assertEquals("foo/titi/bar.txt", toAbsolute("foo/toto", "../titi/bar.txt")); assertEquals("bar.txt", toAbsolute("foo/", "../bar.txt")); assertEquals("bar.txt", toAbsolute("foo/", "./../bar.txt")); assertEquals("toto/bar.txt", toAbsolute("foo/", "../toto/bar.txt")); assertEquals("toto/bar.txt", toAbsolute("foo/", "./../toto/bar.txt")); assertEquals("toto/bar.txt", toAbsolute("foo/titi", "../../toto/bar.txt")); testFaultyToAbsolute("foo", "../../bar.txt"); testFaultyToAbsolute("foo", "./../../bar.txt"); testFaultyToAbsolute("/", "../bar.txt"); testFaultyToAbsolute("", "../bar.txt"); }