mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix ReflectUtil
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import cn.hutool.core.lang.test.bean.ExamInfoDict;
|
||||
import cn.hutool.core.util.ClassUtilTest.TestSubClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.lang.test.bean.ExamInfoDict;
|
||||
import cn.hutool.core.util.ClassUtilTest.TestSubClass;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 反射工具类单元测试
|
||||
@@ -24,13 +22,7 @@ public class ReflectUtilTest {
|
||||
Assert.assertEquals(22, methods.length);
|
||||
|
||||
//过滤器测试
|
||||
methods = ReflectUtil.getMethods(ExamInfoDict.class, new Filter<Method>() {
|
||||
|
||||
@Override
|
||||
public boolean accept(Method t) {
|
||||
return Integer.class.equals(t.getReturnType());
|
||||
}
|
||||
});
|
||||
methods = ReflectUtil.getMethods(ExamInfoDict.class, t -> Integer.class.equals(t.getReturnType()));
|
||||
|
||||
Assert.assertEquals(4, methods.length);
|
||||
final Method method = methods[0];
|
||||
@@ -76,6 +68,13 @@ public class ReflectUtilTest {
|
||||
Field privateField = ReflectUtil.getField(TestSubClass.class, "privateField");
|
||||
Assert.assertNotNull(privateField);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFieldsTest() {
|
||||
// 能够获取到父类字段
|
||||
final Field[] fields = ReflectUtil.getFields(TestSubClass.class);
|
||||
Assert.assertEquals(4, fields.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setFieldTest() {
|
||||
|
Reference in New Issue
Block a user