Class MockitoPostProcessor
java.lang.Object
org.springframework.boot.test.mock.mockito.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.core.Ordered
public class MockitoPostProcessor
extends Object
implements org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor, 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
ConstructorsConstructorDescriptionMockitoPostProcessor(Set<org.springframework.boot.test.mock.mockito.Definition> definitions) Create a newMockitoPostProcessorinstance with the given initial definitions. -
Method Summary
Modifier and TypeMethodDescriptionprotected final ObjectcreateSpyIfNecessary(Object bean, String beanName) intgetOrder()voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) org.springframework.beans.PropertyValuespostProcessProperties(org.springframework.beans.PropertyValues pvs, Object bean, String beanName) static voidregister(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) Register the processor with aBeanDefinitionRegistry.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 aBeanDefinitionRegistry.static voidregister(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Set<org.springframework.boot.test.mock.mockito.Definition> definitions) Register the processor with aBeanDefinitionRegistry.voidsetBeanClassLoader(ClassLoader classLoader) voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessAfterInitialization, postProcessBeforeInitializationMethods inherited from interface org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
postProcessAfterInstantiation, postProcessBeforeInstantiation
-
Constructor Details
-
MockitoPostProcessor
Create a newMockitoPostProcessorinstance with the given initial definitions.- Parameters:
definitions- the initial definitions
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactoryin interfaceorg.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:
postProcessBeanFactoryin interfaceorg.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
-
postProcessProperties
public org.springframework.beans.PropertyValues postProcessProperties(org.springframework.beans.PropertyValues pvs, Object bean, String beanName) throws org.springframework.beans.BeansException - Specified by:
postProcessPropertiesin interfaceorg.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor- Throws:
org.springframework.beans.BeansException
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
register
public static void register(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) Register the processor with aBeanDefinitionRegistry. Not required when using theSpringRunneras 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 aBeanDefinitionRegistry. Not required when using theSpringRunneras registration is automatic.- Parameters:
registry- the bean definition registrydefinitions- 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 aBeanDefinitionRegistry. Not required when using theSpringRunneras registration is automatic.- Parameters:
registry- the bean definition registrypostProcessor- the post processor class to registerdefinitions- the initial mock/spy definitions
-