mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix test
This commit is contained in:
parent
58ce12a8db
commit
4ccf795ee0
@ -537,9 +537,9 @@ public class AnnotatedElementUtil {
|
|||||||
return emptyElement();
|
return emptyElement();
|
||||||
}
|
}
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
return HierarchicalAnnotatedElements.create(element, (es, e) -> getResolvedMetaElementCache(e));
|
return HierarchicalAnnotatedElements.of(element, (es, e) -> getResolvedMetaElementCache(e));
|
||||||
}
|
}
|
||||||
return HierarchicalAnnotatedElements.create(element, (es, e) -> getMetaElementCache(e));
|
return HierarchicalAnnotatedElements.of(element, (es, e) -> getMetaElementCache(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -560,9 +560,9 @@ public class AnnotatedElementUtil {
|
|||||||
return emptyElement();
|
return emptyElement();
|
||||||
}
|
}
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
return HierarchicalAnnotatedElements.create(element, (es, e) -> getResolvedRepeatableMetaElementCache(e));
|
return HierarchicalAnnotatedElements.of(element, (es, e) -> getResolvedRepeatableMetaElementCache(e));
|
||||||
}
|
}
|
||||||
return HierarchicalAnnotatedElements.create(element, (es, e) -> getRepeatableMetaElementCache(e));
|
return HierarchicalAnnotatedElements.of(element, (es, e) -> getRepeatableMetaElementCache(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -575,7 +575,7 @@ public class AnnotatedElementUtil {
|
|||||||
*/
|
*/
|
||||||
public static AnnotatedElement toHierarchyElement(final AnnotatedElement element) {
|
public static AnnotatedElement toHierarchyElement(final AnnotatedElement element) {
|
||||||
return ObjUtil.defaultIfNull(
|
return ObjUtil.defaultIfNull(
|
||||||
element, ele -> HierarchicalAnnotatedElements.create(ele, (es, e) -> e), emptyElement()
|
element, ele -> HierarchicalAnnotatedElements.of(ele, (es, e) -> e), emptyElement()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
|
|||||||
* @return {@code HierarchicalAnnotatedElements}实例,
|
* @return {@code HierarchicalAnnotatedElements}实例,
|
||||||
* 当{@code element}也是一个{@code HierarchicalAnnotatedElements}时,返回{@code element}本身
|
* 当{@code element}也是一个{@code HierarchicalAnnotatedElements}时,返回{@code element}本身
|
||||||
*/
|
*/
|
||||||
public static HierarchicalAnnotatedElements create(final AnnotatedElement element) {
|
public static HierarchicalAnnotatedElements of(final AnnotatedElement element) {
|
||||||
return create(element, (es, e) -> e);
|
return of(element, (es, e) -> e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,7 +100,7 @@ public class HierarchicalAnnotatedElements implements AnnotatedElement, Iterable
|
|||||||
* @return {@code HierarchicalAnnotatedElements}实例,
|
* @return {@code HierarchicalAnnotatedElements}实例,
|
||||||
* 当{@code element}也是一个{@code HierarchicalAnnotatedElements}时,返回{@code element}本身
|
* 当{@code element}也是一个{@code HierarchicalAnnotatedElements}时,返回{@code element}本身
|
||||||
*/
|
*/
|
||||||
public static HierarchicalAnnotatedElements create(
|
public static HierarchicalAnnotatedElements of(
|
||||||
final AnnotatedElement element,
|
final AnnotatedElement element,
|
||||||
final BiFunction<Set<AnnotatedElement>, AnnotatedElement, AnnotatedElement> elementFactory) {
|
final BiFunction<Set<AnnotatedElement>, AnnotatedElement, AnnotatedElement> elementFactory) {
|
||||||
return element instanceof HierarchicalAnnotatedElements ?
|
return element instanceof HierarchicalAnnotatedElements ?
|
||||||
|
@ -36,54 +36,54 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateFromMethod() {
|
public void testCreateFromMethod() {
|
||||||
final Method method1 = Foo.class.getDeclaredMethod("method");
|
final Method method1 = Foo.class.getDeclaredMethod("method");
|
||||||
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(method1);
|
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(method1);
|
||||||
Assertions.assertEquals(3, elements.getElementMappings().size());
|
Assertions.assertEquals(3, elements.getElementMappings().size());
|
||||||
|
|
||||||
final Method method2 = Foo.class.getDeclaredMethod("method2");
|
final Method method2 = Foo.class.getDeclaredMethod("method2");
|
||||||
elements = HierarchicalAnnotatedElements.create(method2);
|
elements = HierarchicalAnnotatedElements.of(method2);
|
||||||
Assertions.assertEquals(1, elements.getElementMappings().size());
|
Assertions.assertEquals(1, elements.getElementMappings().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate() {
|
public void testCreate() {
|
||||||
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
Assertions.assertNotNull(elements);
|
Assertions.assertNotNull(elements);
|
||||||
Assertions.assertEquals(3, elements.getElementMappings().size());
|
Assertions.assertEquals(3, elements.getElementMappings().size());
|
||||||
|
|
||||||
elements = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY);
|
elements = HierarchicalAnnotatedElements.of(Foo.class, ELEMENT_MAPPING_FACTORY);
|
||||||
Assertions.assertNotNull(elements);
|
Assertions.assertNotNull(elements);
|
||||||
Assertions.assertEquals(3, elements.getElementMappings().size());
|
Assertions.assertEquals(3, elements.getElementMappings().size());
|
||||||
|
|
||||||
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.create(elements, ELEMENT_MAPPING_FACTORY));
|
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.of(elements, ELEMENT_MAPPING_FACTORY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class, ELEMENT_MAPPING_FACTORY);
|
||||||
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY));
|
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.of(Foo.class, ELEMENT_MAPPING_FACTORY));
|
||||||
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY));
|
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.of(Super.class, ELEMENT_MAPPING_FACTORY));
|
||||||
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e));
|
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.of(Foo.class, (es, e) -> e));
|
||||||
Assertions.assertNotEquals(elements, null);
|
Assertions.assertNotEquals(elements, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHashCode() {
|
public void testHashCode() {
|
||||||
final int hashCode = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode();
|
final int hashCode = HierarchicalAnnotatedElements.of(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode();
|
||||||
Assertions.assertEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode());
|
Assertions.assertEquals(hashCode, HierarchicalAnnotatedElements.of(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode());
|
||||||
Assertions.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY).hashCode());
|
Assertions.assertNotEquals(hashCode, HierarchicalAnnotatedElements.of(Super.class, ELEMENT_MAPPING_FACTORY).hashCode());
|
||||||
Assertions.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e).hashCode());
|
Assertions.assertNotEquals(hashCode, HierarchicalAnnotatedElements.of(Foo.class, (es, e) -> e).hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetElement() {
|
public void testGetElement() {
|
||||||
final AnnotatedElement element = Foo.class;
|
final AnnotatedElement element = Foo.class;
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(element, ELEMENT_MAPPING_FACTORY);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(element, ELEMENT_MAPPING_FACTORY);
|
||||||
Assertions.assertSame(element, elements.getElement());
|
Assertions.assertSame(element, elements.getElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAnnotationPresent() {
|
public void testIsAnnotationPresent() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
Assertions.assertTrue(elements.isAnnotationPresent(Annotation1.class));
|
Assertions.assertTrue(elements.isAnnotationPresent(Annotation1.class));
|
||||||
Assertions.assertTrue(elements.isAnnotationPresent(Annotation2.class));
|
Assertions.assertTrue(elements.isAnnotationPresent(Annotation2.class));
|
||||||
Assertions.assertTrue(elements.isAnnotationPresent(Annotation3.class));
|
Assertions.assertTrue(elements.isAnnotationPresent(Annotation3.class));
|
||||||
@ -91,7 +91,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAnnotations() {
|
public void testGetAnnotations() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
|
|
||||||
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
||||||
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
|
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
|
||||||
@ -103,7 +103,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAnnotation() {
|
public void testGetAnnotation() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
|
|
||||||
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
||||||
Assertions.assertEquals(annotation1, elements.getAnnotation(Annotation1.class));
|
Assertions.assertEquals(annotation1, elements.getAnnotation(Annotation1.class));
|
||||||
@ -117,7 +117,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAnnotationsByType() {
|
public void testGetAnnotationsByType() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
|
|
||||||
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
||||||
Assertions.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getAnnotationsByType(Annotation1.class));
|
Assertions.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getAnnotationsByType(Annotation1.class));
|
||||||
@ -131,7 +131,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDeclaredAnnotationsByType() {
|
public void testGetDeclaredAnnotationsByType() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
|
|
||||||
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
||||||
Assertions.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getDeclaredAnnotationsByType(Annotation1.class));
|
Assertions.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getDeclaredAnnotationsByType(Annotation1.class));
|
||||||
@ -145,7 +145,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDeclaredAnnotation() {
|
public void testGetDeclaredAnnotation() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
|
|
||||||
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
||||||
Assertions.assertEquals(annotation1, elements.getDeclaredAnnotation(Annotation1.class));
|
Assertions.assertEquals(annotation1, elements.getDeclaredAnnotation(Annotation1.class));
|
||||||
@ -159,7 +159,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDeclaredAnnotations() {
|
public void testGetDeclaredAnnotations() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
|
|
||||||
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
|
||||||
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
|
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
|
||||||
@ -171,7 +171,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIterator() {
|
public void testIterator() {
|
||||||
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
|
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.of(Foo.class);
|
||||||
final Iterator<AnnotatedElement> iterator = elements.iterator();
|
final Iterator<AnnotatedElement> iterator = elements.iterator();
|
||||||
Assertions.assertNotNull(iterator);
|
Assertions.assertNotNull(iterator);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user