Search in sources :

Example 1 with MyHierarchicalOverloadedFieldHolder

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

the class ObjenesisClassloaderExecutorTest method worksWithObjectHierarchyAndOverloadedFields.

@Test
@Ignore("It seems like this test works on certain JVM's and fails on others. WHY!??!")
public void worksWithObjectHierarchyAndOverloadedFields() throws Exception {
    final MockClassLoader classloader = createClassloader();
    final MyHierarchicalOverloadedFieldHolder tested = new MyHierarchicalOverloadedFieldHolder();
    assertSame(tested.getMyArgument1(), tested.getMyArgument2());
    assertEquals(tested.getMyArgument1(), tested.getMyArgument3());
    assertSame(tested.getMyArgument3(), MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
    assertNotSame(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
    assertEquals(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
    new SingleClassloaderExecutor(classloader).execute(new Runnable() {

        public void run() {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            assertSame(tested.getMyArgument1(), tested.getMyArgument2());
            assertEquals(tested.getMyArgument1(), tested.getMyArgument3());
            assertSame(tested.getMyArgument3(), MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
            assertNotSame(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
            assertEquals(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
        }
    });
}
Also used : MyHierarchicalOverloadedFieldHolder(powermock.classloading.classes.MyHierarchicalOverloadedFieldHolder) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with MyHierarchicalOverloadedFieldHolder

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

the class XStreamClassloaderExecutorTest method worksWithObjectHierarchyAndOverloadedFields.

@Test
public void worksWithObjectHierarchyAndOverloadedFields() throws Exception {
    final MockClassLoader classloader = createClassloader();
    final MyHierarchicalOverloadedFieldHolder tested = new MyHierarchicalOverloadedFieldHolder();
    assertSame(tested.getMyArgument1(), tested.getMyArgument2());
    assertEquals(tested.getMyArgument1(), tested.getMyArgument3());
    assertSame(tested.getMyArgument3(), MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
    assertNotSame(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
    assertEquals(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
    new SingleClassloaderExecutor(classloader).execute(new Runnable() {

        public void run() {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            assertSame(tested.getMyArgument1(), tested.getMyArgument2());
            assertEquals(tested.getMyArgument1(), tested.getMyArgument3());
            // Note: Cannot be same using X-Stream
            assertEquals(tested.getMyArgument3(), MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
            assertNotSame(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
            assertEquals(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
        }
    });
}
Also used : MyHierarchicalOverloadedFieldHolder(powermock.classloading.classes.MyHierarchicalOverloadedFieldHolder) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SingleClassloaderExecutor (org.powermock.classloading.SingleClassloaderExecutor)2 MockClassLoader (org.powermock.core.classloader.MockClassLoader)2 MyHierarchicalOverloadedFieldHolder (powermock.classloading.classes.MyHierarchicalOverloadedFieldHolder)2 Ignore (org.junit.Ignore)1