From b94c6fdf7ae1305516166db710070acf4f967f21 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 20 Feb 2015 13:17:26 -0500 Subject: [PATCH] Add tests for SPR-12738 --- .../AnnotatedElementUtilsTests.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index e56533e9da..4d5e3fa329 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -22,8 +22,10 @@ import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.lang.reflect.Method; import java.util.Arrays; +import org.junit.Ignore; import org.junit.Test; import org.springframework.util.MultiValueMap; @@ -123,6 +125,35 @@ public class AnnotatedElementUtilsTests { attributes.getBoolean("readOnly")); } + // SPR-12738 + + @Test + public void getAnnotationAttributesInheritedFromInterface() { + String name = Transactional.class.getName(); + AnnotationAttributes attributes = getAnnotationAttributes(ConcreteClassWithInheritedAnnotation.class, name); +// assertNotNull(attributes); + } + + // SPR-12738 + + @Test + public void getAnnotationAttributesInheritedFromAbstractMethod() throws NoSuchMethodException { + String name = Transactional.class.getName(); + Method method = ConcreteClassWithInheritedAnnotation.class.getMethod("handle"); + AnnotationAttributes attributes = getAnnotationAttributes(method, name); +// assertNotNull(attributes); + } + + // SPR-12738 + + @Test + public void getAnnotationAttributesInheritedFromParameterizedMethod() throws NoSuchMethodException { + String name = Transactional.class.getName(); + Method method = ConcreteClassWithInheritedAnnotation.class.getMethod("handleParameterized", String.class); + AnnotationAttributes attributes = getAnnotationAttributes(ConcreteClassWithInheritedAnnotation.class, name); +// assertNotNull(attributes); + } + // ------------------------------------------------------------------------- @@ -154,7 +185,7 @@ public class AnnotatedElementUtilsTests { // ------------------------------------------------------------------------- @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.TYPE) + @Target({ElementType.TYPE, ElementType.METHOD}) @Documented @Inherited @interface Transactional { @@ -226,4 +257,29 @@ public class AnnotatedElementUtilsTests { static class TxFromMultipleComposedAnnotations { } + @Transactional + static interface InterfaceWithInheritedAnnotation { + } + + static abstract class AbstractClassWithInheritedAnnotation implements InterfaceWithInheritedAnnotation { + + @Transactional + public abstract void handle(); + + @Transactional + public void handleParameterized(T t) { + } + } + + static class ConcreteClassWithInheritedAnnotation extends AbstractClassWithInheritedAnnotation { + + @Override + public void handle() { + } + + @Override + public void handleParameterized(String s) { + } + } + }