Search in sources :

Example 1 with MyEnumHolder

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

the class ObjenesisClassloaderExecutorTest method loadsObjectGraphThatIncludesEnumsInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.

@Test
public void loadsObjectGraphThatIncludesEnumsInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyEnum expected = MyEnum.MyEnum1;
    final MyEnumHolder myClass = new MyEnumHolder(expected);
    MyEnum actual = new SingleClassloaderExecutor(classloader).execute(new Callable<MyEnum>() {

        public MyEnum call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            MyEnum myEnum = myClass.getMyEnum();
            assertEquals(expected, myEnum);
            return myEnum;
        }
    });
    assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
    assertEquals(expected, actual);
}
Also used : MyEnum(powermock.classloading.classes.MyEnum) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) MyEnumHolder(powermock.classloading.classes.MyEnumHolder) Test(org.junit.Test)

Example 2 with MyEnumHolder

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

the class XStreamClassloaderExecutorTest method loadsObjectGraphThatIncludesEnumsInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.

@Test
public void loadsObjectGraphThatIncludesEnumsInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyEnum expected = MyEnum.MyEnum1;
    final MyEnumHolder myClass = new MyEnumHolder(expected);
    MyEnum actual = new SingleClassloaderExecutor(classloader).execute(new Callable<MyEnum>() {

        public MyEnum call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            MyEnum myEnum = myClass.getMyEnum();
            assertEquals(expected, myEnum);
            return myEnum;
        }
    });
    assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
    assertEquals(expected, actual);
}
Also used : MyEnum(powermock.classloading.classes.MyEnum) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) MyEnumHolder(powermock.classloading.classes.MyEnumHolder) Test(org.junit.Test)

Aggregations

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