Merge pull request #3377 from yesh385/flaky-fix

Fixed 2 flaky tests in `hutool-core`
This commit is contained in:
Golden Looly 2023-11-09 08:40:17 +08:00 committed by GitHub
commit 2de4a5ced2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.ReflectUtil;
import org.junit.Assert;
import org.junit.Test;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -11,6 +12,7 @@ import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
/**
* 合成注解{@link GenericSynthesizedAggregateAnnotation}的测试用例
@ -36,9 +38,11 @@ public class GenericSynthesizedAggregateAnnotationTest {
Assert.assertEquals(grandParentAnnotation, syntheticMetaAnnotation.getAnnotation(GrandParentAnnotation.class));
Assert.assertEquals(parentAnnotation, syntheticMetaAnnotation.getAnnotation(ParentAnnotation.class));
Assert.assertEquals(childAnnotation, syntheticMetaAnnotation.getAnnotation(ChildAnnotation.class));
Annotation[] synthesizedAnnotations = syntheticMetaAnnotation.getAnnotations();
Arrays.sort(synthesizedAnnotations, Comparator.comparing(Annotation::toString));
Assert.assertEquals(
Arrays.asList(childAnnotation, grandParentAnnotation, parentAnnotation),
Arrays.asList(syntheticMetaAnnotation.getAnnotations())
Arrays.asList(synthesizedAnnotations)
);
// 扩展方法

View File

@ -15,6 +15,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@ -225,8 +226,10 @@ public class ReflectUtilTest {
final Method[] methods = ReflectUtil.getMethods(TestInterface3.class);
Assert.assertEquals(4, methods.length);
Arrays.sort(methods, Comparator.comparing(Method::toString));
// 接口里调用getMethods和getPublicMethods效果相同
final Method[] publicMethods = ReflectUtil.getPublicMethods(TestInterface3.class);
Arrays.sort(publicMethods, Comparator.comparing(Method::toString));
Assert.assertArrayEquals(methods, publicMethods);
}