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, setSignerspublic 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 ClassWrapperMockClassLoaderConfigurationprotected Class<?> loadClassByThisClassLoader(String className) throws ClassFormatError, ClassNotFoundException
public void setMockTransformerChain(MockTransformerChain mockTransformerChain)
public MockTransformerChain getMockTransformerChain()
protected Class<?> loadUnmockedClass(String name, ProtectionDomain protectionDomain) throws ClassNotFoundException
ClassNotFoundExceptionpublic Class<?> defineClass(String name, ProtectionDomain protectionDomain, byte[] clazz)
protected <T> ClassWrapper<T> transformClass(ClassWrapper<T> wrappedType) throws Exception
Exceptionprotected abstract byte[] defineAndTransformClass(String name, ProtectionDomain protectionDomain) throws ClassNotFoundException
ClassNotFoundExceptionpublic URL getResource(String s)
getResource in class ClassLoaderpublic InputStream getResourceAsStream(String s)
getResourceAsStream in class ClassLoaderpublic Enumeration<URL> getResources(String name) throws IOException
getResources in class ClassLoaderIOExceptionpublic MockClassLoaderConfiguration getConfiguration()
public void cache(Class<?> cls)
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
loadClass in class ClassLoaderClassNotFoundExceptionprotected Object getClassLoadingLock(String className)
getClassLoadingLock in class ClassLoaderprotected URL findResource(String name)
findResource in class ClassLoadername - 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 ClassLoaderIOExceptionCopyright © 2025. All rights reserved.