use of powermock.classloading.classes.MyCollectionHolder 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.MyCollectionHolder in project powermock by powermock.
the class ObjenesisClassloaderExecutorTest method loadsObjectGraphThatIncludesCollectionInSpecifiedClassloaderAndReturnsResultInOriginalClassloader.
@Ignore("It seems like this test works on certain JVM's and fails on others. WHY!??!")
@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"));
}
}
Aggregations