use of powermock.classloading.classes.MyArgument 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 powermock.classloading.classes.MyArgument in project powermock by powermock.
the class XStreamClassloaderExecutorTest 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 powermock.classloading.classes.MyArgument 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 powermock.classloading.classes.MyArgument in project powermock by powermock.
the class XStreamClassloaderExecutorTest method loadsObjectGraphThatIncludesCollectionInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.
@Test
public void loadsObjectGraphThatIncludesCollectionInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
final MockClassLoader classloader = createClassloader();
final Collection<MyReturnValue> expected = new LinkedList<MyReturnValue>();
expected.add(new MyReturnValue(new MyArgument("one")));
expected.add(new MyReturnValue(new MyArgument("two")));
final MyCollectionHolder myClass = new MyCollectionHolder(expected);
Collection<?> actual = new SingleClassloaderExecutor(classloader).execute(new Callable<Collection<?>>() {
public Collection<?> call() throws Exception {
assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
Collection<?> myCollection = myClass.getMyCollection();
for (Object object : myCollection) {
assertEquals(MockClassLoader.class.getName(), object.getClass().getClassLoader().getClass().getName());
}
return myCollection;
}
});
assertFalse(MockClassLoader.class.getName().equals(this.getClass().getClassLoader().getClass().getName()));
assertEquals(2, actual.size());
for (Object object : actual) {
final String value = ((MyReturnValue) object).getMyArgument().getValue();
assertTrue(value.equals("one") || value.equals("two"));
}
}
use of powermock.classloading.classes.MyArgument in project powermock by powermock.
the class ObjenesisClassloaderExecutorTest 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);
}
});
}
Aggregations