### Question:
ProxyTypeInspector { public static Class<?>[] getCompatibleClassHierarchy(ClassLoader loader, Class<?> origin) { Set<Class<?>> hierarchy = new LinkedHashSet<Class<?>>(); Class<?> baseClass = origin; while (baseClass != null && Modifier.isFinal(baseClass.getModifiers())) { baseClass = baseClass.getSuperclass(); } while (baseClass != null && !baseClass.isInterface() && baseClass.getSuperclass() != null && !baseClass.getSuperclass().equals(Object.class) && !Proxies.isInstantiable(baseClass)) { baseClass = baseClass.getSuperclass(); } if (baseClass != null && ClassLoaders.containsClass(loader, baseClass.getName()) && !Object.class.equals(baseClass) && (Proxies.isInstantiable(baseClass) || baseClass.isInterface())) { hierarchy.add(ClassLoaders.loadClass(loader, baseClass)); } baseClass = origin; while (baseClass != null) { for (Class<?> type : baseClass.getInterfaces()) { if (ClassLoaders.containsClass(loader, type.getName())) hierarchy.add(ClassLoaders.loadClass(loader, type)); else hierarchy.addAll(java.util.Arrays.asList(getCompatibleClassHierarchy(loader, type))); } baseClass = baseClass.getSuperclass(); } return hierarchy.toArray(new Class<?>[hierarchy.size()]); }  static Class<?>[] getCompatibleClassHierarchy(ClassLoader loader, Class<?> origin); static boolean superclassHierarchyContains(Class<?> haystack, Class<?> needle);  }### Answer:
@Test public void testExceptionHierarchyFindsThrowable() throws Exception { Class<?>[] hierarchy = ProxyTypeInspector.getCompatibleClassHierarchy(getClass().getClassLoader(), MockException.class); Assert.assertEquals(2, hierarchy.length); Assert.assertEquals(Exception.class, hierarchy[0]); Assert.assertEquals(Serializable.class, hierarchy[1]); }
@Test public void testClassWithInstantiableBaseClass() throws Exception { Class<?>[] hierarchy = ProxyTypeInspector.getCompatibleClassHierarchy(getClass().getClassLoader(), MockExtendsImplementsExternal.class); Assert.assertEquals(MockBaseClassExternal.class, hierarchy[0]); Assert.assertEquals(MockInterface.class, hierarchy[1]); Assert.assertEquals(MockNestedInterface.class, hierarchy[2]); }
@Test public void testInnerClassWithNonInstantiableBaseClass() throws Exception { Class<?>[] hierarchy = ProxyTypeInspector.getCompatibleClassHierarchy(getClass().getClassLoader(), MockExtendsImplementsInternal.class); Assert.assertEquals(MockInterface.class, hierarchy[0]); Assert.assertEquals(MockNestedInterface.class, hierarchy[1]); }