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:

  1. system classes are deferred to another classloader
  2. testing framework classes are loaded, but not modified
  • Field Details

    • 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:
    • CGLIB_ENHANCER

      private static final String CGLIB_ENHANCER
      See Also:
    • CGLIB_METHOD_WRAPPER

      private static final String CGLIB_METHOD_WRAPPER
      See Also:
    • javaAssistClassMarker

      private final JavaAssistClassMarker javaAssistClassMarker
    • mockTransformerChain

      private List<MockTransformer> mockTransformerChain
    • modify

      private final Set<String> modify
    • packagesToLoadButNotModify

      private final String[] packagesToLoadButNotModify
    • specificClassesToLoadButNotModify

      private final String[] specificClassesToLoadButNotModify
    • packagesToBeDeferred

      private static final String[] packagesToBeDeferred
    • classPool

      private final javassist.ClassPool classPool
  • Constructor Details

    • MockClassLoader

      public MockClassLoader(String[] classesToMock, String[] packagesToDefer, UseClassPathAdjuster useClassPathAdjuster)
      Creates a new instance of the MockClassLoader based 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

      MockClassLoader()
    • MockClassLoader

      public MockClassLoader(String[] classesToMock, String[] packagesToDefer)
      Creates a new instance of the MockClassLoader based 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 the MockClassLoader based 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 the MockClassLoader based on the following parameters:
      Parameters:
      classesToMock - The classes that must be modified to prepare for testability.
  • Method Details