use of org.powermock.classloading.SingleClassloaderExecutor in project powermock by powermock.
the class XStreamClassloaderExecutorTest method worksWithObjectHierarchy.
@Test
public void worksWithObjectHierarchy() throws Exception {
final MockClassLoader classloader = createClassloader();
final MyHierarchicalFieldHolder tested = new MyHierarchicalFieldHolder();
assertSame(tested.getMyArgument1(), tested.getMyArgument2());
assertEquals(tested.getMyArgument3(), tested.getMyArgument2());
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.getMyArgument3(), tested.getMyArgument2());
}
});
}
use of org.powermock.classloading.SingleClassloaderExecutor 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);
}
});
}
use of org.powermock.classloading.SingleClassloaderExecutor in project powermock by powermock.
the class XStreamClassloaderExecutorTest 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());
}
use of org.powermock.classloading.SingleClassloaderExecutor in project powermock by powermock.
the class XStreamClassloaderExecutorTest method worksWithReflection.
@Test
public void worksWithReflection() throws Exception {
final MockClassLoader classloader = createClassloader();
final MyArgument myArgument = new MyArgument("test");
final MyReturnValue instance = new MyReturnValue(myArgument);
Method method = instance.getClass().getMethod("getMyArgument");
final ReflectionMethodInvoker tested = new ReflectionMethodInvoker(method, instance);
new SingleClassloaderExecutor(classloader).execute(new Runnable() {
public void run() {
Object invoke = tested.invoke();
assertSame(invoke, myArgument);
}
});
}
use of org.powermock.classloading.SingleClassloaderExecutor in project powermock by powermock.
the class XStreamClassloaderExecutorTest method loadsObjectGraphThatIncludesPrimitiveArraysInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.
@Test
public void loadsObjectGraphThatIncludesPrimitiveArraysInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
MockClassLoader classloader = createClassloader();
final int[] expected = new int[] { 1, 2 };
final MyPrimitiveArrayHolder myClass = new MyPrimitiveArrayHolder(expected);
int[] actual = new SingleClassloaderExecutor(classloader).execute(new Callable<int[]>() {
public int[] call() throws Exception {
assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
int[] myArray = myClass.getMyArray();
assertArrayEquals(expected, myArray);
return myArray;
}
});
assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
assertArrayEquals(expected, actual);
}
Aggregations