Package org.powermock.core.classloader

Examples of org.powermock.core.classloader.MockClassLoader


  }

  @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 ClassloaderExecutor(classloader).execute(new Callable<int[]>() {
      public int[] call() throws Exception {
        assertEquals(MockClassLoader.class.getName(), this.getClass().getClassLoader().getClass().getName());
View Full Code Here


  @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 ClassloaderExecutor(classloader).execute(new Callable<Collection<?>>() {
View Full Code Here

    }
  }

  @Test
  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() {
View Full Code Here

    });
  }

  @Test
  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() {
View Full Code Here

  }

  @Test
  @Ignore("It seems like this test works on certain JVM's and fails on others. WHY!??!")
  public void worksWithObjectHierarchyAndOverloadedFields() throws Exception {
    final MockClassLoader classloader = createClassloader();
    final MyHierarchicalOverloadedFieldHolder tested = new MyHierarchicalOverloadedFieldHolder();
    assertSame(tested.getMyArgument1(), tested.getMyArgument2());
    assertEquals(tested.getMyArgument1(), tested.getMyArgument3());
    assertSame(tested.getMyArgument3(), MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
    assertNotSame(MyReferenceFieldHolder.MY_ARGUMENT, MyHierarchicalOverloadedFieldHolder.MY_ARGUMENT);
View Full Code Here

    });
  }

  @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 ClassloaderExecutor(classloader).execute(new Runnable() {
View Full Code Here

      }
    });
  }

  private MockClassLoader createClassloader() {
    MockClassLoader classloader = new MockClassLoader(new String[] { MyClass.class.getName(),
        MyArgument.class.getName(), MyReturnValue.class.getName() });
    MockTransformer mainMockTransformer = new MockTransformer() {
      public CtClass transform(CtClass clazz) throws Exception {
        return clazz;
      }
    };
    LinkedList<MockTransformer> linkedList = new LinkedList<MockTransformer>();
    linkedList.add(mainMockTransformer);
    classloader.setMockTransformerChain(linkedList);
    return classloader;
  }
View Full Code Here

     * This tests that a inner 'public static final class' can be modified to drop the final modifier. Fixes <a
     * href="http://code.google.com/p/powermock/issues/detail?id=95">Issue 95</a>.
     */
    @Test
    public void staticFinalInnerClassesShouldBecomeNonFinal() throws Exception {
        MockClassLoader mockClassLoader = new MockClassLoader(new String[] { MockClassLoader.MODIFY_ALL_CLASSES });
        mockClassLoader.setMockTransformerChain(Collections.<MockTransformer> singletonList(new MainMockTransformer()));
        Class<?> clazz = Class.forName(SupportClasses.StaticFinalInnerClass.class.getName(), true, mockClassLoader);
        assertFalse(Modifier.isFinal(clazz.getModifiers()));
    }
View Full Code Here

     * This tests that a inner 'public final class' can be modified to drop the final modifier. Fixes <a
     * href="http://code.google.com/p/powermock/issues/detail?id=95">Issue 95</a>.
     */
    @Test
    public void finalInnerClassesShouldBecomeNonFinal() throws Exception {
        MockClassLoader mockClassLoader = new MockClassLoader(new String[] { MockClassLoader.MODIFY_ALL_CLASSES });
        mockClassLoader.setMockTransformerChain(Collections.<MockTransformer> singletonList(new MainMockTransformer()));
        Class<?> clazz = Class.forName(SupportClasses.FinalInnerClass.class.getName(), true, mockClassLoader);
        assertFalse(Modifier.isFinal(clazz.getModifiers()));
    }
View Full Code Here

     * This tests that a inner 'enum' can be modified to drop the final modifier. Fixes <a
     * href="http://code.google.com/p/powermock/issues/detail?id=95">Issue 95</a>.
     */
    @Test
    public void enumClassesShouldBecomeNonFinal() throws Exception {
        MockClassLoader mockClassLoader = new MockClassLoader(new String[] { MockClassLoader.MODIFY_ALL_CLASSES });
        mockClassLoader.setMockTransformerChain(Collections.<MockTransformer> singletonList(new MainMockTransformer()));
        Class<?> clazz = Class.forName(SupportClasses.EnumClass.class.getName(), true, mockClassLoader);
        assertFalse(Modifier.isFinal(clazz.getModifiers()));
    }
View Full Code Here

TOP

Related Classes of org.powermock.core.classloader.MockClassLoader

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.