Class MockClassLoader

    • Field Detail

      • MODIFY_ALL_CLASSES

        public static final java.lang.String MODIFY_ALL_CLASSES
        Pass this string to the constructor to indicate that all classes should be modified.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MockClassLoader

        protected MockClassLoader​(java.lang.String[] classesToMock,
                                  java.lang.String[] packagesToDefer)
        Creates a new instance of the 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

        protected MockClassLoader​(MockClassLoaderConfiguration configuration,
                                  ClassWrapperFactory classWrapperFactory)
        Creates a new instance of the based on the following parameters:
        Parameters:
        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
        See Also:
        MockClassLoaderConfiguration
    • Method Detail

      • loadClassByThisClassLoader

        protected java.lang.Class<?> loadClassByThisClassLoader​(java.lang.String className)
                                                         throws java.lang.ClassFormatError,
                                                                java.lang.ClassNotFoundException
        Specified by:
        loadClassByThisClassLoader in class DeferSupportingClassLoader
        Throws:
        java.lang.ClassFormatError
        java.lang.ClassNotFoundException
      • setMockTransformerChain

        public void setMockTransformerChain​(MockTransformerChain mockTransformerChain)
      • loadUnmockedClass

        protected java.lang.Class<?> loadUnmockedClass​(java.lang.String name,
                                                       java.security.ProtectionDomain protectionDomain)
                                                throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • defineClass

        private java.lang.Class<?> defineClass​(java.lang.String name,
                                               java.net.URL url,
                                               java.security.ProtectionDomain protectionDomain)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readClass

        private byte[] readClass​(java.net.URL url)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • loadMockClass

        private java.lang.Class<?> loadMockClass​(java.lang.String name,
                                                 java.security.ProtectionDomain protectionDomain)
                                          throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.String name,
                                              java.security.ProtectionDomain protectionDomain,
                                              byte[] clazz)
      • transformClass

        protected <T> ClassWrapper<T> transformClass​(ClassWrapper<T> wrappedType)
                                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • defineAndTransformClass

        protected abstract byte[] defineAndTransformClass​(java.lang.String name,
                                                          java.security.ProtectionDomain protectionDomain)
                                                   throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException