@Test public void should_not_detect_synthetic_classes_as_cglib_proxy() throws Exception { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final Enumeration<URL> resources = classLoader.getResources("org/powermock/reflect/internal/proxy"); final List<URL> urls = new ArrayList<URL>(); while (resources.hasMoreElements()) { urls.add(resources.nextElement()); } String className = "Some$$SyntheticClass$$Lambda"; byte[] bytes = ClassFactory.create(className); CustomClassLoader customClassLoader = new CustomClassLoader(urls.toArray(new URL[urls.size()]), classLoader); Class<?> defineClass = customClassLoader.defineClass(className, bytes); UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(defineClass.newInstance()); assertThatOriginalTypeInstanceOf(unproxiedType, defineClass); }
public UnproxiedType getUnproxiedType(Class<?> type) { if (type == null){ return null; } if (isJavaProxy(type)){ return UNPROXIED_TYPE_FACTORY.createFromInterfaces(type.getInterfaces()); } if (isCglibProxyClass(type)) { return UNPROXIED_TYPE_FACTORY.createFromSuperclassAndInterfaces(type.getSuperclass(), type.getInterfaces()); } return UNPROXIED_TYPE_FACTORY.createFromType(type); }
ProxyFrameworks { public UnproxiedType getUnproxiedType(Class<?> type) { if (type == null){ return null; } if (isJavaProxy(type)){ return UNPROXIED_TYPE_FACTORY.createFromInterfaces(type.getInterfaces()); } if (isCglibProxyClass(type)) { return UNPROXIED_TYPE_FACTORY.createFromSuperclassAndInterfaces(type.getSuperclass(), type.getInterfaces()); } return UNPROXIED_TYPE_FACTORY.createFromType(type); } }
ProxyFrameworks { public UnproxiedType getUnproxiedType(Class<?> type) { if (type == null){ return null; } if (isJavaProxy(type)){ return UNPROXIED_TYPE_FACTORY.createFromInterfaces(type.getInterfaces()); } if (isCglibProxyClass(type)) { return UNPROXIED_TYPE_FACTORY.createFromSuperclassAndInterfaces(type.getSuperclass(), type.getInterfaces()); } return UNPROXIED_TYPE_FACTORY.createFromType(type); }  }
ProxyFrameworks { public UnproxiedType getUnproxiedType(Class<?> type) { if (type == null){ return null; } if (isJavaProxy(type)){ return UNPROXIED_TYPE_FACTORY.createFromInterfaces(type.getInterfaces()); } if (isCglibProxyClass(type)) { return UNPROXIED_TYPE_FACTORY.createFromSuperclassAndInterfaces(type.getSuperclass(), type.getInterfaces()); } return UNPROXIED_TYPE_FACTORY.createFromType(type); }  UnproxiedType getUnproxiedType(Class<?> type); UnproxiedType getUnproxiedType(Object o); }
ProxyFrameworks { public UnproxiedType getUnproxiedType(Class<?> type) { if (type == null){ return null; } if (isJavaProxy(type)){ return UNPROXIED_TYPE_FACTORY.createFromInterfaces(type.getInterfaces()); } if (isCglibProxyClass(type)) { return UNPROXIED_TYPE_FACTORY.createFromSuperclassAndInterfaces(type.getSuperclass(), type.getInterfaces()); } return UNPROXIED_TYPE_FACTORY.createFromType(type); }  UnproxiedType getUnproxiedType(Class<?> type); UnproxiedType getUnproxiedType(Object o);  }