Skip to content

Commit b94c6fd

Browse files
committed
Add tests for SPR-12738
1 parent facd240 commit b94c6fd

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import java.lang.annotation.Retention;
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
25+
import java.lang.reflect.Method;
2526
import java.util.Arrays;
2627

28+
import org.junit.Ignore;
2729
import org.junit.Test;
2830

2931
import org.springframework.util.MultiValueMap;
@@ -123,6 +125,35 @@ public void getAnnotationAttributesFavorsInheritedComposedAnnotationsOverMoreLoc
123125
attributes.getBoolean("readOnly"));
124126
}
125127

128+
// SPR-12738
129+
130+
@Test
131+
public void getAnnotationAttributesInheritedFromInterface() {
132+
String name = Transactional.class.getName();
133+
AnnotationAttributes attributes = getAnnotationAttributes(ConcreteClassWithInheritedAnnotation.class, name);
134+
// assertNotNull(attributes);
135+
}
136+
137+
// SPR-12738
138+
139+
@Test
140+
public void getAnnotationAttributesInheritedFromAbstractMethod() throws NoSuchMethodException {
141+
String name = Transactional.class.getName();
142+
Method method = ConcreteClassWithInheritedAnnotation.class.getMethod("handle");
143+
AnnotationAttributes attributes = getAnnotationAttributes(method, name);
144+
// assertNotNull(attributes);
145+
}
146+
147+
// SPR-12738
148+
149+
@Test
150+
public void getAnnotationAttributesInheritedFromParameterizedMethod() throws NoSuchMethodException {
151+
String name = Transactional.class.getName();
152+
Method method = ConcreteClassWithInheritedAnnotation.class.getMethod("handleParameterized", String.class);
153+
AnnotationAttributes attributes = getAnnotationAttributes(ConcreteClassWithInheritedAnnotation.class, name);
154+
// assertNotNull(attributes);
155+
}
156+
126157

127158
// -------------------------------------------------------------------------
128159

@@ -154,7 +185,7 @@ static class MetaCycleAnnotatedClass {
154185
// -------------------------------------------------------------------------
155186

156187
@Retention(RetentionPolicy.RUNTIME)
157-
@Target(ElementType.TYPE)
188+
@Target({ElementType.TYPE, ElementType.METHOD})
158189
@Documented
159190
@Inherited
160191
@interface Transactional {
@@ -226,4 +257,29 @@ static class DerivedTxConfig extends TxConfig {
226257
static class TxFromMultipleComposedAnnotations {
227258
}
228259

260+
@Transactional
261+
static interface InterfaceWithInheritedAnnotation {
262+
}
263+
264+
static abstract class AbstractClassWithInheritedAnnotation<T> implements InterfaceWithInheritedAnnotation {
265+
266+
@Transactional
267+
public abstract void handle();
268+
269+
@Transactional
270+
public void handleParameterized(T t) {
271+
}
272+
}
273+
274+
static class ConcreteClassWithInheritedAnnotation extends AbstractClassWithInheritedAnnotation<String> {
275+
276+
@Override
277+
public void handle() {
278+
}
279+
280+
@Override
281+
public void handleParameterized(String s) {
282+
}
283+
}
284+
229285
}

0 commit comments

Comments
 (0)