Search in sources :

Example 6 with MyReturnValue

use of powermock.classloading.classes.MyReturnValue 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"));
    }
}
Also used : MyArgument(powermock.classloading.classes.MyArgument) MockClassLoader(org.powermock.core.classloader.MockClassLoader) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) LinkedList(java.util.LinkedList) MyCollectionHolder(powermock.classloading.classes.MyCollectionHolder) Collection(java.util.Collection) MyReturnValue(powermock.classloading.classes.MyReturnValue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 SingleClassloaderExecutor (org.powermock.classloading.SingleClassloaderExecutor)6 MockClassLoader (org.powermock.core.classloader.MockClassLoader)6 MyArgument (powermock.classloading.classes.MyArgument)6 MyReturnValue (powermock.classloading.classes.MyReturnValue)6 Method (java.lang.reflect.Method)2 Collection (java.util.Collection)2 LinkedList (java.util.LinkedList)2 MyClass (powermock.classloading.classes.MyClass)2 MyCollectionHolder (powermock.classloading.classes.MyCollectionHolder)2 ReflectionMethodInvoker (powermock.classloading.classes.ReflectionMethodInvoker)2 Ignore (org.junit.Ignore)1