public class MockClassLoader extends DeferSupportingClassLoader
The classloader loads and modified all classes except:
DeferSupportingClassLoader.addIgnorePackage(String...)Testing frameworks classes are loaded, but not modified.
The classloader uses list of MockTransformer to modify classes during loading.
ClassLoader.getSystemClassLoader(),
IgnorePackagesExtractor| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MODIFY_ALL_CLASSES
Pass this string to the constructor to indicate that all classes should
be modified.
|
| Constructor and Description |
|---|
MockClassLoader(java.lang.String[] classesToMock)
Creates a new instance of the based on the
following parameters:
|
MockClassLoader(java.lang.String[] classesToMock,
java.lang.String[] packagesToDefer)
Creates a new instance of the based on the
following parameters:
|
MockClassLoader(java.lang.String[] classesToMock,
java.lang.String[] packagesToDefer,
UseClassPathAdjuster useClassPathAdjuster)
Creates a new instance of the based on the
following parameters:
|
MockClassLoader(java.lang.String[] classesToMock,
UseClassPathAdjuster useClassPathAdjuster)
Creates a new instance of the based on the
following parameters:
|
| Modifier and Type | Method and Description |
|---|---|
void |
addClassesToModify(java.lang.String... classes)
Add classes that will be loaded by the mock classloader, i.e.
|
protected java.lang.Class<?> |
loadModifiedClass(java.lang.String s) |
void |
setMockTransformerChain(java.util.List<MockTransformer> mockTransformerChain) |
protected boolean |
shouldLoadUnmodifiedClass(java.lang.String className) |
protected boolean |
shouldModifyClass(java.lang.String s) |
addIgnorePackage, cache, findResource, findResources, getResource, getResourceAsStream, getResources, loadClass, shouldModifyaddTranslator, delegateLoadingOf, delegateToParent, findClass, loadClassByDelegation, main, run, run, setClassPool, setDomainclearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignerspublic static final java.lang.String MODIFY_ALL_CLASSES
public MockClassLoader(java.lang.String[] classesToMock,
java.lang.String[] packagesToDefer,
UseClassPathAdjuster useClassPathAdjuster)
classesToMock - The classes that must be modified to prepare for testability.packagesToDefer - Classes in these packages will be defered to the system
class-loader.public MockClassLoader(java.lang.String[] classesToMock,
java.lang.String[] packagesToDefer)
classesToMock - The classes that must be modified to prepare for testability.packagesToDefer - Classes in these packages will be defered to the system
class-loader.public MockClassLoader(java.lang.String[] classesToMock,
UseClassPathAdjuster useClassPathAdjuster)
classesToMock - The classes that must be modified to prepare for testability.public MockClassLoader(java.lang.String[] classesToMock)
classesToMock - The classes that must be modified to prepare for testability.public final void addClassesToModify(java.lang.String... classes)
packagesToBeDeferred will be ignored. How ever
classes added here have precedence over additionally deferred (ignored)
packages (those ignored by the user using @PrepareForTest).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.protected java.lang.Class<?> loadModifiedClass(java.lang.String s)
throws java.lang.ClassFormatError,
java.lang.ClassNotFoundException
loadModifiedClass in class DeferSupportingClassLoaderjava.lang.ClassFormatErrorjava.lang.ClassNotFoundExceptionpublic void setMockTransformerChain(java.util.List<MockTransformer> mockTransformerChain)
protected boolean shouldModifyClass(java.lang.String s)
shouldModifyClass in class DeferSupportingClassLoaderprotected boolean shouldLoadUnmodifiedClass(java.lang.String className)
shouldLoadUnmodifiedClass in class DeferSupportingClassLoader