### Question:
ModuleNameUtil { public static String getPackageName(String moduleName) { if (isLocalModuleName(moduleName)) { return null; } if (isReservedModuleName(moduleName)) { return null; } int i = moduleName.indexOf(StringPool.SLASH); if ((moduleName.charAt(0) == CharPool.AT) && (i != -1)) { i = moduleName.indexOf(StringPool.SLASH, i + 1); } if (i == -1) { return moduleName; } return moduleName.substring(0, i); }  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);  }### Answer:
@Test public void testGetPackageName() { Assert.assertEquals( "a-package", ModuleNameUtil.getPackageName("a-package")); Assert.assertEquals( "a-package", ModuleNameUtil.getPackageName("a-package/a-folder/a-module")); Assert.assertEquals( "a-package", ModuleNameUtil.getPackageName("a-package/a-folder/a-module.js")); Assert.assertNull(ModuleNameUtil.getPackageName("./a-module")); }
@Test public void testGetPackageNameNoModule() throws Exception { Assert.assertEquals( "mypackage", ModuleNameUtil.getPackageName("mypackage")); }
@Test public void testGetPackageNameScoped() throws Exception { String packageName = ModuleNameUtil.getPackageName( "@myscope/mypackage/lib/mymodule"); Assert.assertEquals("@myscope/mypackage", packageName); }
@Test public void testGetPackageNameScopedNoModule() throws Exception { String packageName = ModuleNameUtil.getPackageName( "@myscope/mypackage"); Assert.assertEquals("@myscope/mypackage", packageName); }