Restore findAnnotation superclass traversal for java.lang annotations

Closes gh-23929
This commit is contained in:
Juergen Hoeller
2019-11-12 11:51:44 +01:00
parent fac9ca891a
commit 9cc06454aa
2 changed files with 41 additions and 7 deletions

View File

@@ -946,24 +946,24 @@ class AnnotationUtilsTests {
assertThat(synthesizedComponent.value()).as("value from synthesized component: ").isEqualTo("webController");
}
@Test // gh-22702
void findAnnotationWithRepeatablesElements() {
@Test // gh-22702
void findAnnotationWithRepeatablesElements() throws Exception {
assertThat(AnnotationUtils.findAnnotation(TestRepeatablesClass.class,
TestRepeatable.class)).isNull();
assertThat(AnnotationUtils.findAnnotation(TestRepeatablesClass.class,
TestRepeatableContainer.class)).isNotNull();
}
@Test // gh-23856
void findAnnotationFindsRepeatableContainerOnComposedAnnotationMetaAnnotatedWithRepeatableAnnotations() {
@Test // gh-23856
void findAnnotationFindsRepeatableContainerOnComposedAnnotationMetaAnnotatedWithRepeatableAnnotations() throws Exception {
MyRepeatableContainer annotation = AnnotationUtils.findAnnotation(MyRepeatableMeta1And2.class, MyRepeatableContainer.class);
assertThat(annotation).isNotNull();
assertThat(annotation.value()).extracting(MyRepeatable::value).containsExactly("meta1", "meta2");
}
@Test // gh-23856
void findAnnotationFindsRepeatableContainerOnComposedAnnotationMetaAnnotatedWithRepeatableAnnotationsOnMethod() throws NoSuchMethodException {
@Test // gh-23856
void findAnnotationFindsRepeatableContainerOnComposedAnnotationMetaAnnotatedWithRepeatableAnnotationsOnMethod() throws Exception {
Method method = getClass().getDeclaredMethod("methodWithComposedAnnotationMetaAnnotatedWithRepeatableAnnotations");
MyRepeatableContainer annotation = AnnotationUtils.findAnnotation(method, MyRepeatableContainer.class);
@@ -971,6 +971,14 @@ class AnnotationUtilsTests {
assertThat(annotation.value()).extracting(MyRepeatable::value).containsExactly("meta1", "meta2");
}
@Test // gh-23929
void findDeprecatedAnnotation() throws Exception {
assertThat(getAnnotation(DeprecatedClass.class, Deprecated.class)).isNotNull();
assertThat(getAnnotation(SubclassOfDeprecatedClass.class, Deprecated.class)).isNull();
assertThat(findAnnotation(DeprecatedClass.class, Deprecated.class)).isNotNull();
assertThat(findAnnotation(SubclassOfDeprecatedClass.class, Deprecated.class)).isNotNull();
}
@SafeVarargs
static <T> T[] asArray(T... arr) {
@@ -1810,4 +1818,12 @@ class AnnotationUtilsTests {
@TestRepeatable("b")
static class TestRepeatablesClass {
}
@Deprecated
static class DeprecatedClass {
}
static class SubclassOfDeprecatedClass extends DeprecatedClass {
}
}