mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
add test
This commit is contained in:
parent
66c7638a87
commit
3e20e48f54
@ -14,8 +14,6 @@ package org.dromara.hutool.core.bean;
|
||||
|
||||
import org.dromara.hutool.core.map.reference.WeakConcurrentMap;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Bean描述信息工厂类<br>
|
||||
* 通过不同的类和策略,生成对应的{@link BeanDesc},策略包括:
|
||||
@ -38,7 +36,7 @@ public class BeanDescFactory {
|
||||
* @return {@link BeanDesc}
|
||||
*/
|
||||
public static BeanDesc getBeanDesc(final Class<?> clazz) {
|
||||
return getBeanDesc(clazz, () -> getBeanDescWithoutCache(clazz));
|
||||
return bdCache.computeIfAbsent(clazz, (key) -> getBeanDescWithoutCache(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,18 +61,4 @@ public class BeanDescFactory {
|
||||
public static void clearCache() {
|
||||
bdCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得属性名和{@link BeanDesc}Map映射
|
||||
*
|
||||
* @param beanClass Bean的类
|
||||
* @param supplier 对象不存在时创建对象的函数
|
||||
* @param <T> BeanDesc子类
|
||||
* @return 属性名和 {@link BeanDesc}映射
|
||||
* @since 5.4.2
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T extends BeanDesc> T getBeanDesc(final Class<?> beanClass, final Supplier<T> supplier) {
|
||||
return (T) bdCache.computeIfAbsent(beanClass, (key) -> supplier.get());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package org.dromara.hutool.core.bean;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class BeanDescFactoryTest {
|
||||
@Test
|
||||
void getBeanDescTest() {
|
||||
final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(Food.class);
|
||||
final Collection<PropDesc> props = beanDesc.getProps();
|
||||
assertEquals(2, props.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBeanDescWithoutCacheTest() {
|
||||
final BeanDesc beanDesc = BeanDescFactory.getBeanDescWithoutCache(Food.class);
|
||||
final Collection<PropDesc> props = beanDesc.getProps();
|
||||
assertEquals(2, props.size());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Food {
|
||||
private String bookID;
|
||||
private String code;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user