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
ModifierConstructorDescriptionprotected
OverrideMetadata
(Field field, ResolvableType beanType, String beanName, BeanOverrideStrategy strategy) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Object
createOverride
(String beanName, BeanDefinition existingBeanDefinition, Object existingBeanInstance) Create an override instance from thisOverrideMetadata
, optionally provided with an existingBeanDefinition
and/or an original instance, that is a singleton or an early wrapped instance.boolean
static List<OverrideMetadata>
forTestClass
(Class<?> testClass) Parse the giventestClass
and build the corresponding list of beanOverrideMetadata
.Get the bean name to override, ornull
to look for a single matching bean of typegetBeanType()
.final ResolvableType
Get the bean type to override.final Field
getField()
Get the annotatedField
.final BeanOverrideStrategy
Get theBeanOverrideStrategy
for this instance, as a hint on how and when the override instance should be created.int
hashCode()
toString()
protected void
track
(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 giventestClass
and 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, ornull
to look for a single matching bean of typegetBeanType()
. -
getStrategy
Get theBeanOverrideStrategy
for 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 existingBeanDefinition
and/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, ornull
if not relevantexistingBeanInstance
- an existing instance for the supplied bean name for wrapping purposes, ornull
if 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
-