use of org.powermock.core.classloader.MockClassLoader in project powermock by powermock.
the class ObjenesisClassloaderExecutorTest method clonesStaticFinalObjectFields.
@Test
public void clonesStaticFinalObjectFields() throws Exception {
MockClassLoader classloader = createClassloader();
final MyStaticFinalArgumentHolder expected = new MyStaticFinalArgumentHolder();
MyStaticFinalArgumentHolder actual = new SingleClassloaderExecutor(classloader).execute(new Callable<MyStaticFinalArgumentHolder>() {
public MyStaticFinalArgumentHolder call() throws Exception {
assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
MyStaticFinalArgumentHolder actual = new MyStaticFinalArgumentHolder();
assertEquals(expected.getMyObject(), actual.getMyObject());
return actual;
}
});
assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
assertEquals(expected.getMyObject(), actual.getMyObject());
}
use of org.powermock.core.classloader.MockClassLoader 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());
}
use of org.powermock.core.classloader.MockClassLoader 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);
}
use of org.powermock.core.classloader.MockClassLoader 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);
}
});
}
use of org.powermock.core.classloader.MockClassLoader in project powermock by powermock.
the class ObjenesisClassloaderExecutorTest method clonesStaticFinalPrimitiveFields.
@Test
public void clonesStaticFinalPrimitiveFields() throws Exception {
MockClassLoader classloader = createClassloader();
final MyStaticFinalPrimitiveHolder expected = new MyStaticFinalPrimitiveHolder();
MyStaticFinalPrimitiveHolder actual = new SingleClassloaderExecutor(classloader).execute(new Callable<MyStaticFinalPrimitiveHolder>() {
public MyStaticFinalPrimitiveHolder call() throws Exception {
assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
MyStaticFinalPrimitiveHolder actual = new MyStaticFinalPrimitiveHolder();
assertEquals(expected.getMyInt(), actual.getMyInt());
return actual;
}
});
assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
assertEquals(expected.getMyInt(), actual.getMyInt());
}
Aggregations