JavaLibrary { public static String packageName(String qualifiedClassName) { int lastPackageSeparator = qualifiedClassName.lastIndexOf('.'); if (lastPackageSeparator > -1) { return qualifiedClassName.substring(0, lastPackageSeparator); } return ""; }  static String asClasspath(URL[] urls); static String[] asFilePath(URL[] urls); static String simpleClassName(String qualifiedClassName); static String packageName(String qualifiedClassName); static String systemClasspath(); static URL[] systemClasspathURLs(); static void extendSystemClasspathWith(URL[] classpaths); static URL[] extendClasspathWith(String classpath, URL[] destination); static URL[] classpathFrom(String classpath); static void setClasspath(String newClasspath); static void extendSystemClassLoaderClasspathWith(URL[] classpaths); static void extendClassLoaderClasspathWith(URLClassLoader classLoader, URL[] classpaths); static Class<?> classFromClasspath(URL classpath, String qualifiedName); static List<Class<?>> classesFromClasspath(URL[] classpath, Collection<String> qualifiedNames); static List<Class<?>> loadedClassesFrom(ClassLoader classLoader, Collection<String> qualifiedNames); static void close(URLClassLoader loader); static Character classpathSeparator(); static Character folderPathSeparator(); static String lineSeparator();  }
@Test public void packageNameFromQualifiedName() { assertEquals("", packageName("")); assertEquals("", packageName("HelloWorld")); assertEquals("", packageName("HelloWorld$Greeting")); assertEquals("java", packageName("java.HelloWorld")); assertEquals("java.api", packageName("java.api.HelloWorld")); assertEquals("java.api", packageName("java.api.HelloWorld$Greeting")); assertEquals("", packageName(Inner.class.getSimpleName())); assertEquals(getClass().getPackage().toString(), "package " + packageName(Inner.class.getName())); assertEquals("", packageName(Inner.NestedInner.class.getSimpleName())); assertEquals(getClass().getPackage().toString(), "package " + packageName(Inner.NestedInner.class.getName())); }