Skip to content

Commit e5010a8

Browse files
committed
Test for expected behavior of getAllMergedAnnotations vs findAllMergedAnnotations
Issue: SPR-15271 (cherry picked from commit 6108ab1)
1 parent 1db4208 commit e5010a8

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,8 +36,7 @@
3636
import org.junit.internal.ArrayComparisonFailure;
3737
import org.junit.rules.ExpectedException;
3838

39-
import org.springframework.core.annotation.AnnotationUtilsTests.WebController;
40-
import org.springframework.core.annotation.AnnotationUtilsTests.WebMapping;
39+
import org.springframework.core.annotation.AnnotationUtilsTests.*;
4140
import org.springframework.stereotype.Component;
4241
import org.springframework.util.Assert;
4342
import org.springframework.util.MultiValueMap;
@@ -54,6 +53,7 @@
5453
*
5554
* @author Sam Brannen
5655
* @author Rossen Stoyanchev
56+
* @author Juergen Hoeller
5757
* @since 4.0.3
5858
* @see AnnotationUtilsTests
5959
* @see MultipleComposedAnnotationsOnSingleAnnotatedElementTests
@@ -91,6 +91,10 @@ public void getMetaAnnotationTypesOnClassWithMetaDepth2() {
9191
assertEquals(names(TransactionalComponent.class, Transactional.class, Component.class), names);
9292
}
9393

94+
private Set<String> names(Class<?>... classes) {
95+
return stream(classes).map(Class::getName).collect(toSet());
96+
}
97+
9498
@Test
9599
public void hasMetaAnnotationTypesOnNonAnnotatedClass() {
96100
assertFalse(hasMetaAnnotationTypes(NonAnnotatedClass.class, TX_NAME));
@@ -715,8 +719,18 @@ public void javaxAnnotationTypeViaFindMergedAnnotation() throws Exception {
715719
assertEquals(SpringAppConfigClass.class.getAnnotation(Resource.class), findMergedAnnotation(SpringAppConfigClass.class, Resource.class));
716720
}
717721

718-
private Set<String> names(Class<?>... classes) {
719-
return stream(classes).map(Class::getName).collect(toSet());
722+
@Test
723+
public void getAllMergedAnnotationsOnClassWithInterface() throws Exception {
724+
Method m = TransactionalServiceImpl.class.getMethod("doIt");
725+
Set<Transactional> allMergedAnnotations = getAllMergedAnnotations(m, Transactional.class);
726+
assertTrue(allMergedAnnotations.isEmpty());
727+
}
728+
729+
@Test
730+
public void findAllMergedAnnotationsOnClassWithInterface() throws Exception {
731+
Method m = TransactionalServiceImpl.class.getMethod("doIt");
732+
Set<Transactional> allMergedAnnotations = findAllMergedAnnotations(m, Transactional.class);
733+
assertEquals(1, allMergedAnnotations.size());
720734
}
721735

722736

@@ -1271,4 +1285,17 @@ static class SpringAppConfigClass {
12711285
static class ResourceHolder {
12721286
}
12731287

1288+
interface TransactionalService {
1289+
1290+
@Transactional
1291+
void doIt();
1292+
}
1293+
1294+
class TransactionalServiceImpl implements TransactionalService {
1295+
1296+
@Override
1297+
public void doIt() {
1298+
}
1299+
}
1300+
12741301
}

0 commit comments

Comments
 (0)