Package org.powermock.classloading

Examples of org.powermock.classloading.ClassloaderExecutor


  public void loadsObjectGraphThatIncludesEnumsInSpecifiedClassloaderAndReturnsResultInOriginalClassloader()
      throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyEnum expected = MyEnum.MyEnum1;
    final MyEnumHolder myClass = new MyEnumHolder(expected);
    MyEnum actual = new ClassloaderExecutor(classloader).execute(new Callable<MyEnum>() {
      public MyEnum call() throws Exception {
        assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
        MyEnum myEnum = myClass.getMyEnum();
        assertEquals(expected, myEnum);
        return myEnum;
View Full Code Here


  @Test
  public void clonesStaticFinalObjectFields() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyStaticFinalArgumentHolder expected = new MyStaticFinalArgumentHolder();
    MyStaticFinalArgumentHolder actual = new ClassloaderExecutor(classloader)
        .execute(new Callable<MyStaticFinalArgumentHolder>() {
          public MyStaticFinalArgumentHolder call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass()
                .getName());
            MyStaticFinalArgumentHolder actual = new MyStaticFinalArgumentHolder();
View Full Code Here

  @Test
  public void clonesStaticFinalPrimitiveFields() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyStaticFinalPrimitiveHolder expected = new MyStaticFinalPrimitiveHolder();
    MyStaticFinalPrimitiveHolder actual = new ClassloaderExecutor(classloader)
        .execute(new Callable<MyStaticFinalPrimitiveHolder>() {
          public MyStaticFinalPrimitiveHolder call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass()
                .getName());
            MyStaticFinalPrimitiveHolder actual = new MyStaticFinalPrimitiveHolder();
View Full Code Here

  @Test
  public void clonesStaticFinalNumberFields() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyStaticFinalNumberHolder expected = new MyStaticFinalNumberHolder();
    MyStaticFinalNumberHolder actual = new ClassloaderExecutor(classloader)
        .execute(new Callable<MyStaticFinalNumberHolder>() {
          public MyStaticFinalNumberHolder call() throws Exception {
            assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass()
                .getName());
            MyStaticFinalNumberHolder actual = new MyStaticFinalNumberHolder();
View Full Code Here

  public void loadsObjectGraphThatIncludesPrimitiveArraysInSpecifiedClassloaderAndReturnsResultInOriginalClassloader()
      throws Exception {
    MockClassLoader classloader = createClassloader();
    final int[] expected = new int[] { 1, 2 };
    final MyPrimitiveArrayHolder myClass = new MyPrimitiveArrayHolder(expected);
    int[] actual = new ClassloaderExecutor(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;
View Full Code Here

    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 ClassloaderExecutor(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()
View Full Code Here

  public void usesReferenceCloningWhenTwoFieldsPointToSameInstance() throws Exception {
    final MockClassLoader classloader = createClassloader();
    final MyReferenceFieldHolder tested = new MyReferenceFieldHolder();
    assertSame(tested.getMyArgument1(), tested.getMyArgument2());
    assertSame(tested.getMyArgument1(), MyReferenceFieldHolder.MY_ARGUMENT);
    new ClassloaderExecutor(classloader).execute(new Runnable() {
      public void run() {
        assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
        assertEquals(tested.getMyArgument1(), tested.getMyArgument2());
        assertEquals(tested.getMyArgument1(), MyReferenceFieldHolder.MY_ARGUMENT);
        assertSame(tested.getMyArgument1(), tested.getMyArgument2());
View Full Code Here

  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 ClassloaderExecutor(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());
      }
View Full Code Here

    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 ClassloaderExecutor(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
View Full Code Here

    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 ClassloaderExecutor(classloader).execute(new Runnable() {
      public void run() {
        Object invoke = tested.invoke();
        assertSame(invoke, myArgument);
      }
    });
View Full Code Here

TOP

Related Classes of org.powermock.classloading.ClassloaderExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.