ModuleNameUtil { public static String getDependencyPath( String moduleName, String dependency) { if (!isLocalModuleName(dependency)) { return dependency; } List<String> moduleDirNameParts = _getDirNameParts(moduleName); if (dependency.equals(StringPool.PERIOD)) { return StringUtil.merge(moduleDirNameParts, StringPool.SLASH); } if (dependency.equals("..")) { return StringUtil.merge( moduleDirNameParts.subList(0, moduleDirNameParts.size() - 1), StringPool.SLASH); } List<String> dependencyDirNameParts = _getDirNameParts(dependency); for (String dependencyDirNamePart : dependencyDirNameParts) { if (dependencyDirNamePart.equals(StringPool.PERIOD)) { continue; } if (dependencyDirNamePart.equals(StringPool.DOUBLE_PERIOD)) { if (moduleDirNameParts.isEmpty()) { throw new IllegalArgumentException( "Invalid dependency " + dependency); } moduleDirNameParts.remove(moduleDirNameParts.size() - 1); } else { moduleDirNameParts.add(dependencyDirNamePart); } } moduleDirNameParts.add(_getFileName(dependency)); return StringUtil.merge(moduleDirNameParts, StringPool.SLASH); }  static String getDependencyPath(
		String moduleName, String dependency); static String getModuleId(JSPackage jsPackage, String moduleName); static String getModuleResolvedId(
		JSPackage jsPackage, String moduleName); static String getPackageName(String moduleName); static String getPackagePath(String moduleName); static boolean isLocalModuleName(String moduleName); static boolean isReservedModuleName(String moduleName); static String toFileName(String moduleName); static String toModuleName(String fileName);  }
@Test public void testGetDependencyPath() { Assert.assertEquals( "dep", ModuleNameUtil.getDependencyPath("a-dir/a-module", "dep")); Assert.assertEquals( "dep", ModuleNameUtil.getDependencyPath("a-dir/a-module", "../dep")); Assert.assertEquals( "a-dir/dep", ModuleNameUtil.getDependencyPath("a-dir/a-module", "./dep")); Assert.assertEquals( "a-dir/dep", ModuleNameUtil.getDependencyPath( "a-dir/other-dir/a-module", "../dep")); Assert.assertEquals( "a-dir/other-dir", ModuleNameUtil.getDependencyPath("a-dir/other-dir/a-module", ".")); Assert.assertEquals( "a-dir", ModuleNameUtil.getDependencyPath("a-dir/other-dir/a-module", "..")); }
@Test(expected = IllegalArgumentException.class) public void testGetDependencyPathWithInvalidDependency() { ModuleNameUtil.getDependencyPath("a-module", "../dep"); }