Polishing
This commit is contained in:
parent
58adc150c9
commit
02aca9c754
|
@ -41,14 +41,15 @@ public class Spr10744Tests {
|
|||
@Test
|
||||
public void testSpr10744() throws Exception {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MyTestScope scope = new MyTestScope();
|
||||
context.getBeanFactory().registerScope("myTestScope", scope);
|
||||
context.getBeanFactory().registerScope("myTestScope", new MyTestScope());
|
||||
context.register(MyTestConfiguration.class);
|
||||
context.refresh();
|
||||
|
||||
Foo bean1 = context.getBean("foo", Foo.class);
|
||||
Foo bean2 = context.getBean("foo", Foo.class);
|
||||
assertThat(bean1, sameInstance(bean2));
|
||||
// Should have created a single instance for the proxy
|
||||
|
||||
// Should not have invoked constructor for the proxy instance
|
||||
assertThat(createCount, equalTo(0));
|
||||
assertThat(scopeCount, equalTo(0));
|
||||
|
||||
|
@ -118,9 +119,9 @@ public class Spr10744Tests {
|
|||
@Configuration
|
||||
static class MyTestConfiguration extends MyConfiguration {
|
||||
|
||||
@Override
|
||||
@Scope(value = "myTestScope", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@Bean
|
||||
@Scope(value = "myTestScope", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@Override
|
||||
public Foo foo() {
|
||||
return new Foo();
|
||||
}
|
||||
|
|
|
@ -70,8 +70,8 @@ public abstract class AnnotationUtils {
|
|||
* Get a single {@link Annotation} of {@code annotationType} from the supplied
|
||||
* annotation: either the given annotation itself or a meta-annotation thereof.
|
||||
* @param ann the Annotation to check
|
||||
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
|
||||
* @return the matching annotation or {@code null} if not found
|
||||
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
|
||||
* @return the matching annotation, or {@code null} if none found
|
||||
* @since 4.0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -87,8 +87,8 @@ public abstract class AnnotationUtils {
|
|||
* Method, Constructor or Field. Meta-annotations will be searched if the annotation
|
||||
* is not declared locally on the supplied element.
|
||||
* @param ae the Method, Constructor or Field from which to get the annotation
|
||||
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
|
||||
* @return the matching annotation or {@code null} if not found
|
||||
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
|
||||
* @return the matching annotation, or {@code null} if none found
|
||||
* @since 3.1
|
||||
*/
|
||||
public static <T extends Annotation> T getAnnotation(AnnotatedElement ae, Class<T> annotationType) {
|
||||
|
@ -119,7 +119,7 @@ public abstract class AnnotationUtils {
|
|||
* Get a single {@link Annotation} of {@code annotationType} from the supplied {@link Method}.
|
||||
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
||||
* @param method the method to look for annotations on
|
||||
* @param annotationType the annotation class to look for
|
||||
* @param annotationType the annotation type to look for
|
||||
* @return the annotations found
|
||||
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
||||
*/
|
||||
|
@ -135,7 +135,7 @@ public abstract class AnnotationUtils {
|
|||
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
||||
* @param method the method to look for annotations on
|
||||
* @param containerAnnotationType the class of the container that holds the annotations
|
||||
* @param annotationType the annotation class to look for
|
||||
* @param annotationType the annotation type to look for
|
||||
* @return the annotations found
|
||||
* @since 4.0
|
||||
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
||||
|
@ -154,7 +154,7 @@ public abstract class AnnotationUtils {
|
|||
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
||||
* @param annotatedElement the element to look for annotations on
|
||||
* @param containerAnnotationType the class of the container that holds the annotations
|
||||
* @param annotationType the annotation class to look for
|
||||
* @param annotationType the annotation type to look for
|
||||
* @return the annotations found
|
||||
* @since 4.0
|
||||
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
||||
|
@ -170,13 +170,13 @@ public abstract class AnnotationUtils {
|
|||
|
||||
/**
|
||||
* Find a single {@link Annotation} of {@code annotationType} from the supplied
|
||||
* {@link Method}, traversing its super methods (i.e., from super classes and
|
||||
* {@link Method}, traversing its super methods (i.e., from superclasses and
|
||||
* interfaces) if no annotation can be found on the given method itself.
|
||||
* <p>Annotations on methods are not inherited by default, so we need to handle
|
||||
* this explicitly.
|
||||
* @param method the method to look for annotations on
|
||||
* @param annotationType the annotation class to look for
|
||||
* @return the annotation found, or {@code null} if none found
|
||||
* @param annotationType the annotation type to look for
|
||||
* @return the annotation found, or {@code null} if none
|
||||
*/
|
||||
public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) {
|
||||
A annotation = getAnnotation(method, annotationType);
|
||||
|
@ -288,8 +288,7 @@ public abstract class AnnotationUtils {
|
|||
}
|
||||
for (Annotation ann : clazz.getDeclaredAnnotations()) {
|
||||
if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) {
|
||||
A annotation = findAnnotation(ann.annotationType(), annotationType,
|
||||
visited);
|
||||
A annotation = findAnnotation(ann.annotationType(), annotationType, visited);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
}
|
||||
|
@ -312,8 +311,8 @@ public abstract class AnnotationUtils {
|
|||
* <p>The standard {@link Class} API does not provide a mechanism for determining which class
|
||||
* in an inheritance hierarchy actually declares an {@link Annotation}, so we need to handle
|
||||
* this explicitly.
|
||||
* @param annotationType the annotation class to look for, both locally and as a meta-annotation
|
||||
* @param clazz the class on which to check for the annotation, or {@code null}
|
||||
* @param annotationType the annotation type to look for, both locally and as a meta-annotation
|
||||
* @param clazz the class on which to check for the annotation (may be {@code null})
|
||||
* @return the first {@link Class} in the inheritance hierarchy of the specified {@code clazz}
|
||||
* which declares an annotation for the specified {@code annotationType}, or {@code null}
|
||||
* if not found
|
||||
|
@ -509,8 +508,7 @@ public abstract class AnnotationUtils {
|
|||
Annotation[] realAnnotations = (Annotation[]) value;
|
||||
AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
|
||||
for (int i = 0; i < realAnnotations.length; i++) {
|
||||
mappedAnnotations[i] = getAnnotationAttributes(
|
||||
realAnnotations[i], classValuesAsString, true);
|
||||
mappedAnnotations[i] = getAnnotationAttributes(realAnnotations[i], classValuesAsString, true);
|
||||
}
|
||||
attrs.put(method.getName(), mappedAnnotations);
|
||||
}
|
||||
|
@ -634,7 +632,7 @@ public abstract class AnnotationUtils {
|
|||
this.result.add((A) annotation);
|
||||
}
|
||||
else if (ObjectUtils.nullSafeEquals(this.containerAnnotationType, annotation.annotationType())) {
|
||||
result.addAll(Arrays.asList(getValue(annotation)));
|
||||
this.result.addAll(Arrays.asList(getValue(annotation)));
|
||||
}
|
||||
else if (!isInJavaLangAnnotationPackage(annotation)) {
|
||||
process(annotation.annotationType());
|
||||
|
@ -651,8 +649,8 @@ public abstract class AnnotationUtils {
|
|||
return (A[]) method.invoke(annotation);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Unable to read value from repeating annotation container "
|
||||
+ this.containerAnnotationType.getName(), ex);
|
||||
throw new IllegalStateException("Unable to read value from repeating annotation container " +
|
||||
this.containerAnnotationType.getName(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.springframework.util.ReflectionUtils;
|
|||
|
||||
/**
|
||||
* Oracle-specific implementation of the {@link org.springframework.jdbc.core.metadata.TableMetaDataProvider}.
|
||||
* Supports a feature for including synonyms in the metadata lookup. Also supports lookup of current schema using
|
||||
* the sys_context.
|
||||
* Supports a feature for including synonyms in the metadata lookup. Also supports lookup of current schema
|
||||
* using the sys_context.
|
||||
*
|
||||
* <p>Thanks to Mike Youngstrom and Bruce Campbell for submitting the original suggestion for the Oracle
|
||||
* current schema lookup implementation.
|
||||
|
@ -128,7 +128,6 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
|
|||
|
||||
/*
|
||||
* Oracle-based implementation for detecting the current schema.
|
||||
* @param databaseMetaData
|
||||
*/
|
||||
private void lookupDefaultSchema(DatabaseMetaData databaseMetaData) {
|
||||
try {
|
||||
|
|
|
@ -89,21 +89,22 @@ public class TestContextManager {
|
|||
|
||||
|
||||
/**
|
||||
* Construct a new {@code TestContextManager} for the specified {@linkplain Class
|
||||
* test class} and automatically {@link #registerTestExecutionListeners register} the
|
||||
* Construct a new {@code TestContextManager} for the specified {@linkplain Class test class}
|
||||
* and automatically {@link #registerTestExecutionListeners register} the
|
||||
* {@link TestExecutionListener TestExecutionListeners} configured for the test class
|
||||
* via the {@link TestExecutionListeners @TestExecutionListeners} annotation.
|
||||
* @param testClass the test class to be managed
|
||||
* @see #registerTestExecutionListeners(List)
|
||||
* @see #registerTestExecutionListeners
|
||||
*/
|
||||
public TestContextManager(Class<?> testClass) {
|
||||
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = new DefaultCacheAwareContextLoaderDelegate(contextCache);
|
||||
BootstrapContext bootstrapContext = new DefaultBootstrapContext(testClass, cacheAwareContextLoaderDelegate);
|
||||
this.testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(bootstrapContext);
|
||||
this.testContext = new DefaultTestContext(testContextBootstrapper);
|
||||
registerTestExecutionListeners(testContextBootstrapper.getTestExecutionListeners());
|
||||
this.testContext = new DefaultTestContext(this.testContextBootstrapper);
|
||||
registerTestExecutionListeners(this.testContextBootstrapper.getTestExecutionListeners());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the {@link TestContext} managed by this {@code TestContextManager}.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue