ClassLoaderUtil { public static URL[] whichClasses(String className) { return getResources(ClassUtil.getClassNameAsResource(className)); }  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 whichClasses() throws Exception { assertEquals(0, ClassLoaderUtil.whichClasses(null).length); assertEquals(0, ClassLoaderUtil.whichClasses("aaa.NotExistClass").length); URL[] urls = ClassLoaderUtil.whichClasses("java.lang.String"); assertUnique(urls); assertEquals(0, ClassLoaderUtil.whichClasses(null, getClass()).length); assertEquals(0, ClassLoaderUtil.whichClasses(null, (Class<?>) null).length); assertEquals(0, ClassLoaderUtil.whichClasses("aaa.NotExistClass", getClass()).length); assertEquals(0, ClassLoaderUtil.whichClasses("aaa.NotExistClass", (Class<?>) null).length); urls = ClassLoaderUtil.whichClasses("java.lang.String", getClass()); assertUnique(urls); urls = ClassLoaderUtil.whichClasses("java.lang.String", (Class<?>) null); assertUnique(urls); assertEquals(0, ClassLoaderUtil.whichClasses(null, getClass().getClassLoader()).length); assertEquals(0, ClassLoaderUtil.whichClasses(null, (ClassLoader) null).length); assertEquals(0, ClassLoaderUtil.whichClasses("aaa.NotExistClass", getClass().getClassLoader()).length); assertEquals(0, ClassLoaderUtil.whichClasses("aaa.NotExistClass", (ClassLoader) null).length); urls = ClassLoaderUtil.whichClasses("java.lang.String", getClass().getClassLoader()); assertUnique(urls); urls = ClassLoaderUtil.whichClasses("java.lang.String", (ClassLoader) null); assertUnique(urls); }