Best Powermock code snippet using org.powermock.reflect.internal.proxy.ProxyFrameworksTest.assertThatOriginalTypeInstanceOf
Source:ProxyFrameworksTest.java
...19 @Test20 public void should_return_original_class_if_object_not_proxy() throws Exception {21 SomeClass someClass = new SomeClass();22 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someClass);23 assertThatOriginalTypeInstanceOf(unproxiedType, SomeClass.class);24 }25 @Test26 public void should_return_original_class_if_proxy_created_with_java() {27 SomeInterface someInterface = createJavaProxy(new Class[]{ SomeInterface.class });28 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someInterface);29 assertThatOriginalTypeInstanceOf(unproxiedType, SomeInterface.class);30 }31 @Test32 public void should_return_original_class_if_proxy_created_with_cglib() {33 SomeClass someClass = ((SomeClass) (createCglibProxy(SomeClass.class)));34 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someClass);35 assertThatOriginalTypeInstanceOf(unproxiedType, SomeClass.class);36 }37 @Test38 public void should_not_detect_synthetic_classes_as_cglib_proxy() throws Exception {39 final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();40 final Enumeration<URL> resources = classLoader.getResources("org/powermock/reflect/internal/proxy");41 final List<URL> urls = new ArrayList<URL>();42 while (resources.hasMoreElements()) {43 urls.add(resources.nextElement());44 } 45 String className = "Some$$SyntheticClass$$Lambda";46 byte[] bytes = ClassFactory.create(className);47 ProxyFrameworksTest.CustomClassLoader customClassLoader = new ProxyFrameworksTest.CustomClassLoader(urls.toArray(new URL[urls.size()]), classLoader);48 Class<?> defineClass = customClassLoader.defineClass(className, bytes);49 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(defineClass.newInstance());50 assertThatOriginalTypeInstanceOf(unproxiedType, defineClass);51 }52 @Test53 public void should_return_object_as_original_class_if_no_non_no_mocking_interfaces() {54 Factory someClass = ((Factory) (createCglibProxy(Factory.class)));55 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someClass);56 assertThatOriginalTypeInstanceOf(unproxiedType, Object.class);57 }58 @Test59 public void should_return_interface_as_original_type_if_only_one_non_mocking_interface() {60 Factory someClass = ((Factory) (createCglibProxy(Factory.class, SomeInterface.class)));61 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someClass);62 assertThatOriginalTypeInstanceOf(unproxiedType, SomeInterface.class);63 }64 @Test65 public void should_return_interface_and_original_type_if_proxy_has_interface_and_superclass() {66 SomeClass someClass = ((SomeClass) (createCglibProxy(SomeClass.class, SomeInterface.class, AnotherInterface.class)));67 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someClass);68 assertThatOriginalTypeInstanceOfAndInterfaces(unproxiedType, SomeClass.class, new Class[]{ SomeInterface.class, AnotherInterface.class });69 }70 @Test71 public void should_return_interfaces_if_proxy_create_from_several_interfaces() {72 Class[] interfaces = new Class[]{ SomeInterface.class, AnotherInterface.class };73 SomeInterface someInterface = createJavaProxy(interfaces);74 UnproxiedType unproxiedType = proxyFrameworks.getUnproxiedType(someInterface);75 assertThatOriginalIsNullAndInterfaces(unproxiedType, interfaces);76 }77 private static class CustomClassLoader extends URLClassLoader {78 private CustomClassLoader(URL[] urls, ClassLoader parent) {79 super(urls, parent);80 }81 Class<?> defineClass(String name, byte[] b) {82 return defineClass(name, b, 0, b.length);...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!