Search in sources :

Example 1 with ReflectionMethodInvoker

use of powermock.classloading.classes.ReflectionMethodInvoker in project powermock by powermock.

the class XStreamClassloaderExecutorTest method worksWithReflection.

@Test
public void worksWithReflection() throws Exception {
    final MockClassLoader classloader = createClassloader();
    final MyArgument myArgument = new MyArgument("test");
    final MyReturnValue instance = new MyReturnValue(myArgument);
    Method method = instance.getClass().getMethod("getMyArgument");
    final ReflectionMethodInvoker tested = new ReflectionMethodInvoker(method, instance);
    new SingleClassloaderExecutor(classloader).execute(new Runnable() {

        public void run() {
            Object invoke = tested.invoke();
            assertSame(invoke, myArgument);
        }
    });
}
Also used : MyArgument(powermock.classloading.classes.MyArgument) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) Method(java.lang.reflect.Method) ReflectionMethodInvoker(powermock.classloading.classes.ReflectionMethodInvoker) MyReturnValue(powermock.classloading.classes.MyReturnValue) Test(org.junit.Test)

Example 2 with ReflectionMethodInvoker

use of powermock.classloading.classes.ReflectionMethodInvoker in project powermock by powermock.

the class ObjenesisClassloaderExecutorTest method worksWithReflection.

@Test
public void worksWithReflection() throws Exception {
    final MockClassLoader classloader = createClassloader();
    final MyArgument myArgument = new MyArgument("test");
    final MyReturnValue instance = new MyReturnValue(myArgument);
    Method method = instance.getClass().getMethod("getMyArgument");
    final ReflectionMethodInvoker tested = new ReflectionMethodInvoker(method, instance);
    new SingleClassloaderExecutor(classloader).execute(new Runnable() {

        public void run() {
            Object invoke = tested.invoke();
            assertSame(invoke, myArgument);
        }
    });
}
Also used : MyArgument(powermock.classloading.classes.MyArgument) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) Method(java.lang.reflect.Method) ReflectionMethodInvoker(powermock.classloading.classes.ReflectionMethodInvoker) MyReturnValue(powermock.classloading.classes.MyReturnValue) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 SingleClassloaderExecutor (org.powermock.classloading.SingleClassloaderExecutor)2 MockClassLoader (org.powermock.core.classloader.MockClassLoader)2 MyArgument (powermock.classloading.classes.MyArgument)2 MyReturnValue (powermock.classloading.classes.MyReturnValue)2 ReflectionMethodInvoker (powermock.classloading.classes.ReflectionMethodInvoker)2