diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java index 7445efde8..78070ef39 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java @@ -39,7 +39,7 @@ public class AnnotatedElementUtilTest { @Test public void testClearCaches() { - AnnotatedElement type = Foo.class; + final AnnotatedElement type = Foo.class; AnnotatedElement element = AnnotatedElementUtil.getResolvedMetaElementCache(type); Assert.assertSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type)); @@ -94,22 +94,22 @@ public class AnnotatedElementUtilTest { @Test public void testFindAnnotations() { - Annotation[] annotations = AnnotatedElementUtil.findAnnotations(Foo.class); + final Annotation[] annotations = AnnotatedElementUtil.findAnnotations(Foo.class); Assert.assertArrayEquals(ANNOTATIONS, annotations); } @Test public void testFindResolvedAnnotation() { - Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation3.class); + final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation3.class); Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -121,19 +121,19 @@ public class AnnotatedElementUtilTest { @Test public void testFindResolvedAnnotations() { - Annotation[] resolvedAnnotations = AnnotatedElementUtil.findResolvedAnnotations(Foo.class); - Map, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity())); + final Annotation[] resolvedAnnotations = AnnotatedElementUtil.findResolvedAnnotations(Foo.class); + final Map, 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.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -145,16 +145,16 @@ public class AnnotatedElementUtilTest { @Test 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.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -195,7 +195,7 @@ public class AnnotatedElementUtilTest { public void testFindDirectlyResolvedAnnotation() { Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation4.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.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 @@ -207,12 +207,12 @@ public class AnnotatedElementUtilTest { @Test public void testFindDirectlyResolvedAnnotations() { - Annotation[] resolvedAnnotations = AnnotatedElementUtil.findDirectlyResolvedAnnotations(Foo.class); - Map, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity())); + final Annotation[] resolvedAnnotations = AnnotatedElementUtil.findDirectlyResolvedAnnotations(Foo.class); + final Map, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity())); Assert.assertEquals(ANNOTATION4, annotationMap.get(Annotation4.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.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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(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.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 @@ -261,7 +261,7 @@ public class AnnotatedElementUtilTest { @Test public void testGetAnnotations() { - Annotation[] annotations = AnnotatedElementUtil.getAnnotations(Foo.class); + final Annotation[] annotations = AnnotatedElementUtil.getAnnotations(Foo.class); Assert.assertArrayEquals( new Annotation[]{ ANNOTATION3, ANNOTATION2, ANNOTATION1 }, annotations @@ -270,15 +270,15 @@ public class AnnotatedElementUtilTest { @Test 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(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(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(ANNOTATION1, resolvedAnnotation1s[0]); @@ -289,16 +289,16 @@ public class AnnotatedElementUtilTest { @Test public void testGetResolvedAnnotation() { - Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation3.class); + final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation3.class); Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -310,22 +310,22 @@ public class AnnotatedElementUtilTest { @Test 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); - Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; + final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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); - Annotation2 resolvedAnnotation2 = resolvedAnnotation2s[0]; + final Annotation2 resolvedAnnotation2 = resolvedAnnotation2s[0]; Assert.assertNotNull(resolvedAnnotation2); 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); - Annotation1 resolvedAnnotation1 = resolvedAnnotation1s[0]; + final Annotation1 resolvedAnnotation1 = resolvedAnnotation1s[0]; Assert.assertNotNull(resolvedAnnotation1); Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -337,19 +337,19 @@ public class AnnotatedElementUtilTest { @Test public void testGetResolvedAnnotations() { - Map, Annotation> annotationMap = Stream.of(AnnotatedElementUtil.getResolvedAnnotations(Foo.class)) + final Map, Annotation> annotationMap = Stream.of(AnnotatedElementUtil.getResolvedAnnotations(Foo.class)) .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.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -372,9 +372,9 @@ public class AnnotatedElementUtilTest { @Test 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); - Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; + final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; Assert.assertEquals(ANNOTATION3, resolvedAnnotation3); Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length); @@ -386,14 +386,14 @@ public class AnnotatedElementUtilTest { @Test public void testGetDirectlyAnnotations() { - Annotation[] annotations = AnnotatedElementUtil.getDirectlyAnnotations(Foo.class); + final Annotation[] annotations = AnnotatedElementUtil.getDirectlyAnnotations(Foo.class); Assert.assertEquals(1, annotations.length); Assert.assertEquals(ANNOTATION3, annotations[0]); } @Test public void testGetDirectlyResolvedAnnotation() { - Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation3.class); + final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation3.class); Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 @@ -407,9 +407,9 @@ public class AnnotatedElementUtilTest { @Test 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); - Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; + final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0]; Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 @@ -423,10 +423,10 @@ public class AnnotatedElementUtilTest { @Test public void testGetDirectlyResolvedAnnotations() { - Annotation[] annotations = AnnotatedElementUtil.getDirectlyResolvedAnnotations(Foo.class); + final Annotation[] annotations = AnnotatedElementUtil.getDirectlyResolvedAnnotations(Foo.class); Assert.assertEquals(1, annotations.length); - Annotation3 resolvedAnnotation3 = (Annotation3)annotations[0]; + final Annotation3 resolvedAnnotation3 = (Annotation3)annotations[0]; Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名 @@ -436,7 +436,7 @@ public class AnnotatedElementUtilTest { public void testToHierarchyMetaElement() { Assert.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, false)); 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()); @@ -445,17 +445,17 @@ public class AnnotatedElementUtilTest { Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations()); // 解析注解属性 - AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, true); - Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class); + final AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, true); + final Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class); Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -469,7 +469,7 @@ public class AnnotatedElementUtilTest { public void testToHierarchyRepeatableMetaElement() { Assert.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, false)); 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()); @@ -478,17 +478,17 @@ public class AnnotatedElementUtilTest { Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations()); // 解析注解属性 - AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, true); - Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class); + final AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, true); + final Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class); Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -501,7 +501,7 @@ public class AnnotatedElementUtilTest { @Test public void testToHierarchyElement() { 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()); } @@ -520,16 +520,16 @@ public class AnnotatedElementUtilTest { Assert.assertSame(element, AnnotatedElementUtil.toMetaElement(Foo.class, true)); // 第二次获取时从缓存中获取 Assert.assertEquals(3, element.getAnnotations().length); - Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class); + final Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class); Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 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(3, element.getAnnotations().length); - Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class); + final Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class); Assert.assertNotNull(resolvedAnnotation3); Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value()); 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.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.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖 Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名 @@ -567,10 +567,10 @@ public class AnnotatedElementUtilTest { @Test public void testAsElement() { - Annotation[] annotations = new Annotation[]{ANNOTATION1, ANNOTATION2}; + final Annotation[] annotations = new Annotation[]{ANNOTATION1, ANNOTATION2}; 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.getDeclaredAnnotations()); Assert.assertEquals(ANNOTATION1, element.getAnnotation(Annotation1.class)); @@ -579,7 +579,7 @@ public class AnnotatedElementUtilTest { @Test public void testEmptyElement() { - AnnotatedElement element = AnnotatedElementUtil.emptyElement(); + final AnnotatedElement element = AnnotatedElementUtil.emptyElement(); Assert.assertSame(element, AnnotatedElementUtil.emptyElement()); Assert.assertNull(element.getAnnotation(Annotation1.class)); Assert.assertEquals(0, element.getAnnotations().length); diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java index cb81ef2cb..b4fb77fdc 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java @@ -12,36 +12,36 @@ public class CombinationAnnotationElementTest { @Test public void testOf() { - CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); Assert.assertNotNull(element); } @Test 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)); } @Test public void testGetAnnotation() { - AnnotationForTest annotation1 = ClassForTest.class.getAnnotation(AnnotationForTest.class); - MetaAnnotationForTest annotation2 = AnnotationForTest.class.getAnnotation(MetaAnnotationForTest.class); - CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final AnnotationForTest annotation1 = ClassForTest.class.getAnnotation(AnnotationForTest.class); + final MetaAnnotationForTest annotation2 = AnnotationForTest.class.getAnnotation(MetaAnnotationForTest.class); + final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); Assert.assertEquals(annotation1, element.getAnnotation(AnnotationForTest.class)); Assert.assertEquals(annotation2, element.getAnnotation(MetaAnnotationForTest.class)); } @Test public void testGetAnnotations() { - CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); - Annotation[] annotations = element.getAnnotations(); + final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final Annotation[] annotations = element.getAnnotations(); Assert.assertEquals(2, annotations.length); } @Test public void testGetDeclaredAnnotations() { - CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); - Annotation[] annotations = element.getDeclaredAnnotations(); + final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true); + final Annotation[] annotations = element.getDeclaredAnnotations(); Assert.assertEquals(2, annotations.length); } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java index 011cf1419..46b5cea04 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java @@ -19,8 +19,8 @@ public class GenericAnnotationMappingTest { @Test public void testEquals() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertEquals(mapping, mapping); Assert.assertNotEquals(mapping, null); Assert.assertEquals(mapping, GenericAnnotationMapping.create(annotation, false)); @@ -29,8 +29,8 @@ public class GenericAnnotationMappingTest { @Test public void testHashCode() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - int hashCode = GenericAnnotationMapping.create(annotation, false).hashCode(); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final int hashCode = GenericAnnotationMapping.create(annotation, false).hashCode(); Assert.assertEquals(hashCode, GenericAnnotationMapping.create(annotation, false).hashCode()); Assert.assertNotEquals(hashCode, GenericAnnotationMapping.create(annotation, true).hashCode()); } @@ -38,14 +38,14 @@ public class GenericAnnotationMappingTest { @Test public void testCreate() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertNotNull(mapping); } @Test public void testIsRoot() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, true); Assert.assertTrue(mapping.isRoot()); @@ -55,55 +55,55 @@ public class GenericAnnotationMappingTest { @Test public void testGetAnnotation() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertSame(annotation, mapping.getAnnotation()); } @SneakyThrows @Test public void testGetAttributes() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); 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); } } @Test public void testAnnotationType() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertEquals(annotation.annotationType(), mapping.annotationType()); } @Test public void testIsResolved() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertFalse(mapping.isResolved()); } @Test public void testGetAttributeValue() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class)); Assert.assertNull(mapping.getAttributeValue("value", Integer.class)); } @Test public void testGetResolvedAnnotation() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertSame(annotation, mapping.getResolvedAnnotation()); } @Test public void testGetResolvedAttributeValue() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false); Assert.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value", String.class)); Assert.assertNull(mapping.getResolvedAttributeValue("value", Integer.class)); } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java index f4e8a0034..62f577fd1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java @@ -22,11 +22,11 @@ public class HierarchicalAnnotatedElementTest { @SneakyThrows @Test public void testCreateFromMethod() { - Method method1 = Foo.class.getDeclaredMethod("method"); + final Method method1 = Foo.class.getDeclaredMethod("method"); HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(method1); Assert.assertEquals(3, elements.getElementMappings().size()); - Method method2 = Foo.class.getDeclaredMethod("method2"); + final Method method2 = Foo.class.getDeclaredMethod("method2"); elements = HierarchicalAnnotatedElements.create(method2); Assert.assertEquals(1, elements.getElementMappings().size()); } @@ -46,7 +46,7 @@ public class HierarchicalAnnotatedElementTest { @Test 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, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY)); Assert.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY)); @@ -56,7 +56,7 @@ public class HierarchicalAnnotatedElementTest { @Test 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.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY).hashCode()); Assert.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e).hashCode()); @@ -64,14 +64,14 @@ public class HierarchicalAnnotatedElementTest { @Test public void testGetElement() { - AnnotatedElement element = Foo.class; - HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(element, ELEMENT_MAPPING_FACTORY); + final AnnotatedElement element = Foo.class; + final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(element, ELEMENT_MAPPING_FACTORY); Assert.assertSame(element, elements.getElement()); } @Test 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(Annotation2.class)); Assert.assertTrue(elements.isAnnotationPresent(Annotation3.class)); @@ -79,91 +79,91 @@ public class HierarchicalAnnotatedElementTest { @Test public void testGetAnnotations() { - HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); + final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); - Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); - Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); - Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); - Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 }; + final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); + final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); + final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); + final Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 }; Assert.assertArrayEquals(annotations, elements.getAnnotations()); } @Test 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)); - Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); + final Annotation2 annotation2 = Super.class.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)); } @Test 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)); - Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); + final Annotation2 annotation2 = Super.class.getAnnotation(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)); } @Test 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)); - Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); + final Annotation2 annotation2 = Super.class.getAnnotation(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)); } @Test 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)); - Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); + final Annotation2 annotation2 = Super.class.getAnnotation(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)); } @Test public void testGetDeclaredAnnotations() { - HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); + final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); - Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); - Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); - Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); - Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 }; + final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); + final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class); + final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class); + final Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 }; Assert.assertArrayEquals(annotations, elements.getDeclaredAnnotations()); } @Test public void testIterator() { - HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); - Iterator iterator = elements.iterator(); + final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class); + final Iterator iterator = elements.iterator(); Assert.assertNotNull(iterator); - List elementList = new ArrayList<>(); + final List elementList = new ArrayList<>(); iterator.forEachRemaining(elementList::add); Assert.assertEquals(Arrays.asList(Foo.class, Super.class, Interface.class), elementList); } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java index f4cdfdc1d..ff79d53f9 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java @@ -26,7 +26,7 @@ public class MetaAnnotatedElementTest { @Test 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.assertNotEquals(element, null); Assert.assertEquals(element, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY)); @@ -36,7 +36,7 @@ public class MetaAnnotatedElementTest { @Test 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.assertNotEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY).hashCode()); } @@ -44,15 +44,15 @@ public class MetaAnnotatedElementTest { @Test 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)); - 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)); } @Test public void testGetMapping() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); Assert.assertTrue(element.getMapping(Annotation1.class).isPresent()); Assert.assertTrue(element.getMapping(Annotation2.class).isPresent()); Assert.assertTrue(element.getMapping(Annotation3.class).isPresent()); @@ -61,7 +61,7 @@ public class MetaAnnotatedElementTest { @Test public void testGetDeclaredMapping() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); Assert.assertFalse(element.getDeclaredMapping(Annotation1.class).isPresent()); Assert.assertFalse(element.getDeclaredMapping(Annotation2.class).isPresent()); Assert.assertTrue(element.getDeclaredMapping(Annotation3.class).isPresent()); @@ -70,7 +70,7 @@ public class MetaAnnotatedElementTest { @Test public void testIsAnnotationPresent() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); Assert.assertTrue(element.isAnnotationPresent(Annotation1.class)); Assert.assertTrue(element.isAnnotationPresent(Annotation2.class)); Assert.assertTrue(element.isAnnotationPresent(Annotation3.class)); @@ -79,11 +79,11 @@ public class MetaAnnotatedElementTest { @Test public void testGetAnnotation() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); - Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); - Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); + final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); Assert.assertEquals(annotation1, element.getAnnotation(Annotation1.class)); Assert.assertEquals(annotation2, element.getAnnotation(Annotation2.class)); @@ -93,9 +93,9 @@ public class MetaAnnotatedElementTest { @Test public void testGetDeclaredAnnotation() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); - Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); Assert.assertNull(element.getDeclaredAnnotation(Annotation1.class)); Assert.assertNull(element.getDeclaredAnnotation(Annotation2.class)); @@ -105,8 +105,8 @@ public class MetaAnnotatedElementTest { @Test public void testGetAnnotationByType() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); - Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); Assert.assertArrayEquals( new Annotation[]{ annotation4 }, element.getAnnotationsByType(Annotation4.class) @@ -116,8 +116,8 @@ public class MetaAnnotatedElementTest { @Test public void testGetDeclaredAnnotationByType() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); - Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); Assert.assertArrayEquals( new Annotation[]{ annotation4 }, element.getDeclaredAnnotationsByType(Annotation4.class) @@ -127,37 +127,37 @@ public class MetaAnnotatedElementTest { @Test public void testGetAnnotations() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); - Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); - Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); - Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 }; + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); + final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); + final Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 }; Assert.assertArrayEquals(annotations, element.getAnnotations()); } @Test public void testGetDeclaredAnnotations() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); - Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - Annotation[] annotations = new Annotation[]{ annotation3, annotation4 }; + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final Annotation[] annotations = new Annotation[]{ annotation3, annotation4 }; Assert.assertArrayEquals(annotations, element.getDeclaredAnnotations()); } @Test public void testIterator() { - MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); - Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); - Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); - Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 }; + final MetaAnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY); + final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class); + final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class); + final Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 }; - Iterator iterator = element.iterator(); - List mappingList = new ArrayList<>(); + final Iterator iterator = element.iterator(); + final List mappingList = new ArrayList<>(); iterator.forEachRemaining(mapping -> mappingList.add(mapping.getAnnotation())); Assert.assertEquals(Arrays.asList(annotations), mappingList); @@ -165,8 +165,8 @@ public class MetaAnnotatedElementTest { @Test public void testGetElement() { - AnnotatedElement source = Foo.class; - MetaAnnotatedElement element = MetaAnnotatedElement.create(source, MAPPING_FACTORY); + final AnnotatedElement source = Foo.class; + final MetaAnnotatedElement element = MetaAnnotatedElement.create(source, MAPPING_FACTORY); Assert.assertSame(source, element.getElement()); } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java index ac9386a57..098fe81f6 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java @@ -52,15 +52,15 @@ public class RepeatableAnnotationCollectorTest { @Test public void testNone() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none(); + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none(); Assert.assertSame(collector, RepeatableAnnotationCollector.none()); 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)); - 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.getRepeatableAnnotations(annotation3, Annotation3.class)); @@ -70,32 +70,32 @@ public class RepeatableAnnotationCollectorTest { @Test public void testNoneWhenAccumulate() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none(); + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none(); Assert.assertSame(collector, RepeatableAnnotationCollector.none()); 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)); - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3)); } @Test public void testGenericCollector() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard(); + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard(); Assert.assertSame(collector, RepeatableAnnotationCollector.standard()); - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - List annotations = Stream.of(annotation.value()) + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final List annotations = Stream.of(annotation.value()) .map(Annotation2::value) .flatMap(Stream::of) .collect(Collectors.toList()); Assert.assertEquals(annotations, collector.getFinalRepeatableAnnotations(annotation)); 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(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class)); @@ -105,11 +105,11 @@ public class RepeatableAnnotationCollectorTest { @Test public void testGenericCollectorWhenAccumulate() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard(); + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard(); Assert.assertSame(collector, RepeatableAnnotationCollector.standard()); - List annotations = new ArrayList<>(); - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final List annotations = new ArrayList<>(); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); annotations.add(annotation); annotations.addAll(Arrays.asList(annotation.value())); Stream.of(annotation.value()) @@ -120,15 +120,15 @@ public class RepeatableAnnotationCollectorTest { 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)); } @Test public void testConditionCollector() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE); - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - List annotations = Stream.of(annotation.value()) + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final List annotations = Stream.of(annotation.value()) .map(Annotation2::value) .flatMap(Stream::of) .collect(Collectors.toList()); @@ -136,7 +136,7 @@ public class RepeatableAnnotationCollectorTest { 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(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class)); @@ -146,10 +146,10 @@ public class RepeatableAnnotationCollectorTest { @Test public void testConditionCollectorWhenAccumulate() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE); + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.condition(PREDICATE); - List annotations = new ArrayList<>(); - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final List annotations = new ArrayList<>(); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); annotations.add(annotation); annotations.addAll(Arrays.asList(annotation.value())); Stream.of(annotation.value()) @@ -159,18 +159,18 @@ public class RepeatableAnnotationCollectorTest { Assert.assertEquals(annotations, collector.getAllRepeatableAnnotations(annotation)); 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))); } @Test public void testFullCollector() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full(); + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full(); Assert.assertSame(collector, RepeatableAnnotationCollector.full()); 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(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class)); @@ -180,12 +180,12 @@ public class RepeatableAnnotationCollectorTest { @Test public void testFullCollectorWhenAccumulate() { - RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full(); + final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full(); Assert.assertSame(collector, RepeatableAnnotationCollector.full()); 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)); } diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java index 2fc38fe03..26afe079d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java @@ -28,7 +28,7 @@ public class RepeatableMetaAnnotatedElementTest { @Test 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.assertNotEquals(element, null); Assert.assertEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY)); @@ -38,7 +38,7 @@ public class RepeatableMetaAnnotatedElementTest { @Test 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.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY).hashCode()); Assert.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY).hashCode()); @@ -46,7 +46,7 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testIsAnnotationPresent() { - AnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = RepeatableMetaAnnotatedElement.create( RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) ); Assert.assertTrue(element.isAnnotationPresent(Annotation1.class)); @@ -57,13 +57,13 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testGetAnnotations() { - AnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = RepeatableMetaAnnotatedElement.create( RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) ); - List> annotationTypes = Arrays.stream(element.getAnnotations()) + final List> annotationTypes = Arrays.stream(element.getAnnotations()) .map(Annotation::annotationType) .collect(Collectors.toList()); - Map, Integer> countMap = IterUtil.countMap(annotationTypes.iterator()); + final Map, Integer> countMap = IterUtil.countMap(annotationTypes.iterator()); Assert.assertEquals((Integer)1, countMap.get(Annotation1.class)); Assert.assertEquals((Integer)2, countMap.get(Annotation2.class)); @@ -73,26 +73,26 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testGetAnnotation() { - AnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = RepeatableMetaAnnotatedElement.create( 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)); - Annotation4 annotation4 = Annotation1.class.getAnnotation(Annotation4.class); + final Annotation4 annotation4 = Annotation1.class.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)); - Annotation3 annotation3 = annotation2.value()[0]; + final Annotation3 annotation3 = annotation2.value()[0]; Assert.assertEquals(annotation3, element.getAnnotation(Annotation3.class)); } @Test public void testGetAnnotationsByType() { - AnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = RepeatableMetaAnnotatedElement.create( RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) ); @@ -111,13 +111,13 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testGetDeclaredAnnotations() { - AnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = RepeatableMetaAnnotatedElement.create( RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) ); - List> annotationTypes = Arrays.stream(element.getDeclaredAnnotations()) + final List> annotationTypes = Arrays.stream(element.getDeclaredAnnotations()) .map(Annotation::annotationType) .collect(Collectors.toList()); - Map, Integer> countMap = IterUtil.countMap(annotationTypes.iterator()); + final Map, Integer> countMap = IterUtil.countMap(annotationTypes.iterator()); Assert.assertEquals((Integer)1, countMap.get(Annotation1.class)); Assert.assertFalse(countMap.containsKey(Annotation2.class)); @@ -127,11 +127,11 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testGetDeclaredAnnotation() { - AnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = RepeatableMetaAnnotatedElement.create( 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.assertNull(element.getDeclaredAnnotation(Annotation3.class)); Assert.assertNull(element.getDeclaredAnnotation(Annotation4.class)); @@ -140,7 +140,7 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testGetDeclaredAnnotationsByType() { - AnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = RepeatableMetaAnnotatedElement.create( RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) ); @@ -159,8 +159,8 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testGetElement() { - AnnotatedElement element = Foo.class; - RepeatableMetaAnnotatedElement repeatableMetaAnnotatedElement = RepeatableMetaAnnotatedElement.create( + final AnnotatedElement element = Foo.class; + final RepeatableMetaAnnotatedElement repeatableMetaAnnotatedElement = RepeatableMetaAnnotatedElement.create( RepeatableAnnotationCollector.standard(), element, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) ); Assert.assertSame(element, repeatableMetaAnnotatedElement.getElement()); @@ -168,11 +168,11 @@ public class RepeatableMetaAnnotatedElementTest { @Test public void testIterator() { - RepeatableMetaAnnotatedElement element = RepeatableMetaAnnotatedElement.create( + final RepeatableMetaAnnotatedElement element = RepeatableMetaAnnotatedElement.create( RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s)) ); int count = 0; - for (GenericAnnotationMapping mapping : element) { + for (final GenericAnnotationMapping mapping : element) { count++; } Assert.assertEquals(14, count); diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java index adb56f25e..5da4e047b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java @@ -19,15 +19,15 @@ public class ResolvedAnnotationMappingTest { @Test public void testEquals() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); Assert.assertEquals(mapping, mapping); Assert.assertNotEquals(null, mapping); Assert.assertEquals(mapping, ResolvedAnnotationMapping.create(annotation, false)); Assert.assertNotEquals(mapping, ResolvedAnnotationMapping.create(annotation, true)); // Annotation3没有需要解析的属性,因此即使在构造函数指定false也一样 - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); Assert.assertEquals( ResolvedAnnotationMapping.create(annotation3, false), ResolvedAnnotationMapping.create(annotation3, true) @@ -36,13 +36,13 @@ public class ResolvedAnnotationMappingTest { @Test public void testHashCode() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - int hashCode = ResolvedAnnotationMapping.create(annotation, false).hashCode(); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final int hashCode = ResolvedAnnotationMapping.create(annotation, false).hashCode(); Assert.assertEquals(hashCode, ResolvedAnnotationMapping.create(annotation, false).hashCode()); Assert.assertNotEquals(hashCode, ResolvedAnnotationMapping.create(annotation, true).hashCode()); // Annotation3没有需要解析的属性,因此即使在构造函数指定false也一样 - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); Assert.assertEquals( ResolvedAnnotationMapping.create(annotation3, false).hashCode(), ResolvedAnnotationMapping.create(annotation3, true).hashCode() @@ -52,92 +52,92 @@ public class ResolvedAnnotationMappingTest { @Test public void testCreate() { - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); Assert.assertNotNull(mapping3); - Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); - ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); + final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); + final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); Assert.assertNotNull(mapping2); - Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false); + final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false); Assert.assertNotNull(mapping1); } @Test public void testIsRoot() { - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); Assert.assertTrue(mapping3.isRoot()); - Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); - ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); + final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); + final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); Assert.assertFalse(mapping2.isRoot()); } @Test public void testGetRoot() { - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false); Assert.assertSame(mapping3, mapping3.getRoot()); - Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); - ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); + final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); + final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false); Assert.assertSame(mapping3, mapping2.getRoot()); - Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false); + final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false); Assert.assertSame(mapping3, mapping1.getRoot()); } @Test public void testGetAnnotation() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); Assert.assertSame(annotation, mapping.getAnnotation()); } @SneakyThrows @Test public void testGetAttributes() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); 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); } } @Test public void testHasAttribute() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); Assert.assertTrue(mapping.hasAttribute("value", String.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.assertFalse(mapping.hasAttribute(Integer.MIN_VALUE)); } @Test public void testAnnotationType() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); Assert.assertEquals(annotation.annotationType(), mapping.annotationType()); } @Test 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.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); Assert.assertFalse(mapping2.isResolved()); @@ -147,10 +147,10 @@ public class ResolvedAnnotationMappingTest { @Test public void testGetAttributeIndex() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); 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(ResolvedAnnotationMapping.NOT_FOUND_INDEX, mapping.getAttributeIndex("value", Void.class)); @@ -159,29 +159,29 @@ public class ResolvedAnnotationMappingTest { @Test public void testGetAttributeValue() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false); 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("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("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("value2", String.class)); } @Test public void testGetResolvedAnnotation() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true); - Annotation1 synthesis = (Annotation1)mapping.getResolvedAnnotation(); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true); + final Annotation1 synthesis = (Annotation1)mapping.getResolvedAnnotation(); Assert.assertEquals(annotation.annotationType(), synthesis.annotationType()); Assert.assertEquals(annotation.value(), synthesis.value()); @@ -195,7 +195,7 @@ public class ResolvedAnnotationMappingTest { Assert.assertNotEquals(synthesis.hashCode(), annotation.hashCode()); 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()); } @@ -203,8 +203,8 @@ public class ResolvedAnnotationMappingTest { @Test public void testGetResolvedAttributeValueWhenAliased() { - Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true); + final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true); Assert.assertNull(mapping.getResolvedAttributeValue(Integer.MIN_VALUE)); // value = value1 = value2 @@ -232,20 +232,20 @@ public class ResolvedAnnotationMappingTest { @Test public void testGetResolvedAttributeWhenOverwritten() { - Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); - ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, true); + final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class); + final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, true); Assert.assertEquals(annotation3.value(), mapping3.getResolvedAttributeValue("value", String.class)); Assert.assertEquals((Integer)annotation3.alias(), mapping3.getResolvedAttributeValue("alias", Integer.class)); // annotation2中与annotation3同名同类型的属性value、alias被覆写 - Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); - ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, true); + final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class); + final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, true); Assert.assertEquals(annotation3.value(), mapping2.getResolvedAttributeValue("value", String.class)); Assert.assertEquals((Integer)annotation3.alias(), mapping2.getResolvedAttributeValue("alias", Integer.class)); // annotation1中与annotation3同名同类型的属性value被覆写,由于value存在别名value1,value2因此也一并被覆写 - Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); - ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, true); + final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class); + final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, true); Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value", String.class)); Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value1", 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)); } + @SuppressWarnings("unused") @Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.RUNTIME) private @interface Annotation1 {