Package org.powermock.core.classloader

Examples of org.powermock.core.classloader.MockClassLoader


    });
  }

  @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
  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

@Ignore("Since upgrading to JVM 1.6.0_24 lots of tests started to fail")
public class ObjenesisClassloaderExecutorTest {

  @Test
  public void loadsObjectGraphInSpecifiedClassloaderAndReturnsResultInOriginalClassloader() throws Exception {
    MockClassLoader classloader = createClassloader();
    final MyReturnValue expectedConstructorValue = new MyReturnValue(new MyArgument("first value"));
    final MyClass myClass = new MyClass(expectedConstructorValue);
    final MyArgument expected = new MyArgument("A value");
    MyReturnValue[] actual = new ClassloaderExecutor(classloader).execute(new Callable<MyReturnValue[]>() {
      public MyReturnValue[] call() throws Exception {
View Full Code Here

  }

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

  }

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

    assertEquals(expected, actual);
  }

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

    assertEquals(expected.getMyObject(), actual.getMyObject());
  }

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

    assertEquals(expected.getMyInt(), actual.getMyInt());
  }

  @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()
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.