Class MockClassLoaderConfiguration

java.lang.Object
org.powermock.core.classloader.MockClassLoaderConfiguration

public class MockClassLoaderConfiguration extends Object
The instance of the class provides information about classes which have to be mocked, loaded without modification or defer to system class loader.
  • Field Details

    • PACKAGES_TO_BE_DEFERRED

      static final String[] PACKAGES_TO_BE_DEFERRED
    • PACKAGES_TO_LOAD_BUT_NOT_MODIFY

      private static final String[] PACKAGES_TO_LOAD_BUT_NOT_MODIFY
    • specificClassesToLoadButNotModify

      private final String[] specificClassesToLoadButNotModify
    • modify

      private final Set<String> modify
    • deferPackages

      private String[] deferPackages
  • Constructor Details

    • MockClassLoaderConfiguration

      public MockClassLoaderConfiguration()
      Create an instance of configuration without any classes to mock or ignore.
    • MockClassLoaderConfiguration

      public MockClassLoaderConfiguration(String[] classesToMock, String[] packagesToDefer)
      Create an instance of configuration
      Parameters:
      classesToMock - classes that should be modified by MockClassLoader.
      packagesToDefer - classes/packages that should be deferred to system class loader.
  • Method Details

    • addIgnorePackage

      public void addIgnorePackage(String... packagesToIgnore)
      Add packages or classes to ignore. Loading of all classes that locate in the added packages will be delegate to a system classloader.

      Package should be specified with using mask. Example:

           configuration.addIgnorePackage("org.powermock.example.*");
       
      Parameters:
      packagesToIgnore - fully qualified names of classes or names of packages that end by .*
    • addClassesToModify

      public final void addClassesToModify(String... classes)
      Add classes that will be loaded by the mock classloader, i.e. these classes will be byte-code manipulated to allow for testing. Any classes contained in the PACKAGES_TO_BE_DEFERRED will be ignored. How ever classes added here have precedence over additionally deferred (ignored) packages (those ignored by the user using @PrepareForTest).
      Parameters:
      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.
    • shouldDefer

      boolean shouldDefer(String className)
    • shouldMockClass

      boolean shouldMockClass(String className)
    • getDeferPackages

      String[] getDeferPackages()
    • shouldDefer

      private boolean shouldDefer(String[] packages, String name)
    • deferConditionMatches

      private boolean deferConditionMatches(String name, String packageName)
    • shouldIgnore

      private boolean shouldIgnore(String[] packages, String name)
    • shouldLoadUnmodifiedClass

      private boolean shouldLoadUnmodifiedClass(String className)
    • shouldLoadWithMockClassloaderWithoutModifications

      private boolean shouldLoadWithMockClassloaderWithoutModifications(String className)
    • shouldModifyClass

      private boolean shouldModifyClass(String className)
    • shouldIgnore

      private boolean shouldIgnore(String className)
    • shouldModify

      boolean shouldModify(String className)
    • shouldModifyAll

      private boolean shouldModifyAll()
    • getPackagesToDefer

      private static String[] getPackagesToDefer(String[] additionalDeferPackages)