mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -5,6 +5,8 @@ import org.dromara.hutool.core.util.ObjUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -113,7 +115,9 @@ public class AnnotationUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForJreRange(max = JRE.JAVA_8)
|
||||
public void testSetValue() {
|
||||
// jdk9+中抛出异常,须添加`--add-opens=java.base/java.lang=ALL-UNNAMED`启动参数
|
||||
final AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class);
|
||||
final String newValue = "is a new value";
|
||||
Assertions.assertNotEquals(newValue, annotation.value());
|
||||
@@ -124,6 +128,7 @@ public class AnnotationUtilTest {
|
||||
@Test
|
||||
public void testGetAnnotationAlias() {
|
||||
final MetaAnnotationForTest annotation = AnnotationUtil.getAnnotationAlias(AnnotationForTest.class, MetaAnnotationForTest.class);
|
||||
Assertions.assertNotNull(annotation);
|
||||
Assertions.assertEquals(annotation.value(), annotation.alias());
|
||||
Assertions.assertEquals(MetaAnnotationForTest.class, annotation.annotationType());
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import org.dromara.hutool.core.lang.tuple.Tuple;
|
||||
import org.dromara.hutool.core.reflect.MethodUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -181,17 +183,16 @@ public class LambdaUtilTest {
|
||||
|
||||
final BiConsumer<Bean, Long> setId = LambdaUtil.buildSetter(MethodUtil.getMethod(Bean.class, "setId", Long.class));
|
||||
final BiConsumer<Bean, Long> setId2 = LambdaUtil.buildSetter(Bean.class, Bean.Fields.id);
|
||||
final BiConsumer<Bean, Boolean> setFlag = LambdaUtil.buildSetter(Bean.class, Bean.Fields.flag);
|
||||
Assertions.assertEquals(setId, setId2);
|
||||
|
||||
setId.accept(bean, 3L);
|
||||
setFlag.accept(bean, true);
|
||||
Assertions.assertEquals(3L, (long) bean.getId());
|
||||
Assertions.assertTrue(bean.isFlag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildSetterTest() {
|
||||
@EnabledForJreRange(max = JRE.JAVA_8)
|
||||
void buildSetterWithPrimitiveTest() {
|
||||
// 原始类型参数在jdk9+中构建setter异常
|
||||
final Bean bean = new Bean();
|
||||
bean.setId(2L);
|
||||
bean.setFlag(false);
|
||||
@@ -339,7 +340,7 @@ public class LambdaUtilTest {
|
||||
@Test
|
||||
void getInvokeMethodErrorTest() {
|
||||
// 非函数接口返回异常
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
LambdaUtil.getInvokeMethod(LambdaUtilTest.class);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user