Skip to content

Commit 1afdd9b

Browse files
committed
Polishing
(cherry picked from commit 02aca9c)
1 parent d0c839f commit 1afdd9b

File tree

4 files changed

+55
-59
lines changed

4 files changed

+55
-59
lines changed

spring-context/src/test/java/org/springframework/context/annotation/configuration/Spr10744Tests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ public class Spr10744Tests {
4141
@Test
4242
public void testSpr10744() throws Exception {
4343
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
44-
MyTestScope scope = new MyTestScope();
45-
context.getBeanFactory().registerScope("myTestScope", scope);
44+
context.getBeanFactory().registerScope("myTestScope", new MyTestScope());
4645
context.register(MyTestConfiguration.class);
4746
context.refresh();
47+
4848
Foo bean1 = context.getBean("foo", Foo.class);
4949
Foo bean2 = context.getBean("foo", Foo.class);
5050
assertThat(bean1, sameInstance(bean2));
51-
// Should have created a single instance for the proxy
51+
52+
// Should not have invoked constructor for the proxy instance
5253
assertThat(createCount, equalTo(0));
5354
assertThat(scopeCount, equalTo(0));
5455

@@ -118,9 +119,9 @@ public Foo foo() {
118119
@Configuration
119120
static class MyTestConfiguration extends MyConfiguration {
120121

121-
@Override
122-
@Scope(value = "myTestScope", proxyMode = ScopedProxyMode.TARGET_CLASS)
123122
@Bean
123+
@Scope(value = "myTestScope", proxyMode = ScopedProxyMode.TARGET_CLASS)
124+
@Override
124125
public Foo foo() {
125126
return new Foo();
126127
}

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public abstract class AnnotationUtils {
7070
* Get a single {@link Annotation} of {@code annotationType} from the supplied
7171
* annotation: either the given annotation itself or a meta-annotation thereof.
7272
* @param ann the Annotation to check
73-
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
74-
* @return the matching annotation or {@code null} if not found
73+
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
74+
* @return the matching annotation, or {@code null} if none found
7575
* @since 4.0
7676
*/
7777
@SuppressWarnings("unchecked")
@@ -87,8 +87,8 @@ public static <T extends Annotation> T getAnnotation(Annotation ann, Class<T> an
8787
* Method, Constructor or Field. Meta-annotations will be searched if the annotation
8888
* is not declared locally on the supplied element.
8989
* @param ae the Method, Constructor or Field from which to get the annotation
90-
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
91-
* @return the matching annotation or {@code null} if not found
90+
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
91+
* @return the matching annotation, or {@code null} if none found
9292
* @since 3.1
9393
*/
9494
public static <T extends Annotation> T getAnnotation(AnnotatedElement ae, Class<T> annotationType) {
@@ -119,7 +119,7 @@ public static Annotation[] getAnnotations(Method method) {
119119
* Get a single {@link Annotation} of {@code annotationType} from the supplied {@link Method}.
120120
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
121121
* @param method the method to look for annotations on
122-
* @param annotationType the annotation class to look for
122+
* @param annotationType the annotation type to look for
123123
* @return the annotations found
124124
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
125125
*/
@@ -135,7 +135,7 @@ public static <A extends Annotation> A getAnnotation(Method method, Class<A> ann
135135
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
136136
* @param method the method to look for annotations on
137137
* @param containerAnnotationType the class of the container that holds the annotations
138-
* @param annotationType the annotation class to look for
138+
* @param annotationType the annotation type to look for
139139
* @return the annotations found
140140
* @since 4.0
141141
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
@@ -154,7 +154,7 @@ public static <A extends Annotation> Set<A> getRepeatableAnnotation(Method metho
154154
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
155155
* @param annotatedElement the element to look for annotations on
156156
* @param containerAnnotationType the class of the container that holds the annotations
157-
* @param annotationType the annotation class to look for
157+
* @param annotationType the annotation type to look for
158158
* @return the annotations found
159159
* @since 4.0
160160
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
@@ -170,13 +170,13 @@ public static <A extends Annotation> Set<A> getRepeatableAnnotation(AnnotatedEle
170170

171171
/**
172172
* Find a single {@link Annotation} of {@code annotationType} from the supplied
173-
* {@link Method}, traversing its super methods (i.e., from super classes and
173+
* {@link Method}, traversing its super methods (i.e., from superclasses and
174174
* interfaces) if no annotation can be found on the given method itself.
175175
* <p>Annotations on methods are not inherited by default, so we need to handle
176176
* this explicitly.
177177
* @param method the method to look for annotations on
178-
* @param annotationType the annotation class to look for
179-
* @return the annotation found, or {@code null} if none found
178+
* @param annotationType the annotation type to look for
179+
* @return the annotation found, or {@code null} if none
180180
*/
181181
public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) {
182182
A annotation = getAnnotation(method, annotationType);
@@ -288,8 +288,7 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
288288
}
289289
for (Annotation ann : clazz.getDeclaredAnnotations()) {
290290
if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) {
291-
A annotation = findAnnotation(ann.annotationType(), annotationType,
292-
visited);
291+
A annotation = findAnnotation(ann.annotationType(), annotationType, visited);
293292
if (annotation != null) {
294293
return annotation;
295294
}
@@ -312,8 +311,8 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
312311
* <p>The standard {@link Class} API does not provide a mechanism for determining which class
313312
* in an inheritance hierarchy actually declares an {@link Annotation}, so we need to handle
314313
* this explicitly.
315-
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
316-
* @param clazz the class on which to check for the annotation, or {@code null}
314+
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
315+
* @param clazz the class on which to check for the annotation (may be {@code null})
317316
* @return the first {@link Class} in the inheritance hierarchy of the specified {@code clazz}
318317
* which declares an annotation for the specified {@code annotationType}, or {@code null}
319318
* if not found
@@ -509,8 +508,7 @@ else if (nestedAnnotationsAsMap && value instanceof Annotation[]) {
509508
Annotation[] realAnnotations = (Annotation[]) value;
510509
AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
511510
for (int i = 0; i < realAnnotations.length; i++) {
512-
mappedAnnotations[i] = getAnnotationAttributes(
513-
realAnnotations[i], classValuesAsString, true);
511+
mappedAnnotations[i] = getAnnotationAttributes(realAnnotations[i], classValuesAsString, true);
514512
}
515513
attrs.put(method.getName(), mappedAnnotations);
516514
}
@@ -634,7 +632,7 @@ private void process(AnnotatedElement annotatedElement) {
634632
this.result.add((A) annotation);
635633
}
636634
else if (ObjectUtils.nullSafeEquals(this.containerAnnotationType, annotation.annotationType())) {
637-
result.addAll(Arrays.asList(getValue(annotation)));
635+
this.result.addAll(Arrays.asList(getValue(annotation)));
638636
}
639637
else if (!isInJavaLangAnnotationPackage(annotation)) {
640638
process(annotation.annotationType());
@@ -651,8 +649,8 @@ private A[] getValue(Annotation annotation) {
651649
return (A[]) method.invoke(annotation);
652650
}
653651
catch (Exception ex) {
654-
throw new IllegalStateException("Unable to read value from repeating annotation container "
655-
+ this.containerAnnotationType.getName(), ex);
652+
throw new IllegalStateException("Unable to read value from repeating annotation container " +
653+
this.containerAnnotationType.getName(), ex);
656654
}
657655
}
658656
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
/**
3131
* Oracle-specific implementation of the {@link org.springframework.jdbc.core.metadata.TableMetaDataProvider}.
32-
* Supports a feature for including synonyms in the metadata lookup. Also supports lookup of current schema using
33-
* the sys_context.
32+
* Supports a feature for including synonyms in the metadata lookup. Also supports lookup of current schema
33+
* using the sys_context.
3434
*
3535
* <p>Thanks to Mike Youngstrom and Bruce Campbell for submitting the original suggestion for the Oracle
3636
* current schema lookup implementation.
@@ -128,7 +128,6 @@ public void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData,
128128

129129
/*
130130
* Oracle-based implementation for detecting the current schema.
131-
* @param databaseMetaData
132131
*/
133132
private void lookupDefaultSchema(DatabaseMetaData databaseMetaData) {
134133
try {

spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,24 @@
2828
import org.apache.commons.logging.LogFactory;
2929

3030
import org.springframework.beans.BeanUtils;
31-
import org.springframework.context.ApplicationContext;
3231
import org.springframework.core.annotation.AnnotationAttributes;
33-
import org.springframework.test.context.MetaAnnotationUtils.*;
3432
import org.springframework.util.Assert;
3533
import org.springframework.util.ClassUtils;
3634
import org.springframework.util.ObjectUtils;
3735

38-
import static org.springframework.test.context.MetaAnnotationUtils.*;
39-
4036
/**
41-
* <p>
42-
* {@code TestContextManager} is the main entry point into the
43-
* <em>Spring TestContext Framework</em>, which provides support for loading and
44-
* accessing {@link ApplicationContext application contexts}, dependency
45-
* injection of test instances,
46-
* {@link org.springframework.transaction.annotation.Transactional
47-
* transactional} execution of test methods, etc.
48-
* </p>
49-
* <p>
50-
* Specifically, a {@code TestContextManager} is responsible for managing a
37+
* {@code TestContextManager} is the main entry point into the <em>Spring
38+
* TestContext Framework</em>, which provides support for loading and accessing
39+
* {@link org.springframework.context.ApplicationContext application contexts},
40+
* dependency injection of test instances,
41+
* {@link org.springframework.transaction.annotation.Transactional transactional}
42+
* execution of test methods, etc.
43+
*
44+
* <p>Specifically, a {@code TestContextManager} is responsible for managing a
5145
* single {@link TestContext} and signaling events to all registered
5246
* {@link TestExecutionListener TestExecutionListeners} at well defined test
5347
* execution points:
54-
* </p>
48+
*
5549
* <ul>
5650
* <li>{@link #beforeTestClass() before test class execution}: prior to any
5751
* <em>before class methods</em> of a particular testing framework (e.g., JUnit
@@ -88,9 +82,10 @@ public class TestContextManager {
8882
private static final Log logger = LogFactory.getLog(TestContextManager.class);
8983

9084
/**
91-
* Cache of Spring application contexts. This needs to be static, as tests
92-
* may be destroyed and recreated between running individual test methods,
93-
* for example with JUnit.
85+
* Cache of Spring application contexts.
86+
* <p>This needs to be static, since test instances may be destroyed and
87+
* recreated between invocations of individual test methods, as is the case
88+
* with JUnit.
9489
*/
9590
static final ContextCache contextCache = new ContextCache();
9691

@@ -100,34 +95,36 @@ public class TestContextManager {
10095

10196

10297
/**
103-
* Delegates to {@link #TestContextManager(Class, String)} with a value of
98+
* Construct a new {@code TestContextManager} for the specified {@linkplain Class test class}
99+
* and automatically {@link #registerTestExecutionListeners register} the
100+
* {@link TestExecutionListener TestExecutionListeners} configured for the test class
101+
* via the {@link TestExecutionListeners &#064;TestExecutionListeners} annotation.
102+
* <p>Delegates to {@link #TestContextManager(Class, String)} with a value of
104103
* {@code null} for the default {@code ContextLoader} class name.
105104
*/
106105
public TestContextManager(Class<?> testClass) {
107106
this(testClass, null);
108107
}
109108

110109
/**
111-
* Constructs a new {@code TestContextManager} for the specified {@linkplain Class
112-
* test class} and automatically {@link #registerTestExecutionListeners registers} the
110+
* Construct a new {@code TestContextManager} for the specified {@linkplain Class test class}
111+
* and automatically {@link #registerTestExecutionListeners register} the
113112
* {@link TestExecutionListener TestExecutionListeners} configured for the test class
114-
* via the {@link TestExecutionListeners @TestExecutionListeners} annotation.
113+
* via the {@link TestExecutionListeners &#064;TestExecutionListeners} annotation.
115114
* @param testClass the test class to be managed
116-
* @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
117-
* class to use (may be {@code null})
118-
* @see #registerTestExecutionListeners(TestExecutionListener...)
119-
* @deprecated Spring Framework 4.1 will introduce a bootstrap strategy for
120-
* the TestContext framework at which point this constructor will be removed.
115+
* @param defaultContextLoaderClassName the name of the default {@code ContextLoader} class
116+
* to use (may be {@code null})
117+
* @see #registerTestExecutionListeners
121118
*/
122119
@Deprecated
123120
public TestContextManager(Class<?> testClass, String defaultContextLoaderClassName) {
124121
this.testContext = new DefaultTestContext(testClass, contextCache, defaultContextLoaderClassName);
125122
registerTestExecutionListeners(retrieveTestExecutionListeners(testClass));
126123
}
127124

125+
128126
/**
129-
* Returns the {@link TestContext} managed by this
130-
* {@code TestContextManager}.
127+
* Get the {@link TestContext} managed by this {@code TestContextManager}.
131128
*/
132129
protected final TestContext getTestContext() {
133130
return this.testContext;
@@ -183,7 +180,8 @@ private TestExecutionListener[] retrieveTestExecutionListeners(Class<?> clazz) {
183180
Class<TestExecutionListeners> annotationType = TestExecutionListeners.class;
184181
List<Class<? extends TestExecutionListener>> classesList = new ArrayList<Class<? extends TestExecutionListener>>();
185182

186-
AnnotationDescriptor<TestExecutionListeners> descriptor = findAnnotationDescriptor(clazz, annotationType);
183+
MetaAnnotationUtils.AnnotationDescriptor<TestExecutionListeners> descriptor =
184+
MetaAnnotationUtils.findAnnotationDescriptor(clazz, annotationType);
187185

188186
// Use defaults?
189187
if (descriptor == null) {
@@ -223,8 +221,8 @@ else if (!ObjectUtils.isEmpty(valueListenerClasses)) {
223221
classesList.addAll(0, Arrays.<Class<? extends TestExecutionListener>> asList(listenerClasses));
224222
}
225223

226-
descriptor = (annAttrs.getBoolean("inheritListeners") ? findAnnotationDescriptor(
227-
descriptor.getRootDeclaringClass().getSuperclass(), annotationType) : null);
224+
descriptor = (annAttrs.getBoolean("inheritListeners") ? MetaAnnotationUtils.findAnnotationDescriptor(
225+
descriptor.getRootDeclaringClass().getSuperclass(), annotationType) : null);
228226
}
229227
}
230228

0 commit comments

Comments
 (0)