ReflectHelpers { public static ClassLoader findClassLoader(final ClassLoader proposed) { ClassLoader classLoader = proposed; if (classLoader == null) { classLoader = ReflectHelpers.class.getClassLoader(); } if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } return classLoader; }  static String formatMethod(Method input); static String formatMethodWithClass(Method input); static String formatAnnotation(Annotation annotation); static String simpleTypeDescription(Type input); static Iterable<Method> getClosureOfMethodsOnInterfaces(
      Iterable<? extends Class<?>> interfaces); static Iterable<Method> getClosureOfMethodsOnInterface(Class<?> iface); static Iterable<T> loadServicesOrdered(Class<T> iface, ClassLoader classLoader); static Iterable<T> loadServicesOrdered(Class<T> iface); static ClassLoader findClassLoader(final ClassLoader proposed); static ClassLoader findClassLoader(final Class<?>... classes); static ClassLoader findClassLoader();  }
@Test public void testFindProperClassLoaderIfContextClassLoaderIsNull() throws InterruptedException { final ClassLoader[] classLoader = new ClassLoader[1]; Thread thread = new Thread(() -> classLoader[0] = ReflectHelpers.findClassLoader()); thread.setContextClassLoader(null); thread.start(); thread.join(); assertEquals(ReflectHelpers.class.getClassLoader(), classLoader[0]); }
@Test public void testFindProperClassLoaderIfContextClassLoaderIsAvailable() throws InterruptedException { final ClassLoader[] classLoader = new ClassLoader[1]; Thread thread = new Thread(() -> classLoader[0] = ReflectHelpers.findClassLoader()); ClassLoader cl = new ClassLoader() {}; thread.setContextClassLoader(cl); thread.start(); thread.join(); assertEquals(cl, classLoader[0]); }