Search in sources :

Example 1 with MyReferenceFieldHolder

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

the class XStreamClassloaderExecutorTest method usesReferenceCloningWhenTwoFieldsPointToSameInstance.

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

        public void run() {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            assertEquals(tested.getMyArgument1(), tested.getMyArgument2());
            assertEquals(tested.getMyArgument1(), MyReferenceFieldHolder.MY_ARGUMENT);
            assertSame(tested.getMyArgument1(), tested.getMyArgument2());
        // FIXME: This assertion should work:
        // assertSame(tested.getMyArgument1(), MyReferenceFieldHolder.MY_ARGUMENT);
        }
    });
}
Also used : MockClassLoader(org.powermock.core.classloader.MockClassLoader) MyReferenceFieldHolder(powermock.classloading.classes.MyReferenceFieldHolder) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) Test(org.junit.Test)

Example 2 with MyReferenceFieldHolder

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

the class ObjenesisClassloaderExecutorTest method usesReferenceCloningWhenTwoFieldsPointToSameInstance.

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

        public void run() {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
            assertEquals(tested.getMyArgument1(), tested.getMyArgument2());
            assertEquals(tested.getMyArgument1(), MyReferenceFieldHolder.MY_ARGUMENT);
            assertSame(tested.getMyArgument1(), tested.getMyArgument2());
        // FIXME: This assertion should work:
        // assertSame(tested.getMyArgument1(), MyReferenceFieldHolder.MY_ARGUMENT);
        }
    });
}
Also used : MockClassLoader(org.powermock.core.classloader.MockClassLoader) MyReferenceFieldHolder(powermock.classloading.classes.MyReferenceFieldHolder) 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 MyReferenceFieldHolder (powermock.classloading.classes.MyReferenceFieldHolder)2