Package org.powermock.core.classloader
Class MockClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- javassist.Loader
-
- org.powermock.core.classloader.DeferSupportingClassLoader
-
- org.powermock.core.classloader.MockClassLoader
-
public class MockClassLoader extends DeferSupportingClassLoader
Mock all classes except system classes. Notice that there are two different types of classes that are not mocked:- system classes are deferred to another classloader
- testing framework classes are loaded, but not modified
- Author:
- Johan Haleby, Jan Kronquist
-
-
Field Summary
Fields Modifier and Type Field Description static StringMODIFY_ALL_CLASSESPass this string to the constructor to indicate that all classes should be modified.
-
Constructor Summary
Constructors Constructor Description MockClassLoader(String[] classesToMock)Creates a new instance of theMockClassLoaderbased on the following parameters:MockClassLoader(String[] classesToMock, String[] packagesToDefer)Creates a new instance of theMockClassLoaderbased on the following parameters:MockClassLoader(String[] classesToMock, String[] packagesToDefer, UseClassPathAdjuster useClassPathAdjuster)Creates a new instance of theMockClassLoaderbased on the following parameters:MockClassLoader(String[] classesToMock, UseClassPathAdjuster useClassPathAdjuster)Creates a new instance of theMockClassLoaderbased on the following parameters:
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClassesToModify(String... classes)Add classes that will be loaded by the mock classloader, i.e.protected Class<?>loadModifiedClass(String s)voidsetMockTransformerChain(List<MockTransformer> mockTransformerChain)protected booleanshouldLoadUnmodifiedClass(String className)protected booleanshouldModifyClass(String s)-
Methods inherited from class org.powermock.core.classloader.DeferSupportingClassLoader
addIgnorePackage, cache, findResource, findResources, getResource, getResourceAsStream, getResources, loadClass, shouldModify
-
Methods inherited from class javassist.Loader
addTranslator, delegateLoadingOf, delegateToParent, findClass, loadClassByDelegation, main, run, run, setClassPool, setDomain
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
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, UseClassPathAdjuster useClassPathAdjuster)
Creates a new instance of theMockClassLoaderbased 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, String[] packagesToDefer)
Creates a new instance of theMockClassLoaderbased 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, UseClassPathAdjuster useClassPathAdjuster)
Creates a new instance of theMockClassLoaderbased on the following parameters:- Parameters:
classesToMock- The classes that must be modified to prepare for testability.
-
MockClassLoader
public MockClassLoader(String[] classesToMock)
Creates a new instance of theMockClassLoaderbased on the following parameters:- Parameters:
classesToMock- The classes that must be modified to prepare for testability.
-
-
Method Detail
-
addClassesToModify
public final 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 thepackagesToBeDeferredwill be ignored. How ever classes added here have precedence over additionally deferred (ignored) packages (those ignored by the user using @PrepareForTest).- 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:
loadModifiedClassin classDeferSupportingClassLoader- Throws:
ClassFormatErrorClassNotFoundException
-
setMockTransformerChain
public void setMockTransformerChain(List<MockTransformer> mockTransformerChain)
-
shouldModifyClass
protected boolean shouldModifyClass(String s)
- Specified by:
shouldModifyClassin classDeferSupportingClassLoader
-
shouldLoadUnmodifiedClass
protected boolean shouldLoadUnmodifiedClass(String className)
- Specified by:
shouldLoadUnmodifiedClassin classDeferSupportingClassLoader
-
-