Class OverrideMetadata
java.lang.Object
org.springframework.test.context.bean.override.OverrideMetadata
Metadata for Bean Override injection points, also responsible for creation of
the overriding instance.
WARNING: implementations are used as a cache key and
must implement proper equals() and hashCode() methods.
Specific implementations of metadata can have state to be used during override instance creation — for example, based on further parsing of the annotation or the annotated field.
- Since:
- 6.2
- Author:
- Simon Baslé, Stephane Nicoll
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOverrideMetadata(Field field, ResolvableType beanType, String beanName, BeanOverrideStrategy strategy) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ObjectcreateOverride(String beanName, BeanDefinition existingBeanDefinition, Object existingBeanInstance) Create an override instance from thisOverrideMetadata, optionally provided with an existingBeanDefinitionand/or an original instance, that is a singleton or an early wrapped instance.booleanstatic List<OverrideMetadata>forTestClass(Class<?> testClass) Parse the giventestClassand build the corresponding list of beanOverrideMetadata.Get the bean name to override, ornullto look for a single matching bean of typegetBeanType().final ResolvableTypeGet the bean type to override.final FieldgetField()Get the annotatedField.final BeanOverrideStrategyGet theBeanOverrideStrategyfor this instance, as a hint on how and when the override instance should be created.inthashCode()toString()protected voidtrack(Object override, SingletonBeanRegistry trackingBeanRegistry) Optionally track objects created by thisOverrideMetadata.
-
Constructor Details
-
OverrideMetadata
protected OverrideMetadata(Field field, ResolvableType beanType, @Nullable String beanName, BeanOverrideStrategy strategy)
-
-
Method Details
-
forTestClass
Parse the giventestClassand build the corresponding list of beanOverrideMetadata.- Parameters:
testClass- the class to parse- Returns:
- a list of
OverrideMetadata
-
getField
Get the annotatedField. -
getBeanType
Get the bean type to override. -
getBeanName
Get the bean name to override, ornullto look for a single matching bean of typegetBeanType(). -
getStrategy
Get theBeanOverrideStrategyfor this instance, as a hint on how and when the override instance should be created. -
createOverride
protected abstract Object createOverride(String beanName, @Nullable BeanDefinition existingBeanDefinition, @Nullable Object existingBeanInstance) Create an override instance from thisOverrideMetadata, optionally provided with an existingBeanDefinitionand/or an original instance, that is a singleton or an early wrapped instance.- Parameters:
beanName- the name of the bean being overriddenexistingBeanDefinition- an existing bean definition for the supplied bean name, ornullif not relevantexistingBeanInstance- an existing instance for the supplied bean name for wrapping purposes, ornullif irrelevant- Returns:
- the instance with which to override the bean
-
track
Optionally track objects created by thisOverrideMetadata.The default is not to track, but this can be overridden in subclasses.
- Parameters:
override- the bean override instance to tracktrackingBeanRegistry- the registry in which trackers can optionally be registered
-
equals
-
hashCode
public int hashCode() -
toString
-