Add MergedAnnotation.getTypeHierarchy method

Add a `getTypeHierarchy()` method to `MergedAnnotation` that can be used
to return the full type hierarchy information. This method is
specifically designed to be used in combination with
`MergedAnnotationPredicates.unique`.

This update also allows us to delete the `parentAndType` method
from `AnnotatedElementUtils`.

Closes gh-22908
This commit is contained in:
Phillip Webb
2019-04-29 10:44:52 -07:00
committed by Juergen Hoeller
parent f86affe404
commit 3b145a5a73
8 changed files with 65 additions and 8 deletions

View File

@@ -245,6 +245,15 @@ public class AnnotationTypeMappingsTests {
assertThat(mappings.get(1).getAnnotationType()).isEqualTo(MappedTarget.class);
}
@Test
public void getAnnotationTypeHierarchyReturnsTypeHierarchy() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(
ThreeDeepA.class);
AnnotationTypeMapping mappingC = mappings.get(2);
assertThat(mappingC.getAnnotationTypeHierarchy()).containsExactly(
ThreeDeepA.class, ThreeDeepB.class, ThreeDeepC.class);
}
@Test
public void getAnnotationWhenRootReturnsNull() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(

View File

@@ -170,6 +170,15 @@ public class MergedAnnotationsTests {
assertThat(annotation.getRoot()).isSameAs(annotation);
}
@Test
public void getTypeHierarchy() {
MergedAnnotation<?> annotation = MergedAnnotations.from(
ComposedTransactionalComponentClass.class).get(
TransactionalComponent.class);
assertThat(annotation.getTypeHierarchy()).containsExactly(
ComposedTransactionalComponent.class, TransactionalComponent.class);
}
@Test
public void collectMultiValueMapFromNonAnnotatedClass() {
MultiValueMap<String, Object> map = MergedAnnotations.from(

View File

@@ -44,6 +44,11 @@ public class MissingMergedAnnotationTests {
assertThatNoSuchElementException().isThrownBy(this.missing::getType);
}
@Test
public void getTypeHierarchyReturnsEmptyList() {
assertThat(this.missing.getTypeHierarchy()).isEmpty();
}
@Test
public void isPresentReturnsFalse() {
assertThat(this.missing.isPresent()).isFalse();