public abstract class MockClassLoader
extends java.lang.ClassLoader
The classloader loads and modified all classes except:
MockClassLoaderConfiguration.addIgnorePackage(String...)
Testing frameworks classes are loaded, but not modified.
The classloader uses list of MockTransformer
to modify classes during loading.
MockClassLoaderConfiguration
,
ClassLoader.getSystemClassLoader()
,
IgnorePackagesExtractor
Modifier and Type | Field and Description |
---|---|
protected ClassMarker |
classMarker |
protected ClassWrapperFactory |
classWrapperFactory |
static java.lang.String |
MODIFY_ALL_CLASSES
Pass this string to the constructor to indicate that all classes should
be modified.
|
Modifier | Constructor and Description |
---|---|
protected |
MockClassLoader(MockClassLoaderConfiguration configuration,
ClassWrapperFactory classWrapperFactory)
Creates a new instance of the based on the
following parameters:
|
protected |
MockClassLoader(java.lang.String[] classesToMock,
java.lang.String[] packagesToDefer)
Creates a new instance of the based on the
following parameters:
|
Modifier and Type | Method and Description |
---|---|
void |
cache(java.lang.Class<?> cls)
Register a class to the cache of this classloader
|
protected abstract byte[] |
defineAndTransformClass(java.lang.String name,
java.security.ProtectionDomain protectionDomain) |
java.lang.Class<?> |
defineClass(java.lang.String name,
java.security.ProtectionDomain protectionDomain,
byte[] clazz) |
protected java.net.URL |
findResource(java.lang.String name)
Finds the resource with the specified name on the search path.
|
protected java.util.Enumeration<java.net.URL> |
findResources(java.lang.String name) |
protected java.lang.Object |
getClassLoadingLock(java.lang.String className) |
MockClassLoaderConfiguration |
getConfiguration() |
MockTransformerChain |
getMockTransformerChain() |
java.net.URL |
getResource(java.lang.String s) |
java.io.InputStream |
getResourceAsStream(java.lang.String s) |
java.util.Enumeration<java.net.URL> |
getResources(java.lang.String name) |
protected java.lang.Class<?> |
loadClass(java.lang.String name,
boolean resolve) |
protected java.lang.Class<?> |
loadClassByThisClassLoader(java.lang.String className) |
protected java.lang.Class<?> |
loadUnmockedClass(java.lang.String name,
java.security.ProtectionDomain protectionDomain) |
void |
setMockTransformerChain(MockTransformerChain mockTransformerChain) |
protected <T> ClassWrapper<T> |
transformClass(ClassWrapper<T> wrappedType) |
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public static final java.lang.String MODIFY_ALL_CLASSES
protected ClassMarker classMarker
protected ClassWrapperFactory classWrapperFactory
protected 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.protected MockClassLoader(MockClassLoaderConfiguration configuration, ClassWrapperFactory classWrapperFactory)
configuration
- The configuration of class loader. Configuration contains information about classes
which should be loaded by class loader, defer to system and mocked.classWrapperFactory
- an instance of ClassWrapperFactory
which is used to wrap internal framework's representation of
the class into ClassWrapper
MockClassLoaderConfiguration
protected java.lang.Class<?> loadClassByThisClassLoader(java.lang.String className) throws java.lang.ClassFormatError, java.lang.ClassNotFoundException
java.lang.ClassFormatError
java.lang.ClassNotFoundException
public void setMockTransformerChain(MockTransformerChain mockTransformerChain)
public MockTransformerChain getMockTransformerChain()
protected java.lang.Class<?> loadUnmockedClass(java.lang.String name, java.security.ProtectionDomain protectionDomain) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public java.lang.Class<?> defineClass(java.lang.String name, java.security.ProtectionDomain protectionDomain, byte[] clazz)
protected <T> ClassWrapper<T> transformClass(ClassWrapper<T> wrappedType) throws java.lang.Exception
java.lang.Exception
protected abstract byte[] defineAndTransformClass(java.lang.String name, java.security.ProtectionDomain protectionDomain) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public java.net.URL getResource(java.lang.String s)
getResource
in class java.lang.ClassLoader
public java.io.InputStream getResourceAsStream(java.lang.String s)
getResourceAsStream
in class java.lang.ClassLoader
public java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOException
getResources
in class java.lang.ClassLoader
java.io.IOException
public MockClassLoaderConfiguration getConfiguration()
public void cache(java.lang.Class<?> cls)
protected java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
loadClass
in class java.lang.ClassLoader
java.lang.ClassNotFoundException
protected java.lang.Object getClassLoadingLock(java.lang.String className)
getClassLoadingLock
in class java.lang.ClassLoader
protected java.net.URL findResource(java.lang.String name)
findResource
in class java.lang.ClassLoader
name
- the name of the resourceURL
for the resource, or null
if the
resource could not be found.protected java.util.Enumeration<java.net.URL> findResources(java.lang.String name) throws java.io.IOException
findResources
in class java.lang.ClassLoader
java.io.IOException