|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -44,19 +44,21 @@ import static org.springframework.test.util.MetaAnnotationUtils.*; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MetaAnnotationUtilsTests { |
|
|
|
public class MetaAnnotationUtilsTests { |
|
|
|
|
|
|
|
|
|
|
|
private void assertAtComponentOnComposedAnnotation(Class<?> rootDeclaringClass, String name, |
|
|
|
private void assertAtComponentOnComposedAnnotation( |
|
|
|
Class<? extends Annotation> composedAnnotationType) { |
|
|
|
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) { |
|
|
|
|
|
|
|
|
|
|
|
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, name, composedAnnotationType); |
|
|
|
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, name, composedAnnotationType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass, String name, |
|
|
|
private void assertAtComponentOnComposedAnnotation( |
|
|
|
Class<? extends Annotation> composedAnnotationType) { |
|
|
|
Class<?> startClass, Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) { |
|
|
|
assertAtComponentOnComposedAnnotation(rootDeclaringClass, rootDeclaringClass, composedAnnotationType, name, |
|
|
|
|
|
|
|
composedAnnotationType); |
|
|
|
assertAtComponentOnComposedAnnotation(startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass, |
|
|
|
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass, |
|
|
|
Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) { |
|
|
|
Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) { |
|
|
|
|
|
|
|
|
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class); |
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class); |
|
|
|
assertNotNull("AnnotationDescriptor should not be null", descriptor); |
|
|
|
assertNotNull("AnnotationDescriptor should not be null", descriptor); |
|
|
|
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); |
|
|
|
@ -67,25 +69,29 @@ public class MetaAnnotationUtilsTests { |
|
|
|
assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType()); |
|
|
|
assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, String name, |
|
|
|
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( |
|
|
|
Class<? extends Annotation> composedAnnotationType) { |
|
|
|
Class<?> startClass, String name, Class<? extends Annotation> composedAnnotationType) { |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, name, |
|
|
|
|
|
|
|
composedAnnotationType); |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( |
|
|
|
|
|
|
|
startClass, startClass, name, composedAnnotationType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, |
|
|
|
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, |
|
|
|
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) { |
|
|
|
Class<?> rootDeclaringClass, String name, Class<? extends Annotation> composedAnnotationType) { |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, rootDeclaringClass, |
|
|
|
|
|
|
|
composedAnnotationType, name, composedAnnotationType); |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( |
|
|
|
|
|
|
|
startClass, rootDeclaringClass, composedAnnotationType, name, composedAnnotationType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, |
|
|
|
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass, |
|
|
|
Class<?> rootDeclaringClass, Class<?> declaringClass, String name, |
|
|
|
Class<?> rootDeclaringClass, Class<?> declaringClass, String name, |
|
|
|
Class<? extends Annotation> composedAnnotationType) { |
|
|
|
Class<? extends Annotation> composedAnnotationType) { |
|
|
|
|
|
|
|
|
|
|
|
Class<Component> annotationType = Component.class; |
|
|
|
Class<Component> annotationType = Component.class; |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( |
|
|
|
annotationType, Order.class, Transactional.class); |
|
|
|
startClass, Service.class, annotationType, Order.class, Transactional.class); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor); |
|
|
|
assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor); |
|
|
|
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass()); |
|
|
|
assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass()); |
|
|
|
@ -96,28 +102,27 @@ public class MetaAnnotationUtilsTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorWithNoAnnotationPresent() throws Exception { |
|
|
|
public void findAnnotationDescriptorWithNoAnnotationPresent() { |
|
|
|
assertNull(findAnnotationDescriptor(NonAnnotatedInterface.class, Transactional.class)); |
|
|
|
assertNull(findAnnotationDescriptor(NonAnnotatedInterface.class, Transactional.class)); |
|
|
|
assertNull(findAnnotationDescriptor(NonAnnotatedClass.class, Transactional.class)); |
|
|
|
assertNull(findAnnotationDescriptor(NonAnnotatedClass.class, Transactional.class)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorWithInheritedAnnotationOnClass() throws Exception { |
|
|
|
public void findAnnotationDescriptorWithInheritedAnnotationOnClass() { |
|
|
|
// Note: @Transactional is inherited
|
|
|
|
// Note: @Transactional is inherited
|
|
|
|
assertEquals(InheritedAnnotationClass.class, |
|
|
|
assertEquals(InheritedAnnotationClass.class, |
|
|
|
findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
findAnnotationDescriptor(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
assertEquals(InheritedAnnotationClass.class, |
|
|
|
assertEquals(InheritedAnnotationClass.class, |
|
|
|
findAnnotationDescriptor(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
findAnnotationDescriptor(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() throws Exception { |
|
|
|
public void findAnnotationDescriptorWithInheritedAnnotationOnInterface() { |
|
|
|
// Note: @Transactional is inherited
|
|
|
|
// Note: @Transactional is inherited
|
|
|
|
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); |
|
|
|
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); |
|
|
|
|
|
|
|
|
|
|
|
AnnotationDescriptor<Transactional> descriptor; |
|
|
|
AnnotationDescriptor<Transactional> descriptor = |
|
|
|
|
|
|
|
findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class); |
|
|
|
descriptor = findAnnotationDescriptor(InheritedAnnotationInterface.class, Transactional.class); |
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
@ -137,22 +142,21 @@ public class MetaAnnotationUtilsTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() throws Exception { |
|
|
|
public void findAnnotationDescriptorForNonInheritedAnnotationOnClass() { |
|
|
|
// Note: @Order is not inherited.
|
|
|
|
// Note: @Order is not inherited.
|
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
findAnnotationDescriptor(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
findAnnotationDescriptor(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
findAnnotationDescriptor(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() throws Exception { |
|
|
|
public void findAnnotationDescriptorForNonInheritedAnnotationOnInterface() { |
|
|
|
// Note: @Order is not inherited.
|
|
|
|
// Note: @Order is not inherited.
|
|
|
|
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); |
|
|
|
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); |
|
|
|
|
|
|
|
|
|
|
|
AnnotationDescriptor<Order> descriptor; |
|
|
|
AnnotationDescriptor<Order> descriptor = |
|
|
|
|
|
|
|
findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class); |
|
|
|
descriptor = findAnnotationDescriptor(NonInheritedAnnotationInterface.class, Order.class); |
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
@ -166,15 +170,16 @@ public class MetaAnnotationUtilsTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorWithMetaComponentAnnotation() throws Exception { |
|
|
|
public void findAnnotationDescriptorWithMetaComponentAnnotation() { |
|
|
|
assertAtComponentOnComposedAnnotation(HasMetaComponentAnnotation.class, "meta1", Meta1.class); |
|
|
|
assertAtComponentOnComposedAnnotation(HasMetaComponentAnnotation.class, "meta1", Meta1.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() throws Exception { |
|
|
|
public void findAnnotationDescriptorWithLocalAndMetaComponentAnnotation() { |
|
|
|
Class<Component> annotationType = Component.class; |
|
|
|
Class<Component> annotationType = Component.class; |
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(HasLocalAndMetaComponentAnnotation.class, |
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor( |
|
|
|
annotationType); |
|
|
|
HasLocalAndMetaComponentAnnotation.class, annotationType); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertNull(descriptor.getComposedAnnotation()); |
|
|
|
assertNull(descriptor.getComposedAnnotation()); |
|
|
|
@ -188,12 +193,10 @@ public class MetaAnnotationUtilsTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() { |
|
|
|
public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() { |
|
|
|
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, |
|
|
|
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class); |
|
|
|
Component.class); |
|
|
|
AnnotationDescriptor<Component> descriptor = |
|
|
|
|
|
|
|
findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class); |
|
|
|
AnnotationDescriptor<Component> descriptor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
descriptor = findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class); |
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(Meta1.class, descriptor.getDeclaringClass()); |
|
|
|
assertEquals(Meta1.class, descriptor.getDeclaringClass()); |
|
|
|
@ -204,7 +207,7 @@ public class MetaAnnotationUtilsTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() { |
|
|
|
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() { |
|
|
|
AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor( |
|
|
|
AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor( |
|
|
|
MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class); |
|
|
|
MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull("AnnotationDescriptor should not be null", descriptor); |
|
|
|
assertNotNull("AnnotationDescriptor should not be null", descriptor); |
|
|
|
assertEquals("rootDeclaringClass", MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals("rootDeclaringClass", MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, descriptor.getRootDeclaringClass()); |
|
|
|
@ -213,20 +216,19 @@ public class MetaAnnotationUtilsTests { |
|
|
|
assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation()); |
|
|
|
assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation()); |
|
|
|
assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType()); |
|
|
|
assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType()); |
|
|
|
|
|
|
|
|
|
|
|
assertArrayEquals("configured classes", new Class[] { String.class }, |
|
|
|
assertArrayEquals("configured classes", new Class<?>[] {String.class}, |
|
|
|
descriptor.getAnnotationAttributes().getClassArray("classes")); |
|
|
|
descriptor.getAnnotationAttributes().getClassArray("classes")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { |
|
|
|
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { |
|
|
|
assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", |
|
|
|
assertAtComponentOnComposedAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); |
|
|
|
Meta2.class); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { |
|
|
|
public void findAnnotationDescriptorForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { |
|
|
|
assertAtComponentOnComposedAnnotation(SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, |
|
|
|
assertAtComponentOnComposedAnnotation(SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, |
|
|
|
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); |
|
|
|
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -253,8 +255,8 @@ public class MetaAnnotationUtilsTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
public void findAnnotationDescriptorOnAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component
|
|
|
|
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component
|
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(InheritedAnnotationClass.class, |
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor( |
|
|
|
Component.class); |
|
|
|
InheritedAnnotationClass.class, Component.class); |
|
|
|
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); |
|
|
|
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -263,8 +265,8 @@ public class MetaAnnotationUtilsTests { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
public void findAnnotationDescriptorOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(MetaCycleAnnotatedClass.class, |
|
|
|
AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor( |
|
|
|
Component.class); |
|
|
|
MetaCycleAnnotatedClass.class, Component.class); |
|
|
|
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); |
|
|
|
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -272,32 +274,30 @@ public class MetaAnnotationUtilsTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesWithNoAnnotationPresent() { |
|
|
|
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedInterface.class, Transactional.class, Component.class)); |
|
|
|
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedInterface.class, Transactional.class, Component.class)); |
|
|
|
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedClass.class, Transactional.class, Order.class)); |
|
|
|
assertNull(findAnnotationDescriptorForTypes(NonAnnotatedClass.class, Transactional.class, Order.class)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnClass() { |
|
|
|
// Note: @Transactional is inherited
|
|
|
|
// Note: @Transactional is inherited
|
|
|
|
|
|
|
|
assertEquals(InheritedAnnotationClass.class, |
|
|
|
|
|
|
|
findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
assertEquals( |
|
|
|
assertEquals( |
|
|
|
InheritedAnnotationClass.class, |
|
|
|
InheritedAnnotationClass.class, |
|
|
|
findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
findAnnotationDescriptorForTypes(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
assertEquals( |
|
|
|
|
|
|
|
InheritedAnnotationClass.class, |
|
|
|
|
|
|
|
findAnnotationDescriptorForTypes(SubInheritedAnnotationClass.class, Transactional.class).getRootDeclaringClass()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesWithInheritedAnnotationOnInterface() { |
|
|
|
// Note: @Transactional is inherited
|
|
|
|
// Note: @Transactional is inherited
|
|
|
|
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); |
|
|
|
Transactional rawAnnotation = InheritedAnnotationInterface.class.getAnnotation(Transactional.class); |
|
|
|
|
|
|
|
|
|
|
|
UntypedAnnotationDescriptor descriptor; |
|
|
|
UntypedAnnotationDescriptor descriptor = |
|
|
|
|
|
|
|
findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class); |
|
|
|
descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationInterface.class, Transactional.class); |
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
assertEquals(InheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
@ -318,23 +318,22 @@ public class MetaAnnotationUtilsTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnClass() { |
|
|
|
// Note: @Order is not inherited.
|
|
|
|
// Note: @Order is not inherited.
|
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
findAnnotationDescriptorForTypes(NonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
assertEquals(NonInheritedAnnotationClass.class, |
|
|
|
findAnnotationDescriptorForTypes(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
findAnnotationDescriptorForTypes(SubNonInheritedAnnotationClass.class, Order.class).getRootDeclaringClass()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesForNonInheritedAnnotationOnInterface() { |
|
|
|
// Note: @Order is not inherited.
|
|
|
|
// Note: @Order is not inherited.
|
|
|
|
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); |
|
|
|
Order rawAnnotation = NonInheritedAnnotationInterface.class.getAnnotation(Order.class); |
|
|
|
|
|
|
|
|
|
|
|
UntypedAnnotationDescriptor descriptor; |
|
|
|
UntypedAnnotationDescriptor descriptor = |
|
|
|
|
|
|
|
findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class); |
|
|
|
descriptor = findAnnotationDescriptorForTypes(NonInheritedAnnotationInterface.class, Order.class); |
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
assertEquals(NonInheritedAnnotationInterface.class, descriptor.getDeclaringClass()); |
|
|
|
@ -349,10 +348,10 @@ public class MetaAnnotationUtilsTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesWithLocalAndMetaComponentAnnotation() { |
|
|
|
Class<Component> annotationType = Component.class; |
|
|
|
Class<Component> annotationType = Component.class; |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( |
|
|
|
HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class); |
|
|
|
HasLocalAndMetaComponentAnnotation.class, Transactional.class, annotationType, Order.class); |
|
|
|
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(HasLocalAndMetaComponentAnnotation.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertNull(descriptor.getComposedAnnotation()); |
|
|
|
assertNull(descriptor.getComposedAnnotation()); |
|
|
|
@ -360,45 +359,45 @@ public class MetaAnnotationUtilsTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesWithMetaComponentAnnotation() { |
|
|
|
Class<HasMetaComponentAnnotation> startClass = HasMetaComponentAnnotation.class; |
|
|
|
Class<HasMetaComponentAnnotation> startClass = HasMetaComponentAnnotation.class; |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class); |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, "meta1", Meta1.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() { |
|
|
|
Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class; |
|
|
|
Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class; |
|
|
|
Class<ContextConfiguration> annotationType = ContextConfiguration.class; |
|
|
|
Class<ContextConfiguration> annotationType = ContextConfiguration.class; |
|
|
|
|
|
|
|
|
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, |
|
|
|
ContextConfiguration.class, Order.class, Transactional.class); |
|
|
|
Service.class, ContextConfiguration.class, Order.class, Transactional.class); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(startClass, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(startClass, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); |
|
|
|
assertArrayEquals(new Class<?>[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); |
|
|
|
assertArrayEquals(new Class[] { MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class }, |
|
|
|
assertArrayEquals(new Class<?>[] {MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class}, |
|
|
|
descriptor.getAnnotationAttributes().getClassArray("classes")); |
|
|
|
descriptor.getAnnotationAttributes().getClassArray("classes")); |
|
|
|
assertNotNull(descriptor.getComposedAnnotation()); |
|
|
|
assertNotNull(descriptor.getComposedAnnotation()); |
|
|
|
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); |
|
|
|
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() throws Exception { |
|
|
|
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() { |
|
|
|
Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class; |
|
|
|
Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class; |
|
|
|
Class<ContextConfiguration> annotationType = ContextConfiguration.class; |
|
|
|
Class<ContextConfiguration> annotationType = ContextConfiguration.class; |
|
|
|
|
|
|
|
|
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class, |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( |
|
|
|
ContextConfiguration.class, Order.class, Transactional.class); |
|
|
|
startClass, Service.class, ContextConfiguration.class, Order.class, Transactional.class); |
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(startClass, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(startClass, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertEquals(annotationType, descriptor.getAnnotationType()); |
|
|
|
assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); |
|
|
|
assertArrayEquals(new Class<?>[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value()); |
|
|
|
assertArrayEquals(new Class[] { MetaAnnotationUtilsTests.class }, |
|
|
|
assertArrayEquals(new Class<?>[] {MetaAnnotationUtilsTests.class}, |
|
|
|
descriptor.getAnnotationAttributes().getClassArray("classes")); |
|
|
|
descriptor.getAnnotationAttributes().getClassArray("classes")); |
|
|
|
assertNotNull(descriptor.getComposedAnnotation()); |
|
|
|
assertNotNull(descriptor.getComposedAnnotation()); |
|
|
|
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); |
|
|
|
assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -412,13 +411,11 @@ public class MetaAnnotationUtilsTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() { |
|
|
|
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() { |
|
|
|
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, |
|
|
|
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class); |
|
|
|
Component.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UntypedAnnotationDescriptor descriptor; |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( |
|
|
|
|
|
|
|
ClassWithMetaAnnotatedInterface.class, Service.class, Component.class, Order.class, Transactional.class); |
|
|
|
|
|
|
|
|
|
|
|
descriptor = findAnnotationDescriptorForTypes(ClassWithMetaAnnotatedInterface.class, Service.class, |
|
|
|
|
|
|
|
Component.class, Order.class, Transactional.class); |
|
|
|
|
|
|
|
assertNotNull(descriptor); |
|
|
|
assertNotNull(descriptor); |
|
|
|
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass()); |
|
|
|
assertEquals(Meta1.class, descriptor.getDeclaringClass()); |
|
|
|
assertEquals(Meta1.class, descriptor.getDeclaringClass()); |
|
|
|
@ -435,8 +432,8 @@ public class MetaAnnotationUtilsTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForTypesForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { |
|
|
|
public void findAnnotationDescriptorForTypesForSubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface() { |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( |
|
|
|
SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, |
|
|
|
SubClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, |
|
|
|
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); |
|
|
|
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, "meta2", Meta2.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -445,8 +442,8 @@ public class MetaAnnotationUtilsTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() { |
|
|
|
public void findAnnotationDescriptorForTypesOnMetaMetaAnnotatedClass() { |
|
|
|
Class<MetaMetaAnnotatedClass> startClass = MetaMetaAnnotatedClass.class; |
|
|
|
Class<MetaMetaAnnotatedClass> startClass = MetaMetaAnnotatedClass.class; |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2", |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( |
|
|
|
MetaMeta.class); |
|
|
|
startClass, startClass, Meta2.class, "meta2", MetaMeta.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -455,8 +452,8 @@ public class MetaAnnotationUtilsTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() { |
|
|
|
public void findAnnotationDescriptorForTypesOnMetaMetaMetaAnnotatedClass() { |
|
|
|
Class<MetaMetaMetaAnnotatedClass> startClass = MetaMetaMetaAnnotatedClass.class; |
|
|
|
Class<MetaMetaMetaAnnotatedClass> startClass = MetaMetaMetaAnnotatedClass.class; |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(startClass, startClass, Meta2.class, "meta2", |
|
|
|
assertAtComponentOnComposedAnnotationForMultipleCandidateTypes( |
|
|
|
MetaMetaMeta.class); |
|
|
|
startClass, startClass, Meta2.class, "meta2", MetaMetaMeta.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -467,8 +464,8 @@ public class MetaAnnotationUtilsTests { |
|
|
|
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
|
|
|
|
// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
|
|
|
|
// @Service, or @Order, but it is annotated with @Transactional.
|
|
|
|
// @Service, or @Order, but it is annotated with @Transactional.
|
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(InheritedAnnotationClass.class, |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( |
|
|
|
Service.class, Component.class, Order.class); |
|
|
|
InheritedAnnotationClass.class, Service.class, Component.class, Order.class); |
|
|
|
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); |
|
|
|
assertNull("Should not find @Component on InheritedAnnotationClass", descriptor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -478,8 +475,8 @@ public class MetaAnnotationUtilsTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
public void findAnnotationDescriptorForTypesOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() { |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(MetaCycleAnnotatedClass.class, |
|
|
|
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( |
|
|
|
Service.class, Component.class, Order.class); |
|
|
|
MetaCycleAnnotatedClass.class, Service.class, Component.class, Order.class); |
|
|
|
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); |
|
|
|
assertNull("Should not find @Component on MetaCycleAnnotatedClass", descriptor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|