Add MergedAnnotation.getRoot() method

Update `MergedAnnotation` with a `getRoot()` method that allows the
root direct annotation to be retrieved easily.

Closes gh-22818
This commit is contained in:
Phillip Webb
2019-04-25 14:14:03 -07:00
parent 7cc132b2a9
commit 83cb51aec6
5 changed files with 43 additions and 0 deletions

View File

@@ -154,6 +154,22 @@ public class MergedAnnotationsTests {
.isEqualTo(ComposedTransactionalComponent.class);
}
@Test
public void getRootWhenNotDirect() {
MergedAnnotations annotations = MergedAnnotations.from(ComposedTransactionalComponentClass.class);
MergedAnnotation<?> annotation = annotations.get(TransactionalComponent.class);
assertThat(annotation.getDepth()).isGreaterThan(0);
assertThat(annotation.getRoot().getType()).isEqualTo(ComposedTransactionalComponent.class);
}
@Test
public void getRootWhenDirect() {
MergedAnnotations annotations = MergedAnnotations.from(ComposedTransactionalComponentClass.class);
MergedAnnotation<?> annotation = annotations.get(ComposedTransactionalComponent.class);
assertThat(annotation.getDepth()).isEqualTo(0);
assertThat(annotation.getRoot()).isSameAs(annotation);
}
@Test
public void collectMultiValueMapFromNonAnnotatedClass() {
MultiValueMap<String, Object> map = MergedAnnotations.from(

View File

@@ -78,6 +78,11 @@ public class MissingMergedAnnotationTests {
assertThat(this.missing.getParent()).isNull();
}
@Test
public void getRootReturnsEmptyAnnotation() {
assertThat(this.missing.getRoot()).isSameAs(this.missing);
}
@Test
public void hasNonDefaultValueThrowsNoSuchElementException() {
assertThatNoSuchElementException().isThrownBy(