org.powermock.core.classloader
Class MockClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.powermock.core.classloader.DeferSupportingClassLoader
          extended by org.powermock.core.classloader.MockClassLoader

public final class MockClassLoader
extends DeferSupportingClassLoader

Mock all classes except system classes. Notice that there are two different types of classes that are not mocked:

  1. system classes are deferred to another classloader
  2. testing framework classes are loaded, but not modified

Author:
Johan Haleby, Jan Kronquist

Field Summary
static String MODIFY_ALL_CLASSES
          Pass this string to the constructor to indicate that all classes should be modified.
 
Constructor Summary
MockClassLoader(String[] classesToMock)
          Creates a new instance of the MockClassLoader based on the following parameters:
MockClassLoader(String[] classesToMock, String[] packagesToDefer)
          Creates a new instance of the MockClassLoader based on the following parameters:
 
Method Summary
 void addClassesToModify(String... classes)
          Add classes that will be loaded by the mock classloader, i.e. these classes will be byte-code manipulated to allow for testing.
protected  Class<?> loadModifiedClass(String s)
           
 void setMockTransformerChain(List<MockTransformer> mockTransformerChain)
           
protected  boolean shouldLoadUnmodifiedClass(String className)
           
 boolean shouldModifyAll()
           
protected  boolean shouldModifyClass(String s)
           
 
Methods inherited from class org.powermock.core.classloader.DeferSupportingClassLoader
addIgnorePackage, findResource, loadClass, shouldDefer, shouldIgnore, shouldIgnore, shouldModify
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODIFY_ALL_CLASSES

public static final String MODIFY_ALL_CLASSES
Pass this string to the constructor to indicate that all classes should be modified.

See Also:
Constant Field Values
Constructor Detail

MockClassLoader

public MockClassLoader(String[] classesToMock,
                       String[] packagesToDefer)
Creates a new instance of the MockClassLoader based on the following parameters:

Parameters:
classesToMock - The classes that must be modified to prepare for testability.
packagesToDefer - Classes in these packages will be defered to the system class-loader.

MockClassLoader

public MockClassLoader(String[] classesToMock)
Creates a new instance of the MockClassLoader based on the following parameters:

Parameters:
classesToMock - The classes that must be modified to prepare for testability.
Method Detail

addClassesToModify

public void addClassesToModify(String... classes)
Add classes that will be loaded by the mock classloader, i.e. these classes will be byte-code manipulated to allow for testing. Any classes contained in the packagesToBeDeferred will be ignored.

Parameters:
classes - The fully qualified name of the classes that will be appended to the list of classes that will be byte-code modified to enable testability.

loadModifiedClass

protected Class<?> loadModifiedClass(String s)
                              throws ClassFormatError,
                                     ClassNotFoundException
Specified by:
loadModifiedClass in class DeferSupportingClassLoader
Throws:
ClassFormatError
ClassNotFoundException

shouldModifyAll

public boolean shouldModifyAll()

setMockTransformerChain

public void setMockTransformerChain(List<MockTransformer> mockTransformerChain)

shouldModifyClass

protected boolean shouldModifyClass(String s)
Specified by:
shouldModifyClass in class DeferSupportingClassLoader

shouldLoadUnmodifiedClass

protected boolean shouldLoadUnmodifiedClass(String className)
Specified by:
shouldLoadUnmodifiedClass in class DeferSupportingClassLoader


Copyright © 2007-2012. All Rights Reserved.