ClassLoaderUtil { public static <T> Class<T> loadClass(String className) throws ClassNotFoundException { return loadClass(className, getContextClassLoader()); }  static ClassLoader getContextClassLoader(); static String getClasspath(); static Class<T> loadClass(String className); static Class<T> loadClass(String className, Class<?> referrer); static Class<T> loadClass(String className, ClassLoader classLoader); static Class<T> loadServiceClass(String serviceId); static Class<T> loadServiceClass(String serviceId, Class<?> referrer); static Class<T> loadServiceClass(String serviceId, ClassLoader classLoader); static Class<T> loadServiceClass(String className, String serviceId); static Class<T> loadServiceClass(String className, String serviceId, Class<T> referrer); static Class<T> loadServiceClass(String className, String serviceId, ClassLoader classLoader); static T newInstance(String className); static Object newInstance(String className, Class<?> referrer); static Object newInstance(String className, ClassLoader classLoader); static T newInstance(Class<T> clazz); static T newServiceInstance(String serviceId); static T newServiceInstance(String serviceId, Class<T> referrer); static T newServiceInstance(String serviceId, ClassLoader classLoader); static T newServiceInstance(String className, String serviceId); static T newServiceInstance(String className, String serviceId, Class<T> referrer); static T newServiceInstance(String className, String serviceId, ClassLoader classLoader); static URL[] getResources(String resourceName); static URL[] getResources(String resourceName, Class<?> referrer); static URL[] getResources(String resourceName, ClassLoader classLoader); static URL getResource(String resourceName); static URL getResource(String resourceName, Class<?> referrer); static URL getResource(String resourceName, ClassLoader classLoader); static InputStream getResourceAsStream(String resourceName); static InputStream getResourceAsStream(String resourceName, Class<?> referrer); static InputStream getResourceAsStream(String resourceName, ClassLoader classLoader); static URL[] whichClasses(String className); static URL[] whichClasses(String className, Class<T> referrer); static URL[] whichClasses(String className, ClassLoader classLoader); static URL whichClass(String className); static URL whichClass(String className, Class<T> referrer); static URL whichClass(String className, ClassLoader classLoader);  }
@Test public void loadClass() throws Exception { assertNull(ClassLoaderUtil.loadClass(null)); assertSame(String.class, ClassLoaderUtil.loadClass("java.lang.String")); assertNull(ClassLoaderUtil.loadClass(null, getClass())); assertNull(ClassLoaderUtil.loadClass(null, (Class<?>) null)); assertSame(String.class, ClassLoaderUtil.loadClass("java.lang.String", getClass())); assertSame(String.class, ClassLoaderUtil.loadClass("java.lang.String", (Class<?>) null)); assertNull(ClassLoaderUtil.loadClass(null, getClass().getClassLoader())); assertNull(ClassLoaderUtil.loadClass(null, (ClassLoader) null)); assertSame(String.class, ClassLoaderUtil.loadClass("java.lang.String", getClass().getClassLoader())); assertSame(String.class, ClassLoaderUtil.loadClass("java.lang.String", (ClassLoader) null)); }