Document & test status quo for getMetaAnnotationTypes()
This commit documents the status quo for the getMetaAnnotationTypes() method in AnnotatedElementUtils and adds appropriate regression tests to AnnotatedElementUtilsTests. In addition, this commit also introduces a SimpleAnnotationProcessor base class in AnnotatedElementUtils. Issue: SPR-11514
This commit is contained in:
@@ -24,10 +24,13 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -42,6 +45,28 @@ import static org.springframework.core.annotation.AnnotatedElementUtils.*;
|
||||
*/
|
||||
public class AnnotatedElementUtilsTests {
|
||||
|
||||
private Set<String> names(Class<?>... classes) {
|
||||
return Arrays.stream(classes).map(clazz -> clazz.getName()).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaAnnotationTypesOnNonAnnotatedClass() {
|
||||
assertNull(getMetaAnnotationTypes(NonAnnotatedClass.class, TransactionalComponent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaAnnotationTypesOnClassWithMetaDepth1() {
|
||||
Set<String> names = getMetaAnnotationTypes(TransactionalComponentClass.class, TransactionalComponent.class);
|
||||
assertEquals(names(Transactional.class, Component.class, Retention.class, Documented.class, Target.class, Inherited.class), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaAnnotationTypesOnClassWithMetaDepth2() {
|
||||
Set<String> names = getMetaAnnotationTypes(ComposedTransactionalComponentClass.class,
|
||||
ComposedTransactionalComponent.class);
|
||||
assertEquals(names(TransactionalComponent.class, Transactional.class, Component.class, Retention.class, Documented.class, Target.class, Inherited.class), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllAnnotationAttributesOnClassWithLocalAnnotation() {
|
||||
MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(TxConfig.class,
|
||||
@@ -318,8 +343,30 @@ public class AnnotatedElementUtilsTests {
|
||||
@interface TxComposed2 {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Component
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface TransactionalComponent {
|
||||
}
|
||||
|
||||
@TransactionalComponent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface ComposedTransactionalComponent {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
static class NonAnnotatedClass {
|
||||
}
|
||||
|
||||
@TransactionalComponent
|
||||
static class TransactionalComponentClass {
|
||||
}
|
||||
|
||||
@ComposedTransactionalComponent
|
||||
static class ComposedTransactionalComponentClass {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
static class ClassWithInheritedAnnotation {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user