fix ReflectUtil

This commit is contained in:
Looly
2019-12-18 10:00:57 +08:00
parent c62ede5276
commit 7ffdc2c473
3 changed files with 34 additions and 17 deletions

View File

@@ -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() {