Skip to content

Commit 4e9b503

Browse files
committed
Polish OverrideMetadata
1 parent ba1d01d commit 4e9b503

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

spring-test/src/main/java/org/springframework/test/context/bean/override/OverrideMetadata.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@
4444
* <p><strong>WARNING</strong>: implementations are used as a cache key and
4545
* must implement proper {@code equals()} and {@code hashCode()} methods.
4646
*
47-
* <p>Specific implementations of metadata can have state to be used during
48-
* override {@linkplain #createOverride(String, BeanDefinition, Object)
49-
* instance creation} &mdash; for example, based on further parsing of the
47+
* <p>Concrete implementations of {@code OverrideMetadata} can store state to use
48+
* during override {@linkplain #createOverride(String, BeanDefinition, Object)
49+
* instance creation} &mdash; for example, based on further processing of the
5050
* annotation or the annotated field.
5151
*
5252
* @author Simon Baslé
5353
* @author Stephane Nicoll
54+
* @author Sam Brannen
5455
* @since 6.2
5556
*/
5657
public abstract class OverrideMetadata {
@@ -67,25 +68,27 @@ public abstract class OverrideMetadata {
6768

6869
protected OverrideMetadata(Field field, ResolvableType beanType, @Nullable String beanName,
6970
BeanOverrideStrategy strategy) {
71+
7072
this.field = field;
7173
this.beanType = beanType;
7274
this.beanName = beanName;
7375
this.strategy = strategy;
7476
}
7577

7678
/**
77-
* Parse the given {@code testClass} and build the corresponding list of
78-
* bean {@code OverrideMetadata}.
79-
* @param testClass the class to parse
79+
* Process the given {@code testClass} and build the corresponding list of
80+
* {@code OverrideMetadata} derived from {@link BeanOverride @BeanOverride}
81+
* fields in the test class and its type hierarchy.
82+
* @param testClass the test class to process
8083
* @return a list of {@code OverrideMetadata}
8184
*/
8285
public static List<OverrideMetadata> forTestClass(Class<?> testClass) {
8386
List<OverrideMetadata> metadata = new LinkedList<>();
84-
ReflectionUtils.doWithFields(testClass, field -> parseField(field, testClass, metadata));
87+
ReflectionUtils.doWithFields(testClass, field -> processField(field, testClass, metadata));
8588
return metadata;
8689
}
8790

88-
private static void parseField(Field field, Class<?> testClass, List<OverrideMetadata> metadataList) {
91+
private static void processField(Field field, Class<?> testClass, List<OverrideMetadata> metadataList) {
8992
AtomicBoolean overrideAnnotationFound = new AtomicBoolean();
9093
MergedAnnotations.from(field, DIRECT).stream(BeanOverride.class).forEach(mergedAnnotation -> {
9194
MergedAnnotation<?> metaSource = mergedAnnotation.getMetaSource();
@@ -127,20 +130,20 @@ public final String getBeanName() {
127130
}
128131

129132
/**
130-
* Get the {@link BeanOverrideStrategy} for this instance, as a hint on
131-
* how and when the override instance should be created.
133+
* Get the {@link BeanOverrideStrategy} for this {@code OverrideMetadata},
134+
* which influences how and when the bean override instance should be created.
132135
*/
133136
public final BeanOverrideStrategy getStrategy() {
134137
return this.strategy;
135138
}
136139

137140
/**
138-
* Create an override instance from this {@link OverrideMetadata},
139-
* optionally provided with an existing {@link BeanDefinition} and/or an
141+
* Create a bean override instance for this {@code OverrideMetadata},
142+
* optionally based on an existing {@link BeanDefinition} and/or an
140143
* original instance, that is a singleton or an early wrapped instance.
141144
* @param beanName the name of the bean being overridden
142145
* @param existingBeanDefinition an existing bean definition for the supplied
143-
* bean name, or {@code null} if not relevant
146+
* bean name, or {@code null} if irrelevant
144147
* @param existingBeanInstance an existing instance for the supplied bean name
145148
* for wrapping purposes, or {@code null} if irrelevant
146149
* @return the instance with which to override the bean
@@ -149,8 +152,9 @@ protected abstract Object createOverride(String beanName, @Nullable BeanDefiniti
149152
@Nullable Object existingBeanInstance);
150153

151154
/**
152-
* Optionally track objects created by this {@link OverrideMetadata}.
153-
* <p>The default is not to track, but this can be overridden in subclasses.
155+
* Optionally track objects created by this {@code OverrideMetadata}.
156+
* <p>The default implementation does not track the supplied instance, but
157+
* this can be overridden in subclasses as appropriate.
154158
* @param override the bean override instance to track
155159
* @param trackingBeanRegistry the registry in which trackers can
156160
* optionally be registered

0 commit comments

Comments
 (0)