Search in sources :

Example 1 with MyClass

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

the class ObjenesisClassloaderExecutorTest method loadsObjectGraphInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.

@Test
public void loadsObjectGraphInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyReturnValue expectedConstructorValue = new MyReturnValue(new MyArgument("first value"));
    final MyClass myClass = new MyClass(expectedConstructorValue);
    final MyArgument expected = new MyArgument("A value");
    MyReturnValue[] actual = new SingleClassloaderExecutor(classloader).execute(new Callable<MyReturnValue[]>() {

        public MyReturnValue[] call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            return myClass.myMethod(expected);
        }
    });
    assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
    final MyReturnValue myReturnValue = actual[0];
    assertEquals(expectedConstructorValue.getMyArgument().getValue(), myReturnValue.getMyArgument().getValue());
    assertEquals(expected.getValue(), actual[1].getMyArgument().getValue());
}
Also used : MyArgument(powermock.classloading.classes.MyArgument) MyClass(powermock.classloading.classes.MyClass) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) MyReturnValue(powermock.classloading.classes.MyReturnValue) Test(org.junit.Test)

Example 2 with MyClass

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

the class XStreamClassloaderExecutorTest method loadsObjectGraphInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.

@Test
public void loadsObjectGraphInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyReturnValue expectedConstructorValue = new MyReturnValue(new MyArgument("first value"));
    final MyClass myClass = new MyClass(expectedConstructorValue);
    final MyArgument expected = new MyArgument("A value");
    MyReturnValue[] actual = new SingleClassloaderExecutor(classloader).execute(new Callable<MyReturnValue[]>() {

        public MyReturnValue[] call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            return myClass.myMethod(expected);
        }
    });
    assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
    final MyReturnValue myReturnValue = actual[0];
    assertEquals(expectedConstructorValue.getMyArgument().getValue(), myReturnValue.getMyArgument().getValue());
    assertEquals(expected.getValue(), actual[1].getMyArgument().getValue());
}
Also used : MyArgument(powermock.classloading.classes.MyArgument) MyClass(powermock.classloading.classes.MyClass) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) MyReturnValue(powermock.classloading.classes.MyReturnValue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SingleClassloaderExecutor (org.powermock.classloading.SingleClassloaderExecutor)2 MockClassLoader (org.powermock.core.classloader.MockClassLoader)2 MyArgument (powermock.classloading.classes.MyArgument)2 MyClass (powermock.classloading.classes.MyClass)2 MyReturnValue (powermock.classloading.classes.MyReturnValue)2