Search in sources :

Example 6 with ValueHolder

use of org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder in project spring-boot by spring-projects.

the class MockitoPostProcessor method register.

/**
	 * Register the processor with a {@link BeanDefinitionRegistry}. Not required when
	 * using the {@link SpringRunner} as registration is automatic.
	 * @param registry the bean definition registry
	 * @param postProcessor the post processor class to register
	 * @param definitions the initial mock/spy definitions
	 */
@SuppressWarnings("unchecked")
public static void register(BeanDefinitionRegistry registry, Class<? extends MockitoPostProcessor> postProcessor, Set<Definition> definitions) {
    SpyPostProcessor.register(registry);
    BeanDefinition definition = getOrAddBeanDefinition(registry, postProcessor);
    ValueHolder constructorArg = definition.getConstructorArgumentValues().getIndexedArgumentValue(0, Set.class);
    Set<Definition> existing = (Set<Definition>) constructorArg.getValue();
    if (definitions != null) {
        existing.addAll(definitions);
    }
}
Also used : TreeSet(java.util.TreeSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ValueHolder(org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)

Aggregations

ValueHolder (org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder)6 LinkedHashSet (java.util.LinkedHashSet)4 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)4 InjectionPoint (org.springframework.beans.factory.InjectionPoint)3 Set (java.util.Set)2 BeansException (org.springframework.beans.BeansException)2 TypeConverter (org.springframework.beans.TypeConverter)2 TypeMismatchException (org.springframework.beans.TypeMismatchException)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1