From ee2022e54c56a2dbe8df3cf263450f3fb04dc776 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 5 Jan 2014 03:01:44 +0100 Subject: [PATCH] Polishing --- .../aspectj/AspectJAsyncConfiguration.java | 3 +- .../AbstractAsyncConfiguration.java | 3 +- .../annotation/ProxyAsyncConfiguration.java | 7 +- .../core/annotation/AnnotationUtilsTests.java | 94 ++++++++----------- 4 files changed, 44 insertions(+), 63 deletions(-) diff --git a/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AspectJAsyncConfiguration.java b/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AspectJAsyncConfiguration.java index 7d57047787..a40a01ddb3 100644 --- a/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AspectJAsyncConfiguration.java +++ b/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AspectJAsyncConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.springframework.scheduling.annotation.EnableAsync; * @since 3.1 * @see EnableAsync * @see org.springframework.scheduling.annotation.AsyncConfigurationSelector + * @see org.springframework.scheduling.annotation.ProxyAsyncConfiguration */ @Configuration public class AspectJAsyncConfiguration extends AbstractAsyncConfiguration { diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java index e8bb072345..95ba8a99ef 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java @@ -54,7 +54,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware { /** * Collect any {@link AsyncConfigurer} beans through autowiring. */ - @Autowired(required = false) + @Autowired(required=false) void setConfigurers(Collection configurers) { if (CollectionUtils.isEmpty(configurers)) { return; @@ -65,4 +65,5 @@ public abstract class AbstractAsyncConfiguration implements ImportAware { AsyncConfigurer configurer = configurers.iterator().next(); this.executor = configurer.getAsyncExecutor(); } + } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java index 515295a3e9..19595dfb48 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,21 +42,16 @@ public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration { @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public AsyncAnnotationBeanPostProcessor asyncAdvisor() { Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected"); - AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor(); - Class customAsyncAnnotation = enableAsync.getClass("annotation"); if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) { bpp.setAsyncAnnotationType(customAsyncAnnotation); } - if (this.executor != null) { bpp.setExecutor(this.executor); } - bpp.setProxyTargetClass(this.enableAsync.getBoolean("proxyTargetClass")); bpp.setOrder(this.enableAsync.getNumber("order")); - return bpp; } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java index 0de78f64a0..e54f50aec0 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Set; import org.junit.Test; + import org.springframework.core.Ordered; import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass; import org.springframework.stereotype.Component; @@ -37,6 +38,8 @@ import static org.junit.Assert.*; import static org.springframework.core.annotation.AnnotationUtils.*; /** + * Unit tests for {@link AnnotationUtils}. + * * @author Rod Johnson * @author Juergen Hoeller * @author Sam Brannen @@ -97,9 +100,9 @@ public class AnnotationUtilsTests { // } @Test - public void findAnnotationPrefersInteracesOverLocalMetaAnnotations() { + public void findAnnotationPrefersInterfacesOverLocalMetaAnnotations() { Component component = AnnotationUtils.findAnnotation( - ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class); + ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class); // By inspecting ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface, one // might expect that "meta2" should be found; however, with the current @@ -144,8 +147,7 @@ public class AnnotationUtilsTests { // inherited class-level annotation; note: @Transactional is inherited assertEquals(InheritedAnnotationInterface.class, findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationInterface.class)); - assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, - SubInheritedAnnotationInterface.class)); + assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationInterface.class)); assertEquals(InheritedAnnotationClass.class, findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationClass.class)); assertEquals(InheritedAnnotationClass.class, @@ -301,8 +303,7 @@ public class AnnotationUtilsTests { } @Test - public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() - throws Exception { + public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() throws Exception { Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo"); Order order = findAnnotation(method, Order.class); assertNotNull(order); @@ -322,13 +323,13 @@ public class AnnotationUtilsTests { } - @Component(value = "meta1") + @Component(value="meta1") @Order @Retention(RetentionPolicy.RUNTIME) @interface Meta1 { } - @Component(value = "meta2") + @Component(value="meta2") @Transactional @Retention(RetentionPolicy.RUNTIME) @interface Meta2 { @@ -353,25 +354,20 @@ public class AnnotationUtilsTests { @Order(27) public void annotatedOnRoot() { - } public void overrideToAnnotate() { - } @Order(27) public void overrideWithoutNewAnnotation() { - } public void notAnnotated() { - } @Override public void fromInterfaceImplementedByRoot() { - } } @@ -379,21 +375,23 @@ public class AnnotationUtilsTests { @Order(25) public void annotatedOnLeaf() { - } @Override @Order(1) public void overrideToAnnotate() { - } @Override public void overrideWithoutNewAnnotation() { - } } + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @interface Transactional { + } + public static abstract class Foo { @Order(1) @@ -405,7 +403,6 @@ public class AnnotationUtilsTests { @Override @Transactional public void something(final String arg) { - } } @@ -474,58 +471,45 @@ public class AnnotationUtilsTests { } } - public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod implements - InterfaceWithAnnotatedMethod { + public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod + implements InterfaceWithAnnotatedMethod { } - public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod extends - AbstractDoesNotImplementInterfaceWithAnnotatedMethod { + public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod + extends AbstractDoesNotImplementInterfaceWithAnnotatedMethod { @Override public void foo() { } } + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @interface MyRepeatableContainer { + + MyRepeatable[] value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @Repeatable(MyRepeatableContainer.class) + @interface MyRepeatable { + + String value(); + } + + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @MyRepeatable("meta") + @interface MyRepeatableMeta { + } + public static interface InterfaceWithRepeated { @MyRepeatable("a") @MyRepeatableContainer({ @MyRepeatable("b"), @MyRepeatable("c") }) @MyRepeatableMeta void foo(); - } } - - -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@interface Transactional { - -} - - -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@interface MyRepeatableContainer { - - MyRepeatable[] value(); - -} - - -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Repeatable(MyRepeatableContainer.class) -@interface MyRepeatable { - - String value(); - -} - - -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@MyRepeatable("meta") -@interface MyRepeatableMeta { -}