public abstract class MockClassLoader extends 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 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(String[] classesToMock,
String[] packagesToDefer)
Creates a new instance of the based on the
following parameters:
|
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 String MODIFY_ALL_CLASSES
protected ClassMarker classMarker
protected ClassWrapperFactory classWrapperFactory
protected MockClassLoader(String[] classesToMock, 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 Class<?> loadClassByThisClassLoader(String className) throws ClassFormatError, ClassNotFoundException
public void setMockTransformerChain(MockTransformerChain mockTransformerChain)
public MockTransformerChain getMockTransformerChain()
protected Class<?> loadUnmockedClass(String name, ProtectionDomain protectionDomain) throws ClassNotFoundException
ClassNotFoundException
public Class<?> defineClass(String name, ProtectionDomain protectionDomain, byte[] clazz)
protected <T> ClassWrapper<T> transformClass(ClassWrapper<T> wrappedType) throws Exception
Exception
protected abstract byte[] defineAndTransformClass(String name, ProtectionDomain protectionDomain) throws ClassNotFoundException
ClassNotFoundException
public URL getResource(String s)
getResource
in class ClassLoader
public InputStream getResourceAsStream(String s)
getResourceAsStream
in class ClassLoader
public Enumeration<URL> getResources(String name) throws IOException
getResources
in class ClassLoader
IOException
public MockClassLoaderConfiguration getConfiguration()
public void cache(Class<?> cls)
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
loadClass
in class ClassLoader
ClassNotFoundException
protected Object getClassLoadingLock(String className)
getClassLoadingLock
in class ClassLoader
protected URL findResource(String name)
findResource
in class ClassLoader
name
- the name of the resourceURL
for the resource, or null
if the
resource could not be found.protected Enumeration<URL> findResources(String name) throws IOException
findResources
in class ClassLoader
IOException
Copyright © 2019. All rights reserved.