Class MockitoPostProcessor

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor, org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor, org.springframework.core.Ordered

    public class MockitoPostProcessor
    extends org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
    implements org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.core.Ordered
    A BeanFactoryPostProcessor used to register and inject @MockBeans with the ApplicationContext. An initial set of definitions can be passed to the processor with additional definitions being automatically created from @Configuration classes that use @MockBean.
    Since:
    1.4.0
    • Field Summary

      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      ConstructorDescription
      MockitoPostProcessor​(Set<org.springframework.boot.test.mock.mockito.Definition> definitions)
      Create a new MockitoPostProcessor instance with the given initial definitions.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      protected ObjectcreateSpyIfNecessary​(Object bean, String beanName) 
      intgetOrder() 
      voidpostProcessBeanFactory​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) 
      org.springframework.beans.PropertyValuespostProcessPropertyValues​(org.springframework.beans.PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) 
      static voidregister​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      Register the processor with a BeanDefinitionRegistry.
      static voidregister​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Class<? extends MockitoPostProcessor> postProcessor, Set<org.springframework.boot.test.mock.mockito.Definition> definitions)
      Register the processor with a BeanDefinitionRegistry.
      static voidregister​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Set<org.springframework.boot.test.mock.mockito.Definition> definitions)
      Register the processor with a BeanDefinitionRegistry.
      voidsetBeanClassLoader​(ClassLoader classLoader) 
      voidsetBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory) 
      • Methods inherited from class org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter

        determineCandidateConstructors, getEarlyBeanReference, postProcessAfterInitialization, postProcessAfterInstantiation, postProcessBeforeInitialization, postProcessBeforeInstantiation, postProcessProperties, predictBeanType
    • Constructor Detail

      • MockitoPostProcessor

        public MockitoPostProcessor​(Set<org.springframework.boot.test.mock.mockito.Definition> definitions)
        Create a new MockitoPostProcessor instance with the given initial definitions.
        Parameters:
        definitions - the initial definitions
    • Method Detail

      • setBeanClassLoader

        public void setBeanClassLoader​(ClassLoader classLoader)
        Specified by:
        setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAware
      • setBeanFactory

        public void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)
                            throws org.springframework.beans.BeansException
        Specified by:
        setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
        Throws:
        org.springframework.beans.BeansException
      • postProcessBeanFactory

        public void postProcessBeanFactory​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
                                    throws org.springframework.beans.BeansException
        Specified by:
        postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
        Throws:
        org.springframework.beans.BeansException
      • createSpyIfNecessary

        protected final Object createSpyIfNecessary​(Object bean,
                                                    String beanName)
                                             throws org.springframework.beans.BeansException
        Throws:
        org.springframework.beans.BeansException
      • postProcessPropertyValues

        public org.springframework.beans.PropertyValues postProcessPropertyValues​(org.springframework.beans.PropertyValues pvs,
                                                                                  PropertyDescriptor[] pds,
                                                                                  Object bean,
                                                                                  String beanName)
                                                                           throws org.springframework.beans.BeansException
        Specified by:
        postProcessPropertyValues in interface org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
        Overrides:
        postProcessPropertyValues in class org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
        Throws:
        org.springframework.beans.BeansException
      • getOrder

        public int getOrder()
        Specified by:
        getOrder in interface org.springframework.core.Ordered
      • register

        public static void register​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
        Register the processor with a BeanDefinitionRegistry. Not required when using the SpringRunner as registration is automatic.
        Parameters:
        registry - the bean definition registry
      • register

        public static void register​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry,
                                    Set<org.springframework.boot.test.mock.mockito.Definition> definitions)
        Register the processor with a BeanDefinitionRegistry. Not required when using the SpringRunner as registration is automatic.
        Parameters:
        registry - the bean definition registry
        definitions - the initial mock/spy definitions
      • register

        public static void register​(org.springframework.beans.factory.support.BeanDefinitionRegistry registry,
                                    Class<? extends MockitoPostProcessor> postProcessor,
                                    Set<org.springframework.boot.test.mock.mockito.Definition> definitions)
        Register the processor with a BeanDefinitionRegistry. Not required when using the SpringRunner as registration is automatic.
        Parameters:
        registry - the bean definition registry
        postProcessor - the post processor class to register
        definitions - the initial mock/spy definitions