注解工具类支持主动清空缓存

This commit is contained in:
huangchengxing
2022-09-22 14:09:19 +08:00
parent bf76657b12
commit dbbccf3fc8
5 changed files with 75 additions and 6 deletions

View File

@@ -37,6 +37,31 @@ public class AnnotatedElementUtilTest {
ANNOTATION6, ANNOTATION5 // Interface.class's annotations
};
@Test
public void testClearCaches() {
AnnotatedElement type = Foo.class;
AnnotatedElement element = AnnotatedElementUtil.getResolvedMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type));
element = AnnotatedElementUtil.getMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getMetaElementCache(type));
element = AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type));
element = AnnotatedElementUtil.getRepeatableMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getRepeatableMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getRepeatableMetaElementCache(type));
}
@Test
public void testIsAnnotated() {
Assert.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation1.class));

View File

@@ -19,6 +19,9 @@ public class AnnotationUtilTest {
Annotation[] annotations = AnnotationUtil.getDeclaredAnnotations(ClassForTest.class);
Assert.assertArrayEquals(annotations, ClassForTest.class.getDeclaredAnnotations());
Assert.assertSame(annotations, AnnotationUtil.getDeclaredAnnotations(ClassForTest.class));
AnnotationUtil.clearCaches();
Assert.assertNotSame(annotations, AnnotationUtil.getDeclaredAnnotations(ClassForTest.class));
}
@Test