Search in sources :

Example 1 with MyPrimitiveArrayHolder

use of powermock.classloading.classes.MyPrimitiveArrayHolder 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);
}
Also used : MockClassLoader(org.powermock.core.classloader.MockClassLoader) MyPrimitiveArrayHolder(powermock.classloading.classes.MyPrimitiveArrayHolder) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) Test(org.junit.Test)

Example 2 with MyPrimitiveArrayHolder

use of powermock.classloading.classes.MyPrimitiveArrayHolder in project powermock by powermock.

the class ObjenesisClassloaderExecutorTest 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);
}
Also used : MockClassLoader(org.powermock.core.classloader.MockClassLoader) MyPrimitiveArrayHolder(powermock.classloading.classes.MyPrimitiveArrayHolder) SingleClassloaderExecutor(org.powermock.classloading.SingleClassloaderExecutor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SingleClassloaderExecutor (org.powermock.classloading.SingleClassloaderExecutor)2 MockClassLoader (org.powermock.core.classloader.MockClassLoader)2 MyPrimitiveArrayHolder (powermock.classloading.classes.MyPrimitiveArrayHolder)2