This commit is contained in:
Looly 2023-03-12 23:49:14 +08:00
parent 4da3e62e64
commit f05e084a3b
8 changed files with 273 additions and 272 deletions

View File

@ -39,7 +39,7 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testClearCaches() { public void testClearCaches() {
AnnotatedElement type = Foo.class; final AnnotatedElement type = Foo.class;
AnnotatedElement element = AnnotatedElementUtil.getResolvedMetaElementCache(type); AnnotatedElement element = AnnotatedElementUtil.getResolvedMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type)); Assert.assertSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type));
@ -94,22 +94,22 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testFindAnnotations() { public void testFindAnnotations() {
Annotation[] annotations = AnnotatedElementUtil.findAnnotations(Foo.class); final Annotation[] annotations = AnnotatedElementUtil.findAnnotations(Foo.class);
Assert.assertArrayEquals(ANNOTATIONS, annotations); Assert.assertArrayEquals(ANNOTATIONS, annotations);
} }
@Test @Test
public void testFindResolvedAnnotation() { public void testFindResolvedAnnotation() {
Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation3.class); final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation2.class); final Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation1.class); final Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -121,19 +121,19 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testFindResolvedAnnotations() { public void testFindResolvedAnnotations() {
Annotation[] resolvedAnnotations = AnnotatedElementUtil.findResolvedAnnotations(Foo.class); final Annotation[] resolvedAnnotations = AnnotatedElementUtil.findResolvedAnnotations(Foo.class);
Map<Class<?>, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity())); final Map<Class<?>, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity()));
Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class); final Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = (Annotation2)annotationMap.get(Annotation2.class); final Annotation2 resolvedAnnotation2 = (Annotation2)annotationMap.get(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = (Annotation1)annotationMap.get(Annotation1.class); final Annotation1 resolvedAnnotation1 = (Annotation1)annotationMap.get(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -145,16 +145,16 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testFindAllResolvedAnnotations() { public void testFindAllResolvedAnnotations() {
Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation3.class)[0]; final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation3.class)[0];
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation2.class)[0]; final Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation2.class)[0];
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation1.class)[0]; final Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation1.class)[0];
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -195,7 +195,7 @@ public class AnnotatedElementUtilTest {
public void testFindDirectlyResolvedAnnotation() { public void testFindDirectlyResolvedAnnotation() {
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation4.class)); Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation4.class));
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation6.class)); Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation6.class));
Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation3.class); final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
@ -207,12 +207,12 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testFindDirectlyResolvedAnnotations() { public void testFindDirectlyResolvedAnnotations() {
Annotation[] resolvedAnnotations = AnnotatedElementUtil.findDirectlyResolvedAnnotations(Foo.class); final Annotation[] resolvedAnnotations = AnnotatedElementUtil.findDirectlyResolvedAnnotations(Foo.class);
Map<Class<?>, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity())); final Map<Class<?>, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity()));
Assert.assertEquals(ANNOTATION4, annotationMap.get(Annotation4.class)); Assert.assertEquals(ANNOTATION4, annotationMap.get(Annotation4.class));
Assert.assertEquals(ANNOTATION6, annotationMap.get(Annotation6.class)); Assert.assertEquals(ANNOTATION6, annotationMap.get(Annotation6.class));
Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class); final Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
@ -227,7 +227,7 @@ public class AnnotatedElementUtilTest {
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class)[0]); Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class)[0]);
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class)[0]); Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class)[0]);
Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation3.class)[0]; final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation3.class)[0];
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
@ -261,7 +261,7 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetAnnotations() { public void testGetAnnotations() {
Annotation[] annotations = AnnotatedElementUtil.getAnnotations(Foo.class); final Annotation[] annotations = AnnotatedElementUtil.getAnnotations(Foo.class);
Assert.assertArrayEquals( Assert.assertArrayEquals(
new Annotation[]{ ANNOTATION3, ANNOTATION2, ANNOTATION1 }, new Annotation[]{ ANNOTATION3, ANNOTATION2, ANNOTATION1 },
annotations annotations
@ -270,15 +270,15 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetAllAnnotations() { public void testGetAllAnnotations() {
Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation3.class); final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length); Assert.assertEquals(1, resolvedAnnotation3s.length);
Assert.assertEquals(ANNOTATION3, resolvedAnnotation3s[0]); // value与alias互为别名 Assert.assertEquals(ANNOTATION3, resolvedAnnotation3s[0]); // value与alias互为别名
Annotation2[] resolvedAnnotation2s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation2.class); final Annotation2[] resolvedAnnotation2s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation2.class);
Assert.assertEquals(1, resolvedAnnotation2s.length); Assert.assertEquals(1, resolvedAnnotation2s.length);
Assert.assertEquals(ANNOTATION2, resolvedAnnotation2s[0]); // value与alias互为别名 Assert.assertEquals(ANNOTATION2, resolvedAnnotation2s[0]); // value与alias互为别名
Annotation1[] resolvedAnnotation1s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation1.class); final Annotation1[] resolvedAnnotation1s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation1.class);
Assert.assertEquals(1, resolvedAnnotation1s.length); Assert.assertEquals(1, resolvedAnnotation1s.length);
Assert.assertEquals(ANNOTATION1, resolvedAnnotation1s[0]); Assert.assertEquals(ANNOTATION1, resolvedAnnotation1s[0]);
@ -289,16 +289,16 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetResolvedAnnotation() { public void testGetResolvedAnnotation() {
Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation3.class); final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation2.class); final Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation1.class); final Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -310,22 +310,22 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetAllResolvedAnnotations() { public void testGetAllResolvedAnnotations() {
Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation3.class); final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length); Assert.assertEquals(1, resolvedAnnotation3s.length);
Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0];
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2[] resolvedAnnotation2s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation2.class); final Annotation2[] resolvedAnnotation2s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation2.class);
Assert.assertEquals(1, resolvedAnnotation2s.length); Assert.assertEquals(1, resolvedAnnotation2s.length);
Annotation2 resolvedAnnotation2 = resolvedAnnotation2s[0]; final Annotation2 resolvedAnnotation2 = resolvedAnnotation2s[0];
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1[] resolvedAnnotation1s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation1.class); final Annotation1[] resolvedAnnotation1s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation1.class);
Assert.assertEquals(1, resolvedAnnotation1s.length); Assert.assertEquals(1, resolvedAnnotation1s.length);
Annotation1 resolvedAnnotation1 = resolvedAnnotation1s[0]; final Annotation1 resolvedAnnotation1 = resolvedAnnotation1s[0];
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -337,19 +337,19 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetResolvedAnnotations() { public void testGetResolvedAnnotations() {
Map<Class<?>, Annotation> annotationMap = Stream.of(AnnotatedElementUtil.getResolvedAnnotations(Foo.class)) final Map<Class<?>, Annotation> annotationMap = Stream.of(AnnotatedElementUtil.getResolvedAnnotations(Foo.class))
.collect(Collectors.toMap(Annotation::annotationType, Function.identity())); .collect(Collectors.toMap(Annotation::annotationType, Function.identity()));
Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class); final Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = (Annotation2)annotationMap.get(Annotation2.class); final Annotation2 resolvedAnnotation2 = (Annotation2)annotationMap.get(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = (Annotation1)annotationMap.get(Annotation1.class); final Annotation1 resolvedAnnotation1 = (Annotation1)annotationMap.get(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -372,9 +372,9 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetAllDirectlyAnnotations() { public void testGetAllDirectlyAnnotations() {
Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllDirectlyAnnotations(Foo.class, Annotation3.class); final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllDirectlyAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length); Assert.assertEquals(1, resolvedAnnotation3s.length);
Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0];
Assert.assertEquals(ANNOTATION3, resolvedAnnotation3); Assert.assertEquals(ANNOTATION3, resolvedAnnotation3);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length); Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length);
@ -386,14 +386,14 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetDirectlyAnnotations() { public void testGetDirectlyAnnotations() {
Annotation[] annotations = AnnotatedElementUtil.getDirectlyAnnotations(Foo.class); final Annotation[] annotations = AnnotatedElementUtil.getDirectlyAnnotations(Foo.class);
Assert.assertEquals(1, annotations.length); Assert.assertEquals(1, annotations.length);
Assert.assertEquals(ANNOTATION3, annotations[0]); Assert.assertEquals(ANNOTATION3, annotations[0]);
} }
@Test @Test
public void testGetDirectlyResolvedAnnotation() { public void testGetDirectlyResolvedAnnotation() {
Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation3.class); final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
@ -407,9 +407,9 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetDirectlyAllResolvedAnnotations() { public void testGetDirectlyAllResolvedAnnotations() {
Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation3.class); final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length); Assert.assertEquals(1, resolvedAnnotation3s.length);
Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0];
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
@ -423,10 +423,10 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testGetDirectlyResolvedAnnotations() { public void testGetDirectlyResolvedAnnotations() {
Annotation[] annotations = AnnotatedElementUtil.getDirectlyResolvedAnnotations(Foo.class); final Annotation[] annotations = AnnotatedElementUtil.getDirectlyResolvedAnnotations(Foo.class);
Assert.assertEquals(1, annotations.length); Assert.assertEquals(1, annotations.length);
Annotation3 resolvedAnnotation3 = (Annotation3)annotations[0]; final Annotation3 resolvedAnnotation3 = (Annotation3)annotations[0];
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
@ -436,7 +436,7 @@ public class AnnotatedElementUtilTest {
public void testToHierarchyMetaElement() { public void testToHierarchyMetaElement() {
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, false)); Assert.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, false));
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, true)); Assert.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, true));
AnnotatedElement element = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, false); final AnnotatedElement element = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, false);
// 带有元注解 // 带有元注解
Assert.assertArrayEquals(ANNOTATIONS, element.getAnnotations()); Assert.assertArrayEquals(ANNOTATIONS, element.getAnnotations());
@ -445,17 +445,17 @@ public class AnnotatedElementUtilTest {
Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations()); Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations());
// 解析注解属性 // 解析注解属性
AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, true); final AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, true);
Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class); final Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = resolvedElement.getAnnotation(Annotation2.class); final Annotation2 resolvedAnnotation2 = resolvedElement.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = resolvedElement.getAnnotation(Annotation1.class); final Annotation1 resolvedAnnotation1 = resolvedElement.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -469,7 +469,7 @@ public class AnnotatedElementUtilTest {
public void testToHierarchyRepeatableMetaElement() { public void testToHierarchyRepeatableMetaElement() {
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, false)); Assert.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, false));
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, true)); Assert.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, true));
AnnotatedElement element = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, false); final AnnotatedElement element = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, false);
// 带有元注解 // 带有元注解
Assert.assertArrayEquals(ANNOTATIONS, element.getAnnotations()); Assert.assertArrayEquals(ANNOTATIONS, element.getAnnotations());
@ -478,17 +478,17 @@ public class AnnotatedElementUtilTest {
Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations()); Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations());
// 解析注解属性 // 解析注解属性
AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, true); final AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, true);
Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class); final Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = resolvedElement.getAnnotation(Annotation2.class); final Annotation2 resolvedAnnotation2 = resolvedElement.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = resolvedElement.getAnnotation(Annotation1.class); final Annotation1 resolvedAnnotation1 = resolvedElement.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -501,7 +501,7 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testToHierarchyElement() { public void testToHierarchyElement() {
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyElement(Foo.class)); Assert.assertNotNull(AnnotatedElementUtil.toHierarchyElement(Foo.class));
AnnotatedElement element = AnnotatedElementUtil.toHierarchyElement(Foo.class); final AnnotatedElement element = AnnotatedElementUtil.toHierarchyElement(Foo.class);
Assert.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION4, ANNOTATION6}, element.getAnnotations()); Assert.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION4, ANNOTATION6}, element.getAnnotations());
} }
@ -520,16 +520,16 @@ public class AnnotatedElementUtilTest {
Assert.assertSame(element, AnnotatedElementUtil.toMetaElement(Foo.class, true)); // 第二次获取时从缓存中获取 Assert.assertSame(element, AnnotatedElementUtil.toMetaElement(Foo.class, true)); // 第二次获取时从缓存中获取
Assert.assertEquals(3, element.getAnnotations().length); Assert.assertEquals(3, element.getAnnotations().length);
Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class); final Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = element.getAnnotation(Annotation2.class); final Annotation2 resolvedAnnotation2 = element.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = element.getAnnotation(Annotation1.class); final Annotation1 resolvedAnnotation1 = element.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -550,16 +550,16 @@ public class AnnotatedElementUtilTest {
Assert.assertEquals(element, AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), true)); // 第二次获取时从缓存中获取 Assert.assertEquals(element, AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), true)); // 第二次获取时从缓存中获取
Assert.assertEquals(3, element.getAnnotations().length); Assert.assertEquals(3, element.getAnnotations().length);
Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class); final Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3); Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Annotation2 resolvedAnnotation2 = element.getAnnotation(Annotation2.class); final Annotation2 resolvedAnnotation2 = element.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2); Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖 Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Annotation1 resolvedAnnotation1 = element.getAnnotation(Annotation1.class); final Annotation1 resolvedAnnotation1 = element.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1); Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
@ -567,10 +567,10 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testAsElement() { public void testAsElement() {
Annotation[] annotations = new Annotation[]{ANNOTATION1, ANNOTATION2}; final Annotation[] annotations = new Annotation[]{ANNOTATION1, ANNOTATION2};
Assert.assertNotNull(AnnotatedElementUtil.asElement()); Assert.assertNotNull(AnnotatedElementUtil.asElement());
AnnotatedElement element = AnnotatedElementUtil.asElement(ANNOTATION1, null, ANNOTATION2); final AnnotatedElement element = AnnotatedElementUtil.asElement(ANNOTATION1, null, ANNOTATION2);
Assert.assertArrayEquals(annotations, element.getAnnotations()); Assert.assertArrayEquals(annotations, element.getAnnotations());
Assert.assertArrayEquals(annotations, element.getDeclaredAnnotations()); Assert.assertArrayEquals(annotations, element.getDeclaredAnnotations());
Assert.assertEquals(ANNOTATION1, element.getAnnotation(Annotation1.class)); Assert.assertEquals(ANNOTATION1, element.getAnnotation(Annotation1.class));
@ -579,7 +579,7 @@ public class AnnotatedElementUtilTest {
@Test @Test
public void testEmptyElement() { public void testEmptyElement() {
AnnotatedElement element = AnnotatedElementUtil.emptyElement(); final AnnotatedElement element = AnnotatedElementUtil.emptyElement();
Assert.assertSame(element, AnnotatedElementUtil.emptyElement()); Assert.assertSame(element, AnnotatedElementUtil.emptyElement());
Assert.assertNull(element.getAnnotation(Annotation1.class)); Assert.assertNull(element.getAnnotation(Annotation1.class));
Assert.assertEquals(0, element.getAnnotations().length); Assert.assertEquals(0, element.getAnnotations().length);

View File

@ -12,36 +12,36 @@ public class CombinationAnnotationElementTest {
@Test @Test
public void testOf() { public void testOf() {
CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Assert.assertNotNull(element); Assert.assertNotNull(element);
} }
@Test @Test
public void testIsAnnotationPresent() { public void testIsAnnotationPresent() {
CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Assert.assertTrue(element.isAnnotationPresent(MetaAnnotationForTest.class)); Assert.assertTrue(element.isAnnotationPresent(MetaAnnotationForTest.class));
} }
@Test @Test
public void testGetAnnotation() { public void testGetAnnotation() {
AnnotationForTest annotation1 = ClassForTest.class.getAnnotation(AnnotationForTest.class); final AnnotationForTest annotation1 = ClassForTest.class.getAnnotation(AnnotationForTest.class);
MetaAnnotationForTest annotation2 = AnnotationForTest.class.getAnnotation(MetaAnnotationForTest.class); final MetaAnnotationForTest annotation2 = AnnotationForTest.class.getAnnotation(MetaAnnotationForTest.class);
CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Assert.assertEquals(annotation1, element.getAnnotation(AnnotationForTest.class)); Assert.assertEquals(annotation1, element.getAnnotation(AnnotationForTest.class));
Assert.assertEquals(annotation2, element.getAnnotation(MetaAnnotationForTest.class)); Assert.assertEquals(annotation2, element.getAnnotation(MetaAnnotationForTest.class));
} }
@Test @Test
public void testGetAnnotations() { public void testGetAnnotations() {
CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Annotation[] annotations = element.getAnnotations(); final Annotation[] annotations = element.getAnnotations();
Assert.assertEquals(2, annotations.length); Assert.assertEquals(2, annotations.length);
} }
@Test @Test
public void testGetDeclaredAnnotations() { public void testGetDeclaredAnnotations() {
CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Annotation[] annotations = element.getDeclaredAnnotations(); final Annotation[] annotations = element.getDeclaredAnnotations();
Assert.assertEquals(2, annotations.length); Assert.assertEquals(2, annotations.length);
} }

View File

@ -19,8 +19,8 @@ public class GenericAnnotationMappingTest {
@Test @Test
public void testEquals() { public void testEquals() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(mapping, mapping); Assert.assertEquals(mapping, mapping);
Assert.assertNotEquals(mapping, null); Assert.assertNotEquals(mapping, null);
Assert.assertEquals(mapping, GenericAnnotationMapping.create(annotation, false)); Assert.assertEquals(mapping, GenericAnnotationMapping.create(annotation, false));
@ -29,8 +29,8 @@ public class GenericAnnotationMappingTest {
@Test @Test
public void testHashCode() { public void testHashCode() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
int hashCode = GenericAnnotationMapping.create(annotation, false).hashCode(); final int hashCode = GenericAnnotationMapping.create(annotation, false).hashCode();
Assert.assertEquals(hashCode, GenericAnnotationMapping.create(annotation, false).hashCode()); Assert.assertEquals(hashCode, GenericAnnotationMapping.create(annotation, false).hashCode());
Assert.assertNotEquals(hashCode, GenericAnnotationMapping.create(annotation, true).hashCode()); Assert.assertNotEquals(hashCode, GenericAnnotationMapping.create(annotation, true).hashCode());
} }
@ -38,14 +38,14 @@ public class GenericAnnotationMappingTest {
@Test @Test
public void testCreate() { public void testCreate() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertNotNull(mapping); Assert.assertNotNull(mapping);
} }
@Test @Test
public void testIsRoot() { public void testIsRoot() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, true); GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, true);
Assert.assertTrue(mapping.isRoot()); Assert.assertTrue(mapping.isRoot());
@ -55,55 +55,55 @@ public class GenericAnnotationMappingTest {
@Test @Test
public void testGetAnnotation() { public void testGetAnnotation() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertSame(annotation, mapping.getAnnotation()); Assert.assertSame(annotation, mapping.getAnnotation());
} }
@SneakyThrows @SneakyThrows
@Test @Test
public void testGetAttributes() { public void testGetAttributes() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
for (int i = 0; i < mapping.getAttributes().length; i++) { for (int i = 0; i < mapping.getAttributes().length; i++) {
Method method = mapping.getAttributes()[i]; final Method method = mapping.getAttributes()[i];
Assert.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method); Assert.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method);
} }
} }
@Test @Test
public void testAnnotationType() { public void testAnnotationType() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.annotationType(), mapping.annotationType()); Assert.assertEquals(annotation.annotationType(), mapping.annotationType());
} }
@Test @Test
public void testIsResolved() { public void testIsResolved() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertFalse(mapping.isResolved()); Assert.assertFalse(mapping.isResolved());
} }
@Test @Test
public void testGetAttributeValue() { public void testGetAttributeValue() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class)); Assert.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class));
Assert.assertNull(mapping.getAttributeValue("value", Integer.class)); Assert.assertNull(mapping.getAttributeValue("value", Integer.class));
} }
@Test @Test
public void testGetResolvedAnnotation() { public void testGetResolvedAnnotation() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertSame(annotation, mapping.getResolvedAnnotation()); Assert.assertSame(annotation, mapping.getResolvedAnnotation());
} }
@Test @Test
public void testGetResolvedAttributeValue() { public void testGetResolvedAttributeValue() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value", String.class)); Assert.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value", String.class));
Assert.assertNull(mapping.getResolvedAttributeValue("value", Integer.class)); Assert.assertNull(mapping.getResolvedAttributeValue("value", Integer.class));
} }

View File

@ -22,11 +22,11 @@ public class HierarchicalAnnotatedElementTest {
@SneakyThrows @SneakyThrows
@Test @Test
public void testCreateFromMethod() { public void testCreateFromMethod() {
Method method1 = Foo.class.getDeclaredMethod("method"); final Method method1 = Foo.class.getDeclaredMethod("method");
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(method1); HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(method1);
Assert.assertEquals(3, elements.getElementMappings().size()); Assert.assertEquals(3, elements.getElementMappings().size());
Method method2 = Foo.class.getDeclaredMethod("method2"); final Method method2 = Foo.class.getDeclaredMethod("method2");
elements = HierarchicalAnnotatedElements.create(method2); elements = HierarchicalAnnotatedElements.create(method2);
Assert.assertEquals(1, elements.getElementMappings().size()); Assert.assertEquals(1, elements.getElementMappings().size());
} }
@ -46,7 +46,7 @@ public class HierarchicalAnnotatedElementTest {
@Test @Test
public void testEquals() { public void testEquals() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY);
Assert.assertEquals(elements, elements); Assert.assertEquals(elements, elements);
Assert.assertEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY)); Assert.assertEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY));
Assert.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY)); Assert.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY));
@ -56,7 +56,7 @@ public class HierarchicalAnnotatedElementTest {
@Test @Test
public void testHashCode() { public void testHashCode() {
int hashCode = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode(); final int hashCode = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode();
Assert.assertEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode()); Assert.assertEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY).hashCode()); Assert.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e).hashCode()); Assert.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e).hashCode());
@ -64,14 +64,14 @@ public class HierarchicalAnnotatedElementTest {
@Test @Test
public void testGetElement() { public void testGetElement() {
AnnotatedElement element = Foo.class; final AnnotatedElement element = Foo.class;
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(element, ELEMENT_MAPPING_FACTORY); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(element, ELEMENT_MAPPING_FACTORY);
Assert.assertSame(element, elements.getElement()); Assert.assertSame(element, elements.getElement());
} }
@Test @Test
public void testIsAnnotationPresent() { public void testIsAnnotationPresent() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Assert.assertTrue(elements.isAnnotationPresent(Annotation1.class)); Assert.assertTrue(elements.isAnnotationPresent(Annotation1.class));
Assert.assertTrue(elements.isAnnotationPresent(Annotation2.class)); Assert.assertTrue(elements.isAnnotationPresent(Annotation2.class));
Assert.assertTrue(elements.isAnnotationPresent(Annotation3.class)); Assert.assertTrue(elements.isAnnotationPresent(Annotation3.class));
@ -79,91 +79,91 @@ public class HierarchicalAnnotatedElementTest {
@Test @Test
public void testGetAnnotations() { public void testGetAnnotations() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 }; final Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 };
Assert.assertArrayEquals(annotations, elements.getAnnotations()); Assert.assertArrayEquals(annotations, elements.getAnnotations());
} }
@Test @Test
public void testGetAnnotation() { public void testGetAnnotation() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, elements.getAnnotation(Annotation1.class)); Assert.assertEquals(annotation1, elements.getAnnotation(Annotation1.class));
Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertEquals(annotation2, elements.getAnnotation(Annotation2.class)); Assert.assertEquals(annotation2, elements.getAnnotation(Annotation2.class));
Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertEquals(annotation3, elements.getAnnotation(Annotation3.class)); Assert.assertEquals(annotation3, elements.getAnnotation(Annotation3.class));
} }
@Test @Test
public void testGetAnnotationsByType() { public void testGetAnnotationsByType() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getAnnotationsByType(Annotation1.class)); Assert.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getAnnotationsByType(Annotation1.class));
Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getAnnotationsByType(Annotation2.class)); Assert.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getAnnotationsByType(Annotation2.class));
Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getAnnotationsByType(Annotation3.class)); Assert.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getAnnotationsByType(Annotation3.class));
} }
@Test @Test
public void testGetDeclaredAnnotationsByType() { public void testGetDeclaredAnnotationsByType() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getDeclaredAnnotationsByType(Annotation1.class)); Assert.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getDeclaredAnnotationsByType(Annotation1.class));
Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getDeclaredAnnotationsByType(Annotation2.class)); Assert.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getDeclaredAnnotationsByType(Annotation2.class));
Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getDeclaredAnnotationsByType(Annotation3.class)); Assert.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getDeclaredAnnotationsByType(Annotation3.class));
} }
@Test @Test
public void testGetDeclaredAnnotation() { public void testGetDeclaredAnnotation() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, elements.getDeclaredAnnotation(Annotation1.class)); Assert.assertEquals(annotation1, elements.getDeclaredAnnotation(Annotation1.class));
Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertEquals(annotation2, elements.getDeclaredAnnotation(Annotation2.class)); Assert.assertEquals(annotation2, elements.getDeclaredAnnotation(Annotation2.class));
Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertEquals(annotation3, elements.getDeclaredAnnotation(Annotation3.class)); Assert.assertEquals(annotation3, elements.getDeclaredAnnotation(Annotation3.class));
} }
@Test @Test
public void testGetDeclaredAnnotations() { public void testGetDeclaredAnnotations() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 }; final Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 };
Assert.assertArrayEquals(annotations, elements.getDeclaredAnnotations()); Assert.assertArrayEquals(annotations, elements.getDeclaredAnnotations());
} }
@Test @Test
public void testIterator() { public void testIterator() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Iterator<AnnotatedElement> iterator = elements.iterator(); final Iterator<AnnotatedElement> iterator = elements.iterator();
Assert.assertNotNull(iterator); Assert.assertNotNull(iterator);
List<AnnotatedElement> elementList = new ArrayList<>(); final List<AnnotatedElement> elementList = new ArrayList<>();
iterator.forEachRemaining(elementList::add); iterator.forEachRemaining(elementList::add);
Assert.assertEquals(Arrays.asList(Foo.class, Super.class, Interface.class), elementList); Assert.assertEquals(Arrays.asList(Foo.class, Super.class, Interface.class), elementList);
} }

View File

@ -26,7 +26,7 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testEquals() { public void testEquals() {
AnnotatedElement element = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY); final AnnotatedElement element = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY);
Assert.assertEquals(element, element); Assert.assertEquals(element, element);
Assert.assertNotEquals(element, null); Assert.assertNotEquals(element, null);
Assert.assertEquals(element, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY)); Assert.assertEquals(element, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY));
@ -36,7 +36,7 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testHashCode() { public void testHashCode() {
int hashCode = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode(); final int hashCode = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode();
Assert.assertEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode()); Assert.assertEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY).hashCode()); Assert.assertNotEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY).hashCode());
} }
@ -44,15 +44,15 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testCreate() { public void testCreate() {
// 第二次创建时优先从缓存中获取 // 第二次创建时优先从缓存中获取
AnnotatedElement resolvedElement = MetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY); final AnnotatedElement resolvedElement = MetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY);
Assert.assertEquals(resolvedElement, MetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY)); Assert.assertEquals(resolvedElement, MetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
AnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final AnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertEquals(element, MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY)); Assert.assertEquals(element, MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY));
} }
@Test @Test
public void testGetMapping() { public void testGetMapping() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertTrue(element.getMapping(Annotation1.class).isPresent()); Assert.assertTrue(element.getMapping(Annotation1.class).isPresent());
Assert.assertTrue(element.getMapping(Annotation2.class).isPresent()); Assert.assertTrue(element.getMapping(Annotation2.class).isPresent());
Assert.assertTrue(element.getMapping(Annotation3.class).isPresent()); Assert.assertTrue(element.getMapping(Annotation3.class).isPresent());
@ -61,7 +61,7 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testGetDeclaredMapping() { public void testGetDeclaredMapping() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertFalse(element.getDeclaredMapping(Annotation1.class).isPresent()); Assert.assertFalse(element.getDeclaredMapping(Annotation1.class).isPresent());
Assert.assertFalse(element.getDeclaredMapping(Annotation2.class).isPresent()); Assert.assertFalse(element.getDeclaredMapping(Annotation2.class).isPresent());
Assert.assertTrue(element.getDeclaredMapping(Annotation3.class).isPresent()); Assert.assertTrue(element.getDeclaredMapping(Annotation3.class).isPresent());
@ -70,7 +70,7 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testIsAnnotationPresent() { public void testIsAnnotationPresent() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertTrue(element.isAnnotationPresent(Annotation1.class)); Assert.assertTrue(element.isAnnotationPresent(Annotation1.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation2.class)); Assert.assertTrue(element.isAnnotationPresent(Annotation2.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation3.class)); Assert.assertTrue(element.isAnnotationPresent(Annotation3.class));
@ -79,11 +79,11 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testGetAnnotation() { public void testGetAnnotation() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class);
Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, element.getAnnotation(Annotation1.class)); Assert.assertEquals(annotation1, element.getAnnotation(Annotation1.class));
Assert.assertEquals(annotation2, element.getAnnotation(Annotation2.class)); Assert.assertEquals(annotation2, element.getAnnotation(Annotation2.class));
@ -93,9 +93,9 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testGetDeclaredAnnotation() { public void testGetDeclaredAnnotation() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertNull(element.getDeclaredAnnotation(Annotation1.class)); Assert.assertNull(element.getDeclaredAnnotation(Annotation1.class));
Assert.assertNull(element.getDeclaredAnnotation(Annotation2.class)); Assert.assertNull(element.getDeclaredAnnotation(Annotation2.class));
@ -105,8 +105,8 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testGetAnnotationByType() { public void testGetAnnotationByType() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Assert.assertArrayEquals( Assert.assertArrayEquals(
new Annotation[]{ annotation4 }, new Annotation[]{ annotation4 },
element.getAnnotationsByType(Annotation4.class) element.getAnnotationsByType(Annotation4.class)
@ -116,8 +116,8 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testGetDeclaredAnnotationByType() { public void testGetDeclaredAnnotationByType() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Assert.assertArrayEquals( Assert.assertArrayEquals(
new Annotation[]{ annotation4 }, new Annotation[]{ annotation4 },
element.getDeclaredAnnotationsByType(Annotation4.class) element.getDeclaredAnnotationsByType(Annotation4.class)
@ -127,37 +127,37 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testGetAnnotations() { public void testGetAnnotations() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class);
Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class);
Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 }; final Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 };
Assert.assertArrayEquals(annotations, element.getAnnotations()); Assert.assertArrayEquals(annotations, element.getAnnotations());
} }
@Test @Test
public void testGetDeclaredAnnotations() { public void testGetDeclaredAnnotations() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Annotation[] annotations = new Annotation[]{ annotation3, annotation4 }; final Annotation[] annotations = new Annotation[]{ annotation3, annotation4 };
Assert.assertArrayEquals(annotations, element.getDeclaredAnnotations()); Assert.assertArrayEquals(annotations, element.getDeclaredAnnotations());
} }
@Test @Test
public void testIterator() { public void testIterator() {
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class);
Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class);
Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 }; final Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 };
Iterator<ResolvedAnnotationMapping> iterator = element.iterator(); final Iterator<ResolvedAnnotationMapping> iterator = element.iterator();
List<Annotation> mappingList = new ArrayList<>(); final List<Annotation> mappingList = new ArrayList<>();
iterator.forEachRemaining(mapping -> mappingList.add(mapping.getAnnotation())); iterator.forEachRemaining(mapping -> mappingList.add(mapping.getAnnotation()));
Assert.assertEquals(Arrays.asList(annotations), mappingList); Assert.assertEquals(Arrays.asList(annotations), mappingList);
@ -165,8 +165,8 @@ public class MetaAnnotatedElementTest {
@Test @Test
public void testGetElement() { public void testGetElement() {
AnnotatedElement source = Foo.class; final AnnotatedElement source = Foo.class;
MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(source, MAPPING_FACTORY); final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(source, MAPPING_FACTORY);
Assert.assertSame(source, element.getElement()); Assert.assertSame(source, element.getElement());
} }

View File

@ -52,15 +52,15 @@ public class RepeatableAnnotationCollectorTest {
@Test @Test
public void testNone() { public void testNone() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none(); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none();
Assert.assertSame(collector, RepeatableAnnotationCollector.none()); Assert.assertSame(collector, RepeatableAnnotationCollector.none());
Assert.assertEquals(0, collector.getFinalRepeatableAnnotations(null).size()); Assert.assertEquals(0, collector.getFinalRepeatableAnnotations(null).size());
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(Collections.singletonList(annotation), collector.getFinalRepeatableAnnotations(annotation)); Assert.assertEquals(Collections.singletonList(annotation), collector.getFinalRepeatableAnnotations(annotation));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(annotation3), collector.getRepeatableAnnotations(annotation3, Annotation3.class)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getRepeatableAnnotations(annotation3, Annotation3.class));
@ -70,32 +70,32 @@ public class RepeatableAnnotationCollectorTest {
@Test @Test
public void testNoneWhenAccumulate() { public void testNoneWhenAccumulate() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none(); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none();
Assert.assertSame(collector, RepeatableAnnotationCollector.none()); Assert.assertSame(collector, RepeatableAnnotationCollector.none());
Assert.assertEquals(0, collector.getAllRepeatableAnnotations(null).size()); Assert.assertEquals(0, collector.getAllRepeatableAnnotations(null).size());
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(Collections.singletonList(annotation), collector.getAllRepeatableAnnotations(annotation)); Assert.assertEquals(Collections.singletonList(annotation), collector.getAllRepeatableAnnotations(annotation));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
} }
@Test @Test
public void testGenericCollector() { public void testGenericCollector() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard(); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard();
Assert.assertSame(collector, RepeatableAnnotationCollector.standard()); Assert.assertSame(collector, RepeatableAnnotationCollector.standard());
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
List<Annotation3> annotations = Stream.of(annotation.value()) final List<Annotation3> annotations = Stream.of(annotation.value())
.map(Annotation2::value) .map(Annotation2::value)
.flatMap(Stream::of) .flatMap(Stream::of)
.collect(Collectors.toList()); .collect(Collectors.toList());
Assert.assertEquals(annotations, collector.getFinalRepeatableAnnotations(annotation)); Assert.assertEquals(annotations, collector.getFinalRepeatableAnnotations(annotation));
Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1)); Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class)); Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
@ -105,11 +105,11 @@ public class RepeatableAnnotationCollectorTest {
@Test @Test
public void testGenericCollectorWhenAccumulate() { public void testGenericCollectorWhenAccumulate() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard(); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard();
Assert.assertSame(collector, RepeatableAnnotationCollector.standard()); Assert.assertSame(collector, RepeatableAnnotationCollector.standard());
List<Annotation> annotations = new ArrayList<>(); final List<Annotation> annotations = new ArrayList<>();
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
annotations.add(annotation); annotations.add(annotation);
annotations.addAll(Arrays.asList(annotation.value())); annotations.addAll(Arrays.asList(annotation.value()));
Stream.of(annotation.value()) Stream.of(annotation.value())
@ -120,15 +120,15 @@ public class RepeatableAnnotationCollectorTest {
Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1)); Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
} }
@Test @Test
public void testConditionCollector() { public void testConditionCollector() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE);
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
List<Annotation3> annotations = Stream.of(annotation.value()) final List<Annotation3> annotations = Stream.of(annotation.value())
.map(Annotation2::value) .map(Annotation2::value)
.flatMap(Stream::of) .flatMap(Stream::of)
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -136,7 +136,7 @@ public class RepeatableAnnotationCollectorTest {
Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1)); Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class)); Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
@ -146,10 +146,10 @@ public class RepeatableAnnotationCollectorTest {
@Test @Test
public void testConditionCollectorWhenAccumulate() { public void testConditionCollectorWhenAccumulate() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE);
List<Annotation> annotations = new ArrayList<>(); final List<Annotation> annotations = new ArrayList<>();
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
annotations.add(annotation); annotations.add(annotation);
annotations.addAll(Arrays.asList(annotation.value())); annotations.addAll(Arrays.asList(annotation.value()));
Stream.of(annotation.value()) Stream.of(annotation.value())
@ -159,18 +159,18 @@ public class RepeatableAnnotationCollectorTest {
Assert.assertEquals(annotations, collector.getAllRepeatableAnnotations(annotation)); Assert.assertEquals(annotations, collector.getAllRepeatableAnnotations(annotation));
Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1)); Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations((annotation3))); Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations((annotation3)));
} }
@Test @Test
public void testFullCollector() { public void testFullCollector() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full(); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full();
Assert.assertSame(collector, RepeatableAnnotationCollector.full()); Assert.assertSame(collector, RepeatableAnnotationCollector.full());
Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1)); Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class)); Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
@ -180,12 +180,12 @@ public class RepeatableAnnotationCollectorTest {
@Test @Test
public void testFullCollectorWhenAccumulate() { public void testFullCollectorWhenAccumulate() {
RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full(); final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full();
Assert.assertSame(collector, RepeatableAnnotationCollector.full()); Assert.assertSame(collector, RepeatableAnnotationCollector.full());
Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1)); Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3)); Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
} }

View File

@ -28,7 +28,7 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testEquals() { public void testEquals() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY); final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY);
Assert.assertEquals(element, element); Assert.assertEquals(element, element);
Assert.assertNotEquals(element, null); Assert.assertNotEquals(element, null);
Assert.assertEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY)); Assert.assertEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
@ -38,7 +38,7 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testHashCode() { public void testHashCode() {
int hashCode = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode(); final int hashCode = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode();
Assert.assertEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode()); Assert.assertEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY).hashCode()); Assert.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY).hashCode()); Assert.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY).hashCode());
@ -46,7 +46,7 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testIsAnnotationPresent() { public void testIsAnnotationPresent() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create( final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
Assert.assertTrue(element.isAnnotationPresent(Annotation1.class)); Assert.assertTrue(element.isAnnotationPresent(Annotation1.class));
@ -57,13 +57,13 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testGetAnnotations() { public void testGetAnnotations() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create( final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
List<Class<? extends Annotation>> annotationTypes = Arrays.stream(element.getAnnotations()) final List<Class<? extends Annotation>> annotationTypes = Arrays.stream(element.getAnnotations())
.map(Annotation::annotationType) .map(Annotation::annotationType)
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<Class<? extends Annotation>, Integer> countMap = IterUtil.countMap(annotationTypes.iterator()); final Map<Class<? extends Annotation>, Integer> countMap = IterUtil.countMap(annotationTypes.iterator());
Assert.assertEquals((Integer)1, countMap.get(Annotation1.class)); Assert.assertEquals((Integer)1, countMap.get(Annotation1.class));
Assert.assertEquals((Integer)2, countMap.get(Annotation2.class)); Assert.assertEquals((Integer)2, countMap.get(Annotation2.class));
@ -73,26 +73,26 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testGetAnnotation() { public void testGetAnnotation() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create( final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, element.getAnnotation(Annotation1.class)); Assert.assertEquals(annotation1, element.getAnnotation(Annotation1.class));
Annotation4 annotation4 = Annotation1.class.getAnnotation(Annotation4.class); final Annotation4 annotation4 = Annotation1.class.getAnnotation(Annotation4.class);
Assert.assertEquals(annotation4, element.getAnnotation(Annotation4.class)); Assert.assertEquals(annotation4, element.getAnnotation(Annotation4.class));
Annotation2 annotation2 = annotation1.value()[0]; final Annotation2 annotation2 = annotation1.value()[0];
Assert.assertEquals(annotation2, element.getAnnotation(Annotation2.class)); Assert.assertEquals(annotation2, element.getAnnotation(Annotation2.class));
Annotation3 annotation3 = annotation2.value()[0]; final Annotation3 annotation3 = annotation2.value()[0];
Assert.assertEquals(annotation3, element.getAnnotation(Annotation3.class)); Assert.assertEquals(annotation3, element.getAnnotation(Annotation3.class));
} }
@Test @Test
public void testGetAnnotationsByType() { public void testGetAnnotationsByType() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create( final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
@ -111,13 +111,13 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testGetDeclaredAnnotations() { public void testGetDeclaredAnnotations() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create( final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
List<Class<? extends Annotation>> annotationTypes = Arrays.stream(element.getDeclaredAnnotations()) final List<Class<? extends Annotation>> annotationTypes = Arrays.stream(element.getDeclaredAnnotations())
.map(Annotation::annotationType) .map(Annotation::annotationType)
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<Class<? extends Annotation>, Integer> countMap = IterUtil.countMap(annotationTypes.iterator()); final Map<Class<? extends Annotation>, Integer> countMap = IterUtil.countMap(annotationTypes.iterator());
Assert.assertEquals((Integer)1, countMap.get(Annotation1.class)); Assert.assertEquals((Integer)1, countMap.get(Annotation1.class));
Assert.assertFalse(countMap.containsKey(Annotation2.class)); Assert.assertFalse(countMap.containsKey(Annotation2.class));
@ -127,11 +127,11 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testGetDeclaredAnnotation() { public void testGetDeclaredAnnotation() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create( final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
Annotation1 annotation1 = Foo.class.getDeclaredAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getDeclaredAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, element.getDeclaredAnnotation(Annotation1.class)); Assert.assertEquals(annotation1, element.getDeclaredAnnotation(Annotation1.class));
Assert.assertNull(element.getDeclaredAnnotation(Annotation3.class)); Assert.assertNull(element.getDeclaredAnnotation(Annotation3.class));
Assert.assertNull(element.getDeclaredAnnotation(Annotation4.class)); Assert.assertNull(element.getDeclaredAnnotation(Annotation4.class));
@ -140,7 +140,7 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testGetDeclaredAnnotationsByType() { public void testGetDeclaredAnnotationsByType() {
AnnotatedElement element = RepeatableMetaAnnotatedElement.create( final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
@ -159,8 +159,8 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testGetElement() { public void testGetElement() {
AnnotatedElement element = Foo.class; final AnnotatedElement element = Foo.class;
RepeatableMetaAnnotatedElement<GenericAnnotationMapping> repeatableMetaAnnotatedElement = RepeatableMetaAnnotatedElement.create( final RepeatableMetaAnnotatedElement<GenericAnnotationMapping> repeatableMetaAnnotatedElement = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), element, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), element, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
Assert.assertSame(element, repeatableMetaAnnotatedElement.getElement()); Assert.assertSame(element, repeatableMetaAnnotatedElement.getElement());
@ -168,11 +168,11 @@ public class RepeatableMetaAnnotatedElementTest {
@Test @Test
public void testIterator() { public void testIterator() {
RepeatableMetaAnnotatedElement<GenericAnnotationMapping> element = RepeatableMetaAnnotatedElement.create( final RepeatableMetaAnnotatedElement<GenericAnnotationMapping> element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
); );
int count = 0; int count = 0;
for (GenericAnnotationMapping mapping : element) { for (final GenericAnnotationMapping mapping : element) {
count++; count++;
} }
Assert.assertEquals(14, count); Assert.assertEquals(14, count);

View File

@ -19,15 +19,15 @@ public class ResolvedAnnotationMappingTest {
@Test @Test
public void testEquals() { public void testEquals() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertEquals(mapping, mapping); Assert.assertEquals(mapping, mapping);
Assert.assertNotEquals(null, mapping); Assert.assertNotEquals(null, mapping);
Assert.assertEquals(mapping, ResolvedAnnotationMapping.create(annotation, false)); Assert.assertEquals(mapping, ResolvedAnnotationMapping.create(annotation, false));
Assert.assertNotEquals(mapping, ResolvedAnnotationMapping.create(annotation, true)); Assert.assertNotEquals(mapping, ResolvedAnnotationMapping.create(annotation, true));
// Annotation3没有需要解析的属性因此即使在构造函数指定false也一样 // Annotation3没有需要解析的属性因此即使在构造函数指定false也一样
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals( Assert.assertEquals(
ResolvedAnnotationMapping.create(annotation3, false), ResolvedAnnotationMapping.create(annotation3, false),
ResolvedAnnotationMapping.create(annotation3, true) ResolvedAnnotationMapping.create(annotation3, true)
@ -36,13 +36,13 @@ public class ResolvedAnnotationMappingTest {
@Test @Test
public void testHashCode() { public void testHashCode() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
int hashCode = ResolvedAnnotationMapping.create(annotation, false).hashCode(); final int hashCode = ResolvedAnnotationMapping.create(annotation, false).hashCode();
Assert.assertEquals(hashCode, ResolvedAnnotationMapping.create(annotation, false).hashCode()); Assert.assertEquals(hashCode, ResolvedAnnotationMapping.create(annotation, false).hashCode());
Assert.assertNotEquals(hashCode, ResolvedAnnotationMapping.create(annotation, true).hashCode()); Assert.assertNotEquals(hashCode, ResolvedAnnotationMapping.create(annotation, true).hashCode());
// Annotation3没有需要解析的属性因此即使在构造函数指定false也一样 // Annotation3没有需要解析的属性因此即使在构造函数指定false也一样
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals( Assert.assertEquals(
ResolvedAnnotationMapping.create(annotation3, false).hashCode(), ResolvedAnnotationMapping.create(annotation3, false).hashCode(),
ResolvedAnnotationMapping.create(annotation3, true).hashCode() ResolvedAnnotationMapping.create(annotation3, true).hashCode()
@ -52,92 +52,92 @@ public class ResolvedAnnotationMappingTest {
@Test @Test
public void testCreate() { public void testCreate() {
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false);
Assert.assertNotNull(mapping3); Assert.assertNotNull(mapping3);
Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false);
Assert.assertNotNull(mapping2); Assert.assertNotNull(mapping2);
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false); final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false);
Assert.assertNotNull(mapping1); Assert.assertNotNull(mapping1);
} }
@Test @Test
public void testIsRoot() { public void testIsRoot() {
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false);
Assert.assertTrue(mapping3.isRoot()); Assert.assertTrue(mapping3.isRoot());
Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false);
Assert.assertFalse(mapping2.isRoot()); Assert.assertFalse(mapping2.isRoot());
} }
@Test @Test
public void testGetRoot() { public void testGetRoot() {
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false);
Assert.assertSame(mapping3, mapping3.getRoot()); Assert.assertSame(mapping3, mapping3.getRoot());
Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false);
Assert.assertSame(mapping3, mapping2.getRoot()); Assert.assertSame(mapping3, mapping2.getRoot());
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false); final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false);
Assert.assertSame(mapping3, mapping1.getRoot()); Assert.assertSame(mapping3, mapping1.getRoot());
} }
@Test @Test
public void testGetAnnotation() { public void testGetAnnotation() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertSame(annotation, mapping.getAnnotation()); Assert.assertSame(annotation, mapping.getAnnotation());
} }
@SneakyThrows @SneakyThrows
@Test @Test
public void testGetAttributes() { public void testGetAttributes() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
for (int i = 0; i < mapping.getAttributes().length; i++) { for (int i = 0; i < mapping.getAttributes().length; i++) {
Method method = mapping.getAttributes()[i]; final Method method = mapping.getAttributes()[i];
Assert.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method); Assert.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method);
} }
} }
@Test @Test
public void testHasAttribute() { public void testHasAttribute() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertTrue(mapping.hasAttribute("value", String.class)); Assert.assertTrue(mapping.hasAttribute("value", String.class));
Assert.assertFalse(mapping.hasAttribute("value", Integer.class)); Assert.assertFalse(mapping.hasAttribute("value", Integer.class));
int index = mapping.getAttributeIndex("value", String.class); final int index = mapping.getAttributeIndex("value", String.class);
Assert.assertTrue(mapping.hasAttribute(index)); Assert.assertTrue(mapping.hasAttribute(index));
Assert.assertFalse(mapping.hasAttribute(Integer.MIN_VALUE)); Assert.assertFalse(mapping.hasAttribute(Integer.MIN_VALUE));
} }
@Test @Test
public void testAnnotationType() { public void testAnnotationType() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.annotationType(), mapping.annotationType()); Assert.assertEquals(annotation.annotationType(), mapping.annotationType());
} }
@Test @Test
public void testIsResolved() { public void testIsResolved() {
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(annotation1, true); final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(annotation1, true);
Assert.assertTrue(mapping1.isResolved()); Assert.assertTrue(mapping1.isResolved());
Assert.assertFalse(ResolvedAnnotationMapping.create(annotation1, false).isResolved()); Assert.assertFalse(ResolvedAnnotationMapping.create(annotation1, false).isResolved());
Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(annotation2, true); ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(annotation2, true);
Assert.assertFalse(mapping2.isResolved()); Assert.assertFalse(mapping2.isResolved());
@ -147,10 +147,10 @@ public class ResolvedAnnotationMappingTest {
@Test @Test
public void testGetAttributeIndex() { public void testGetAttributeIndex() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
for (int i = 0; i < mapping.getAttributes().length; i++) { for (int i = 0; i < mapping.getAttributes().length; i++) {
Method method = mapping.getAttributes()[i]; final Method method = mapping.getAttributes()[i];
Assert.assertEquals(i, mapping.getAttributeIndex(method.getName(), method.getReturnType())); Assert.assertEquals(i, mapping.getAttributeIndex(method.getName(), method.getReturnType()));
} }
Assert.assertEquals(ResolvedAnnotationMapping.NOT_FOUND_INDEX, mapping.getAttributeIndex("value", Void.class)); Assert.assertEquals(ResolvedAnnotationMapping.NOT_FOUND_INDEX, mapping.getAttributeIndex("value", Void.class));
@ -159,29 +159,29 @@ public class ResolvedAnnotationMappingTest {
@Test @Test
public void testGetAttributeValue() { public void testGetAttributeValue() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertNull(mapping.getAttribute(Integer.MAX_VALUE)); Assert.assertNull(mapping.getAttribute(Integer.MAX_VALUE));
int valueIdx = mapping.getAttributeIndex("value", String.class); final int valueIdx = mapping.getAttributeIndex("value", String.class);
Assert.assertEquals(annotation.value(), mapping.getAttributeValue(valueIdx)); Assert.assertEquals(annotation.value(), mapping.getAttributeValue(valueIdx));
Assert.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class)); Assert.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class));
int name1Idx = mapping.getAttributeIndex("value1", String.class); final int name1Idx = mapping.getAttributeIndex("value1", String.class);
Assert.assertEquals(annotation.value1(), mapping.getAttributeValue(name1Idx)); Assert.assertEquals(annotation.value1(), mapping.getAttributeValue(name1Idx));
Assert.assertEquals(annotation.value1(), mapping.getAttributeValue("value1", String.class)); Assert.assertEquals(annotation.value1(), mapping.getAttributeValue("value1", String.class));
int name2Idx = mapping.getAttributeIndex("value2", String.class); final int name2Idx = mapping.getAttributeIndex("value2", String.class);
Assert.assertEquals(annotation.value2(), mapping.getAttributeValue(name2Idx)); Assert.assertEquals(annotation.value2(), mapping.getAttributeValue(name2Idx));
Assert.assertEquals(annotation.value2(), mapping.getAttributeValue("value2", String.class)); Assert.assertEquals(annotation.value2(), mapping.getAttributeValue("value2", String.class));
} }
@Test @Test
public void testGetResolvedAnnotation() { public void testGetResolvedAnnotation() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true);
Annotation1 synthesis = (Annotation1)mapping.getResolvedAnnotation(); final Annotation1 synthesis = (Annotation1)mapping.getResolvedAnnotation();
Assert.assertEquals(annotation.annotationType(), synthesis.annotationType()); Assert.assertEquals(annotation.annotationType(), synthesis.annotationType());
Assert.assertEquals(annotation.value(), synthesis.value()); Assert.assertEquals(annotation.value(), synthesis.value());
@ -195,7 +195,7 @@ public class ResolvedAnnotationMappingTest {
Assert.assertNotEquals(synthesis.hashCode(), annotation.hashCode()); Assert.assertNotEquals(synthesis.hashCode(), annotation.hashCode());
Assert.assertNotEquals(synthesis.toString(), annotation.toString()); Assert.assertNotEquals(synthesis.toString(), annotation.toString());
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertSame(annotation3, ResolvedAnnotationMapping.create(annotation3, true).getResolvedAnnotation()); Assert.assertSame(annotation3, ResolvedAnnotationMapping.create(annotation3, true).getResolvedAnnotation());
} }
@ -203,8 +203,8 @@ public class ResolvedAnnotationMappingTest {
@Test @Test
public void testGetResolvedAttributeValueWhenAliased() { public void testGetResolvedAttributeValueWhenAliased() {
Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true); final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true);
Assert.assertNull(mapping.getResolvedAttributeValue(Integer.MIN_VALUE)); Assert.assertNull(mapping.getResolvedAttributeValue(Integer.MIN_VALUE));
// value = value1 = value2 // value = value1 = value2
@ -232,20 +232,20 @@ public class ResolvedAnnotationMappingTest {
@Test @Test
public void testGetResolvedAttributeWhenOverwritten() { public void testGetResolvedAttributeWhenOverwritten() {
Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, true); final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, true);
Assert.assertEquals(annotation3.value(), mapping3.getResolvedAttributeValue("value", String.class)); Assert.assertEquals(annotation3.value(), mapping3.getResolvedAttributeValue("value", String.class));
Assert.assertEquals((Integer)annotation3.alias(), mapping3.getResolvedAttributeValue("alias", Integer.class)); Assert.assertEquals((Integer)annotation3.alias(), mapping3.getResolvedAttributeValue("alias", Integer.class));
// annotation2中与annotation3同名同类型的属性valuealias被覆写 // annotation2中与annotation3同名同类型的属性valuealias被覆写
Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, true); final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, true);
Assert.assertEquals(annotation3.value(), mapping2.getResolvedAttributeValue("value", String.class)); Assert.assertEquals(annotation3.value(), mapping2.getResolvedAttributeValue("value", String.class));
Assert.assertEquals((Integer)annotation3.alias(), mapping2.getResolvedAttributeValue("alias", Integer.class)); Assert.assertEquals((Integer)annotation3.alias(), mapping2.getResolvedAttributeValue("alias", Integer.class));
// annotation1中与annotation3同名同类型的属性value被覆写由于value存在别名value1value2因此也一并被覆写 // annotation1中与annotation3同名同类型的属性value被覆写由于value存在别名value1value2因此也一并被覆写
Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, true); final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, true);
Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value", String.class)); Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value", String.class));
Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value1", String.class)); Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value1", String.class));
Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value2", String.class)); Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value2", String.class));
@ -253,6 +253,7 @@ public class ResolvedAnnotationMappingTest {
Assert.assertEquals(annotation1.alias(), mapping1.getResolvedAttributeValue("alias", String.class)); Assert.assertEquals(annotation1.alias(), mapping1.getResolvedAttributeValue("alias", String.class));
} }
@SuppressWarnings("unused")
@Target(ElementType.TYPE_USE) @Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
private @interface Annotation1 { private @interface Annotation1 {