Search in sources :

Example 1 with MyIntegerHolder

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

the class XStreamClassloaderExecutorTest method loadsObjectGraphThatIncludesPrimitiveValuesInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.

@Test
public void loadsObjectGraphThatIncludesPrimitiveValuesInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
    MockClassLoader classloader = createClassloader();
    final Integer expected = 42;
    final MyIntegerHolder myClass = new MyIntegerHolder(expected);
    Integer actual = new SingleClassloaderExecutor(classloader).execute(new Callable<Integer>() {

        public Integer call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            final int myInteger = myClass.getMyInteger();
            assertEquals((int) expected, myInteger);
            return myInteger;
        }
    });
    assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
    assertEquals(expected, actual);
}
Also used : MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) MyIntegerHolder(powermock.classloading.classes.MyIntegerHolder) Test(org.junit.Test)

Example 2 with MyIntegerHolder

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

the class ObjenesisClassloaderExecutorTest method loadsObjectGraphThatIncludesPrimitiveValuesInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.

@Test
public void loadsObjectGraphThatIncludesPrimitiveValuesInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
    MockClassLoader classloader = createClassloader();
    final Integer expected = 42;
    final MyIntegerHolder myClass = new MyIntegerHolder(expected);
    Integer actual = new SingleClassloaderExecutor(classloader).execute(new Callable<Integer>() {

        public Integer call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            final int myInteger = myClass.getMyInteger();
            assertEquals((int) expected, myInteger);
            return myInteger;
        }
    });
    assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
    assertEquals(expected, actual);
}
Also used : MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) MyIntegerHolder(powermock.classloading.classes.MyIntegerHolder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SingleClassloaderExecutor (org.powermock.classloading.SingleClassloaderExecutor)2 MockClassLoader (org.powermock.core.classloader.MockClassLoader)2 MyIntegerHolder (powermock.classloading.classes.MyIntegerHolder)2