update to junit5

This commit is contained in:
Looly 2023-03-31 02:56:36 +08:00
parent 210fed9621
commit c14390dd6d
507 changed files with 8903 additions and 8847 deletions

View File

@ -1,7 +1,7 @@
package cn.hutool.core.annotation;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.*;
import java.lang.reflect.AnnotatedElement;
@ -42,81 +42,81 @@ public class AnnotatedElementUtilTest {
final AnnotatedElement type = Foo.class;
AnnotatedElement element = AnnotatedElementUtil.getResolvedMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type));
Assertions.assertSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type));
Assertions.assertNotSame(element, AnnotatedElementUtil.getResolvedMetaElementCache(type));
element = AnnotatedElementUtil.getMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getMetaElementCache(type));
Assertions.assertSame(element, AnnotatedElementUtil.getMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getMetaElementCache(type));
Assertions.assertNotSame(element, AnnotatedElementUtil.getMetaElementCache(type));
element = AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type));
Assertions.assertSame(element, AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type));
Assertions.assertNotSame(element, AnnotatedElementUtil.getResolvedRepeatableMetaElementCache(type));
element = AnnotatedElementUtil.getRepeatableMetaElementCache(type);
Assert.assertSame(element, AnnotatedElementUtil.getRepeatableMetaElementCache(type));
Assertions.assertSame(element, AnnotatedElementUtil.getRepeatableMetaElementCache(type));
AnnotatedElementUtil.clearCaches();
Assert.assertNotSame(element, AnnotatedElementUtil.getRepeatableMetaElementCache(type));
Assertions.assertNotSame(element, AnnotatedElementUtil.getRepeatableMetaElementCache(type));
}
@Test
public void testIsAnnotated() {
Assert.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation1.class));
Assert.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation2.class));
Assert.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation3.class));
Assert.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation4.class));
Assert.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation5.class));
Assert.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation6.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation1.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation2.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation3.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation4.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation5.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotated(Foo.class, Annotation6.class));
}
@Test
public void testFindAnnotation() {
Assert.assertEquals(ANNOTATION1, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation1.class));
Assert.assertEquals(ANNOTATION2, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation2.class));
Assert.assertEquals(ANNOTATION3, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation3.class));
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation4.class));
Assert.assertEquals(ANNOTATION5, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation5.class));
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation6.class));
Assertions.assertEquals(ANNOTATION1, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation1.class));
Assertions.assertEquals(ANNOTATION2, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation2.class));
Assertions.assertEquals(ANNOTATION3, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation3.class));
Assertions.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation4.class));
Assertions.assertEquals(ANNOTATION5, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation5.class));
Assertions.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAnnotation(Foo.class, Annotation6.class));
}
@Test
public void testFindAllAnnotations() {
Assert.assertArrayEquals(new Annotation[]{ANNOTATION1}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation1.class));
Assert.assertArrayEquals(new Annotation[]{ANNOTATION2}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation2.class));
Assert.assertArrayEquals(new Annotation[]{ANNOTATION3}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation3.class));
Assert.assertArrayEquals(new Annotation[]{ANNOTATION4}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation4.class));
Assert.assertArrayEquals(new Annotation[]{ANNOTATION5}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation5.class));
Assert.assertArrayEquals(new Annotation[]{ANNOTATION6}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation6.class));
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION1}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation1.class));
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION2}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation2.class));
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION3}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation3.class));
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION4}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation4.class));
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION5}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation5.class));
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION6}, AnnotatedElementUtil.findAllAnnotations(Foo.class, Annotation6.class));
}
@Test
public void testFindAnnotations() {
final Annotation[] annotations = AnnotatedElementUtil.findAnnotations(Foo.class);
Assert.assertArrayEquals(ANNOTATIONS, annotations);
Assertions.assertArrayEquals(ANNOTATIONS, annotations);
}
@Test
public void testFindResolvedAnnotation() {
final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation4.class));
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation6.class));
Assert.assertEquals(ANNOTATION5, AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation5.class));
Assertions.assertEquals(ANNOTATION4, AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation4.class));
Assertions.assertEquals(ANNOTATION6, AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation6.class));
Assertions.assertEquals(ANNOTATION5, AnnotatedElementUtil.findResolvedAnnotation(Foo.class, Annotation5.class));
}
@Test
@ -125,84 +125,84 @@ public class AnnotatedElementUtilTest {
final Map<Class<?>, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity()));
final Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = (Annotation2)annotationMap.get(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = (Annotation1)annotationMap.get(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertEquals(ANNOTATION4, annotationMap.get(Annotation4.class));
Assert.assertEquals(ANNOTATION6, annotationMap.get(Annotation6.class));
Assert.assertEquals(ANNOTATION5, annotationMap.get(Annotation5.class));
Assertions.assertEquals(ANNOTATION4, annotationMap.get(Annotation4.class));
Assertions.assertEquals(ANNOTATION6, annotationMap.get(Annotation6.class));
Assertions.assertEquals(ANNOTATION5, annotationMap.get(Annotation5.class));
}
@Test
public void testFindAllResolvedAnnotations() {
final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation3.class)[0];
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation2.class)[0];
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation1.class)[0];
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation4.class)[0]);
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation6.class)[0]);
Assert.assertEquals(ANNOTATION5, AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation5.class)[0]);
Assertions.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation4.class)[0]);
Assertions.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation6.class)[0]);
Assertions.assertEquals(ANNOTATION5, AnnotatedElementUtil.findAllResolvedAnnotations(Foo.class, Annotation5.class)[0]);
}
@Test
public void testFindDirectlyAnnotation() {
Assert.assertNull(AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation1.class));
Assert.assertNull(AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation2.class));
Assert.assertEquals(ANNOTATION3, AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation3.class));
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation4.class));
Assert.assertNull(AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation5.class));
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation6.class));
Assertions.assertNull(AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation1.class));
Assertions.assertNull(AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation2.class));
Assertions.assertEquals(ANNOTATION3, AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation3.class));
Assertions.assertEquals(ANNOTATION4, AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation4.class));
Assertions.assertNull(AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation5.class));
Assertions.assertEquals(ANNOTATION6, AnnotatedElementUtil.findDirectlyAnnotation(Foo.class, Annotation6.class));
}
@Test
public void testFindAllDirectlyAnnotations() {
Assert.assertEquals(0, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation1.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation2.class).length);
Assert.assertArrayEquals(new Annotation[]{ANNOTATION3}, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation3.class));
Assert.assertArrayEquals(new Annotation[]{ANNOTATION4}, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation4.class));
Assert.assertEquals(0, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation5.class).length);
Assert.assertArrayEquals(new Annotation[]{ANNOTATION6}, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation6.class));
Assertions.assertEquals(0, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation1.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation2.class).length);
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION3}, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation3.class));
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION4}, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation4.class));
Assertions.assertEquals(0, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation5.class).length);
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION6}, AnnotatedElementUtil.findAllDirectlyAnnotations(Foo.class, Annotation6.class));
}
@Test
public void testFindDirectlyAnnotations() {
Assert.assertArrayEquals(
Assertions.assertArrayEquals(
DECLARED_ANNOTATIONS, AnnotatedElementUtil.findDirectlyAnnotations(Foo.class)
);
}
@Test
public void testFindDirectlyResolvedAnnotation() {
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation4.class));
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation6.class));
Assertions.assertEquals(ANNOTATION4, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation4.class));
Assertions.assertEquals(ANNOTATION6, AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation6.class));
final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assert.assertNull(AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation1.class));
Assert.assertNull(AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation2.class));
Assert.assertNull(AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation5.class));
Assertions.assertNull(AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation1.class));
Assertions.assertNull(AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation2.class));
Assertions.assertNull(AnnotatedElementUtil.findDirectlyResolvedAnnotation(Foo.class, Annotation5.class));
}
@Test
@ -210,59 +210,59 @@ public class AnnotatedElementUtilTest {
final Annotation[] resolvedAnnotations = AnnotatedElementUtil.findDirectlyResolvedAnnotations(Foo.class);
final Map<Class<?>, Annotation> annotationMap = Stream.of(resolvedAnnotations).collect(Collectors.toMap(Annotation::annotationType, Function.identity()));
Assert.assertEquals(ANNOTATION4, annotationMap.get(Annotation4.class));
Assert.assertEquals(ANNOTATION6, annotationMap.get(Annotation6.class));
Assertions.assertEquals(ANNOTATION4, annotationMap.get(Annotation4.class));
Assertions.assertEquals(ANNOTATION6, annotationMap.get(Annotation6.class));
final Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assert.assertNull(annotationMap.get(Annotation1.class));
Assert.assertNull(annotationMap.get(Annotation2.class));
Assert.assertNull(annotationMap.get(Annotation5.class));
Assertions.assertNull(annotationMap.get(Annotation1.class));
Assertions.assertNull(annotationMap.get(Annotation2.class));
Assertions.assertNull(annotationMap.get(Annotation5.class));
}
@Test
public void testFindAllDirectlyResolvedAnnotations() {
Assert.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class)[0]);
Assert.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class)[0]);
Assertions.assertEquals(ANNOTATION4, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class)[0]);
Assertions.assertEquals(ANNOTATION6, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class)[0]);
final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation3.class)[0];
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assert.assertEquals(0, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation1.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation5.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation1.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.findAllDirectlyResolvedAnnotations(Foo.class, Annotation5.class).length);
}
@Test
public void testIsAnnotationPresent() {
Assert.assertTrue(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation1.class));
Assert.assertTrue(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation2.class));
Assert.assertTrue(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation3.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation1.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation2.class));
Assertions.assertTrue(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation3.class));
Assert.assertFalse(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation4.class));
Assert.assertFalse(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation5.class));
Assert.assertFalse(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation6.class));
Assertions.assertFalse(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation4.class));
Assertions.assertFalse(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation5.class));
Assertions.assertFalse(AnnotatedElementUtil.isAnnotationPresent(Foo.class, Annotation6.class));
}
@Test
public void testGetAnnotation() {
Assert.assertEquals(ANNOTATION1, AnnotatedElementUtil.getAnnotation(Foo.class, Annotation1.class));
Assert.assertEquals(ANNOTATION2, AnnotatedElementUtil.getAnnotation(Foo.class, Annotation2.class));
Assert.assertEquals(ANNOTATION3, AnnotatedElementUtil.getAnnotation(Foo.class, Annotation3.class));
Assertions.assertEquals(ANNOTATION1, AnnotatedElementUtil.getAnnotation(Foo.class, Annotation1.class));
Assertions.assertEquals(ANNOTATION2, AnnotatedElementUtil.getAnnotation(Foo.class, Annotation2.class));
Assertions.assertEquals(ANNOTATION3, AnnotatedElementUtil.getAnnotation(Foo.class, Annotation3.class));
Assert.assertNull(AnnotatedElementUtil.getAnnotation(Foo.class, Annotation4.class));
Assert.assertNull(AnnotatedElementUtil.getAnnotation(Foo.class, Annotation5.class));
Assert.assertNull(AnnotatedElementUtil.getAnnotation(Foo.class, Annotation6.class));
Assertions.assertNull(AnnotatedElementUtil.getAnnotation(Foo.class, Annotation4.class));
Assertions.assertNull(AnnotatedElementUtil.getAnnotation(Foo.class, Annotation5.class));
Assertions.assertNull(AnnotatedElementUtil.getAnnotation(Foo.class, Annotation6.class));
}
@Test
public void testGetAnnotations() {
final Annotation[] annotations = AnnotatedElementUtil.getAnnotations(Foo.class);
Assert.assertArrayEquals(
Assertions.assertArrayEquals(
new Annotation[]{ ANNOTATION3, ANNOTATION2, ANNOTATION1 },
annotations
);
@ -271,68 +271,68 @@ public class AnnotatedElementUtilTest {
@Test
public void testGetAllAnnotations() {
final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length);
Assert.assertEquals(ANNOTATION3, resolvedAnnotation3s[0]); // value与alias互为别名
Assertions.assertEquals(1, resolvedAnnotation3s.length);
Assertions.assertEquals(ANNOTATION3, resolvedAnnotation3s[0]); // value与alias互为别名
final Annotation2[] resolvedAnnotation2s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation2.class);
Assert.assertEquals(1, resolvedAnnotation2s.length);
Assert.assertEquals(ANNOTATION2, resolvedAnnotation2s[0]); // value与alias互为别名
Assertions.assertEquals(1, resolvedAnnotation2s.length);
Assertions.assertEquals(ANNOTATION2, resolvedAnnotation2s[0]); // value与alias互为别名
final Annotation1[] resolvedAnnotation1s = AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation1.class);
Assert.assertEquals(1, resolvedAnnotation1s.length);
Assert.assertEquals(ANNOTATION1, resolvedAnnotation1s[0]);
Assertions.assertEquals(1, resolvedAnnotation1s.length);
Assertions.assertEquals(ANNOTATION1, resolvedAnnotation1s[0]);
Assert.assertEquals(0, AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation4.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation5.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation6.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation4.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation5.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllAnnotations(Foo.class, Annotation6.class).length);
}
@Test
public void testGetResolvedAnnotation() {
final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertNull(AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation4.class));
Assert.assertNull(AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation5.class));
Assert.assertNull(AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation6.class));
Assertions.assertNull(AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation4.class));
Assertions.assertNull(AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation5.class));
Assertions.assertNull(AnnotatedElementUtil.getResolvedAnnotation(Foo.class, Annotation6.class));
}
@Test
public void testGetAllResolvedAnnotations() {
final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length);
Assertions.assertEquals(1, resolvedAnnotation3s.length);
final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0];
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2[] resolvedAnnotation2s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation2.class);
Assert.assertEquals(1, resolvedAnnotation2s.length);
Assertions.assertEquals(1, resolvedAnnotation2s.length);
final Annotation2 resolvedAnnotation2 = resolvedAnnotation2s[0];
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1[] resolvedAnnotation1s = AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation1.class);
Assert.assertEquals(1, resolvedAnnotation1s.length);
Assertions.assertEquals(1, resolvedAnnotation1s.length);
final Annotation1 resolvedAnnotation1 = resolvedAnnotation1s[0];
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertEquals(0, AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation4.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation5.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation6.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation4.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation5.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllResolvedAnnotations(Foo.class, Annotation6.class).length);
}
@Test
@ -341,249 +341,249 @@ public class AnnotatedElementUtilTest {
.collect(Collectors.toMap(Annotation::annotationType, Function.identity()));
final Annotation3 resolvedAnnotation3 = (Annotation3)annotationMap.get(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = (Annotation2)annotationMap.get(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = (Annotation1)annotationMap.get(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertFalse(annotationMap.containsKey(Annotation4.class));
Assert.assertFalse(annotationMap.containsKey(Annotation5.class));
Assert.assertFalse(annotationMap.containsKey(Annotation6.class));
Assertions.assertFalse(annotationMap.containsKey(Annotation4.class));
Assertions.assertFalse(annotationMap.containsKey(Annotation5.class));
Assertions.assertFalse(annotationMap.containsKey(Annotation6.class));
}
@Test
public void testGetDirectlyAnnotation() {
Assert.assertEquals(ANNOTATION3, AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation3.class));
Assertions.assertEquals(ANNOTATION3, AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation3.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation2.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation1.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation4.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation5.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation6.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation2.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation1.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation4.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation5.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyAnnotation(Foo.class, Annotation6.class));
}
@Test
public void testGetAllDirectlyAnnotations() {
final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllDirectlyAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length);
Assertions.assertEquals(1, resolvedAnnotation3s.length);
final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0];
Assert.assertEquals(ANNOTATION3, resolvedAnnotation3);
Assertions.assertEquals(ANNOTATION3, resolvedAnnotation3);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation1.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation5.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation1.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation5.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class).length);
}
@Test
public void testGetDirectlyAnnotations() {
final Annotation[] annotations = AnnotatedElementUtil.getDirectlyAnnotations(Foo.class);
Assert.assertEquals(1, annotations.length);
Assert.assertEquals(ANNOTATION3, annotations[0]);
Assertions.assertEquals(1, annotations.length);
Assertions.assertEquals(ANNOTATION3, annotations[0]);
}
@Test
public void testGetDirectlyResolvedAnnotation() {
final Annotation3 resolvedAnnotation3 = AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assert.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation2.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation1.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation4.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation5.class));
Assert.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation6.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation2.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation1.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation4.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation5.class));
Assertions.assertNull(AnnotatedElementUtil.getDirectlyResolvedAnnotation(Foo.class, Annotation6.class));
}
@Test
public void testGetDirectlyAllResolvedAnnotations() {
final Annotation3[] resolvedAnnotation3s = AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation3.class);
Assert.assertEquals(1, resolvedAnnotation3s.length);
Assertions.assertEquals(1, resolvedAnnotation3s.length);
final Annotation3 resolvedAnnotation3 = resolvedAnnotation3s[0];
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation1.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation5.class).length);
Assert.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation2.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation1.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation4.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation5.class).length);
Assertions.assertEquals(0, AnnotatedElementUtil.getAllDirectlyResolvedAnnotations(Foo.class, Annotation6.class).length);
}
@Test
public void testGetDirectlyResolvedAnnotations() {
final Annotation[] annotations = AnnotatedElementUtil.getDirectlyResolvedAnnotations(Foo.class);
Assert.assertEquals(1, annotations.length);
Assertions.assertEquals(1, annotations.length);
final Annotation3 resolvedAnnotation3 = (Annotation3)annotations[0];
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
}
@Test
public void testToHierarchyMetaElement() {
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, false));
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, true));
Assertions.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, false));
Assertions.assertNotNull(AnnotatedElementUtil.toHierarchyMetaElement(null, true));
final AnnotatedElement element = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, false);
// 带有元注解
Assert.assertArrayEquals(ANNOTATIONS, element.getAnnotations());
Assertions.assertArrayEquals(ANNOTATIONS, element.getAnnotations());
// 不带元注解
Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations());
Assertions.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations());
// 解析注解属性
final AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyMetaElement(Foo.class, true);
final Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = resolvedElement.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = resolvedElement.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertEquals(ANNOTATION4, resolvedElement.getAnnotation(Annotation4.class));
Assert.assertEquals(ANNOTATION6, resolvedElement.getAnnotation(Annotation6.class));
Assert.assertEquals(ANNOTATION5, resolvedElement.getAnnotation(Annotation5.class));
Assertions.assertEquals(ANNOTATION4, resolvedElement.getAnnotation(Annotation4.class));
Assertions.assertEquals(ANNOTATION6, resolvedElement.getAnnotation(Annotation6.class));
Assertions.assertEquals(ANNOTATION5, resolvedElement.getAnnotation(Annotation5.class));
}
@Test
public void testToHierarchyRepeatableMetaElement() {
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, false));
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, true));
Assertions.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, false));
Assertions.assertNotNull(AnnotatedElementUtil.toHierarchyRepeatableMetaElement(null, true));
final AnnotatedElement element = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, false);
// 带有元注解
Assert.assertArrayEquals(ANNOTATIONS, element.getAnnotations());
Assertions.assertArrayEquals(ANNOTATIONS, element.getAnnotations());
// 不带元注解
Assert.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations());
Assertions.assertArrayEquals(DECLARED_ANNOTATIONS, element.getDeclaredAnnotations());
// 解析注解属性
final AnnotatedElement resolvedElement = AnnotatedElementUtil.toHierarchyRepeatableMetaElement(Foo.class, true);
final Annotation3 resolvedAnnotation3 = resolvedElement.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = resolvedElement.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = resolvedElement.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assert.assertEquals(ANNOTATION4, resolvedElement.getAnnotation(Annotation4.class));
Assert.assertEquals(ANNOTATION6, resolvedElement.getAnnotation(Annotation6.class));
Assert.assertEquals(ANNOTATION5, resolvedElement.getAnnotation(Annotation5.class));
Assertions.assertEquals(ANNOTATION4, resolvedElement.getAnnotation(Annotation4.class));
Assertions.assertEquals(ANNOTATION6, resolvedElement.getAnnotation(Annotation6.class));
Assertions.assertEquals(ANNOTATION5, resolvedElement.getAnnotation(Annotation5.class));
}
@Test
public void testToHierarchyElement() {
Assert.assertNotNull(AnnotatedElementUtil.toHierarchyElement(Foo.class));
Assertions.assertNotNull(AnnotatedElementUtil.toHierarchyElement(Foo.class));
final AnnotatedElement element = AnnotatedElementUtil.toHierarchyElement(Foo.class);
Assert.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION4, ANNOTATION6}, element.getAnnotations());
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION4, ANNOTATION6}, element.getAnnotations());
}
@Test
public void testToMetaElement() {
Assert.assertNotNull(AnnotatedElementUtil.toMetaElement(null, false));
Assert.assertNotNull(AnnotatedElementUtil.toMetaElement(null, true));
Assertions.assertNotNull(AnnotatedElementUtil.toMetaElement(null, false));
Assertions.assertNotNull(AnnotatedElementUtil.toMetaElement(null, true));
// 不解析注解属性
AnnotatedElement element = AnnotatedElementUtil.toMetaElement(Foo.class, false);
Assert.assertSame(element, AnnotatedElementUtil.toMetaElement(Foo.class, false)); // 第二次获取时从缓存中获取
Assert.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION2, ANNOTATION1}, element.getAnnotations());
Assertions.assertSame(element, AnnotatedElementUtil.toMetaElement(Foo.class, false)); // 第二次获取时从缓存中获取
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION2, ANNOTATION1}, element.getAnnotations());
// 解析注解属性
element = AnnotatedElementUtil.toMetaElement(Foo.class, true);
Assert.assertSame(element, AnnotatedElementUtil.toMetaElement(Foo.class, true)); // 第二次获取时从缓存中获取
Assert.assertEquals(3, element.getAnnotations().length);
Assertions.assertSame(element, AnnotatedElementUtil.toMetaElement(Foo.class, true)); // 第二次获取时从缓存中获取
Assertions.assertEquals(3, element.getAnnotations().length);
final Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = element.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = element.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
}
@Test
public void testToRepeatableMetaElement() {
Assert.assertNotNull(AnnotatedElementUtil.toRepeatableMetaElement(null, RepeatableAnnotationCollector.none(), false));
Assert.assertNotNull(AnnotatedElementUtil.toRepeatableMetaElement(null, RepeatableAnnotationCollector.none(), true));
Assertions.assertNotNull(AnnotatedElementUtil.toRepeatableMetaElement(null, RepeatableAnnotationCollector.none(), false));
Assertions.assertNotNull(AnnotatedElementUtil.toRepeatableMetaElement(null, RepeatableAnnotationCollector.none(), true));
// 不解析注解属性
AnnotatedElement element = AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), false);
Assert.assertEquals(element, AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), false)); // 第二次获取时从缓存中获取
Assert.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION2, ANNOTATION1}, element.getAnnotations());
Assertions.assertEquals(element, AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), false)); // 第二次获取时从缓存中获取
Assertions.assertArrayEquals(new Annotation[]{ANNOTATION3, ANNOTATION2, ANNOTATION1}, element.getAnnotations());
// 解析注解属性
element = AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), true);
Assert.assertEquals(element, AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), true)); // 第二次获取时从缓存中获取
Assert.assertEquals(3, element.getAnnotations().length);
Assertions.assertEquals(element, AnnotatedElementUtil.toRepeatableMetaElement(Foo.class, RepeatableAnnotationCollector.none(), true)); // 第二次获取时从缓存中获取
Assertions.assertEquals(3, element.getAnnotations().length);
final Annotation3 resolvedAnnotation3 = element.getAnnotation(Annotation3.class);
Assert.assertNotNull(resolvedAnnotation3);
Assert.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assert.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation3);
Assertions.assertEquals(resolvedAnnotation3.alias(), ANNOTATION3.value());
Assertions.assertEquals(resolvedAnnotation3.alias(), resolvedAnnotation3.value()); // value与alias互为别名
final Annotation2 resolvedAnnotation2 = element.getAnnotation(Annotation2.class);
Assert.assertNotNull(resolvedAnnotation2);
Assert.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
Assertions.assertNotNull(resolvedAnnotation2);
Assertions.assertEquals(resolvedAnnotation2.num(), ANNOTATION3.num()); // num属性被Annotation3.num覆盖
final Annotation1 resolvedAnnotation1 = element.getAnnotation(Annotation1.class);
Assert.assertNotNull(resolvedAnnotation1);
Assert.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assert.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
Assertions.assertNotNull(resolvedAnnotation1);
Assertions.assertEquals(ANNOTATION3.value(), resolvedAnnotation1.value()); // value属性被Annotation3.value覆盖
Assertions.assertEquals(resolvedAnnotation1.value(), resolvedAnnotation1.alias()); // value与alias互为别名
}
@Test
public void testAsElement() {
final Annotation[] annotations = new Annotation[]{ANNOTATION1, ANNOTATION2};
Assert.assertNotNull(AnnotatedElementUtil.asElement());
Assertions.assertNotNull(AnnotatedElementUtil.asElement());
final AnnotatedElement element = AnnotatedElementUtil.asElement(ANNOTATION1, null, ANNOTATION2);
Assert.assertArrayEquals(annotations, element.getAnnotations());
Assert.assertArrayEquals(annotations, element.getDeclaredAnnotations());
Assert.assertEquals(ANNOTATION1, element.getAnnotation(Annotation1.class));
Assert.assertNull(element.getAnnotation(Annotation3.class));
Assertions.assertArrayEquals(annotations, element.getAnnotations());
Assertions.assertArrayEquals(annotations, element.getDeclaredAnnotations());
Assertions.assertEquals(ANNOTATION1, element.getAnnotation(Annotation1.class));
Assertions.assertNull(element.getAnnotation(Annotation3.class));
}
@Test
public void testEmptyElement() {
final AnnotatedElement element = AnnotatedElementUtil.emptyElement();
Assert.assertSame(element, AnnotatedElementUtil.emptyElement());
Assert.assertNull(element.getAnnotation(Annotation1.class));
Assert.assertEquals(0, element.getAnnotations().length);
Assert.assertEquals(0, element.getDeclaredAnnotations().length);
Assertions.assertSame(element, AnnotatedElementUtil.emptyElement());
Assertions.assertNull(element.getAnnotation(Annotation1.class));
Assertions.assertEquals(0, element.getAnnotations().length);
Assertions.assertEquals(0, element.getDeclaredAnnotations().length);
}
// ================= super =================

View File

@ -3,14 +3,10 @@ package cn.hutool.core.annotation;
import cn.hutool.core.array.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import lombok.SneakyThrows;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.util.Map;
@ -22,135 +18,135 @@ public class AnnotationUtilTest {
@Test
public void testGetDeclaredAnnotations() {
final Annotation[] annotations = AnnotationUtil.getDeclaredAnnotations(ClassForTest.class);
Assert.assertArrayEquals(annotations, ClassForTest.class.getDeclaredAnnotations());
Assert.assertSame(annotations, AnnotationUtil.getDeclaredAnnotations(ClassForTest.class));
Assertions.assertArrayEquals(annotations, ClassForTest.class.getDeclaredAnnotations());
Assertions.assertSame(annotations, AnnotationUtil.getDeclaredAnnotations(ClassForTest.class));
AnnotationUtil.clearCaches();
Assert.assertNotSame(annotations, AnnotationUtil.getDeclaredAnnotations(ClassForTest.class));
Assertions.assertNotSame(annotations, AnnotationUtil.getDeclaredAnnotations(ClassForTest.class));
}
@Test
public void testToCombination() {
final CombinationAnnotationElement element = AnnotationUtil.toCombination(ClassForTest.class);
Assert.assertEquals(2, element.getAnnotations().length);
Assertions.assertEquals(2, element.getAnnotations().length);
}
@Test
public void testGetAnnotations() {
Annotation[] annotations = AnnotationUtil.getAnnotations(ClassForTest.class, true);
Assert.assertEquals(2, annotations.length);
Assertions.assertEquals(2, annotations.length);
annotations = AnnotationUtil.getAnnotations(ClassForTest.class, false);
Assert.assertEquals(1, annotations.length);
Assertions.assertEquals(1, annotations.length);
}
@Test
public void testGetCombinationAnnotations() {
final MetaAnnotationForTest[] annotations = AnnotationUtil.getCombinationAnnotations(ClassForTest.class, MetaAnnotationForTest.class);
Assert.assertEquals(1, annotations.length);
Assertions.assertEquals(1, annotations.length);
}
@Test
public void testAnnotations() {
MetaAnnotationForTest[] annotations1 = AnnotationUtil.getAnnotations(ClassForTest.class, false, MetaAnnotationForTest.class);
Assert.assertEquals(0, annotations1.length);
Assertions.assertEquals(0, annotations1.length);
annotations1 = AnnotationUtil.getAnnotations(ClassForTest.class, true, MetaAnnotationForTest.class);
Assert.assertEquals(1, annotations1.length);
Assertions.assertEquals(1, annotations1.length);
Annotation[] annotations2 = AnnotationUtil.getAnnotations(
ClassForTest.class, false, t -> ObjUtil.equals(t.annotationType(), MetaAnnotationForTest.class)
);
Assert.assertEquals(0, annotations2.length);
Assertions.assertEquals(0, annotations2.length);
annotations2 = AnnotationUtil.getAnnotations(
ClassForTest.class, true, t -> ObjUtil.equals(t.annotationType(), MetaAnnotationForTest.class)
);
Assert.assertEquals(1, annotations2.length);
Assertions.assertEquals(1, annotations2.length);
}
@Test
public void testGetAnnotation() {
final MetaAnnotationForTest annotation = AnnotationUtil.getAnnotation(ClassForTest.class, MetaAnnotationForTest.class);
Assert.assertNotNull(annotation);
Assertions.assertNotNull(annotation);
}
@Test
public void testHasAnnotation() {
Assert.assertTrue(AnnotationUtil.hasAnnotation(ClassForTest.class, MetaAnnotationForTest.class));
Assertions.assertTrue(AnnotationUtil.hasAnnotation(ClassForTest.class, MetaAnnotationForTest.class));
}
@Test
public void testGetAnnotationValue() {
final AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class);
Assert.assertEquals(annotation.value(), AnnotationUtil.getAnnotationValue(ClassForTest.class, AnnotationForTest.class));
Assert.assertEquals(annotation.value(), AnnotationUtil.getAnnotationValue(ClassForTest.class, AnnotationForTest.class, "value"));
Assert.assertNull(AnnotationUtil.getAnnotationValue(ClassForTest.class, AnnotationForTest.class, "property"));
Assertions.assertEquals(annotation.value(), AnnotationUtil.getAnnotationValue(ClassForTest.class, AnnotationForTest.class));
Assertions.assertEquals(annotation.value(), AnnotationUtil.getAnnotationValue(ClassForTest.class, AnnotationForTest.class, "value"));
Assertions.assertNull(AnnotationUtil.getAnnotationValue(ClassForTest.class, AnnotationForTest.class, "property"));
}
@Test
public void testGetAnnotationValueMap() {
final AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class);
final Map<String, Object> valueMap = AnnotationUtil.getAnnotationValueMap(ClassForTest.class, AnnotationForTest.class);
Assert.assertNotNull(valueMap);
Assert.assertEquals(2, valueMap.size());
Assert.assertEquals(annotation.value(), valueMap.get("value"));
Assertions.assertNotNull(valueMap);
Assertions.assertEquals(2, valueMap.size());
Assertions.assertEquals(annotation.value(), valueMap.get("value"));
}
@Test
public void testGetRetentionPolicy() {
final RetentionPolicy policy = AnnotationForTest.class.getAnnotation(Retention.class).value();
Assert.assertEquals(policy, AnnotationUtil.getRetentionPolicy(AnnotationForTest.class));
Assertions.assertEquals(policy, AnnotationUtil.getRetentionPolicy(AnnotationForTest.class));
}
@Test
public void testGetTargetType() {
final ElementType[] types = AnnotationForTest.class.getAnnotation(Target.class).value();
Assert.assertArrayEquals(types, AnnotationUtil.getTargetType(AnnotationForTest.class));
Assertions.assertArrayEquals(types, AnnotationUtil.getTargetType(AnnotationForTest.class));
}
@Test
public void testIsDocumented() {
Assert.assertFalse(AnnotationUtil.isDocumented(AnnotationForTest.class));
Assertions.assertFalse(AnnotationUtil.isDocumented(AnnotationForTest.class));
}
@Test
public void testIsInherited() {
Assert.assertFalse(AnnotationUtil.isInherited(AnnotationForTest.class));
Assertions.assertFalse(AnnotationUtil.isInherited(AnnotationForTest.class));
}
@Test
public void testSetValue() {
final AnnotationForTest annotation = ClassForTest.class.getAnnotation(AnnotationForTest.class);
final String newValue = "is a new value";
Assert.assertNotEquals(newValue, annotation.value());
Assertions.assertNotEquals(newValue, annotation.value());
AnnotationUtil.setValue(annotation, "value", newValue);
Assert.assertEquals(newValue, annotation.value());
Assertions.assertEquals(newValue, annotation.value());
}
@Test
public void testGetAnnotationAlias() {
final MetaAnnotationForTest annotation = AnnotationUtil.getAnnotationAlias(AnnotationForTest.class, MetaAnnotationForTest.class);
Assert.assertEquals(annotation.value(), annotation.alias());
Assert.assertEquals(MetaAnnotationForTest.class, annotation.annotationType());
Assertions.assertEquals(annotation.value(), annotation.alias());
Assertions.assertEquals(MetaAnnotationForTest.class, annotation.annotationType());
}
@Test
public void testGetAnnotationAttributes() {
final Method[] methods = AnnotationUtil.getAnnotationAttributes(AnnotationForTest.class);
Assert.assertArrayEquals(methods, AnnotationUtil.getAnnotationAttributes(AnnotationForTest.class));
Assert.assertEquals(2, methods.length);
Assert.assertArrayEquals(AnnotationForTest.class.getDeclaredMethods(), methods);
Assertions.assertArrayEquals(methods, AnnotationUtil.getAnnotationAttributes(AnnotationForTest.class));
Assertions.assertEquals(2, methods.length);
Assertions.assertArrayEquals(AnnotationForTest.class.getDeclaredMethods(), methods);
}
@SneakyThrows
@Test
public void testIsAnnotationAttribute() {
Assert.assertFalse(AnnotationUtil.isAnnotationAttribute(AnnotationForTest.class.getMethod("equals", Object.class)));
Assert.assertTrue(AnnotationUtil.isAnnotationAttribute(AnnotationForTest.class.getMethod("value")));
Assertions.assertFalse(AnnotationUtil.isAnnotationAttribute(AnnotationForTest.class.getMethod("equals", Object.class)));
Assertions.assertTrue(AnnotationUtil.isAnnotationAttribute(AnnotationForTest.class.getMethod("value")));
}
@Test
public void getAnnotationValueTest2() {
final String[] names = AnnotationUtil.getAnnotationValue(ClassForTest.class, AnnotationForTest::names);
Assert.assertTrue(ArrayUtil.equals(names, new String[]{"测试1", "测试2"}));
Assertions.assertTrue(ArrayUtil.equals(names, new String[]{"测试1", "测试2"}));
}
@Target(ElementType.TYPE_USE)

View File

@ -1,7 +1,7 @@
package cn.hutool.core.annotation;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.*;
@ -13,13 +13,13 @@ public class CombinationAnnotationElementTest {
@Test
public void testOf() {
final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Assert.assertNotNull(element);
Assertions.assertNotNull(element);
}
@Test
public void testIsAnnotationPresent() {
final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Assert.assertTrue(element.isAnnotationPresent(MetaAnnotationForTest.class));
Assertions.assertTrue(element.isAnnotationPresent(MetaAnnotationForTest.class));
}
@Test
@ -27,22 +27,22 @@ public class CombinationAnnotationElementTest {
final AnnotationForTest annotation1 = ClassForTest.class.getAnnotation(AnnotationForTest.class);
final MetaAnnotationForTest annotation2 = AnnotationForTest.class.getAnnotation(MetaAnnotationForTest.class);
final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
Assert.assertEquals(annotation1, element.getAnnotation(AnnotationForTest.class));
Assert.assertEquals(annotation2, element.getAnnotation(MetaAnnotationForTest.class));
Assertions.assertEquals(annotation1, element.getAnnotation(AnnotationForTest.class));
Assertions.assertEquals(annotation2, element.getAnnotation(MetaAnnotationForTest.class));
}
@Test
public void testGetAnnotations() {
final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
final Annotation[] annotations = element.getAnnotations();
Assert.assertEquals(2, annotations.length);
Assertions.assertEquals(2, annotations.length);
}
@Test
public void testGetDeclaredAnnotations() {
final CombinationAnnotationElement element = CombinationAnnotationElement.of(ClassForTest.class, a -> true);
final Annotation[] annotations = element.getDeclaredAnnotations();
Assert.assertEquals(2, annotations.length);
Assertions.assertEquals(2, annotations.length);
}
@Target(ElementType.TYPE_USE)

View File

@ -1,8 +1,8 @@
package cn.hutool.core.annotation;
import lombok.SneakyThrows;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -21,18 +21,17 @@ public class GenericAnnotationMappingTest {
public void testEquals() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(mapping, mapping);
Assert.assertNotEquals(mapping, null);
Assert.assertEquals(mapping, GenericAnnotationMapping.create(annotation, false));
Assert.assertNotEquals(mapping, GenericAnnotationMapping.create(annotation, true));
Assertions.assertNotEquals(mapping, null);
Assertions.assertEquals(mapping, GenericAnnotationMapping.create(annotation, false));
Assertions.assertNotEquals(mapping, GenericAnnotationMapping.create(annotation, true));
}
@Test
public void testHashCode() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final int hashCode = GenericAnnotationMapping.create(annotation, false).hashCode();
Assert.assertEquals(hashCode, GenericAnnotationMapping.create(annotation, false).hashCode());
Assert.assertNotEquals(hashCode, GenericAnnotationMapping.create(annotation, true).hashCode());
Assertions.assertEquals(hashCode, GenericAnnotationMapping.create(annotation, false).hashCode());
Assertions.assertNotEquals(hashCode, GenericAnnotationMapping.create(annotation, true).hashCode());
}
@ -40,24 +39,24 @@ public class GenericAnnotationMappingTest {
public void testCreate() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertNotNull(mapping);
Assertions.assertNotNull(mapping);
}
@Test
public void testIsRoot() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, true);
Assert.assertTrue(mapping.isRoot());
Assertions.assertTrue(mapping.isRoot());
mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertFalse(mapping.isRoot());
Assertions.assertFalse(mapping.isRoot());
}
@Test
public void testGetAnnotation() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertSame(annotation, mapping.getAnnotation());
Assertions.assertSame(annotation, mapping.getAnnotation());
}
@SneakyThrows
@ -67,7 +66,7 @@ public class GenericAnnotationMappingTest {
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
for (int i = 0; i < mapping.getAttributes().length; i++) {
final Method method = mapping.getAttributes()[i];
Assert.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method);
Assertions.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method);
}
}
@ -75,37 +74,37 @@ public class GenericAnnotationMappingTest {
public void testAnnotationType() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.annotationType(), mapping.annotationType());
Assertions.assertEquals(annotation.annotationType(), mapping.annotationType());
}
@Test
public void testIsResolved() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertFalse(mapping.isResolved());
Assertions.assertFalse(mapping.isResolved());
}
@Test
public void testGetAttributeValue() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class));
Assert.assertNull(mapping.getAttributeValue("value", Integer.class));
Assertions.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class));
Assertions.assertNull(mapping.getAttributeValue("value", Integer.class));
}
@Test
public void testGetResolvedAnnotation() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertSame(annotation, mapping.getResolvedAnnotation());
Assertions.assertSame(annotation, mapping.getResolvedAnnotation());
}
@Test
public void testGetResolvedAttributeValue() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value", String.class));
Assert.assertNull(mapping.getResolvedAttributeValue("value", Integer.class));
Assertions.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value", String.class));
Assertions.assertNull(mapping.getResolvedAttributeValue("value", Integer.class));
}
@Target(ElementType.TYPE_USE)

View File

@ -1,8 +1,8 @@
package cn.hutool.core.annotation;
import lombok.SneakyThrows;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.*;
import java.lang.reflect.AnnotatedElement;
@ -24,57 +24,56 @@ public class HierarchicalAnnotatedElementTest {
public void testCreateFromMethod() {
final Method method1 = Foo.class.getDeclaredMethod("method");
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(method1);
Assert.assertEquals(3, elements.getElementMappings().size());
Assertions.assertEquals(3, elements.getElementMappings().size());
final Method method2 = Foo.class.getDeclaredMethod("method2");
elements = HierarchicalAnnotatedElements.create(method2);
Assert.assertEquals(1, elements.getElementMappings().size());
Assertions.assertEquals(1, elements.getElementMappings().size());
}
@Test
public void testCreate() {
HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Assert.assertNotNull(elements);
Assert.assertEquals(3, elements.getElementMappings().size());
Assertions.assertNotNull(elements);
Assertions.assertEquals(3, elements.getElementMappings().size());
elements = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY);
Assert.assertNotNull(elements);
Assert.assertEquals(3, elements.getElementMappings().size());
Assertions.assertNotNull(elements);
Assertions.assertEquals(3, elements.getElementMappings().size());
Assert.assertEquals(elements, HierarchicalAnnotatedElements.create(elements, ELEMENT_MAPPING_FACTORY));
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.create(elements, ELEMENT_MAPPING_FACTORY));
}
@Test
public void testEquals() {
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY);
Assert.assertEquals(elements, elements);
Assert.assertEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY));
Assert.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY));
Assert.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e));
Assert.assertNotEquals(elements, null);
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY));
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY));
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e));
Assertions.assertNotEquals(elements, null);
}
@Test
public void testHashCode() {
final int hashCode = HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode();
Assert.assertEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e).hashCode());
Assertions.assertEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, ELEMENT_MAPPING_FACTORY).hashCode());
Assertions.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Super.class, ELEMENT_MAPPING_FACTORY).hashCode());
Assertions.assertNotEquals(hashCode, HierarchicalAnnotatedElements.create(Foo.class, (es, e) -> e).hashCode());
}
@Test
public void testGetElement() {
final AnnotatedElement element = Foo.class;
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(element, ELEMENT_MAPPING_FACTORY);
Assert.assertSame(element, elements.getElement());
Assertions.assertSame(element, elements.getElement());
}
@Test
public void testIsAnnotationPresent() {
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
Assert.assertTrue(elements.isAnnotationPresent(Annotation1.class));
Assert.assertTrue(elements.isAnnotationPresent(Annotation2.class));
Assert.assertTrue(elements.isAnnotationPresent(Annotation3.class));
Assertions.assertTrue(elements.isAnnotationPresent(Annotation1.class));
Assertions.assertTrue(elements.isAnnotationPresent(Annotation2.class));
Assertions.assertTrue(elements.isAnnotationPresent(Annotation3.class));
}
@Test
@ -86,7 +85,7 @@ public class HierarchicalAnnotatedElementTest {
final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
final Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 };
Assert.assertArrayEquals(annotations, elements.getAnnotations());
Assertions.assertArrayEquals(annotations, elements.getAnnotations());
}
@Test
@ -94,13 +93,13 @@ public class HierarchicalAnnotatedElementTest {
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, elements.getAnnotation(Annotation1.class));
Assertions.assertEquals(annotation1, elements.getAnnotation(Annotation1.class));
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertEquals(annotation2, elements.getAnnotation(Annotation2.class));
Assertions.assertEquals(annotation2, elements.getAnnotation(Annotation2.class));
final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertEquals(annotation3, elements.getAnnotation(Annotation3.class));
Assertions.assertEquals(annotation3, elements.getAnnotation(Annotation3.class));
}
@Test
@ -108,13 +107,13 @@ public class HierarchicalAnnotatedElementTest {
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getAnnotationsByType(Annotation1.class));
Assertions.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getAnnotationsByType(Annotation1.class));
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getAnnotationsByType(Annotation2.class));
Assertions.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getAnnotationsByType(Annotation2.class));
final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getAnnotationsByType(Annotation3.class));
Assertions.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getAnnotationsByType(Annotation3.class));
}
@Test
@ -122,13 +121,13 @@ public class HierarchicalAnnotatedElementTest {
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getDeclaredAnnotationsByType(Annotation1.class));
Assertions.assertArrayEquals(new Annotation[]{ annotation1 }, elements.getDeclaredAnnotationsByType(Annotation1.class));
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getDeclaredAnnotationsByType(Annotation2.class));
Assertions.assertArrayEquals(new Annotation[]{ annotation2 }, elements.getDeclaredAnnotationsByType(Annotation2.class));
final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getDeclaredAnnotationsByType(Annotation3.class));
Assertions.assertArrayEquals(new Annotation[]{ annotation3 }, elements.getDeclaredAnnotationsByType(Annotation3.class));
}
@Test
@ -136,13 +135,13 @@ public class HierarchicalAnnotatedElementTest {
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, elements.getDeclaredAnnotation(Annotation1.class));
Assertions.assertEquals(annotation1, elements.getDeclaredAnnotation(Annotation1.class));
final Annotation2 annotation2 = Super.class.getAnnotation(Annotation2.class);
Assert.assertEquals(annotation2, elements.getDeclaredAnnotation(Annotation2.class));
Assertions.assertEquals(annotation2, elements.getDeclaredAnnotation(Annotation2.class));
final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
Assert.assertEquals(annotation3, elements.getDeclaredAnnotation(Annotation3.class));
Assertions.assertEquals(annotation3, elements.getDeclaredAnnotation(Annotation3.class));
}
@Test
@ -154,18 +153,18 @@ public class HierarchicalAnnotatedElementTest {
final Annotation3 annotation3 = Interface.class.getAnnotation(Annotation3.class);
final Annotation[] annotations = new Annotation[]{ annotation1, annotation2, annotation3 };
Assert.assertArrayEquals(annotations, elements.getDeclaredAnnotations());
Assertions.assertArrayEquals(annotations, elements.getDeclaredAnnotations());
}
@Test
public void testIterator() {
final HierarchicalAnnotatedElements elements = HierarchicalAnnotatedElements.create(Foo.class);
final Iterator<AnnotatedElement> iterator = elements.iterator();
Assert.assertNotNull(iterator);
Assertions.assertNotNull(iterator);
final List<AnnotatedElement> elementList = new ArrayList<>();
iterator.forEachRemaining(elementList::add);
Assert.assertEquals(Arrays.asList(Foo.class, Super.class, Interface.class), elementList);
Assertions.assertEquals(Arrays.asList(Foo.class, Super.class, Interface.class), elementList);
}
@Target({ElementType.TYPE_USE, ElementType.METHOD})
@ -180,6 +179,7 @@ public class HierarchicalAnnotatedElementTest {
@Retention(RetentionPolicy.RUNTIME)
private @interface Annotation1 { }
@SuppressWarnings("unused")
@Annotation3
private interface Interface {
@Annotation3

View File

@ -1,7 +1,7 @@
package cn.hutool.core.annotation;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.*;
import java.lang.reflect.AnnotatedElement;
@ -27,54 +27,53 @@ public class MetaAnnotatedElementTest {
@Test
public void testEquals() {
final AnnotatedElement element = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY);
Assert.assertEquals(element, element);
Assert.assertNotEquals(element, null);
Assert.assertEquals(element, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY));
Assert.assertNotEquals(element, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY));
Assert.assertNotEquals(element, new MetaAnnotatedElement<>(Annotation1.class, MAPPING_FACTORY));
Assertions.assertNotEquals(element, null);
Assertions.assertEquals(element, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY));
Assertions.assertNotEquals(element, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY));
Assertions.assertNotEquals(element, new MetaAnnotatedElement<>(Annotation1.class, MAPPING_FACTORY));
}
@Test
public void testHashCode() {
final int hashCode = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode();
Assert.assertEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY).hashCode());
Assertions.assertEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode());
Assertions.assertNotEquals(hashCode, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY).hashCode());
}
@Test
public void testCreate() {
// 第二次创建时优先从缓存中获取
final AnnotatedElement resolvedElement = MetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY);
Assert.assertEquals(resolvedElement, MetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
Assertions.assertEquals(resolvedElement, MetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
final AnnotatedElement element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertEquals(element, MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY));
Assertions.assertEquals(element, MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY));
}
@Test
public void testGetMapping() {
final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertTrue(element.getMapping(Annotation1.class).isPresent());
Assert.assertTrue(element.getMapping(Annotation2.class).isPresent());
Assert.assertTrue(element.getMapping(Annotation3.class).isPresent());
Assert.assertTrue(element.getMapping(Annotation4.class).isPresent());
Assertions.assertTrue(element.getMapping(Annotation1.class).isPresent());
Assertions.assertTrue(element.getMapping(Annotation2.class).isPresent());
Assertions.assertTrue(element.getMapping(Annotation3.class).isPresent());
Assertions.assertTrue(element.getMapping(Annotation4.class).isPresent());
}
@Test
public void testGetDeclaredMapping() {
final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertFalse(element.getDeclaredMapping(Annotation1.class).isPresent());
Assert.assertFalse(element.getDeclaredMapping(Annotation2.class).isPresent());
Assert.assertTrue(element.getDeclaredMapping(Annotation3.class).isPresent());
Assert.assertTrue(element.getDeclaredMapping(Annotation4.class).isPresent());
Assertions.assertFalse(element.getDeclaredMapping(Annotation1.class).isPresent());
Assertions.assertFalse(element.getDeclaredMapping(Annotation2.class).isPresent());
Assertions.assertTrue(element.getDeclaredMapping(Annotation3.class).isPresent());
Assertions.assertTrue(element.getDeclaredMapping(Annotation4.class).isPresent());
}
@Test
public void testIsAnnotationPresent() {
final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
Assert.assertTrue(element.isAnnotationPresent(Annotation1.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation2.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation3.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation4.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation1.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation2.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation3.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation4.class));
}
@Test
@ -85,10 +84,10 @@ public class MetaAnnotatedElementTest {
final Annotation2 annotation2 = Annotation3.class.getAnnotation(Annotation2.class);
final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, element.getAnnotation(Annotation1.class));
Assert.assertEquals(annotation2, element.getAnnotation(Annotation2.class));
Assert.assertEquals(annotation3, element.getAnnotation(Annotation3.class));
Assert.assertEquals(annotation4, element.getAnnotation(Annotation4.class));
Assertions.assertEquals(annotation1, element.getAnnotation(Annotation1.class));
Assertions.assertEquals(annotation2, element.getAnnotation(Annotation2.class));
Assertions.assertEquals(annotation3, element.getAnnotation(Annotation3.class));
Assertions.assertEquals(annotation4, element.getAnnotation(Annotation4.class));
}
@Test
@ -97,32 +96,32 @@ public class MetaAnnotatedElementTest {
final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertNull(element.getDeclaredAnnotation(Annotation1.class));
Assert.assertNull(element.getDeclaredAnnotation(Annotation2.class));
Assert.assertEquals(annotation3, element.getDeclaredAnnotation(Annotation3.class));
Assert.assertEquals(annotation4, element.getDeclaredAnnotation(Annotation4.class));
Assertions.assertNull(element.getDeclaredAnnotation(Annotation1.class));
Assertions.assertNull(element.getDeclaredAnnotation(Annotation2.class));
Assertions.assertEquals(annotation3, element.getDeclaredAnnotation(Annotation3.class));
Assertions.assertEquals(annotation4, element.getDeclaredAnnotation(Annotation4.class));
}
@Test
public void testGetAnnotationByType() {
final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Assert.assertArrayEquals(
Assertions.assertArrayEquals(
new Annotation[]{ annotation4 },
element.getAnnotationsByType(Annotation4.class)
);
Assert.assertEquals(0, element.getAnnotationsByType(None.class).length);
Assertions.assertEquals(0, element.getAnnotationsByType(None.class).length);
}
@Test
public void testGetDeclaredAnnotationByType() {
final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY);
final Annotation4 annotation4 = Foo.class.getAnnotation(Annotation4.class);
Assert.assertArrayEquals(
Assertions.assertArrayEquals(
new Annotation[]{ annotation4 },
element.getDeclaredAnnotationsByType(Annotation4.class)
);
Assert.assertEquals(0, element.getDeclaredAnnotationsByType(None.class).length);
Assertions.assertEquals(0, element.getDeclaredAnnotationsByType(None.class).length);
}
@Test
@ -134,7 +133,7 @@ public class MetaAnnotatedElementTest {
final Annotation1 annotation1 = Annotation2.class.getAnnotation(Annotation1.class);
final Annotation[] annotations = new Annotation[]{ annotation3, annotation4, annotation2, annotation1 };
Assert.assertArrayEquals(annotations, element.getAnnotations());
Assertions.assertArrayEquals(annotations, element.getAnnotations());
}
@Test
@ -144,7 +143,7 @@ public class MetaAnnotatedElementTest {
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
final Annotation[] annotations = new Annotation[]{ annotation3, annotation4 };
Assert.assertArrayEquals(annotations, element.getDeclaredAnnotations());
Assertions.assertArrayEquals(annotations, element.getDeclaredAnnotations());
}
@Test
@ -160,14 +159,14 @@ public class MetaAnnotatedElementTest {
final List<Annotation> mappingList = new ArrayList<>();
iterator.forEachRemaining(mapping -> mappingList.add(mapping.getAnnotation()));
Assert.assertEquals(Arrays.asList(annotations), mappingList);
Assertions.assertEquals(Arrays.asList(annotations), mappingList);
}
@Test
public void testGetElement() {
final AnnotatedElement source = Foo.class;
final MetaAnnotatedElement<ResolvedAnnotationMapping> element = MetaAnnotatedElement.create(source, MAPPING_FACTORY);
Assert.assertSame(source, element.getElement());
Assertions.assertSame(source, element.getElement());
}
@Annotation4 // 循环引用
@ -175,6 +174,7 @@ public class MetaAnnotatedElementTest {
@Retention(RetentionPolicy.RUNTIME)
private @interface None { }
@SuppressWarnings("unused")
@Annotation4 // 循环引用
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@ -185,6 +185,7 @@ public class MetaAnnotatedElementTest {
String name() default "";
}
@SuppressWarnings("unused")
@Annotation1("Annotation2")
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)

View File

@ -1,8 +1,8 @@
package cn.hutool.core.annotation;
import cn.hutool.core.text.CharSequenceUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.*;
import java.lang.reflect.Method;
@ -53,60 +53,60 @@ public class RepeatableAnnotationCollectorTest {
@Test
public void testNone() {
final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none();
Assert.assertSame(collector, RepeatableAnnotationCollector.none());
Assertions.assertSame(collector, RepeatableAnnotationCollector.none());
Assert.assertEquals(0, collector.getFinalRepeatableAnnotations(null).size());
Assertions.assertEquals(0, collector.getFinalRepeatableAnnotations(null).size());
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(Collections.singletonList(annotation), collector.getFinalRepeatableAnnotations(annotation));
Assertions.assertEquals(Collections.singletonList(annotation), collector.getFinalRepeatableAnnotations(annotation));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(annotation3), collector.getRepeatableAnnotations(annotation3, Annotation3.class));
Assert.assertTrue(collector.getRepeatableAnnotations(annotation3, Annotation1.class).isEmpty());
Assert.assertTrue(collector.getRepeatableAnnotations(null, Annotation1.class).isEmpty());
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getRepeatableAnnotations(annotation3, Annotation3.class));
Assertions.assertTrue(collector.getRepeatableAnnotations(annotation3, Annotation1.class).isEmpty());
Assertions.assertTrue(collector.getRepeatableAnnotations(null, Annotation1.class).isEmpty());
}
@Test
public void testNoneWhenAccumulate() {
final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.none();
Assert.assertSame(collector, RepeatableAnnotationCollector.none());
Assertions.assertSame(collector, RepeatableAnnotationCollector.none());
Assert.assertEquals(0, collector.getAllRepeatableAnnotations(null).size());
Assertions.assertEquals(0, collector.getAllRepeatableAnnotations(null).size());
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(Collections.singletonList(annotation), collector.getAllRepeatableAnnotations(annotation));
Assertions.assertEquals(Collections.singletonList(annotation), collector.getAllRepeatableAnnotations(annotation));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
}
@Test
public void testGenericCollector() {
final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard();
Assert.assertSame(collector, RepeatableAnnotationCollector.standard());
Assertions.assertSame(collector, RepeatableAnnotationCollector.standard());
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final List<Annotation3> annotations = Stream.of(annotation.value())
.map(Annotation2::value)
.flatMap(Stream::of)
.collect(Collectors.toList());
Assert.assertEquals(annotations, collector.getFinalRepeatableAnnotations(annotation));
Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
Assertions.assertEquals(annotations, collector.getFinalRepeatableAnnotations(annotation));
Assertions.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
Assert.assertEquals(ANNOTATION2S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation2.class));
Assert.assertEquals(ANNOTATION3S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation3.class));
Assertions.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
Assertions.assertEquals(ANNOTATION2S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation2.class));
Assertions.assertEquals(ANNOTATION3S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation3.class));
}
@Test
public void testGenericCollectorWhenAccumulate() {
final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.standard();
Assert.assertSame(collector, RepeatableAnnotationCollector.standard());
Assertions.assertSame(collector, RepeatableAnnotationCollector.standard());
final List<Annotation> annotations = new ArrayList<>();
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
@ -116,12 +116,12 @@ public class RepeatableAnnotationCollectorTest {
.map(Annotation2::value)
.flatMap(Stream::of)
.forEach(annotations::add);
Assert.assertEquals(annotations, collector.getAllRepeatableAnnotations(annotation));
Assertions.assertEquals(annotations, collector.getAllRepeatableAnnotations(annotation));
Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
Assertions.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
}
@Test
@ -132,16 +132,16 @@ public class RepeatableAnnotationCollectorTest {
.map(Annotation2::value)
.flatMap(Stream::of)
.collect(Collectors.toList());
Assert.assertEquals(annotations, collector.getFinalRepeatableAnnotations(annotation));
Assertions.assertEquals(annotations, collector.getFinalRepeatableAnnotations(annotation));
Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
Assertions.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
Assert.assertEquals(ANNOTATION2S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation2.class));
Assert.assertEquals(ANNOTATION3S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation3.class));
Assertions.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
Assertions.assertEquals(ANNOTATION2S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation2.class));
Assertions.assertEquals(ANNOTATION3S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation3.class));
}
@Test
@ -156,37 +156,37 @@ public class RepeatableAnnotationCollectorTest {
.map(Annotation2::value)
.flatMap(Stream::of)
.forEach(annotations::add);
Assert.assertEquals(annotations, collector.getAllRepeatableAnnotations(annotation));
Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
Assertions.assertEquals(annotations, collector.getAllRepeatableAnnotations(annotation));
Assertions.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations((annotation3)));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations((annotation3)));
}
@Test
public void testFullCollector() {
final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full();
Assert.assertSame(collector, RepeatableAnnotationCollector.full());
Assertions.assertSame(collector, RepeatableAnnotationCollector.full());
Assert.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
Assertions.assertEquals(ANNOTATION3S, collector.getFinalRepeatableAnnotations(ANNOTATION1));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getFinalRepeatableAnnotations(annotation3));
Assert.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
Assert.assertEquals(ANNOTATION2S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation2.class));
Assert.assertEquals(ANNOTATION3S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation3.class));
Assertions.assertEquals(Collections.singletonList(ANNOTATION1), collector.getRepeatableAnnotations(ANNOTATION1, Annotation1.class));
Assertions.assertEquals(ANNOTATION2S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation2.class));
Assertions.assertEquals(ANNOTATION3S, collector.getRepeatableAnnotations(ANNOTATION1, Annotation3.class));
}
@Test
public void testFullCollectorWhenAccumulate() {
final RepeatableAnnotationCollector collector = RepeatableAnnotationCollector.full();
Assert.assertSame(collector, RepeatableAnnotationCollector.full());
Assertions.assertSame(collector, RepeatableAnnotationCollector.full());
Assert.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
Assertions.assertEquals(ANNOTATIONS, collector.getAllRepeatableAnnotations(ANNOTATION1));
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
Assertions.assertEquals(Collections.singletonList(annotation3), collector.getAllRepeatableAnnotations(annotation3));
}
@Target(ElementType.TYPE_USE)
@ -202,6 +202,7 @@ public class RepeatableAnnotationCollectorTest {
Annotation3[] value() default {};
}
@SuppressWarnings("unused")
@Repeatable(Annotation2.class)
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)

View File

@ -1,8 +1,8 @@
package cn.hutool.core.annotation;
import cn.hutool.core.collection.iter.IterUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.*;
import java.lang.reflect.AnnotatedElement;
@ -29,19 +29,18 @@ public class RepeatableMetaAnnotatedElementTest {
@Test
public void testEquals() {
final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY);
Assert.assertEquals(element, element);
Assert.assertNotEquals(element, null);
Assert.assertEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
Assert.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY));
Assert.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY));
Assertions.assertNotEquals(element, null);
Assertions.assertEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
Assertions.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY));
Assertions.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY));
}
@Test
public void testHashCode() {
final int hashCode = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode();
Assert.assertEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY).hashCode());
Assert.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY).hashCode());
Assertions.assertEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY).hashCode());
Assertions.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY).hashCode());
Assertions.assertNotEquals(hashCode, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY).hashCode());
}
@Test
@ -49,10 +48,10 @@ public class RepeatableMetaAnnotatedElementTest {
final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), Foo.class, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
);
Assert.assertTrue(element.isAnnotationPresent(Annotation1.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation2.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation3.class));
Assert.assertTrue(element.isAnnotationPresent(Annotation4.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation1.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation2.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation3.class));
Assertions.assertTrue(element.isAnnotationPresent(Annotation4.class));
}
@Test
@ -65,10 +64,10 @@ public class RepeatableMetaAnnotatedElementTest {
.collect(Collectors.toList());
final Map<Class<? extends Annotation>, Integer> countMap = IterUtil.countMap(annotationTypes.iterator());
Assert.assertEquals((Integer)1, countMap.get(Annotation1.class));
Assert.assertEquals((Integer)2, countMap.get(Annotation2.class));
Assert.assertEquals((Integer)4, countMap.get(Annotation3.class));
Assert.assertEquals((Integer)7, countMap.get(Annotation4.class));
Assertions.assertEquals((Integer)1, countMap.get(Annotation1.class));
Assertions.assertEquals((Integer)2, countMap.get(Annotation2.class));
Assertions.assertEquals((Integer)4, countMap.get(Annotation3.class));
Assertions.assertEquals((Integer)7, countMap.get(Annotation4.class));
}
@Test
@ -78,16 +77,16 @@ public class RepeatableMetaAnnotatedElementTest {
);
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, element.getAnnotation(Annotation1.class));
Assertions.assertEquals(annotation1, element.getAnnotation(Annotation1.class));
final Annotation4 annotation4 = Annotation1.class.getAnnotation(Annotation4.class);
Assert.assertEquals(annotation4, element.getAnnotation(Annotation4.class));
Assertions.assertEquals(annotation4, element.getAnnotation(Annotation4.class));
final Annotation2 annotation2 = annotation1.value()[0];
Assert.assertEquals(annotation2, element.getAnnotation(Annotation2.class));
Assertions.assertEquals(annotation2, element.getAnnotation(Annotation2.class));
final Annotation3 annotation3 = annotation2.value()[0];
Assert.assertEquals(annotation3, element.getAnnotation(Annotation3.class));
Assertions.assertEquals(annotation3, element.getAnnotation(Annotation3.class));
}
@Test
@ -97,16 +96,16 @@ public class RepeatableMetaAnnotatedElementTest {
);
Annotation[] annotations = element.getAnnotationsByType(Annotation1.class);
Assert.assertEquals(1, annotations.length);
Assertions.assertEquals(1, annotations.length);
annotations = element.getAnnotationsByType(Annotation2.class);
Assert.assertEquals(2, annotations.length);
Assertions.assertEquals(2, annotations.length);
annotations = element.getAnnotationsByType(Annotation3.class);
Assert.assertEquals(4, annotations.length);
Assertions.assertEquals(4, annotations.length);
annotations = element.getAnnotationsByType(Annotation4.class);
Assert.assertEquals(7, annotations.length);
Assertions.assertEquals(7, annotations.length);
}
@Test
@ -119,10 +118,10 @@ public class RepeatableMetaAnnotatedElementTest {
.collect(Collectors.toList());
final Map<Class<? extends Annotation>, Integer> countMap = IterUtil.countMap(annotationTypes.iterator());
Assert.assertEquals((Integer)1, countMap.get(Annotation1.class));
Assert.assertFalse(countMap.containsKey(Annotation2.class));
Assert.assertFalse(countMap.containsKey(Annotation3.class));
Assert.assertFalse(countMap.containsKey(Annotation4.class));
Assertions.assertEquals((Integer)1, countMap.get(Annotation1.class));
Assertions.assertFalse(countMap.containsKey(Annotation2.class));
Assertions.assertFalse(countMap.containsKey(Annotation3.class));
Assertions.assertFalse(countMap.containsKey(Annotation4.class));
}
@Test
@ -132,10 +131,10 @@ public class RepeatableMetaAnnotatedElementTest {
);
final Annotation1 annotation1 = Foo.class.getDeclaredAnnotation(Annotation1.class);
Assert.assertEquals(annotation1, element.getDeclaredAnnotation(Annotation1.class));
Assert.assertNull(element.getDeclaredAnnotation(Annotation3.class));
Assert.assertNull(element.getDeclaredAnnotation(Annotation4.class));
Assert.assertNull(element.getDeclaredAnnotation(Annotation2.class));
Assertions.assertEquals(annotation1, element.getDeclaredAnnotation(Annotation1.class));
Assertions.assertNull(element.getDeclaredAnnotation(Annotation3.class));
Assertions.assertNull(element.getDeclaredAnnotation(Annotation4.class));
Assertions.assertNull(element.getDeclaredAnnotation(Annotation2.class));
}
@Test
@ -145,16 +144,16 @@ public class RepeatableMetaAnnotatedElementTest {
);
Annotation[] annotations = element.getDeclaredAnnotationsByType(Annotation1.class);
Assert.assertEquals(1, annotations.length);
Assertions.assertEquals(1, annotations.length);
annotations = element.getDeclaredAnnotationsByType(Annotation2.class);
Assert.assertEquals(0, annotations.length);
Assertions.assertEquals(0, annotations.length);
annotations = element.getDeclaredAnnotationsByType(Annotation3.class);
Assert.assertEquals(0, annotations.length);
Assertions.assertEquals(0, annotations.length);
annotations = element.getDeclaredAnnotationsByType(Annotation4.class);
Assert.assertEquals(0, annotations.length);
Assertions.assertEquals(0, annotations.length);
}
@Test
@ -163,7 +162,7 @@ public class RepeatableMetaAnnotatedElementTest {
final RepeatableMetaAnnotatedElement<GenericAnnotationMapping> repeatableMetaAnnotatedElement = RepeatableMetaAnnotatedElement.create(
RepeatableAnnotationCollector.standard(), element, (s, a) -> new GenericAnnotationMapping(a, Objects.isNull(s))
);
Assert.assertSame(element, repeatableMetaAnnotatedElement.getElement());
Assertions.assertSame(element, repeatableMetaAnnotatedElement.getElement());
}
@Test
@ -173,9 +172,10 @@ public class RepeatableMetaAnnotatedElementTest {
);
int count = 0;
for (final GenericAnnotationMapping mapping : element) {
Assertions.assertNotNull(mapping);
count++;
}
Assert.assertEquals(14, count);
Assertions.assertEquals(14, count);
}
@Annotation4

View File

@ -1,8 +1,8 @@
package cn.hutool.core.annotation;
import lombok.SneakyThrows;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -21,14 +21,13 @@ public class ResolvedAnnotationMappingTest {
public void testEquals() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertEquals(mapping, mapping);
Assert.assertNotEquals(null, mapping);
Assert.assertEquals(mapping, ResolvedAnnotationMapping.create(annotation, false));
Assert.assertNotEquals(mapping, ResolvedAnnotationMapping.create(annotation, true));
Assertions.assertNotEquals(null, mapping);
Assertions.assertEquals(mapping, ResolvedAnnotationMapping.create(annotation, false));
Assertions.assertNotEquals(mapping, ResolvedAnnotationMapping.create(annotation, true));
// Annotation3没有需要解析的属性因此即使在构造函数指定false也一样
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(
Assertions.assertEquals(
ResolvedAnnotationMapping.create(annotation3, false),
ResolvedAnnotationMapping.create(annotation3, true)
);
@ -38,12 +37,12 @@ public class ResolvedAnnotationMappingTest {
public void testHashCode() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final int hashCode = ResolvedAnnotationMapping.create(annotation, false).hashCode();
Assert.assertEquals(hashCode, ResolvedAnnotationMapping.create(annotation, false).hashCode());
Assert.assertNotEquals(hashCode, ResolvedAnnotationMapping.create(annotation, true).hashCode());
Assertions.assertEquals(hashCode, ResolvedAnnotationMapping.create(annotation, false).hashCode());
Assertions.assertNotEquals(hashCode, ResolvedAnnotationMapping.create(annotation, true).hashCode());
// Annotation3没有需要解析的属性因此即使在构造函数指定false也一样
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertEquals(
Assertions.assertEquals(
ResolvedAnnotationMapping.create(annotation3, false).hashCode(),
ResolvedAnnotationMapping.create(annotation3, true).hashCode()
);
@ -54,48 +53,48 @@ public class ResolvedAnnotationMappingTest {
public void testCreate() {
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false);
Assert.assertNotNull(mapping3);
Assertions.assertNotNull(mapping3);
final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false);
Assert.assertNotNull(mapping2);
Assertions.assertNotNull(mapping2);
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false);
Assert.assertNotNull(mapping1);
Assertions.assertNotNull(mapping1);
}
@Test
public void testIsRoot() {
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false);
Assert.assertTrue(mapping3.isRoot());
Assertions.assertTrue(mapping3.isRoot());
final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false);
Assert.assertFalse(mapping2.isRoot());
Assertions.assertFalse(mapping2.isRoot());
}
@Test
public void testGetRoot() {
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, false);
Assert.assertSame(mapping3, mapping3.getRoot());
Assertions.assertSame(mapping3, mapping3.getRoot());
final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, false);
Assert.assertSame(mapping3, mapping2.getRoot());
Assertions.assertSame(mapping3, mapping2.getRoot());
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, false);
Assert.assertSame(mapping3, mapping1.getRoot());
Assertions.assertSame(mapping3, mapping1.getRoot());
}
@Test
public void testGetAnnotation() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertSame(annotation, mapping.getAnnotation());
Assertions.assertSame(annotation, mapping.getAnnotation());
}
@SneakyThrows
@ -105,7 +104,7 @@ public class ResolvedAnnotationMappingTest {
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
for (int i = 0; i < mapping.getAttributes().length; i++) {
final Method method = mapping.getAttributes()[i];
Assert.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method);
Assertions.assertEquals(Annotation1.class.getDeclaredMethod(method.getName()), method);
}
}
@ -114,19 +113,19 @@ public class ResolvedAnnotationMappingTest {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertTrue(mapping.hasAttribute("value", String.class));
Assert.assertFalse(mapping.hasAttribute("value", Integer.class));
Assertions.assertTrue(mapping.hasAttribute("value", String.class));
Assertions.assertFalse(mapping.hasAttribute("value", Integer.class));
final int index = mapping.getAttributeIndex("value", String.class);
Assert.assertTrue(mapping.hasAttribute(index));
Assert.assertFalse(mapping.hasAttribute(Integer.MIN_VALUE));
Assertions.assertTrue(mapping.hasAttribute(index));
Assertions.assertFalse(mapping.hasAttribute(Integer.MIN_VALUE));
}
@Test
public void testAnnotationType() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertEquals(annotation.annotationType(), mapping.annotationType());
Assertions.assertEquals(annotation.annotationType(), mapping.annotationType());
}
@Test
@ -134,15 +133,15 @@ public class ResolvedAnnotationMappingTest {
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(annotation1, true);
Assert.assertTrue(mapping1.isResolved());
Assert.assertFalse(ResolvedAnnotationMapping.create(annotation1, false).isResolved());
Assertions.assertTrue(mapping1.isResolved());
Assertions.assertFalse(ResolvedAnnotationMapping.create(annotation1, false).isResolved());
final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(annotation2, true);
Assert.assertFalse(mapping2.isResolved());
Assertions.assertFalse(mapping2.isResolved());
mapping2 = ResolvedAnnotationMapping.create(mapping1, annotation2, true);
Assert.assertTrue(mapping2.isResolved());
Assertions.assertTrue(mapping2.isResolved());
}
@Test
@ -151,10 +150,10 @@ public class ResolvedAnnotationMappingTest {
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
for (int i = 0; i < mapping.getAttributes().length; i++) {
final Method method = mapping.getAttributes()[i];
Assert.assertEquals(i, mapping.getAttributeIndex(method.getName(), method.getReturnType()));
Assertions.assertEquals(i, mapping.getAttributeIndex(method.getName(), method.getReturnType()));
}
Assert.assertEquals(ResolvedAnnotationMapping.NOT_FOUND_INDEX, mapping.getAttributeIndex("value", Void.class));
Assert.assertEquals(ResolvedAnnotationMapping.NOT_FOUND_INDEX, mapping.getAttributeIndex("nonexistent", Void.class));
Assertions.assertEquals(ResolvedAnnotationMapping.NOT_FOUND_INDEX, mapping.getAttributeIndex("value", Void.class));
Assertions.assertEquals(ResolvedAnnotationMapping.NOT_FOUND_INDEX, mapping.getAttributeIndex("nonexistent", Void.class));
}
@Test
@ -162,19 +161,19 @@ public class ResolvedAnnotationMappingTest {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, false);
Assert.assertNull(mapping.getAttribute(Integer.MAX_VALUE));
Assertions.assertNull(mapping.getAttribute(Integer.MAX_VALUE));
final int valueIdx = mapping.getAttributeIndex("value", String.class);
Assert.assertEquals(annotation.value(), mapping.getAttributeValue(valueIdx));
Assert.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class));
Assertions.assertEquals(annotation.value(), mapping.getAttributeValue(valueIdx));
Assertions.assertEquals(annotation.value(), mapping.getAttributeValue("value", String.class));
final int name1Idx = mapping.getAttributeIndex("value1", String.class);
Assert.assertEquals(annotation.value1(), mapping.getAttributeValue(name1Idx));
Assert.assertEquals(annotation.value1(), mapping.getAttributeValue("value1", String.class));
Assertions.assertEquals(annotation.value1(), mapping.getAttributeValue(name1Idx));
Assertions.assertEquals(annotation.value1(), mapping.getAttributeValue("value1", String.class));
final int name2Idx = mapping.getAttributeIndex("value2", String.class);
Assert.assertEquals(annotation.value2(), mapping.getAttributeValue(name2Idx));
Assert.assertEquals(annotation.value2(), mapping.getAttributeValue("value2", String.class));
Assertions.assertEquals(annotation.value2(), mapping.getAttributeValue(name2Idx));
Assertions.assertEquals(annotation.value2(), mapping.getAttributeValue("value2", String.class));
}
@Test
@ -183,20 +182,20 @@ public class ResolvedAnnotationMappingTest {
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true);
final Annotation1 synthesis = (Annotation1)mapping.getResolvedAnnotation();
Assert.assertEquals(annotation.annotationType(), synthesis.annotationType());
Assert.assertEquals(annotation.value(), synthesis.value());
Assert.assertEquals(annotation.value(), synthesis.value1());
Assert.assertEquals(annotation.value(), synthesis.value2());
Assertions.assertEquals(annotation.annotationType(), synthesis.annotationType());
Assertions.assertEquals(annotation.value(), synthesis.value());
Assertions.assertEquals(annotation.value(), synthesis.value1());
Assertions.assertEquals(annotation.value(), synthesis.value2());
Assert.assertTrue(AnnotationMappingProxy.isProxied(synthesis));
Assert.assertSame(mapping, ((AnnotationMappingProxy.Proxied)synthesis).getMapping());
Assertions.assertTrue(AnnotationMappingProxy.isProxied(synthesis));
Assertions.assertSame(mapping, ((AnnotationMappingProxy.Proxied)synthesis).getMapping());
Assert.assertNotEquals(synthesis, annotation);
Assert.assertNotEquals(synthesis.hashCode(), annotation.hashCode());
Assert.assertNotEquals(synthesis.toString(), annotation.toString());
Assertions.assertNotEquals(synthesis, annotation);
Assertions.assertNotEquals(synthesis.hashCode(), annotation.hashCode());
Assertions.assertNotEquals(synthesis.toString(), annotation.toString());
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
Assert.assertSame(annotation3, ResolvedAnnotationMapping.create(annotation3, true).getResolvedAnnotation());
Assertions.assertSame(annotation3, ResolvedAnnotationMapping.create(annotation3, true).getResolvedAnnotation());
}
// ======================= resolved attribute value =======================
@ -205,26 +204,26 @@ public class ResolvedAnnotationMappingTest {
public void testGetResolvedAttributeValueWhenAliased() {
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping = ResolvedAnnotationMapping.create(annotation, true);
Assert.assertNull(mapping.getResolvedAttributeValue(Integer.MIN_VALUE));
Assertions.assertNull(mapping.getResolvedAttributeValue(Integer.MIN_VALUE));
// value = value1 = value2
Assert.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value", String.class));
Assert.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value1", String.class));
Assert.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value2", String.class));
Assertions.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value", String.class));
Assertions.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value1", String.class));
Assertions.assertEquals(annotation.value(), mapping.getResolvedAttributeValue("value2", String.class));
// alias == alias1 == alias2
Assert.assertEquals(annotation.alias(), mapping.getResolvedAttributeValue("alias", String.class));
Assert.assertEquals(annotation.alias(), mapping.getResolvedAttributeValue("alias1", String.class));
Assert.assertEquals(annotation.alias(), mapping.getResolvedAttributeValue("alias2", String.class));
Assertions.assertEquals(annotation.alias(), mapping.getResolvedAttributeValue("alias", String.class));
Assertions.assertEquals(annotation.alias(), mapping.getResolvedAttributeValue("alias1", String.class));
Assertions.assertEquals(annotation.alias(), mapping.getResolvedAttributeValue("alias2", String.class));
// defVal1 == defVal2
Assert.assertEquals(
Assertions.assertEquals(
mapping.getResolvedAttributeValue("defVal", String.class),
mapping.getResolvedAttributeValue("defVal2", String.class)
);
// unDefVal1 == unDefVal2
Assert.assertEquals(
Assertions.assertEquals(
mapping.getResolvedAttributeValue("unDefVal", String.class),
mapping.getResolvedAttributeValue("unDefVal2", String.class)
);
@ -234,23 +233,23 @@ public class ResolvedAnnotationMappingTest {
public void testGetResolvedAttributeWhenOverwritten() {
final Annotation3 annotation3 = Foo.class.getAnnotation(Annotation3.class);
final ResolvedAnnotationMapping mapping3 = ResolvedAnnotationMapping.create(annotation3, true);
Assert.assertEquals(annotation3.value(), mapping3.getResolvedAttributeValue("value", String.class));
Assert.assertEquals((Integer)annotation3.alias(), mapping3.getResolvedAttributeValue("alias", Integer.class));
Assertions.assertEquals(annotation3.value(), mapping3.getResolvedAttributeValue("value", String.class));
Assertions.assertEquals((Integer)annotation3.alias(), mapping3.getResolvedAttributeValue("alias", Integer.class));
// annotation2中与annotation3同名同类型的属性valuealias被覆写
final Annotation2 annotation2 = Foo.class.getAnnotation(Annotation2.class);
final ResolvedAnnotationMapping mapping2 = ResolvedAnnotationMapping.create(mapping3, annotation2, true);
Assert.assertEquals(annotation3.value(), mapping2.getResolvedAttributeValue("value", String.class));
Assert.assertEquals((Integer)annotation3.alias(), mapping2.getResolvedAttributeValue("alias", Integer.class));
Assertions.assertEquals(annotation3.value(), mapping2.getResolvedAttributeValue("value", String.class));
Assertions.assertEquals((Integer)annotation3.alias(), mapping2.getResolvedAttributeValue("alias", Integer.class));
// annotation1中与annotation3同名同类型的属性value被覆写由于value存在别名value1value2因此也一并被覆写
final Annotation1 annotation1 = Foo.class.getAnnotation(Annotation1.class);
final ResolvedAnnotationMapping mapping1 = ResolvedAnnotationMapping.create(mapping2, annotation1, true);
Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value", String.class));
Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value1", String.class));
Assert.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value2", String.class));
Assertions.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value", String.class));
Assertions.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value1", String.class));
Assertions.assertEquals(annotation3.value(), mapping1.getResolvedAttributeValue("value2", String.class));
// 而alias由于类型不同不会被覆写
Assert.assertEquals(annotation1.alias(), mapping1.getResolvedAttributeValue("alias", String.class));
Assertions.assertEquals(annotation1.alias(), mapping1.getResolvedAttributeValue("alias", String.class));
}
@SuppressWarnings("unused")

View File

@ -4,8 +4,8 @@ import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.map.MapUtil;
import lombok.Builder;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class BeanCopyMappingTest {
@ -25,8 +25,8 @@ public class BeanCopyMappingTest {
BeanUtil.copyProperties(b, a, copyOptions);
BeanUtil.copyProperties(a, c);
Assert.assertEquals("12312312", a.getCarNo());
Assert.assertEquals("12312312", c.getCarNo());
Assertions.assertEquals("12312312", a.getCarNo());
Assertions.assertEquals("12312312", c.getCarNo());
}
@Data

View File

@ -1,7 +1,7 @@
package cn.hutool.core.bean;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* {@link BeanDesc} 单元测试类
@ -14,13 +14,13 @@ public class BeanDescTest {
@Test
public void propDescTes() {
final BeanDesc desc = BeanUtil.getBeanDesc(User.class);
Assert.assertEquals("User", desc.getSimpleName());
Assertions.assertEquals("User", desc.getSimpleName());
Assert.assertEquals("age", desc.getField("age").getName());
Assert.assertEquals("getAge", desc.getGetter("age").getName());
Assert.assertEquals("setAge", desc.getSetter("age").getName());
Assert.assertEquals(1, desc.getSetter("age").getParameterTypes().length);
Assert.assertSame(int.class, desc.getSetter("age").getParameterTypes()[0]);
Assertions.assertEquals("age", desc.getField("age").getName());
Assertions.assertEquals("getAge", desc.getGetter("age").getName());
Assertions.assertEquals("setAge", desc.getSetter("age").getName());
Assertions.assertEquals(1, desc.getSetter("age").getParameterTypes().length);
Assertions.assertSame(int.class, desc.getSetter("age").getParameterTypes()[0]);
}
@ -29,29 +29,29 @@ public class BeanDescTest {
final BeanDesc desc = BeanUtil.getBeanDesc(User.class);
final PropDesc prop = desc.getProp("name");
Assert.assertEquals("name", prop.getFieldName());
Assert.assertEquals("getName", prop.getGetter().getName());
Assert.assertEquals("setName", prop.getSetter().getName());
Assert.assertEquals(1, prop.getSetter().getParameterTypes().length);
Assert.assertSame(String.class, prop.getSetter().getParameterTypes()[0]);
Assertions.assertEquals("name", prop.getFieldName());
Assertions.assertEquals("getName", prop.getGetter().getName());
Assertions.assertEquals("setName", prop.getSetter().getName());
Assertions.assertEquals(1, prop.getSetter().getParameterTypes().length);
Assertions.assertSame(String.class, prop.getSetter().getParameterTypes()[0]);
}
@Test
public void propDescOfBooleanTest() {
final BeanDesc desc = BeanUtil.getBeanDesc(User.class);
Assert.assertEquals("isAdmin", desc.getGetter("isAdmin").getName());
Assert.assertEquals("setAdmin", desc.getSetter("isAdmin").getName());
Assert.assertEquals("isGender", desc.getGetter("gender").getName());
Assert.assertEquals("setGender", desc.getSetter("gender").getName());
Assertions.assertEquals("isAdmin", desc.getGetter("isAdmin").getName());
Assertions.assertEquals("setAdmin", desc.getSetter("isAdmin").getName());
Assertions.assertEquals("isGender", desc.getGetter("gender").getName());
Assertions.assertEquals("setGender", desc.getSetter("gender").getName());
}
@Test
public void propDescOfBooleanTest2() {
final BeanDesc desc = BeanUtil.getBeanDesc(User.class);
Assert.assertEquals("isIsSuper", desc.getGetter("isSuper").getName());
Assert.assertEquals("setIsSuper", desc.getSetter("isSuper").getName());
Assertions.assertEquals("isIsSuper", desc.getGetter("isSuper").getName());
Assertions.assertEquals("setIsSuper", desc.getSetter("isSuper").getName());
}
@Test
@ -60,10 +60,10 @@ public class BeanDescTest {
final User user = new User();
desc.getProp("name").setValue(user, "张三");
Assert.assertEquals("张三", user.getName());
Assertions.assertEquals("张三", user.getName());
final Object value = desc.getProp("name").getValue(user);
Assert.assertEquals("张三", value);
Assertions.assertEquals("张三", value);
}
public static class User {

View File

@ -1,13 +1,13 @@
package cn.hutool.core.bean;
import cn.hutool.core.array.ArrayUtil;
import cn.hutool.core.lang.test.bean.ExamInfoDict;
import cn.hutool.core.lang.test.bean.UserInfoDict;
import cn.hutool.core.map.Dict;
import cn.hutool.core.array.ArrayUtil;
import lombok.Data;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
@ -24,7 +24,7 @@ public class BeanPathTest {
Map<String, Object> tempMap;
@Before
@BeforeEach
public void init() {
// ------------------------------------------------- 考试信息列表
final ExamInfoDict examInfoDict = new ExamInfoDict();
@ -62,36 +62,36 @@ public class BeanPathTest {
@Test
public void beanPathTest1() {
final BeanPath pattern = new BeanPath("userInfo.examInfoDict[0].id");
Assert.assertEquals("userInfo", pattern.patternParts.get(0));
Assert.assertEquals("examInfoDict", pattern.patternParts.get(1));
Assert.assertEquals("0", pattern.patternParts.get(2));
Assert.assertEquals("id", pattern.patternParts.get(3));
Assertions.assertEquals("userInfo", pattern.patternParts.get(0));
Assertions.assertEquals("examInfoDict", pattern.patternParts.get(1));
Assertions.assertEquals("0", pattern.patternParts.get(2));
Assertions.assertEquals("id", pattern.patternParts.get(3));
}
@Test
public void beanPathTest2() {
final BeanPath pattern = new BeanPath("[userInfo][examInfoDict][0][id]");
Assert.assertEquals("userInfo", pattern.patternParts.get(0));
Assert.assertEquals("examInfoDict", pattern.patternParts.get(1));
Assert.assertEquals("0", pattern.patternParts.get(2));
Assert.assertEquals("id", pattern.patternParts.get(3));
Assertions.assertEquals("userInfo", pattern.patternParts.get(0));
Assertions.assertEquals("examInfoDict", pattern.patternParts.get(1));
Assertions.assertEquals("0", pattern.patternParts.get(2));
Assertions.assertEquals("id", pattern.patternParts.get(3));
}
@Test
public void beanPathTest3() {
final BeanPath pattern = new BeanPath("['userInfo']['examInfoDict'][0]['id']");
Assert.assertEquals("userInfo", pattern.patternParts.get(0));
Assert.assertEquals("examInfoDict", pattern.patternParts.get(1));
Assert.assertEquals("0", pattern.patternParts.get(2));
Assert.assertEquals("id", pattern.patternParts.get(3));
Assertions.assertEquals("userInfo", pattern.patternParts.get(0));
Assertions.assertEquals("examInfoDict", pattern.patternParts.get(1));
Assertions.assertEquals("0", pattern.patternParts.get(2));
Assertions.assertEquals("id", pattern.patternParts.get(3));
}
@Test
public void getTest() {
final BeanPath pattern = BeanPath.of("userInfo.examInfoDict[0].id");
final Object result = pattern.get(tempMap);
Assert.assertEquals(1, result);
Assertions.assertEquals(1, result);
}
@Test
@ -99,7 +99,7 @@ public class BeanPathTest {
final BeanPath pattern = BeanPath.of("userInfo.examInfoDict[0].id");
pattern.set(tempMap, 2);
final Object result = pattern.get(tempMap);
Assert.assertEquals(2, result);
Assertions.assertEquals(2, result);
}
@Test
@ -107,8 +107,8 @@ public class BeanPathTest {
final BeanPath pattern = BeanPath.of("userInfo[id, photoPath]");
@SuppressWarnings("unchecked")
final Map<String, Object> result = (Map<String, Object>)pattern.get(tempMap);
Assert.assertEquals(1, result.get("id"));
Assert.assertEquals("yx.mm.com", result.get("photoPath"));
Assertions.assertEquals(1, result.get("id"));
Assertions.assertEquals("yx.mm.com", result.get("photoPath"));
}
@Test
@ -118,15 +118,15 @@ public class BeanPathTest {
dataMap.put("aa.bb.cc", "value111111");// key 是类名 格式 ' . '
final BeanPath pattern = BeanPath.of("'aa.bb.cc'");
Assert.assertEquals("value111111", pattern.get(dataMap));
Assertions.assertEquals("value111111", pattern.get(dataMap));
}
@Test
public void compileTest(){
final BeanPath of = BeanPath.of("'abc.dd'.ee.ff'.'");
Assert.assertEquals("abc.dd", of.getPatternParts().get(0));
Assert.assertEquals("ee", of.getPatternParts().get(1));
Assert.assertEquals("ff.", of.getPatternParts().get(2));
Assertions.assertEquals("abc.dd", of.getPatternParts().get(0));
Assertions.assertEquals("ee", of.getPatternParts().get(1));
Assertions.assertEquals("ff.", of.getPatternParts().get(2));
}
@Test
@ -135,24 +135,24 @@ public class BeanPathTest {
BeanPath beanPath = BeanPath.of("list[0].name");
beanPath.set(map, "张三");
Assert.assertEquals("{list=[{name=张三}]}", map.toString());
Assertions.assertEquals("{list=[{name=张三}]}", map.toString());
map.clear();
beanPath = BeanPath.of("list[1].name");
beanPath.set(map, "张三");
Assert.assertEquals("{list=[null, {name=张三}]}", map.toString());
Assertions.assertEquals("{list=[null, {name=张三}]}", map.toString());
map.clear();
beanPath = BeanPath.of("list[0].1.name");
beanPath.set(map, "张三");
Assert.assertEquals("{list=[[null, {name=张三}]]}", map.toString());
Assertions.assertEquals("{list=[[null, {name=张三}]]}", map.toString());
}
@Test
public void putByPathTest() {
final Dict dict = new Dict();
BeanPath.of("aa.bb").set(dict, "BB");
Assert.assertEquals("{aa={bb=BB}}", dict.toString());
Assertions.assertEquals("{aa={bb=BB}}", dict.toString());
}
@Test
@ -163,7 +163,7 @@ public class BeanPathTest {
BeanPath.of("hobby[1]").set(myUser, "KFC");
BeanPath.of("hobby[2]").set(myUser, "COFFE");
Assert.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(myUser.getHobby()));
Assertions.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(myUser.getHobby()));
}
@Test
@ -174,7 +174,7 @@ public class BeanPathTest {
BeanPath.of("myUser.hobby[1]").set(myUser, "KFC");
BeanPath.of("myUser.hobby[2]").set(myUser, "COFFE");
Assert.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(myUser.getMyUser().getHobby()));
Assertions.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(myUser.getMyUser().getHobby()));
}
@Data

View File

@ -1,6 +1,7 @@
package cn.hutool.core.bean;
import cn.hutool.core.annotation.Alias;
import cn.hutool.core.array.ArrayUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.bean.copier.ValueProvider;
import cn.hutool.core.collection.ListUtil;
@ -9,30 +10,22 @@ import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.array.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -47,7 +40,7 @@ public class BeanUtilTest {
// HashMap不包含setXXX方法不是bean
final boolean isBean = BeanUtil.isBean(HashMap.class);
Assert.assertFalse(isBean);
Assertions.assertFalse(isBean);
}
@Test
@ -73,8 +66,8 @@ public class BeanUtilTest {
}, CopyOptions.of());
Assert.assertEquals("张三", person.getName());
Assert.assertEquals(18, person.getAge());
Assertions.assertEquals("张三", person.getName());
Assertions.assertEquals(18, person.getAge());
}
@Test
@ -85,9 +78,9 @@ public class BeanUtilTest {
.put("openId", "DFDFSDFWERWER")
.build();
final SubPerson person = BeanUtil.fillBeanWithMapIgnoreCase(map, new SubPerson(), false);
Assert.assertEquals("Joe", person.getName());
Assert.assertEquals(12, person.getAge());
Assert.assertEquals("DFDFSDFWERWER", person.getOpenid());
Assertions.assertEquals("Joe", person.getName());
Assertions.assertEquals(12, person.getAge());
Assertions.assertEquals("DFDFSDFWERWER", person.getOpenid());
}
@Test
@ -99,11 +92,11 @@ public class BeanUtilTest {
person.setSubName("sub名字");
final Map<?, ?> map = BeanUtil.toBean(person, Map.class);
Assert.assertEquals("测试A11", map.get("name"));
Assert.assertEquals(14, map.get("age"));
Assert.assertEquals("11213232", map.get("openid"));
Assertions.assertEquals("测试A11", map.get("name"));
Assertions.assertEquals(14, map.get("age"));
Assertions.assertEquals("11213232", map.get("openid"));
// static属性应被忽略
Assert.assertFalse(map.containsKey("SUBNAME"));
Assertions.assertFalse(map.containsKey("SUBNAME"));
}
/**
@ -117,9 +110,9 @@ public class BeanUtilTest {
map.put("age", "aaaaaa");
final Person person = BeanUtil.toBean(map, Person.class, CopyOptions.of().setIgnoreError(true));
Assert.assertEquals("Joe", person.getName());
Assertions.assertEquals("Joe", person.getName());
// 错误的类型不copy这个字段使用对象创建的默认值
Assert.assertEquals(0, person.getAge());
Assertions.assertEquals(0, person.getAge());
}
@Test
@ -129,8 +122,8 @@ public class BeanUtilTest {
map.put("aGe", 12);
final Person person = BeanUtil.toBean(map, Person.class, CopyOptions.of().setIgnoreCase(true));
Assert.assertEquals("Joe", person.getName());
Assert.assertEquals(12, person.getAge());
Assertions.assertEquals("Joe", person.getName());
Assertions.assertEquals(12, person.getAge());
}
@Test
@ -145,8 +138,8 @@ public class BeanUtilTest {
mapping.put("b_age", "age");
final Person person = BeanUtil.toBean(map, Person.class, CopyOptions.of().setFieldMapping(mapping));
Assert.assertEquals("Joe", person.getName());
Assert.assertEquals(12, person.getAge());
Assertions.assertEquals("Joe", person.getName());
Assertions.assertEquals(12, person.getAge());
}
/**
@ -160,18 +153,20 @@ public class BeanUtilTest {
// 非空构造也可以实例化成功
final Person2 person = BeanUtil.toBean(map, Person2.class, CopyOptions.of());
Assert.assertEquals("Joe", person.name);
Assert.assertEquals(12, person.age);
Assertions.assertEquals("Joe", person.name);
Assertions.assertEquals(12, person.age);
}
/**
* 测试在不忽略错误情况下转换失败需要报错
*/
@Test(expected = NumberFormatException.class)
@Test
public void mapToBeanWinErrorTest() {
final Map<String, String> map = new HashMap<>();
map.put("age", "哈哈");
BeanUtil.toBean(map, Person.class);
Assertions.assertThrows(NumberFormatException.class, ()->{
final Map<String, String> map = new HashMap<>();
map.put("age", "哈哈");
BeanUtil.toBean(map, Person.class);
});
}
@Test
@ -184,11 +179,11 @@ public class BeanUtilTest {
final Map<String, Object> map = BeanUtil.beanToMap(person);
Assert.assertEquals("测试A11", map.get("name"));
Assert.assertEquals(14, map.get("age"));
Assert.assertEquals("11213232", map.get("openid"));
Assertions.assertEquals("测试A11", map.get("name"));
Assertions.assertEquals(14, map.get("age"));
Assertions.assertEquals("11213232", map.get("openid"));
// static属性应被忽略
Assert.assertFalse(map.containsKey("SUBNAME"));
Assertions.assertFalse(map.containsKey("SUBNAME"));
}
@Test
@ -201,11 +196,11 @@ public class BeanUtilTest {
final Map<String, Object> map = BeanUtil.beanToMap(person, (String[])null);
Assert.assertEquals("测试A11", map.get("name"));
Assert.assertEquals(14, map.get("age"));
Assert.assertEquals("11213232", map.get("openid"));
Assertions.assertEquals("测试A11", map.get("name"));
Assertions.assertEquals(14, map.get("age"));
Assertions.assertEquals("11213232", map.get("openid"));
// static属性应被忽略
Assert.assertFalse(map.containsKey("SUBNAME"));
Assertions.assertFalse(map.containsKey("SUBNAME"));
}
@Test
@ -217,7 +212,7 @@ public class BeanUtilTest {
person.setSubName("sub名字");
final Map<String, Object> map = BeanUtil.beanToMap(person, true, true);
Assert.assertEquals("sub名字", map.get("sub_name"));
Assertions.assertEquals("sub名字", map.get("sub_name"));
}
@Test
@ -233,7 +228,7 @@ public class BeanUtilTest {
entry.setValue(entry.getKey() + "_" + entry.getValue());
return entry;
}));
Assert.assertEquals("subName_sub名字", map.get("subName"));
Assertions.assertEquals("subName_sub名字", map.get("subName"));
}
@Test
@ -248,7 +243,7 @@ public class BeanUtilTest {
person.setBooleanb(true);
final Map<String, Object> map = BeanUtil.beanToMap(person);
Assert.assertEquals("sub名字", map.get("aliasSubName"));
Assertions.assertEquals("sub名字", map.get("aliasSubName"));
}
@Test
@ -260,12 +255,12 @@ public class BeanUtilTest {
map.put("is_booleanb", true);
final SubPersonWithAlias subPersonWithAlias = BeanUtil.toBean(map, SubPersonWithAlias.class);
Assert.assertEquals("sub名字", subPersonWithAlias.getSubName());
Assertions.assertEquals("sub名字", subPersonWithAlias.getSubName());
// https://gitee.com/dromara/hutool/issues/I6H0XF
// is_booleana并不匹配booleana字段
Assert.assertFalse(subPersonWithAlias.isBooleana());
Assert.assertNull(subPersonWithAlias.getBooleanb());
Assertions.assertFalse(subPersonWithAlias.isBooleana());
Assertions.assertNull(subPersonWithAlias.getBooleanb());
}
@Test
@ -281,8 +276,8 @@ public class BeanUtilTest {
person.setDate2(now.toLocalDate());
final Map<String, Object> map = BeanUtil.beanToMap(person, false, true);
Assert.assertEquals(now, map.get("date"));
Assert.assertEquals(now.toLocalDate(), map.get("date2"));
Assertions.assertEquals(now, map.get("date"));
Assertions.assertEquals(now.toLocalDate(), map.get("date2"));
}
@Test
@ -294,16 +289,16 @@ public class BeanUtilTest {
person.setSubName("sub名字");
final Object name = BeanUtil.getProperty(person, "name");
Assert.assertEquals("测试A11", name);
Assertions.assertEquals("测试A11", name);
final Object subName = BeanUtil.getProperty(person, "subName");
Assert.assertEquals("sub名字", subName);
Assertions.assertEquals("sub名字", subName);
}
@Test
@SuppressWarnings("ConstantConditions")
public void getNullPropertyTest() {
final Object property = BeanUtil.getProperty(null, "name");
Assert.assertNull(property);
Assertions.assertNull(property);
}
@Test
@ -313,12 +308,12 @@ public class BeanUtilTest {
for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
set.add(propertyDescriptor.getName());
}
Assert.assertTrue(set.contains("age"));
Assert.assertTrue(set.contains("id"));
Assert.assertTrue(set.contains("name"));
Assert.assertTrue(set.contains("openid"));
Assert.assertTrue(set.contains("slow"));
Assert.assertTrue(set.contains("subName"));
Assertions.assertTrue(set.contains("age"));
Assertions.assertTrue(set.contains("id"));
Assertions.assertTrue(set.contains("name"));
Assertions.assertTrue(set.contains("openid"));
Assertions.assertTrue(set.contains("slow"));
Assertions.assertTrue(set.contains("subName"));
}
@Test
@ -330,14 +325,14 @@ public class BeanUtilTest {
person.setSubName("sub名字");
final SubPerson person1 = BeanUtil.copyProperties(person, SubPerson.class);
Assert.assertEquals(14, person1.getAge());
Assert.assertEquals("11213232", person1.getOpenid());
Assert.assertEquals("测试A11", person1.getName());
Assert.assertEquals("sub名字", person1.getSubName());
Assertions.assertEquals(14, person1.getAge());
Assertions.assertEquals("11213232", person1.getOpenid());
Assertions.assertEquals("测试A11", person1.getName());
Assertions.assertEquals("sub名字", person1.getSubName());
}
@Test
@Ignore
@Disabled
public void multiThreadTest(){
final Student student = new Student();
student.setName("张三");
@ -375,12 +370,12 @@ public class BeanUtilTest {
// 测试boolean参数值isXXX形式
final SubPerson p2 = new SubPerson();
BeanUtil.copyProperties(p1, p2);
Assert.assertTrue(p2.getSlow());
Assertions.assertTrue(p2.getSlow());
// 测试boolean参数值非isXXX形式
final SubPerson2 p3 = new SubPerson2();
BeanUtil.copyProperties(p1, p3);
Assert.assertTrue(p3.getSlow());
Assertions.assertTrue(p3.getSlow());
}
@Test
@ -394,11 +389,11 @@ public class BeanUtilTest {
// null值不覆盖目标属性
BeanUtil.copyProperties(p1, p2, CopyOptions.of().ignoreNullValue());
Assert.assertEquals("oldName", p2.getName());
Assertions.assertEquals("oldName", p2.getName());
// null覆盖目标属性
BeanUtil.copyProperties(p1, p2);
Assert.assertNull(p2.getName());
Assertions.assertNull(p2.getName());
}
@Test
@ -411,9 +406,9 @@ public class BeanUtilTest {
final Map<String, Object> map = MapUtil.newHashMap();
BeanUtil.copyProperties(p1, map);
Assert.assertTrue((Boolean) map.get("slow"));
Assert.assertEquals("测试", map.get("name"));
Assert.assertEquals("sub测试", map.get("subName"));
Assertions.assertTrue((Boolean) map.get("slow"));
Assertions.assertEquals("测试", map.get("name"));
Assertions.assertEquals("sub测试", map.get("subName"));
}
@Test
@ -426,9 +421,9 @@ public class BeanUtilTest {
final Map<String, Object> map = MapUtil.newHashMap();
BeanUtil.copyProperties(p1, map);
Assert.assertTrue((Boolean) map.get("isSlow"));
Assert.assertEquals("测试", map.get("name"));
Assert.assertEquals("sub测试", map.get("subName"));
Assertions.assertTrue((Boolean) map.get("isSlow"));
Assertions.assertEquals("测试", map.get("name"));
Assertions.assertEquals("sub测试", map.get("subName"));
}
@Test
@ -440,8 +435,8 @@ public class BeanUtilTest {
final Person person2 = BeanUtil.trimStrFields(person);
// 是否改变原对象
Assert.assertEquals("张三", person.getName());
Assert.assertEquals("张三", person2.getName());
Assertions.assertEquals("张三", person.getName());
Assertions.assertEquals("张三", person2.getName());
}
// -----------------------------------------------------------------------------------------------------------------
@ -526,9 +521,9 @@ public class BeanUtilTest {
final SubPersonWithOverlayTransientField dest = new SubPersonWithOverlayTransientField();
BeanUtil.copyProperties(source, dest);
Assert.assertEquals(source.getName(), dest.getName());
Assert.assertEquals(source.getAge(), dest.getAge());
Assert.assertEquals(source.getOpenid(), dest.getOpenid());
Assertions.assertEquals(source.getName(), dest.getName());
Assertions.assertEquals(source.getAge(), dest.getAge());
Assertions.assertEquals(source.getOpenid(), dest.getOpenid());
}
@Test
@ -559,8 +554,8 @@ public class BeanUtilTest {
info.setCode("123");
final HllFoodEntity entity = new HllFoodEntity();
BeanUtil.copyProperties(info, entity);
Assert.assertEquals(info.getBookID(), entity.getBookId());
Assert.assertEquals(info.getCode(), entity.getCode2());
Assertions.assertEquals(info.getBookID(), entity.getBookId());
Assertions.assertEquals(info.getCode(), entity.getCode2());
}
@Test
@ -569,13 +564,13 @@ public class BeanUtilTest {
info.setBookID("0");
info.setCode("123");
final Food newFood = BeanUtil.copyProperties(info, Food.class, "code");
Assert.assertEquals(info.getBookID(), newFood.getBookID());
Assert.assertNull(newFood.getCode());
Assertions.assertEquals(info.getBookID(), newFood.getBookID());
Assertions.assertNull(newFood.getCode());
}
@Test
public void copyNullTest() {
Assert.assertNull(BeanUtil.copyProperties(null, Food.class));
Assertions.assertNull(BeanUtil.copyProperties(null, Food.class));
}
@Test
@ -588,9 +583,9 @@ public class BeanUtilTest {
final Map<String, Object> map = MapUtil.newHashMap();
BeanUtil.copyProperties(p1, map, CopyOptions.of().setIgnoreNullValue(true));
Assert.assertTrue((Boolean) map.get("isSlow"));
Assert.assertEquals("测试", map.get("name"));
Assert.assertFalse(map.containsKey("subName"));
Assertions.assertTrue((Boolean) map.get("isSlow"));
Assertions.assertEquals("测试", map.get("name"));
Assertions.assertFalse(map.containsKey("subName"));
}
@Test
@ -601,8 +596,8 @@ public class BeanUtilTest {
final Food newFood = new Food();
final CopyOptions copyOptions = CopyOptions.of().setPropertiesFilter((f, v) -> !(v instanceof CharSequence) || StrUtil.isNotBlank(v.toString()));
BeanUtil.copyProperties(info, newFood, copyOptions);
Assert.assertEquals(info.getBookID(), newFood.getBookID());
Assert.assertNull(newFood.getCode());
Assertions.assertEquals(info.getBookID(), newFood.getBookID());
Assertions.assertNull(newFood.getCode());
}
@Test
@ -618,8 +613,8 @@ public class BeanUtilTest {
BeanUtil.copyProperties(o, n, copyOptions);
// 是否忽略拷贝属性
Assert.assertNotEquals(o.getAge(),n.getAge());
Assert.assertNotEquals(o.getOpenid(),n.getOpenid());
Assertions.assertNotEquals(o.getAge(),n.getAge());
Assertions.assertNotEquals(o.getOpenid(),n.getOpenid());
}
@Data
@ -642,7 +637,7 @@ public class BeanUtilTest {
public void setPropertiesTest() {
final Map<String, Object> resultMap = MapUtil.newHashMap();
BeanUtil.setProperty(resultMap, "codeList[0].name", "张三");
Assert.assertEquals("{codeList=[{name=张三}]}", resultMap.toString());
Assertions.assertEquals("{codeList=[{name=张三}]}", resultMap.toString());
}
@Test
@ -653,7 +648,7 @@ public class BeanUtilTest {
final Station station2 = new Station();
BeanUtil.copyProperties(station, station2);
Assert.assertEquals(new Long(123456L), station2.getId());
Assertions.assertEquals(new Long(123456L), station2.getId());
}
static class Station extends Tree<Long> {}
@ -679,10 +674,10 @@ public class BeanUtilTest {
final List<Student> studentList = ListUtil.view(student, student2);
final List<Person> people = BeanUtil.copyToList(studentList, Person.class);
Assert.assertEquals(studentList.size(), people.size());
Assertions.assertEquals(studentList.size(), people.size());
for (int i = 0; i < studentList.size(); i++) {
Assert.assertEquals(studentList.get(i).getName(), people.get(i).getName());
Assert.assertEquals(studentList.get(i).getAge(), people.get(i).getAge());
Assertions.assertEquals(studentList.get(i).getName(), people.get(i).getName());
Assertions.assertEquals(studentList.get(i).getAge(), people.get(i).getAge());
}
}
@ -702,11 +697,11 @@ public class BeanUtilTest {
final List<Student> studentList = ListUtil.view(student, student2);
final List<Person> people = BeanUtil.copyToList(studentList, Person.class, CopyOptions.of().setFieldMapping(MapUtil.of("no", "openid")));
Assert.assertEquals(studentList.size(), people.size());
Assertions.assertEquals(studentList.size(), people.size());
for (int i = 0; i < studentList.size(); i++) {
Assert.assertEquals(studentList.get(i).getName(), people.get(i).getName());
Assert.assertEquals(studentList.get(i).getAge(), people.get(i).getAge());
Assert.assertEquals(studentList.get(i).getNo().toString(), people.get(i).getOpenid());
Assertions.assertEquals(studentList.get(i).getName(), people.get(i).getName());
Assertions.assertEquals(studentList.get(i).getAge(), people.get(i).getAge());
Assertions.assertEquals(studentList.get(i).getNo().toString(), people.get(i).getOpenid());
}
}
@ -731,7 +726,7 @@ public class BeanUtilTest {
}
return entry;
});
Assert.assertFalse(f.containsKey(null));
Assertions.assertFalse(f.containsKey(null));
}
@Data
@ -762,8 +757,8 @@ public class BeanUtilTest {
final BeanPath beanPath = BeanPath.of("testPojo2List.age");
final Object o = beanPath.get(testPojo);
Assert.assertEquals(Integer.valueOf(2), ArrayUtil.get(o, 0));
Assert.assertEquals(Integer.valueOf(3), ArrayUtil.get(o, 1));
Assertions.assertEquals(Integer.valueOf(2), ArrayUtil.get(o, 0));
Assertions.assertEquals(Integer.valueOf(3), ArrayUtil.get(o, 1));
}
@Data
@ -810,10 +805,10 @@ public class BeanUtilTest {
final ChildVo2 childVo2 = new ChildVo2();
BeanUtil.copyProperties(childVo1, childVo2, copyOptions);
Assert.assertEquals(childVo1.getChild_address(), childVo2.getChildAddress());
Assert.assertEquals(childVo1.getChild_name(), childVo2.getChildName());
Assert.assertEquals(childVo1.getChild_father_name(), childVo2.getChildFatherName());
Assert.assertEquals(childVo1.getChild_mother_name(), childVo2.getChildMotherName());
Assertions.assertEquals(childVo1.getChild_address(), childVo2.getChildAddress());
Assertions.assertEquals(childVo1.getChild_name(), childVo2.getChildName());
Assertions.assertEquals(childVo1.getChild_father_name(), childVo2.getChildFatherName());
Assertions.assertEquals(childVo1.getChild_mother_name(), childVo2.getChildMotherName());
}
@Data
@ -837,7 +832,7 @@ public class BeanUtilTest {
final Test1 t1 = new Test1().setStrList(ListUtil.of("list"));
final Test2 t2_hu = new Test2();
BeanUtil.copyProperties(t1, t2_hu, CopyOptions.of().setIgnoreError(true));
Assert.assertNull(t2_hu.getStrList());
Assertions.assertNull(t2_hu.getStrList());
}
@Data
@ -860,7 +855,7 @@ public class BeanUtilTest {
final WkCrmCustomer customer = new WkCrmCustomer();
BeanUtil.copyProperties(map, customer);
Assert.assertNull(customer.getStatusIdUpdateTime());
Assertions.assertNull(customer.getStatusIdUpdateTime());
}
@Data
@ -890,13 +885,13 @@ public class BeanUtilTest {
return map.containsKey(key);
}
}, copyOptions);
Assert.assertEquals("123", pojo.getName());
Assertions.assertEquals("123", pojo.getName());
}
@Test
public void hasGetterTest() {
// https://gitee.com/dromara/hutool/issues/I6M7Z7
final boolean b = BeanUtil.hasGetter(Object.class);
Assert.assertFalse(b);
Assertions.assertFalse(b);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.bean;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class BeanWithReturnThisTest {
@ -12,7 +12,7 @@ public class BeanWithReturnThisTest {
final PropDesc prop = beanDesc.getProp("a");
prop.setValue(bean, "123");
Assert.assertEquals("123", bean.getA());
Assertions.assertEquals("123", bean.getA());
}
static class BeanWithRetuenThis{

View File

@ -1,8 +1,8 @@
package cn.hutool.core.bean;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* {@link DynaBean}单元测试
@ -19,18 +19,18 @@ public class DynaBeanTest {
bean.set("age", 12);
final String name = bean.get("name");
Assert.assertEquals(user.getName(), name);
Assertions.assertEquals(user.getName(), name);
final int age = bean.get("age");
Assert.assertEquals(user.getAge(), age);
Assertions.assertEquals(user.getAge(), age);
//重复包装测试
final DynaBean bean2 = new DynaBean(bean);
final User user2 = bean2.getBean();
Assert.assertEquals(user, user2);
Assertions.assertEquals(user, user2);
//执行指定方法
final Object invoke = bean2.invoke("testMethod");
Assert.assertEquals("test for 李华", invoke);
Assertions.assertEquals("test for 李华", invoke);
}
@ -43,19 +43,19 @@ public class DynaBeanTest {
bean.set("age", age_before);
final String name_after = bean.get("name");
Assert.assertEquals(name_before, name_after);
Assertions.assertEquals(name_before, name_after);
final int age_after = bean.get("age");
Assert.assertEquals(age_before, age_after);
Assertions.assertEquals(age_before, age_after);
//重复包装测试
final DynaBean bean2 = new DynaBean(bean);
final User user2 = bean2.getBean();
final User user1 = bean.getBean();
Assert.assertEquals(user1, user2);
Assertions.assertEquals(user1, user2);
//执行指定方法
final Object invoke = bean2.invoke("testMethod");
Assert.assertEquals("test for 李华", invoke);
Assertions.assertEquals("test for 李华", invoke);
}
@ -68,19 +68,19 @@ public class DynaBeanTest {
bean.set("age", age_before);
final String name_after = bean.get("name");
Assert.assertEquals(name_before, name_after);
Assertions.assertEquals(name_before, name_after);
final int age_after = bean.get("age");
Assert.assertEquals(age_before, age_after);
Assertions.assertEquals(age_before, age_after);
//重复包装测试
final DynaBean bean2 = new DynaBean(bean);
final User user2 = bean2.getBean();
final User user1 = bean.getBean();
Assert.assertEquals(user1, user2);
Assertions.assertEquals(user1, user2);
//执行指定方法
final Object invoke = bean2.invoke("testMethod");
Assert.assertEquals("test for 李华", invoke);
Assertions.assertEquals("test for 李华", invoke);
}
@Data

View File

@ -4,8 +4,8 @@ import cn.hutool.core.annotation.Alias;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.map.MapUtil;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.Serializable;
@ -22,8 +22,8 @@ public class Issue1687Test {
final SysUser sysUser = BeanUtil.toBean(sysUserFb, SysUser.class);
// 别名错位导致找不到字段
Assert.assertNull(sysUser.getDepart());
Assert.assertEquals(new Long(456L), sysUser.getOrgId());
Assertions.assertNull(sysUser.getDepart());
Assertions.assertEquals(new Long(456L), sysUser.getOrgId());
}
@Test
@ -38,8 +38,8 @@ public class Issue1687Test {
);
final SysUser sysUser = BeanUtil.toBean(sysUserFb, SysUser.class, copyOptions);
Assert.assertEquals(new Long(123L), sysUser.getDepart());
Assert.assertEquals(new Long(456L), sysUser.getOrgId());
Assertions.assertEquals(new Long(123L), sysUser.getDepart());
Assertions.assertEquals(new Long(456L), sysUser.getOrgId());
}
@Data

View File

@ -1,7 +1,7 @@
package cn.hutool.core.bean;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* https://github.com/dromara/hutool/issues/2009
@ -71,6 +71,6 @@ public class Issue2009Test {
final A a = new A();
BeanUtil.copyProperties(b, a);
Assert.assertEquals(b.getPapss(), a.getPapss());
Assertions.assertEquals(b.getPapss(), a.getPapss());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.bean;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* https://github.com/dromara/hutool/issues/2082<br>
@ -14,7 +14,7 @@ public class Issue2082Test {
public void toBeanTest() {
final TestBean2 testBean2 = new TestBean2();
final TestBean test = BeanUtil.toBean(testBean2, TestBean.class);
Assert.assertNull(test.getId());
Assertions.assertNull(test.getId());
}
@Data

View File

@ -3,8 +3,8 @@ package cn.hutool.core.bean;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.text.NamingCase;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
@ -27,10 +27,10 @@ public class Issue2202Test {
return entry;
}));
Assert.assertEquals("serial", case1.getWechatpaySerial());
Assert.assertEquals("nonce", case1.getWechatpayNonce());
Assert.assertEquals("timestamp", case1.getWechatpayTimestamp());
Assert.assertEquals("signature", case1.getWechatpaySignature());
Assertions.assertEquals("serial", case1.getWechatpaySerial());
Assertions.assertEquals("nonce", case1.getWechatpayNonce());
Assertions.assertEquals("timestamp", case1.getWechatpayTimestamp());
Assertions.assertEquals("signature", case1.getWechatpaySignature());
}
@Data

View File

@ -3,8 +3,8 @@ package cn.hutool.core.bean;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.lang.Console;
import lombok.Data;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
@ -12,7 +12,7 @@ import java.util.List;
public class Issue2649Test {
@Test
@Ignore
@Disabled
public void toListTest() {
final List<View1> view1List = new ArrayList<>();
for (int i = 0; i < 200; i++) {

View File

@ -2,8 +2,8 @@ package cn.hutool.core.bean;
import cn.hutool.core.collection.CollUtil;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.EnumSet;
@ -29,14 +29,14 @@ public class Issue2683Test {
final Vto v1 = new Vto();
v1.setVersions(EnumSet.allOf(Version.class));
final Vto v2 = BeanUtil.copyProperties(v1, Vto.class);
Assert.assertNotNull(v2);
Assert.assertNotNull(v2.getVersions());
Assertions.assertNotNull(v2);
Assertions.assertNotNull(v2.getVersions());
}
@Test
public void enumSetTest() {
final Collection<Version> objects = CollUtil.create(EnumSet.class, Version.class);
Assert.assertNotNull(objects);
Assert.assertTrue(EnumSet.class.isAssignableFrom(objects.getClass()));
Assertions.assertNotNull(objects);
Assertions.assertTrue(EnumSet.class.isAssignableFrom(objects.getClass()));
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.bean;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class IssueI5DDZXTest {
@Test
@ -10,7 +10,7 @@ public class IssueI5DDZXTest {
// 对于final字段private由于没有提供setter方法是无法实现属性赋值的如果设置为public即可
final TeStudent student = new TeStudent("Hutool");
final TePerson tePerson = BeanUtil.copyProperties(student, TePerson.class);
Assert.assertEquals("Hutool", tePerson.getName());
Assertions.assertEquals("Hutool", tePerson.getName());
}
@Data

View File

@ -1,8 +1,8 @@
package cn.hutool.core.bean.copier;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
@ -13,14 +13,14 @@ public class BeanCopierTest {
final A a = new A();
HashMap<Object, Object> map = BeanCopier.of(a, new HashMap<>(), CopyOptions.of()).copy();
Assert.assertEquals(1, map.size());
Assert.assertTrue(map.containsKey("value"));
Assert.assertNull(map.get("value"));
Assertions.assertEquals(1, map.size());
Assertions.assertTrue(map.containsKey("value"));
Assertions.assertNull(map.get("value"));
// 忽略null的情况下空字段不写入map
map = BeanCopier.of(a, new HashMap<>(), CopyOptions.of().ignoreNullValue()).copy();
Assert.assertFalse(map.containsKey("value"));
Assert.assertEquals(0, map.size());
Assertions.assertFalse(map.containsKey("value"));
Assertions.assertEquals(0, map.size());
}
/**
@ -36,7 +36,7 @@ public class BeanCopierTest {
final BeanCopier<B> copier = BeanCopier.of(a, b, CopyOptions.of().setOverride(false));
copier.copy();
Assert.assertEquals("abc", b.getValue());
Assertions.assertEquals("abc", b.getValue());
}
/**
@ -52,7 +52,7 @@ public class BeanCopierTest {
final BeanCopier<B> copier = BeanCopier.of(a, b, CopyOptions.of());
copier.copy();
Assert.assertEquals("123", b.getValue());
Assertions.assertEquals("123", b.getValue());
}
@Data
@ -77,12 +77,12 @@ public class BeanCopierTest {
BeanCopier<B> copier = BeanCopier.of(a, b, CopyOptions.of().setOverride(false));
copier.copy();
Assert.assertEquals("123", b.getValue());
Assertions.assertEquals("123", b.getValue());
b.setValue(null);
copier = BeanCopier.of(a, b, CopyOptions.of().setOverride(false));
copier.copy();
Assert.assertEquals("abc", b.getValue());
Assertions.assertEquals("abc", b.getValue());
}
}

View File

@ -6,9 +6,9 @@ import cn.hutool.core.cache.impl.WeakCache;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ConcurrencyTester;
import cn.hutool.core.thread.ThreadUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicInteger;
@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class CacheConcurrentTest {
@Test
@Ignore
@Disabled
public void fifoCacheTest() {
final int threadCount = 4000;
final Cache<String, String> cache = new FIFOCache<>(3);
@ -52,7 +52,7 @@ public class CacheConcurrentTest {
}
@Test
@Ignore
@Disabled
public void lruCacheTest() {
final int threadCount = 40000;
final Cache<String, String> cache = new LRUCache<>(1000);
@ -103,6 +103,6 @@ public class CacheConcurrentTest {
});
final long interval = concurrencyTester.getInterval();
// 总耗时应与单次操作耗时在同一个数量级
Assert.assertTrue(interval < delay * 2);
Assertions.assertTrue(interval < delay * 2);
}
}

View File

@ -4,8 +4,8 @@ import cn.hutool.core.cache.impl.TimedCache;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 缓存测试用例
@ -19,8 +19,8 @@ public class CacheTest {
final Cache<String,String> fifoCache = CacheUtil.newFIFOCache(3);
fifoCache.setListener((key, value)->{
// 监听测试此测试中只有key1被移除测试是否监听成功
Assert.assertEquals("key1", key);
Assert.assertEquals("value1", value);
Assertions.assertEquals("key1", key);
Assertions.assertEquals("value1", value);
});
fifoCache.put("key1", "value1", DateUnit.SECOND.getMillis() * 3);
@ -30,7 +30,7 @@ public class CacheTest {
//由于缓存容量只有3当加入第四个元素的时候根据FIFO规则最先放入的对象将被移除
final String value1 = fifoCache.get("key1");
Assert.assertNull(value1);
Assertions.assertNull(value1);
}
@Test
@ -39,7 +39,7 @@ public class CacheTest {
for (int i = 0; i < RandomUtil.randomInt(100, 1000); i++) {
fifoCache.put("key" + i, "value" + i);
}
Assert.assertEquals(100, fifoCache.size());
Assertions.assertEquals(100, fifoCache.size());
}
@Test
@ -56,16 +56,16 @@ public class CacheTest {
final String value1 = lfuCache.get("key1");
final String value2 = lfuCache.get("key2");
final String value3 = lfuCache.get("key3");
Assert.assertNotNull(value1);
Assert.assertNull(value2);
Assert.assertNull(value3);
Assertions.assertNotNull(value1);
Assertions.assertNull(value2);
Assertions.assertNull(value3);
}
@Test
public void lfuCacheTest2(){
final Cache<String, String> lfuCache = CacheUtil.newLFUCache(3);
final String s = lfuCache.get(null);
Assert.assertNull(s);
Assertions.assertNull(s);
}
@Test
@ -81,10 +81,10 @@ public class CacheTest {
lruCache.put("key4", "value4", DateUnit.SECOND.getMillis() * 3);
final String value1 = lruCache.get("key1");
Assert.assertNotNull(value1);
Assertions.assertNotNull(value1);
//由于缓存容量只有3当加入第四个元素的时候根据LRU规则最少使用的将被移除2被移除
final String value2 = lruCache.get("key2");
Assert.assertNull(value2);
Assertions.assertNull(value2);
}
@Test
@ -103,20 +103,20 @@ public class CacheTest {
//5毫秒后由于value2设置了5毫秒过期因此只有value2被保留下来
final String value1 = timedCache.get("key1");
Assert.assertNull(value1);
Assertions.assertNull(value1);
final String value2 = timedCache.get("key2");
Assert.assertEquals("value2", value2);
Assertions.assertEquals("value2", value2);
//5毫秒后由于设置了默认过期key3只被保留4毫秒因此为null
final String value3 = timedCache.get("key3");
Assert.assertNull(value3);
Assertions.assertNull(value3);
final String value3Supplier = timedCache.get("key3", () -> "Default supplier");
Assert.assertEquals("Default supplier", value3Supplier);
Assertions.assertEquals("Default supplier", value3Supplier);
// 永不过期
final String value4 = timedCache.get("key4");
Assert.assertEquals("value4", value4);
Assertions.assertEquals("value4", value4);
//取消定时清理
timedCache.cancelPruneSchedule();

View File

@ -1,7 +1,7 @@
package cn.hutool.core.cache;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import cn.hutool.core.cache.file.LFUFileCache;
@ -14,6 +14,6 @@ public class FileCacheTest {
@Test
public void lfuFileCacheTest() {
final LFUFileCache cache = new LFUFileCache(1000, 500, 2000);
Assert.assertNotNull(cache);
Assertions.assertNotNull(cache);
}
}

View File

@ -4,9 +4,9 @@ import cn.hutool.core.cache.impl.LRUCache;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class LRUCacheTest {
@Test
@Ignore
@Disabled
public void putTest(){
//https://github.com/dromara/hutool/issues/2227
final LRUCache<String, String> cache = CacheUtil.newLRUCache(100, 10);
@ -55,7 +55,7 @@ public class LRUCacheTest {
for (int i = 0; i < 10; i++) {
sb1.append(cache.get(i));
}
Assert.assertEquals("0123456789", sb1.toString());
Assertions.assertEquals("0123456789", sb1.toString());
// 新加11此时0最久未使用应该淘汰0
cache.put(11, 11);
@ -64,7 +64,7 @@ public class LRUCacheTest {
for (int i = 0; i < 10; i++) {
sb2.append(cache.get(i));
}
Assert.assertEquals("null123456789", sb2.toString());
Assertions.assertEquals("null123456789", sb2.toString());
}
@Test
@ -82,7 +82,7 @@ public class LRUCacheTest {
cache.put(StrUtil.format("key-{}", i), i);
}
Assert.assertEquals(7, removeCount.get());
Assert.assertEquals(3, cache.size());
Assertions.assertEquals(7, removeCount.get());
Assertions.assertEquals(3, cache.size());
}
}

View File

@ -2,9 +2,9 @@ package cn.hutool.core.cache;
import cn.hutool.core.cache.impl.WeakCache;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class WeakCacheTest {
@ -14,16 +14,16 @@ public class WeakCacheTest {
cache.put("abc", "123");
cache.put("def", "456");
Assert.assertEquals(2, cache.size());
Assertions.assertEquals(2, cache.size());
// 检查被MutableObj包装的key能否正常移除
cache.remove("abc");
Assert.assertEquals(1, cache.size());
Assertions.assertEquals(1, cache.size());
}
@Test
@Ignore
@Disabled
public void removeByGcTest(){
// https://gitee.com/dromara/hutool/issues/I51O7M
final WeakCache<String, String> cache = new WeakCache<>(-1);
@ -31,7 +31,7 @@ public class WeakCacheTest {
cache.put("b", "2");
// 监听
Assert.assertEquals(2, cache.size());
Assertions.assertEquals(2, cache.size());
cache.setListener(Console::log);
// GC测试

View File

@ -1,24 +1,24 @@
package cn.hutool.core.classloader;
import cn.hutool.core.map.Dict;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ClassLoaderUtilTest {
@Test
public void isPresentTest() {
final boolean present = ClassLoaderUtil.isPresent("cn.hutool.core.classloader.ClassLoaderUtil");
Assert.assertTrue(present);
Assertions.assertTrue(present);
}
@Test
public void loadClassTest() {
String name = ClassLoaderUtil.loadClass("java.lang.Thread.State").getName();
Assert.assertEquals("java.lang.Thread$State", name);
Assertions.assertEquals("java.lang.Thread$State", name);
name = ClassLoaderUtil.loadClass("java.lang.Thread$State").getName();
Assert.assertEquals("java.lang.Thread$State", name);
Assertions.assertEquals("java.lang.Thread$State", name);
}
@Test
@ -26,15 +26,15 @@ public class ClassLoaderUtilTest {
final String s = Dict[].class.getName();
final Class<Object> objectClass = ClassLoaderUtil.loadClass(s);
Assert.assertEquals(Dict[].class, objectClass);
Assertions.assertEquals(Dict[].class, objectClass);
}
@Test
public void loadInnerClassTest() {
String name = ClassLoaderUtil.loadClass("cn.hutool.core.classloader.ClassLoaderUtilTest.A").getName();
Assert.assertEquals("cn.hutool.core.classloader.ClassLoaderUtilTest$A", name);
Assertions.assertEquals("cn.hutool.core.classloader.ClassLoaderUtilTest$A", name);
name = ClassLoaderUtil.loadClass("cn.hutool.core.classloader.ClassLoaderUtilTest.A.B").getName();
Assert.assertEquals("cn.hutool.core.classloader.ClassLoaderUtilTest$A$B", name);
Assertions.assertEquals("cn.hutool.core.classloader.ClassLoaderUtilTest$A$B", name);
}
@SuppressWarnings("unused")

View File

@ -3,8 +3,8 @@ package cn.hutool.core.codec;
import cn.hutool.core.codec.binary.Base32;
import cn.hutool.core.util.ByteUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class Base32Test {
@ -12,28 +12,28 @@ public class Base32Test {
public void encodeAndDecodeTest(){
final String a = "伦家是一个非常长的字符串";
final String encode = Base32.encode(a);
Assert.assertEquals("4S6KNZNOW3TJRL7EXCAOJOFK5GOZ5ZNYXDUZLP7HTKCOLLMX46WKNZFYWI======", encode);
Assertions.assertEquals("4S6KNZNOW3TJRL7EXCAOJOFK5GOZ5ZNYXDUZLP7HTKCOLLMX46WKNZFYWI======", encode);
String decodeStr = Base32.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
// 支持小写模式解码
decodeStr = Base32.decodeStr(encode.toLowerCase());
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
public void hexEncodeAndDecodeTest(){
final String a = "伦家是一个非常长的字符串";
final String encode = Base32.encodeHex(ByteUtil.toUtf8Bytes(a));
Assert.assertEquals("SIUADPDEMRJ9HBV4N20E9E5AT6EPTPDON3KPBFV7JA2EBBCNSUMADP5OM8======", encode);
Assertions.assertEquals("SIUADPDEMRJ9HBV4N20E9E5AT6EPTPDON3KPBFV7JA2EBBCNSUMADP5OM8======", encode);
String decodeStr = Base32.decodeStrHex(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
// 支持小写模式解码
decodeStr = Base32.decodeStrHex(encode.toLowerCase());
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
@ -41,13 +41,13 @@ public class Base32Test {
final String a = RandomUtil.randomString(RandomUtil.randomInt(1000));
final String encode = Base32.encode(a);
final String decodeStr = Base32.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
public void decodeTest(){
final String a = "伦家是一个非常长的字符串";
final String decodeStr = Base32.decodeStr("4S6KNZNOW3TJRL7EXCAOJOFK5GOZ5ZNYXDUZLP7HTKCOLLMX46WKNZFYWI");
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.codec;
import cn.hutool.core.codec.binary.Base58;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
@ -12,30 +12,30 @@ public class Base58Test {
public void encodeCheckedTest() {
final String a = "hello world";
String encode = Base58.encodeChecked(0, a.getBytes());
Assert.assertEquals(1 + "3vQB7B6MrGQZaxCuFg4oh", encode);
Assertions.assertEquals(1 + "3vQB7B6MrGQZaxCuFg4oh", encode);
// 无版本位
encode = Base58.encodeChecked(null, a.getBytes());
Assert.assertEquals("3vQB7B6MrGQZaxCuFg4oh", encode);
Assertions.assertEquals("3vQB7B6MrGQZaxCuFg4oh", encode);
}
@Test
public void encodeTest() {
final String a = "hello world";
final String encode = Base58.encode(a.getBytes(StandardCharsets.UTF_8));
Assert.assertEquals("StV1DL6CwTryKyV", encode);
Assertions.assertEquals("StV1DL6CwTryKyV", encode);
}
@Test
public void decodeCheckedTest() {
final String a = "3vQB7B6MrGQZaxCuFg4oh";
byte[] decode = Base58.decodeChecked(1 + a);
Assert.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
Assertions.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
decode = Base58.decodeChecked(a);
Assert.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
Assertions.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
}
@Test
public void testDecode() {
final String a = "StV1DL6CwTryKyV";
final byte[] decode = Base58.decode(a);
Assert.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
Assertions.assertArrayEquals("hello world".getBytes(StandardCharsets.UTF_8),decode);
}
}

View File

@ -2,8 +2,8 @@ package cn.hutool.core.codec;
import cn.hutool.core.codec.binary.Base62;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* Base62单元测试
@ -17,20 +17,20 @@ public class Base62Test {
public void encodeAndDecodeTest() {
final String a = "伦家是一个非常长的字符串66";
final String encode = Base62.encode(a);
Assert.assertEquals("17vKU8W4JMG8dQF8lk9VNnkdMOeWn4rJMva6F0XsLrrT53iKBnqo", encode);
Assertions.assertEquals("17vKU8W4JMG8dQF8lk9VNnkdMOeWn4rJMva6F0XsLrrT53iKBnqo", encode);
final String decodeStr = Base62.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeInvertedTest() {
final String a = "伦家是一个非常长的字符串66";
final String encode = Base62.encodeInverted(a);
Assert.assertEquals("17Vku8w4jmg8Dqf8LK9vnNKDmoEwN4RjmVA6f0xSlRRt53IkbNQO", encode);
Assertions.assertEquals("17Vku8w4jmg8Dqf8LK9vnNKDmoEwN4RjmVA6f0xSlRRt53IkbNQO", encode);
final String decodeStr = Base62.decodeStrInverted(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
@ -38,7 +38,7 @@ public class Base62Test {
final String a = RandomUtil.randomString(RandomUtil.randomInt(1000));
final String encode = Base62.encode(a);
final String decodeStr = Base62.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
@ -46,6 +46,6 @@ public class Base62Test {
final String a = RandomUtil.randomString(RandomUtil.randomInt(1000));
final String encode = Base62.encodeInverted(a);
final String decodeStr = Base62.decodeStrInverted(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
}

View File

@ -4,8 +4,8 @@ import cn.hutool.core.codec.binary.Base64;
import cn.hutool.core.util.ByteUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* Base64单元测试
@ -17,59 +17,59 @@ public class Base64Test {
@Test
public void isBase64Test(){
Assert.assertTrue(Base64.isBase64(Base64.encode(RandomUtil.randomString(1000))));
Assertions.assertTrue(Base64.isBase64(Base64.encode(RandomUtil.randomString(1000))));
}
@Test
public void isBase64Test2(){
String base64 = "dW1kb3MzejR3bmljM2J6djAyZzcwbWk5M213Nnk3cWQ3eDJwOHFuNXJsYmMwaXhxbmg0dmxrcmN0anRkbmd3\n" +
"ZzcyZWFwanI2NWNneTg2dnp6cmJoMHQ4MHpxY2R6c3pjazZtaQ==";
Assert.assertTrue(Base64.isBase64(base64));
Assertions.assertTrue(Base64.isBase64(base64));
// '=' 不位于末尾
base64 = "dW1kb3MzejR3bmljM2J6=djAyZzcwbWk5M213Nnk3cWQ3eDJwOHFuNXJsYmMwaXhxbmg0dmxrcmN0anRkbmd3\n" +
"ZzcyZWFwanI2NWNneTg2dnp6cmJoMHQ4MHpxY2R6c3pjazZtaQ=";
Assert.assertFalse(Base64.isBase64(base64));
Assertions.assertFalse(Base64.isBase64(base64));
}
@Test
public void encodeAndDecodeTest() {
final String a = "伦家是一个非常长的字符串66";
final String encode = Base64.encode(a);
Assert.assertEquals("5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5LiyNjY=", encode);
Assertions.assertEquals("5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5LiyNjY=", encode);
final String decodeStr = Base64.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeWithoutPaddingTest() {
final String a = "伦家是一个非常长的字符串66";
final String encode = Base64.encodeWithoutPadding(ByteUtil.toUtf8Bytes(a));
Assert.assertEquals("5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5LiyNjY", encode);
Assertions.assertEquals("5Lym5a625piv5LiA5Liq6Z2e5bi46ZW/55qE5a2X56ym5LiyNjY", encode);
final String decodeStr = Base64.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeTest2() {
final String a = "a61a5db5a67c01445ca2-HZ20181120172058/pdf/中国电信影像云单体网关Docker版-V1.2.pdf";
final String encode = Base64.encode(a, CharsetUtil.UTF_8);
Assert.assertEquals("YTYxYTVkYjVhNjdjMDE0NDVjYTItSFoyMDE4MTEyMDE3MjA1OC9wZGYv5Lit5Zu955S15L+h5b2x5YOP5LqR5Y2V5L2T572R5YWzRG9ja2Vy54mILVYxLjIucGRm", encode);
Assertions.assertEquals("YTYxYTVkYjVhNjdjMDE0NDVjYTItSFoyMDE4MTEyMDE3MjA1OC9wZGYv5Lit5Zu955S15L+h5b2x5YOP5LqR5Y2V5L2T572R5YWzRG9ja2Vy54mILVYxLjIucGRm", encode);
final String decodeStr = Base64.decodeStr(encode, CharsetUtil.UTF_8);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeTest3() {
final String a = ":";
final String encode = Base64.encode(a);
Assert.assertEquals("Og==", encode);
Assertions.assertEquals("Og==", encode);
final String decodeStr = Base64.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
Assertions.assertEquals(a, decodeStr);
}
@Test
@ -78,7 +78,7 @@ public class Base64Test {
final String result = Base64.encode(orderDescription, CharsetUtil.GBK);
final String s = Base64.decodeStr(result, CharsetUtil.GBK);
Assert.assertEquals(orderDescription, s);
Assertions.assertEquals(orderDescription, s);
}
@Test
@ -88,6 +88,6 @@ public class Base64Test {
// Console.log(encode);
final String decodeStr = Base64.decodeStr(encode);
Assert.assertEquals(str, decodeStr);
Assertions.assertEquals(str, decodeStr);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.codec;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class CaesarTest {
@ -10,9 +10,9 @@ public class CaesarTest {
final String str = "1f2e9df6131b480b9fdddc633cf24996";
final String encode = Caesar.encode(str, 3);
Assert.assertEquals("1H2G9FH6131D480D9HFFFE633EH24996", encode);
Assertions.assertEquals("1H2G9FH6131D480D9HFFFE633EH24996", encode);
final String decode = Caesar.decode(encode, 3);
Assert.assertEquals(str, decode);
Assertions.assertEquals(str, decode);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.codec;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class HashidsTest {
@Test
@ -11,10 +11,10 @@ public class HashidsTest {
final String encoded2 = hashids.encodeFromHex("0x507f1f77bcf86cd799439011");
final String encoded3 = hashids.encodeFromHex("0X507f1f77bcf86cd799439011");
Assert.assertEquals("R2qnd2vkOJTXm7XV7yq4", encoded1);
Assert.assertEquals(encoded1, encoded2);
Assert.assertEquals(encoded1, encoded3);
Assertions.assertEquals("R2qnd2vkOJTXm7XV7yq4", encoded1);
Assertions.assertEquals(encoded1, encoded2);
Assertions.assertEquals(encoded1, encoded3);
final String decoded = hashids.decodeToHex(encoded1);
Assert.assertEquals("507f1f77bcf86cd799439011", decoded);
Assertions.assertEquals("507f1f77bcf86cd799439011", decoded);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.codec;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class MorseTest {
@ -11,23 +11,23 @@ public class MorseTest {
public void test0() {
final String text = "Hello World!";
final String morse = "...././.-../.-../---/-...../.--/---/.-./.-../-../-.-.--/";
Assert.assertEquals(morse, morseCoder.encode(text));
Assert.assertEquals(morseCoder.decode(morse), text.toUpperCase());
Assertions.assertEquals(morse, morseCoder.encode(text));
Assertions.assertEquals(morseCoder.decode(morse), text.toUpperCase());
}
@Test
public void test1() {
final String text = "你好,世界!";
final String morse = "-..----.--...../-.--..-.-----.-/--------....--../-..---....-.--./---.-.-.-..--../--------.......-/";
Assert.assertEquals(morseCoder.encode(text), morse);
Assert.assertEquals(morseCoder.decode(morse), text);
Assertions.assertEquals(morseCoder.encode(text), morse);
Assertions.assertEquals(morseCoder.decode(morse), text);
}
@Test
public void test2() {
final String text = "こんにちは";
final String morse = "--.....-.-..--/--....-..-..--/--.....--.-.--/--.....--....-/--.....--.----/";
Assert.assertEquals(morseCoder.encode(text), morse);
Assert.assertEquals(morseCoder.decode(morse), text);
Assertions.assertEquals(morseCoder.encode(text), morse);
Assertions.assertEquals(morseCoder.decode(morse), text);
}
}

View File

@ -1,18 +1,18 @@
package cn.hutool.core.codec;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class PercentCodecTest {
@Test
public void isSafeTest(){
PercentCodec codec = PercentCodec.Builder.of("=").build();
Assert.assertTrue(codec.isSafe('='));
Assertions.assertTrue(codec.isSafe('='));
codec = PercentCodec.Builder.of("=").or(PercentCodec.Builder.of("abc").build()).build();
Assert.assertTrue(codec.isSafe('a'));
Assert.assertTrue(codec.isSafe('b'));
Assert.assertTrue(codec.isSafe('c'));
Assertions.assertTrue(codec.isSafe('a'));
Assertions.assertTrue(codec.isSafe('b'));
Assertions.assertTrue(codec.isSafe('c'));
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.codec;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class PunyCodeTest {
@ -9,11 +9,11 @@ public class PunyCodeTest {
public void encodeDecodeTest() {
final String text = "Hutool编码器";
final String strPunyCode = PunyCode.encode(text);
Assert.assertEquals("Hutool-ux9js33tgln", strPunyCode);
Assertions.assertEquals("Hutool-ux9js33tgln", strPunyCode);
String decode = PunyCode.decode("Hutool-ux9js33tgln");
Assert.assertEquals(text, decode);
Assertions.assertEquals(text, decode);
decode = PunyCode.decode("xn--Hutool-ux9js33tgln");
Assert.assertEquals(text, decode);
Assertions.assertEquals(text, decode);
}
@Test
@ -21,7 +21,7 @@ public class PunyCodeTest {
// 无需编码和解码
String text = "Hutool";
String strPunyCode = PunyCode.encode(text);
Assert.assertEquals("Hutool", strPunyCode);
Assertions.assertEquals("Hutool", strPunyCode);
}
@Test
@ -29,10 +29,10 @@ public class PunyCodeTest {
// 全中文
final String text = "百度.中国";
final String strPunyCode = PunyCode.encodeDomain(text);
Assert.assertEquals("xn--wxtr44c.xn--fiqs8s", strPunyCode);
Assertions.assertEquals("xn--wxtr44c.xn--fiqs8s", strPunyCode);
final String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(text, decode);
Assertions.assertEquals(text, decode);
}
@Test
@ -40,10 +40,10 @@ public class PunyCodeTest {
// 中英文分段
final String text = "hutool.中国";
final String strPunyCode = PunyCode.encodeDomain(text);
Assert.assertEquals("hutool.xn--fiqs8s", strPunyCode);
Assertions.assertEquals("hutool.xn--fiqs8s", strPunyCode);
final String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(text, decode);
Assertions.assertEquals(text, decode);
}
@Test
@ -51,18 +51,18 @@ public class PunyCodeTest {
// 中英文混合
final String text = "hutool工具.中国";
final String strPunyCode = PunyCode.encodeDomain(text);
Assert.assertEquals("xn--hutool-up2j943f.xn--fiqs8s", strPunyCode);
Assertions.assertEquals("xn--hutool-up2j943f.xn--fiqs8s", strPunyCode);
final String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(text, decode);
Assertions.assertEquals(text, decode);
}
@Test
public void encodeEncodeDomainTest2(){
String domain = "赵新虎.com";
String strPunyCode = PunyCode.encodeDomain(domain);
Assert.assertEquals("xn--efvz93e52e.com", strPunyCode);
Assertions.assertEquals("xn--efvz93e52e.com", strPunyCode);
String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(domain, decode);
Assertions.assertEquals(domain, decode);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.codec;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class RotTest {
@ -10,9 +10,9 @@ public class RotTest {
final String str = "1f2e9df6131b480b9fdddc633cf24996";
final String encode13 = Rot.encode13(str);
Assert.assertEquals("4s5r2qs9464o713o2sqqqp966ps57229", encode13);
Assertions.assertEquals("4s5r2qs9464o713o2sqqqp966ps57229", encode13);
final String decode13 = Rot.decode13(encode13);
Assert.assertEquals(str, decode13);
Assertions.assertEquals(str, decode13);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.codec.hash;
import cn.hutool.core.util.ByteUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class CityHashTest {
@ -10,29 +10,29 @@ public class CityHashTest {
public void hash32Test() {
final CityHash cityHash = CityHash.INSTANCE;
int hv = cityHash.hash32(ByteUtil.toUtf8Bytes(""));
Assert.assertEquals(1290029860, hv);
Assertions.assertEquals(1290029860, hv);
hv = cityHash.hash32(ByteUtil.toUtf8Bytes("你好"));
Assert.assertEquals(1374181357, hv);
Assertions.assertEquals(1374181357, hv);
hv = cityHash.hash32(ByteUtil.toUtf8Bytes("见到你很高兴"));
Assert.assertEquals(1475516842, hv);
Assertions.assertEquals(1475516842, hv);
hv = cityHash.hash32(ByteUtil.toUtf8Bytes("我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件"));
Assert.assertEquals(0x51020cae, hv);
Assertions.assertEquals(0x51020cae, hv);
}
@Test
public void hash64Test() {
final CityHash cityHash = CityHash.INSTANCE;
long hv = cityHash.hash64(ByteUtil.toUtf8Bytes(""));
Assert.assertEquals(-4296898700418225525L, hv);
Assertions.assertEquals(-4296898700418225525L, hv);
hv = cityHash.hash64(ByteUtil.toUtf8Bytes("你好"));
Assert.assertEquals(-4294276205456761303L, hv);
Assertions.assertEquals(-4294276205456761303L, hv);
hv = cityHash.hash64(ByteUtil.toUtf8Bytes("见到你很高兴"));
Assert.assertEquals(272351505337503793L, hv);
Assertions.assertEquals(272351505337503793L, hv);
hv = cityHash.hash64(ByteUtil.toUtf8Bytes("我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件"));
Assert.assertEquals(-8234735310919228703L, hv);
Assertions.assertEquals(-8234735310919228703L, hv);
}
}

View File

@ -1,36 +1,36 @@
package cn.hutool.core.codec.hash;
import cn.hutool.core.util.ByteUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class MurmurHashTest {
@Test
public void hash32Test() {
int hv = MurmurHash.INSTANCE.hash32(ByteUtil.toUtf8Bytes(""));
Assert.assertEquals(-1898877446, hv);
Assertions.assertEquals(-1898877446, hv);
hv = MurmurHash.INSTANCE.hash32(ByteUtil.toUtf8Bytes("你好"));
Assert.assertEquals(337357348, hv);
Assertions.assertEquals(337357348, hv);
hv = MurmurHash.INSTANCE.hash32(ByteUtil.toUtf8Bytes("见到你很高兴"));
Assert.assertEquals(1101306141, hv);
Assertions.assertEquals(1101306141, hv);
hv = MurmurHash.INSTANCE.hash32(ByteUtil.toUtf8Bytes("我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件"));
Assert.assertEquals(-785444229, hv);
Assertions.assertEquals(-785444229, hv);
}
@Test
public void hash64Test() {
long hv = MurmurHash.INSTANCE.hash64(ByteUtil.toUtf8Bytes(""));
Assert.assertEquals(-1349759534971957051L, hv);
Assertions.assertEquals(-1349759534971957051L, hv);
hv = MurmurHash.INSTANCE.hash64(ByteUtil.toUtf8Bytes("你好"));
Assert.assertEquals(-7563732748897304996L, hv);
Assertions.assertEquals(-7563732748897304996L, hv);
hv = MurmurHash.INSTANCE.hash64(ByteUtil.toUtf8Bytes("见到你很高兴"));
Assert.assertEquals(-766658210119995316L, hv);
Assertions.assertEquals(-766658210119995316L, hv);
hv = MurmurHash.INSTANCE.hash64(ByteUtil.toUtf8Bytes("我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件"));
Assert.assertEquals(-7469283059271653317L, hv);
Assertions.assertEquals(-7469283059271653317L, hv);
}
}

View File

@ -2,8 +2,8 @@ package cn.hutool.core.codec.hash;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.text.split.SplitUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class SimhashTest {
@ -14,10 +14,10 @@ public class SimhashTest {
final Simhash simhash = new Simhash();
final long hash = simhash.hash64(SplitUtil.split(text1, StrUtil.SPACE));
Assert.assertTrue(hash != 0);
Assertions.assertTrue(hash != 0);
simhash.store(hash);
final boolean duplicate = simhash.equals(SplitUtil.split(text2, StrUtil.SPACE));
Assert.assertTrue(duplicate);
Assertions.assertTrue(duplicate);
}
}

View File

@ -3,8 +3,8 @@ package cn.hutool.core.codec.hash.metro;
import cn.hutool.core.codec.HexUtil;
import cn.hutool.core.codec.Number128;
import cn.hutool.core.util.ByteUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -12,79 +12,79 @@ import java.nio.ByteOrder;
public class MetroHash128Test {
@Test
public void testEmpty() {
Assert.assertEquals("5F3CA3D41D1CB4606B14684C65FB6", h128(""));
Assertions.assertEquals("5F3CA3D41D1CB4606B14684C65FB6", h128(""));
}
@Test
public void test1Low() {
Assert.assertEquals("E84D9EA70174C3184AC6E55552310F85", h128("a"));
Assertions.assertEquals("E84D9EA70174C3184AC6E55552310F85", h128("a"));
}
@Test
public void test1High() {
Assert.assertEquals("9A5BCED4C3CA98CADE13388E3C14C215", h128("é"));
Assertions.assertEquals("9A5BCED4C3CA98CADE13388E3C14C215", h128("é"));
}
@Test
public void test2Palindrome() {
Assert.assertEquals("3DDDF558587273E1FD034EC7CC917AC8", h128("aa"));
Assertions.assertEquals("3DDDF558587273E1FD034EC7CC917AC8", h128("aa"));
}
@Test
public void test2() {
Assert.assertEquals("458E6A18B65C38AD2552335402A068A2", h128("ab"));
Assertions.assertEquals("458E6A18B65C38AD2552335402A068A2", h128("ab"));
}
@Test
public void test3PalindromeLow() {
Assert.assertEquals("19725A6E67A8DD1A84E3C844A20DA938", h128("aaa"));
Assertions.assertEquals("19725A6E67A8DD1A84E3C844A20DA938", h128("aaa"));
}
@Test
public void test3PalindromeHigh() {
Assert.assertEquals("1DD9CC1D29B5080D5F9F171FB2C50CBB", h128("ééé"));
Assertions.assertEquals("1DD9CC1D29B5080D5F9F171FB2C50CBB", h128("ééé"));
}
@Test
public void test3() {
Assert.assertEquals("89AB9CDB9FAF7BA71CD86385C1F801A5", h128("abc"));
Assertions.assertEquals("89AB9CDB9FAF7BA71CD86385C1F801A5", h128("abc"));
}
@Test
public void test4Palindrome() {
Assert.assertEquals("AFD0BBB3764CA0539E46B914B8CB8911", h128("poop"));
Assertions.assertEquals("AFD0BBB3764CA0539E46B914B8CB8911", h128("poop"));
}
@Test
public void test4() {
Assert.assertEquals("D11B6DB94FE20E3884F3829AD6613D19", h128("fart"));
Assertions.assertEquals("D11B6DB94FE20E3884F3829AD6613D19", h128("fart"));
}
@Test
public void test5() {
Assert.assertEquals("D45A3A74885F9C842081929D2E9A3A3B", h128("Hello"));
Assertions.assertEquals("D45A3A74885F9C842081929D2E9A3A3B", h128("Hello"));
}
@Test
public void test12() {
Assert.assertEquals("A7CEC59B03A9053BA6009EEEC81E81F5", h128("Hello World!"));
Assertions.assertEquals("A7CEC59B03A9053BA6009EEEC81E81F5", h128("Hello World!"));
}
@Test
public void test31() {
Assert.assertEquals("980CA7496A1B26D24E529DFB2B3A870",
Assertions.assertEquals("980CA7496A1B26D24E529DFB2B3A870",
h128("The Quick Brown Fox Jumped Over"));
}
@Test
public void test32() {
Assert.assertEquals("76663CEA442E22F86A6CB41FBA896B9B",
Assertions.assertEquals("76663CEA442E22F86A6CB41FBA896B9B",
h128("The Quick Brown Fox Jumped Over "));
}
@Test
public void testLonger() {
Assert.assertEquals("7010B2D7C8A3515AE3CA4DBBD9ED30D0",
Assertions.assertEquals("7010B2D7C8A3515AE3CA4DBBD9ED30D0",
h128("The Quick Brown Fox Jumped Over The Lazy Dog"));
}
@ -95,14 +95,14 @@ public class MetroHash128Test {
public void testLittleEndian() {
final ByteBuffer output = ByteBuffer.allocate(16);
MetroHash128.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.LITTLE_ENDIAN);
Assert.assertEquals("C77CE2BFA4ED9F9B0548B2AC5074A297", hex(output.array()));
Assertions.assertEquals("C77CE2BFA4ED9F9B0548B2AC5074A297", hex(output.array()));
}
@Test
public void testBigEndian() {
final ByteBuffer output = ByteBuffer.allocate(16);
MetroHash128.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.BIG_ENDIAN);
Assert.assertEquals("97A27450ACB248059B9FEDA4BFE27CC7", hex(output.array()));
Assertions.assertEquals("97A27450ACB248059B9FEDA4BFE27CC7", hex(output.array()));
}
static String h128(final String input) {

View File

@ -2,8 +2,8 @@ package cn.hutool.core.codec.hash.metro;
import cn.hutool.core.codec.HexUtil;
import cn.hutool.core.util.ByteUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -14,80 +14,80 @@ import java.nio.ByteOrder;
public class MetroHash64Test {
@Test
public void testEmpty() {
Assert.assertEquals("705FB008071E967D", h64(""));
Assertions.assertEquals("705FB008071E967D", h64(""));
}
@Test
public void test1Low() {
Assert.assertEquals("AF6F242B7ED32BCB", h64("a"));
Assertions.assertEquals("AF6F242B7ED32BCB", h64("a"));
}
@Test
public void test1High() {
Assert.assertEquals("D51BA21D219C37B3", h64("é"));
Assertions.assertEquals("D51BA21D219C37B3", h64("é"));
}
@Test
public void test2Palindrome() {
Assert.assertEquals("3CF3A8F204CAE1B6", h64("aa"));
Assertions.assertEquals("3CF3A8F204CAE1B6", h64("aa"));
}
@Test
public void test2() {
Assert.assertEquals("CD2EA2738FC27D98", h64("ab"));
Assertions.assertEquals("CD2EA2738FC27D98", h64("ab"));
}
@Test
public void test3PalindromeLow() {
Assert.assertEquals("E59031D8D046D241", h64("aaa"));
Assertions.assertEquals("E59031D8D046D241", h64("aaa"));
}
@Test
public void test3PalindromeHigh() {
Assert.assertEquals("FE8325DC6F40511D", h64("ééé"));
Assertions.assertEquals("FE8325DC6F40511D", h64("ééé"));
}
@Test
public void test3() {
Assert.assertEquals("ED4F5524E6FAFFBB", h64("abc"));
Assertions.assertEquals("ED4F5524E6FAFFBB", h64("abc"));
}
@Test
public void test4Palindrome() {
Assert.assertEquals("CD77F739885CCB2C", h64("poop"));
Assertions.assertEquals("CD77F739885CCB2C", h64("poop"));
}
@Test
public void test4() {
Assert.assertEquals("B642DCB026D9573C", h64("fart"));
Assertions.assertEquals("B642DCB026D9573C", h64("fart"));
}
@Test
public void test5() {
Assert.assertEquals("A611009FEE6AF8B", h64("Hello"));
Assertions.assertEquals("A611009FEE6AF8B", h64("Hello"));
}
@Test
public void test12() {
Assert.assertEquals("14BCB49B74E3B404", h64("Hello World!"));
Assertions.assertEquals("14BCB49B74E3B404", h64("Hello World!"));
}
@Test
public void test31() {
Assert.assertEquals("D27A7BFACC320E2F",
Assertions.assertEquals("D27A7BFACC320E2F",
h64("The Quick Brown Fox Jumped Over"));
}
@Test
public void test32() {
Assert.assertEquals("C313A3A811EAB43B",
Assertions.assertEquals("C313A3A811EAB43B",
h64("The Quick Brown Fox Jumped Over "));
}
@Test
public void testLonger() {
Assert.assertEquals("C7047C2FCA234C05",
Assertions.assertEquals("C7047C2FCA234C05",
h64("The Quick Brown Fox Jumped Over The Lazy Dog"));
}
@ -98,14 +98,14 @@ public class MetroHash64Test {
public void testLittleEndian() {
final ByteBuffer output = ByteBuffer.allocate(8);
MetroHash64.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.LITTLE_ENDIAN);
Assert.assertEquals("6B753DAE06704BAD", hex(output.array()));
Assertions.assertEquals("6B753DAE06704BAD", hex(output.array()));
}
@Test
public void testBigEndian() {
final ByteBuffer output = ByteBuffer.allocate(8);
MetroHash64.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.BIG_ENDIAN);
Assert.assertEquals("AD4B7006AE3D756B", hex(output.array()));
Assertions.assertEquals("AD4B7006AE3D756B", hex(output.array()));
}
private String h64(final String value) {

View File

@ -6,9 +6,9 @@ import cn.hutool.core.codec.hash.CityHash;
import cn.hutool.core.util.ByteUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* https://gitee.com/dromara/hutool/pulls/532
@ -17,39 +17,39 @@ public class MetroHashTest {
@Test
public void testEmpty() {
Assert.assertEquals("705fb008071e967d", HexUtil.toHex(MetroHash64.of(0).hash64(ByteUtil.toUtf8Bytes(""))));
Assertions.assertEquals("705fb008071e967d", HexUtil.toHex(MetroHash64.of(0).hash64(ByteUtil.toUtf8Bytes(""))));
}
@Test
public void test1Low() {
Assert.assertEquals("AF6F242B7ED32BCB", h64("a"));
Assertions.assertEquals("AF6F242B7ED32BCB", h64("a"));
}
@Test
public void test1High() {
Assert.assertEquals("D51BA21D219C37B3", h64("é"));
Assertions.assertEquals("D51BA21D219C37B3", h64("é"));
}
@Test
public void metroHash64Test() {
final byte[] str = "我是一段测试123".getBytes(CharsetUtil.UTF_8);
final long hash64 = MetroHash64.of(0).hash64(str);
Assert.assertEquals(147395857347476456L, hash64);
Assertions.assertEquals(147395857347476456L, hash64);
}
@Test
public void metroHash128Test() {
final byte[] str = "我是一段测试123".getBytes(CharsetUtil.UTF_8);
final long[] hash128 = MetroHash128.of(0).hash128(str).getLongArray();
Assert.assertEquals(228255164667538345L, hash128[0]);
Assert.assertEquals(-6394585948993412256L, hash128[1]);
Assertions.assertEquals(228255164667538345L, hash128[0]);
Assertions.assertEquals(-6394585948993412256L, hash128[1]);
}
/**
* 数据量越大 MetroHash 优势越明显
*/
@Test
@Ignore
@Disabled
public void bulkHashing64Test() {
final String[] strArray = getRandomStringArray();
final long startCity = System.currentTimeMillis();
@ -73,7 +73,7 @@ public class MetroHashTest {
* 数据量越大 MetroHash 优势越明显
*/
@Test
@Ignore
@Disabled
public void bulkHashing128Test() {
final String[] strArray = getRandomStringArray();
final long startCity = System.currentTimeMillis();

View File

@ -4,8 +4,8 @@ import cn.hutool.core.map.MapUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.*;
import java.util.stream.Collector;
@ -19,54 +19,54 @@ public class CollStreamUtilTest {
@Test
public void testToIdentityMap() {
Map<Long, Student> map = CollStreamUtil.toIdentityMap(null, Student::getStudentId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
final List<Student> list = new ArrayList<>();
map = CollStreamUtil.toIdentityMap(list, Student::getStudentId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
list.add(new Student(1, 1, 1, "张三"));
list.add(new Student(1, 1, 2, "李四"));
list.add(new Student(1, 1, 3, "王五"));
map = CollStreamUtil.toIdentityMap(list, Student::getStudentId);
Assert.assertEquals(map.get(1L).getName(), "张三");
Assert.assertEquals(map.get(2L).getName(), "李四");
Assert.assertEquals(map.get(3L).getName(), "王五");
Assert.assertNull(map.get(4L));
Assertions.assertEquals(map.get(1L).getName(), "张三");
Assertions.assertEquals(map.get(2L).getName(), "李四");
Assertions.assertEquals(map.get(3L).getName(), "王五");
Assertions.assertNull(map.get(4L));
// 测试value为空时
list.add(null);
map = CollStreamUtil.toIdentityMap(list, Student::getStudentId);
Assert.assertNull(map.get(4L));
Assertions.assertNull(map.get(4L));
}
@Test
public void testToMap() {
Map<Long, String> map = CollStreamUtil.toMap(null, Student::getStudentId, Student::getName);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
final List<Student> list = new ArrayList<>();
map = CollStreamUtil.toMap(list, Student::getStudentId, Student::getName);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
list.add(new Student(1, 1, 1, "张三"));
list.add(new Student(1, 1, 2, "李四"));
list.add(new Student(1, 1, 3, "王五"));
map = CollStreamUtil.toMap(list, Student::getStudentId, Student::getName);
Assert.assertEquals(map.get(1L), "张三");
Assert.assertEquals(map.get(2L), "李四");
Assert.assertEquals(map.get(3L), "王五");
Assert.assertNull(map.get(4L));
Assertions.assertEquals(map.get(1L), "张三");
Assertions.assertEquals(map.get(2L), "李四");
Assertions.assertEquals(map.get(3L), "王五");
Assertions.assertNull(map.get(4L));
// 测试value为空时
list.add(new Student(1, 1, 4, null));
map = CollStreamUtil.toMap(list, Student::getStudentId, Student::getName);
Assert.assertNull(map.get(4L));
Assertions.assertNull(map.get(4L));
}
@Test
public void testGroupByKey() {
Map<Long, List<Student>> map = CollStreamUtil.groupByKey(null, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
final List<Student> list = new ArrayList<>();
map = CollStreamUtil.groupByKey(list, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
list.add(new Student(1, 1, 1, "张三"));
list.add(new Student(1, 2, 2, "李四"));
list.add(new Student(2, 1, 1, "擎天柱"));
@ -86,16 +86,16 @@ public class CollStreamUtilTest {
final List<Student> class3 = new ArrayList<>();
class3.add(new Student(2, 3, 2, "霸天虎"));
compare.put(3L, class3);
Assert.assertEquals(map, compare);
Assertions.assertEquals(map, compare);
}
@Test
public void testGroupBy2Key() {
Map<Long, Map<Long, List<Student>>> map = CollStreamUtil.groupBy2Key(null, Student::getTermId, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
final List<Student> list = new ArrayList<>();
map = CollStreamUtil.groupBy2Key(list, Student::getTermId, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
list.add(new Student(1, 1, 1, "张三"));
list.add(new Student(1, 2, 2, "李四"));
list.add(new Student(1, 2, 3, "王五"));
@ -125,17 +125,17 @@ public class CollStreamUtilTest {
list22.add(new Student(2, 2, 3, "霸天虎"));
map2.put(2L, list22);
compare.put(2L, map2);
Assert.assertEquals(map, compare);
Assertions.assertEquals(map, compare);
}
@Test
public void testGroup2Map() {
Map<Long, Map<Long, Student>> map = CollStreamUtil.group2Map(null, Student::getTermId, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
final List<Student> list = new ArrayList<>();
map = CollStreamUtil.group2Map(list, Student::getTermId, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
list.add(new Student(1, 1, 1, "张三"));
list.add(new Student(1, 2, 1, "李四"));
list.add(new Student(2, 2, 1, "王五"));
@ -148,7 +148,7 @@ public class CollStreamUtilTest {
final Map<Long, Student> map2 = new HashMap<>();
map2.put(2L, new Student(2, 2, 1, "王五"));
compare.put(2L, map2);
Assert.assertEquals(compare, map);
Assertions.assertEquals(compare, map);
// 对null友好
final Map<Long, Map<Long, Student>> termIdClassIdStudentMap = CollStreamUtil.group2Map(Arrays.asList(null, new Student(2, 2, 1, "王五")), Student::getTermId, Student::getClassId);
@ -158,17 +158,17 @@ public class CollStreamUtilTest {
put(null, MapUtil.empty());
put(2L, MapUtil.of(2L, new Student(2, 2, 1, "王五")));
}};
Assert.assertEquals(termIdClassIdStudentCompareMap, termIdClassIdStudentMap);
Assertions.assertEquals(termIdClassIdStudentCompareMap, termIdClassIdStudentMap);
}
@Test
public void testGroupKeyValue() {
Map<Long, List<Long>> map = CollStreamUtil.groupKeyValue(null, Student::getTermId, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
final List<Student> list = new ArrayList<>();
map = CollStreamUtil.groupKeyValue(list, Student::getTermId, Student::getClassId);
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
list.add(new Student(1, 1, 1, "张三"));
list.add(new Student(1, 2, 1, "李四"));
list.add(new Student(2, 2, 1, "王五"));
@ -177,7 +177,7 @@ public class CollStreamUtilTest {
final Map<Long, List<Long>> compare = new HashMap<>();
compare.put(1L, Arrays.asList(1L, 2L));
compare.put(2L, Collections.singletonList(2L));
Assert.assertEquals(compare, map);
Assertions.assertEquals(compare, map);
}
@Test
@ -186,12 +186,12 @@ public class CollStreamUtilTest {
// 参数null测试
Map<Long, List<Student>> map = CollStreamUtil.groupBy(null, Student::getTermId, Collectors.toList());
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
// 参数空数组测试
final List<Student> list = new ArrayList<>();
map = CollStreamUtil.groupBy(list, Student::getTermId, Collectors.toList());
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
// 放入元素
list.add(new Student(1, 1, 1, "张三"));
@ -200,11 +200,11 @@ public class CollStreamUtilTest {
// 先根据termId分组再通过classId比较找出最大值所属的那个Student,返回的Optional
final Map<Long, Optional<Student>> longOptionalMap = CollStreamUtil.groupBy(list, Student::getTermId, Collectors.maxBy(Comparator.comparing(Student::getClassId)));
//noinspection OptionalGetWithoutIsPresent
Assert.assertEquals("李四", longOptionalMap.get(1L).get().getName());
Assertions.assertEquals("李四", longOptionalMap.get(1L).get().getName());
// 先根据termId分组再转换为Map<studentId,name>
final Map<Long, HashMap<Long, String>> groupThen = CollStreamUtil.groupBy(list, Student::getTermId, Collector.of(HashMap::new, (m, v) -> m.put(v.getStudentId(), v.getName()), (l, r) -> l));
Assert.assertEquals(
Assertions.assertEquals(
MapUtil.builder()
.put(1L, MapUtil.builder().put(1L, "李四").build())
.put(2L, MapUtil.builder().put(1L, "王五").build())
@ -219,23 +219,23 @@ public class CollStreamUtilTest {
final Map<Long, List<Student>> termIdStudentsCompareMap = new HashMap<>();
termIdStudentsCompareMap.put(null, Collections.emptyList());
termIdStudentsCompareMap.put(1L, Arrays.asList(new Student(1L, 1, 1, "张三"), new Student(1L, 2, 1, "李四")));
Assert.assertEquals(termIdStudentsCompareMap, termIdStudentsMap);
Assertions.assertEquals(termIdStudentsCompareMap, termIdStudentsMap);
final Map<Long, Long> termIdCountMap = CollStreamUtil.groupBy(students, Student::getTermId, Collectors.counting());
final Map<Long, Long> termIdCountCompareMap = new HashMap<>();
termIdCountCompareMap.put(null, 2L);
termIdCountCompareMap.put(1L, 2L);
Assert.assertEquals(termIdCountCompareMap, termIdCountMap);
Assertions.assertEquals(termIdCountCompareMap, termIdCountMap);
}
@Test
public void testTranslate2List() {
List<String> list = CollStreamUtil.toList(null, Student::getName);
Assert.assertEquals(list, Collections.EMPTY_LIST);
Assertions.assertEquals(list, Collections.EMPTY_LIST);
final List<Student> students = new ArrayList<>();
list = CollStreamUtil.toList(students, Student::getName);
Assert.assertEquals(list, Collections.EMPTY_LIST);
Assertions.assertEquals(list, Collections.EMPTY_LIST);
students.add(new Student(1, 1, 1, "张三"));
students.add(new Student(1, 2, 2, "李四"));
students.add(new Student(2, 1, 1, "李四"));
@ -248,16 +248,16 @@ public class CollStreamUtilTest {
compare.add("李四");
compare.add("李四");
compare.add("霸天虎");
Assert.assertEquals(list, compare);
Assertions.assertEquals(list, compare);
}
@Test
public void testTranslate2Set() {
Set<String> set = CollStreamUtil.toSet(null, Student::getName);
Assert.assertEquals(set, Collections.EMPTY_SET);
Assertions.assertEquals(set, Collections.EMPTY_SET);
final List<Student> students = new ArrayList<>();
set = CollStreamUtil.toSet(students, Student::getName);
Assert.assertEquals(set, Collections.EMPTY_SET);
Assertions.assertEquals(set, Collections.EMPTY_SET);
students.add(new Student(1, 1, 1, "张三"));
students.add(new Student(1, 2, 2, "李四"));
students.add(new Student(2, 1, 1, "李四"));
@ -268,7 +268,7 @@ public class CollStreamUtilTest {
compare.add("张三");
compare.add("李四");
compare.add("霸天虎");
Assert.assertEquals(set, compare);
Assertions.assertEquals(set, compare);
}
@SuppressWarnings("ConstantValue")
@ -277,19 +277,19 @@ public class CollStreamUtilTest {
Map<Long, Student> map1 = null;
Map<Long, Student> map2 = Collections.emptyMap();
Map<Long, String> map = CollStreamUtil.merge(map1, map2, (s1, s2) -> s1.getName() + s2.getName());
Assert.assertEquals(map, Collections.EMPTY_MAP);
Assertions.assertEquals(map, Collections.EMPTY_MAP);
map1 = new HashMap<>();
map1.put(1L, new Student(1, 1, 1, "张三"));
map = CollStreamUtil.merge(map1, map2, this::merge);
final Map<Long, String> temp = new HashMap<>();
temp.put(1L, "张三");
Assert.assertEquals(map, temp);
Assertions.assertEquals(map, temp);
map2 = new HashMap<>();
map2.put(1L, new Student(2, 1, 1, "李四"));
map = CollStreamUtil.merge(map1, map2, this::merge);
final Map<Long, String> compare = new HashMap<>();
compare.put(1L, "张三李四");
Assert.assertEquals(map, compare);
Assertions.assertEquals(map, compare);
}
private String merge(final Student student1, final Student student2) {

View File

@ -4,8 +4,8 @@ import cn.hutool.core.collection.iter.FilterIter;
import cn.hutool.core.collection.iter.IterUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.*;
@ -19,7 +19,7 @@ public class IterUtilTest {
@Test
public void getFirstNonNullTest() {
final List<String> strings = ListUtil.of(null, null, "123", "456", null);
Assert.assertEquals("123", CollUtil.getFirstNoneNull(strings));
Assertions.assertEquals("123", CollUtil.getFirstNoneNull(strings));
}
@Test
@ -27,39 +27,39 @@ public class IterUtilTest {
final List<Car> carList = ListUtil.of(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
final Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList.iterator(), "carNumber");
Assert.assertEquals("大众", carNameMap.get("123").getCarName());
Assert.assertEquals("奔驰", carNameMap.get("345").getCarName());
Assert.assertEquals("路虎", carNameMap.get("567").getCarName());
Assertions.assertEquals("大众", carNameMap.get("123").getCarName());
Assertions.assertEquals("奔驰", carNameMap.get("345").getCarName());
Assertions.assertEquals("路虎", carNameMap.get("567").getCarName());
}
@Test
public void joinTest() {
final List<String> list = ListUtil.of("1", "2", "3", "4");
final String join = IterUtil.join(list.iterator(), ":");
Assert.assertEquals("1:2:3:4", join);
Assertions.assertEquals("1:2:3:4", join);
final List<Integer> list1 = ListUtil.of(1, 2, 3, 4);
final String join1 = IterUtil.join(list1.iterator(), ":");
Assert.assertEquals("1:2:3:4", join1);
Assertions.assertEquals("1:2:3:4", join1);
// 包装每个节点
final List<String> list2 = ListUtil.of("1", "2", "3", "4");
final String join2 = IterUtil.join(list2.iterator(), ":", "\"", "\"");
Assert.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
Assertions.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
}
@Test
public void joinWithFuncTest() {
final List<String> list = ListUtil.of("1", "2", "3", "4");
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
Assert.assertEquals("1:2:3:4", join);
Assertions.assertEquals("1:2:3:4", join);
}
@Test
public void joinWithNullTest() {
final List<String> list = ListUtil.of("1", null, "3", "4");
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
Assert.assertEquals("1:null:3:4", join);
Assertions.assertEquals("1:null:3:4", join);
}
@Test
@ -70,7 +70,7 @@ public class IterUtilTest {
final Map<String, List<String>> testMap = IterUtil.toListMap(Arrays.asList("and", "brave", "back"),
v -> v.substring(0, 1));
Assert.assertEquals(testMap, expectedMap);
Assertions.assertEquals(testMap, expectedMap);
}
@Test
@ -84,14 +84,14 @@ public class IterUtilTest {
expectedMap.put("456", benz);
final Map<String, Car> testMap = IterUtil.toMap(Arrays.asList(bmw, benz), Car::getCarNumber);
Assert.assertEquals(expectedMap, testMap);
Assertions.assertEquals(expectedMap, testMap);
}
@Test
public void getElementTypeTest() {
final List<Integer> integers = Arrays.asList(null, 1);
final Class<?> elementType = IterUtil.getElementType(integers);
Assert.assertEquals(Integer.class, elementType);
Assertions.assertEquals(Integer.class, elementType);
}
@Data
@ -108,8 +108,8 @@ public class IterUtilTest {
IterUtil.remove(obj.iterator(), (e)-> false == obj2.contains(e));
Assert.assertEquals(1, obj.size());
Assert.assertEquals("3", obj.get(0));
Assertions.assertEquals(1, obj.size());
Assertions.assertEquals("3", obj.get(0));
}
@Test
@ -119,8 +119,8 @@ public class IterUtilTest {
final FilterIter<String> filtered = IterUtil.filtered(obj.iterator(), obj2::contains);
Assert.assertEquals("3", filtered.next());
Assert.assertFalse(filtered.hasNext());
Assertions.assertEquals("3", filtered.next());
Assertions.assertFalse(filtered.hasNext());
}
@Test
@ -130,14 +130,14 @@ public class IterUtilTest {
final List<String> filtered = IterUtil.filterToList(obj.iterator(), obj2::contains);
Assert.assertEquals(1, filtered.size());
Assert.assertEquals("3", filtered.get(0));
Assertions.assertEquals(1, filtered.size());
Assertions.assertEquals("3", filtered.get(0));
}
@Test
public void getTest() {
final HashSet<String> set = SetUtil.ofLinked("A", "B", "C", "D");
final String str = IterUtil.get(set.iterator(), 2);
Assert.assertEquals("C", str);
Assertions.assertEquals("C", str);
}
}

View File

@ -6,9 +6,9 @@ import cn.hutool.core.lang.page.PageInfo;
import cn.hutool.core.util.RandomUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
@ -18,22 +18,22 @@ public class ListUtilTest {
@Test
public void partitionTest() {
List<List<Object>> lists = ListUtil.partition(null, 3);
Assert.assertEquals(ListUtil.empty(), lists);
Assertions.assertEquals(ListUtil.empty(), lists);
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 1);
Assert.assertEquals("[[1], [2], [3], [4]]", lists.toString());
Assertions.assertEquals("[[1], [2], [3], [4]]", lists.toString());
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 2);
Assert.assertEquals("[[1, 2], [3, 4]]", lists.toString());
Assertions.assertEquals("[[1, 2], [3, 4]]", lists.toString());
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 3);
Assert.assertEquals("[[1, 2, 3], [4]]", lists.toString());
Assertions.assertEquals("[[1, 2, 3], [4]]", lists.toString());
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 4);
Assert.assertEquals("[[1, 2, 3, 4]]", lists.toString());
Assertions.assertEquals("[[1, 2, 3, 4]]", lists.toString());
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 5);
Assert.assertEquals("[[1, 2, 3, 4]]", lists.toString());
Assertions.assertEquals("[[1, 2, 3, 4]]", lists.toString());
}
@Test
@Ignore
@Disabled
public void partitionBenchTest() {
final List<String> list = new ArrayList<>();
CollUtil.padRight(list, RandomUtil.randomInt(1000_0000, 1_0000_0000), "test");
@ -51,7 +51,7 @@ public class ListUtilTest {
final List<List<String>> ListSplitResult = ListUtil.partition(list, size);
stopWatch.stop();
Assert.assertEquals(CollSplitResult, ListSplitResult);
Assertions.assertEquals(CollSplitResult, ListSplitResult);
Console.log(stopWatch.prettyPrint());
}
@ -59,45 +59,47 @@ public class ListUtilTest {
@Test
public void splitAvgTest() {
List<List<Object>> lists = ListUtil.avgPartition(null, 3);
Assert.assertEquals(ListUtil.empty(), lists);
Assertions.assertEquals(ListUtil.empty(), lists);
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 1);
Assert.assertEquals("[[1, 2, 3, 4]]", lists.toString());
Assertions.assertEquals("[[1, 2, 3, 4]]", lists.toString());
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 2);
Assert.assertEquals("[[1, 2], [3, 4]]", lists.toString());
Assertions.assertEquals("[[1, 2], [3, 4]]", lists.toString());
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 3);
Assert.assertEquals("[[1, 2], [3], [4]]", lists.toString());
Assertions.assertEquals("[[1, 2], [3], [4]]", lists.toString());
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 4);
Assert.assertEquals("[[1], [2], [3], [4]]", lists.toString());
Assertions.assertEquals("[[1], [2], [3], [4]]", lists.toString());
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3), 5);
Assert.assertEquals("[[1], [2], [3], [], []]", lists.toString());
Assertions.assertEquals("[[1], [2], [3], [], []]", lists.toString());
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3), 2);
Assert.assertEquals("[[1, 2], [3]]", lists.toString());
Assertions.assertEquals("[[1, 2], [3]]", lists.toString());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void splitAvgNotZero() {
// limit不能小于等于0
ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 0);
Assertions.assertThrows(IllegalArgumentException.class, ()->{
// limit不能小于等于0
ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 0);
});
}
@Test
public void editTest() {
final List<String> a = ListUtil.ofLinked("1", "2", "3");
final List<String> filter = CollUtil.edit(a, str -> "edit" + str);
Assert.assertEquals("edit1", filter.get(0));
Assert.assertEquals("edit2", filter.get(1));
Assert.assertEquals("edit3", filter.get(2));
Assertions.assertEquals("edit1", filter.get(0));
Assertions.assertEquals("edit2", filter.get(1));
Assertions.assertEquals("edit3", filter.get(2));
}
@Test
public void indexOfAll() {
final List<String> a = ListUtil.ofLinked("1", "2", "3", "4", "3", "2", "1");
final int[] indexArray = CollUtil.indexOfAll(a, "2"::equals);
Assert.assertArrayEquals(new int[]{1, 5}, indexArray);
Assertions.assertArrayEquals(new int[]{1, 5}, indexArray);
final int[] indexArray2 = CollUtil.indexOfAll(a, "1"::equals);
Assert.assertArrayEquals(new int[]{0, 6}, indexArray2);
Assertions.assertArrayEquals(new int[]{0, 6}, indexArray2);
}
@Test
@ -109,11 +111,11 @@ public class ListUtilTest {
final int[] a2 = ListUtil.page(a, 1, 2).stream().mapToInt(Integer::valueOf).toArray();
final int[] a3 = ListUtil.page(a, 2, 2).stream().mapToInt(Integer::valueOf).toArray();
final int[] a4 = ListUtil.page(a, 3, 2).stream().mapToInt(Integer::valueOf).toArray();
Assert.assertArrayEquals(new int[]{1, 2}, a_1);
Assert.assertArrayEquals(new int[]{1, 2}, a1);
Assert.assertArrayEquals(new int[]{3, 4}, a2);
Assert.assertArrayEquals(new int[]{5}, a3);
Assert.assertArrayEquals(new int[]{}, a4);
Assertions.assertArrayEquals(new int[]{1, 2}, a_1);
Assertions.assertArrayEquals(new int[]{1, 2}, a1);
Assertions.assertArrayEquals(new int[]{3, 4}, a2);
Assertions.assertArrayEquals(new int[]{5}, a3);
Assertions.assertArrayEquals(new int[]{}, a4);
}
@Test
@ -121,7 +123,7 @@ public class ListUtilTest {
final List<Integer> a = ListUtil.ofLinked(1, 2, 3, 4, 5);
final int[] d1 = ListUtil.page(a, PageInfo.of(a.size(), 8).setFirstPageNo(0).setPageNo(0))
.stream().mapToInt(Integer::valueOf).toArray();
Assert.assertArrayEquals(new int[]{1, 2, 3, 4, 5}, d1);
Assertions.assertArrayEquals(new int[]{1, 2, 3, 4, 5}, d1);
}
@Test
@ -130,9 +132,9 @@ public class ListUtilTest {
// page with consumer
final List<List<Integer>> pageListData = new ArrayList<>();
ListUtil.page(a, 2, pageListData::add);
Assert.assertArrayEquals(new int[]{1, 2}, pageListData.get(0).stream().mapToInt(Integer::valueOf).toArray());
Assert.assertArrayEquals(new int[]{3, 4}, pageListData.get(1).stream().mapToInt(Integer::valueOf).toArray());
Assert.assertArrayEquals(new int[]{5}, pageListData.get(2).stream().mapToInt(Integer::valueOf).toArray());
Assertions.assertArrayEquals(new int[]{1, 2}, pageListData.get(0).stream().mapToInt(Integer::valueOf).toArray());
Assertions.assertArrayEquals(new int[]{3, 4}, pageListData.get(1).stream().mapToInt(Integer::valueOf).toArray());
Assertions.assertArrayEquals(new int[]{5}, pageListData.get(2).stream().mapToInt(Integer::valueOf).toArray());
pageListData.clear();
@ -142,9 +144,9 @@ public class ListUtilTest {
pageList.clear();
}
});
Assert.assertArrayEquals(new int[]{}, pageListData.get(0).stream().mapToInt(Integer::valueOf).toArray());
Assert.assertArrayEquals(new int[]{3, 4}, pageListData.get(1).stream().mapToInt(Integer::valueOf).toArray());
Assert.assertArrayEquals(new int[]{5}, pageListData.get(2).stream().mapToInt(Integer::valueOf).toArray());
Assertions.assertArrayEquals(new int[]{}, pageListData.get(0).stream().mapToInt(Integer::valueOf).toArray());
Assertions.assertArrayEquals(new int[]{3, 4}, pageListData.get(1).stream().mapToInt(Integer::valueOf).toArray());
Assertions.assertArrayEquals(new int[]{5}, pageListData.get(2).stream().mapToInt(Integer::valueOf).toArray());
}
@Test
@ -154,8 +156,8 @@ public class ListUtilTest {
sub.remove(0);
// 对子列表操作不影响原列表
Assert.assertEquals(4, of.size());
Assert.assertEquals(1, sub.size());
Assertions.assertEquals(4, of.size());
Assertions.assertEquals(1, sub.size());
}
@Test
@ -176,18 +178,18 @@ public class ListUtilTest {
);
final List<TestBean> order = ListUtil.sortByProperty(beanList, "order");
Assert.assertEquals("test1", order.get(0).getName());
Assert.assertEquals("test2", order.get(1).getName());
Assert.assertEquals("test3", order.get(2).getName());
Assert.assertEquals("test4", order.get(3).getName());
Assert.assertEquals("test5", order.get(4).getName());
Assertions.assertEquals("test1", order.get(0).getName());
Assertions.assertEquals("test2", order.get(1).getName());
Assertions.assertEquals("test3", order.get(2).getName());
Assertions.assertEquals("test4", order.get(3).getName());
Assertions.assertEquals("test5", order.get(4).getName());
}
@Test
public void swapIndex() {
final List<Integer> list = Arrays.asList(7, 2, 8, 9);
ListUtil.swapTo(list, 8, 1);
Assert.assertEquals(8, (int) list.get(1));
Assertions.assertEquals(8, (int) list.get(1));
}
@Test
@ -201,11 +203,11 @@ public class ListUtilTest {
final List<Map<String, String>> list = Arrays.asList(map1, map2, map3);
ListUtil.swapElement(list, map2, map3);
Map<String, String> map = list.get(2);
Assert.assertEquals("李四", map.get("2"));
Assertions.assertEquals("李四", map.get("2"));
ListUtil.swapElement(list, map2, map1);
map = list.get(0);
Assert.assertEquals("李四", map.get("2"));
Assertions.assertEquals("李四", map.get("2"));
}
@Test
@ -218,10 +220,10 @@ public class ListUtilTest {
list2.add("3");
ListUtil.addAllIfNotContains(list1, list2);
Assert.assertEquals(3, list1.size());
Assert.assertEquals("1", list1.get(0));
Assert.assertEquals("2", list1.get(1));
Assert.assertEquals("3", list1.get(2));
Assertions.assertEquals(3, list1.size());
Assertions.assertEquals("1", list1.get(0));
Assertions.assertEquals("2", list1.get(1));
Assertions.assertEquals("3", list1.get(2));
}
@Test
@ -231,26 +233,26 @@ public class ListUtilTest {
// 替换原值
ListUtil.setOrPadding(list, 0, "a");
Assert.assertEquals("[a]", list.toString());
Assertions.assertEquals("[a]", list.toString());
//append值
ListUtil.setOrPadding(list, 1, "a");
Assert.assertEquals("[a, a]", list.toString());
Assertions.assertEquals("[a, a]", list.toString());
// padding null 后加入值
ListUtil.setOrPadding(list, 3, "a");
Assert.assertEquals(4, list.size());
Assertions.assertEquals(4, list.size());
}
@Test
public void ofCopyOnWriteTest(){
final CopyOnWriteArrayList<String> strings = ListUtil.ofCopyOnWrite(ListUtil.of("a", "b"));
Assert.assertEquals(2, strings.size());
Assertions.assertEquals(2, strings.size());
}
@Test
public void ofCopyOnWriteTest2(){
final CopyOnWriteArrayList<String> strings = ListUtil.ofCopyOnWrite("a", "b");
Assert.assertEquals(2, strings.size());
Assertions.assertEquals(2, strings.size());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.collection;
import cn.hutool.core.map.MapProxy;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
@ -19,14 +19,14 @@ public class MapProxyTest {
final MapProxy mapProxy = new MapProxy(map);
final Integer b = mapProxy.getInt("b");
Assert.assertEquals(new Integer(2), b);
Assertions.assertEquals(new Integer(2), b);
final Set<Object> keys = mapProxy.keySet();
Assert.assertFalse(keys.isEmpty());
Assertions.assertFalse(keys.isEmpty());
final Set<Entry<Object,Object>> entrys = mapProxy.entrySet();
//noinspection ConstantConditions
Assert.assertFalse(entrys.isEmpty());
Assertions.assertFalse(entrys.isEmpty());
}
private interface Student {
@ -41,7 +41,7 @@ public class MapProxyTest {
public void classProxyTest() {
final Student student = MapProxy.of(new HashMap<>()).toProxyBean(Student.class);
student.setName("小明").setAge(18);
Assert.assertEquals(student.getAge(), 18);
Assert.assertEquals(student.getName(), "小明");
Assertions.assertEquals(student.getAge(), 18);
Assertions.assertEquals(student.getName(), "小明");
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.collection;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class MemorySafeLinkedBlockingQueueTest {
@ -10,10 +10,10 @@ public class MemorySafeLinkedBlockingQueueTest {
public void offerTest(){
// 设置初始值达到最大这样任何时候元素都无法加入队列
final MemorySafeLinkedBlockingQueue<String> queue = new MemorySafeLinkedBlockingQueue<>(Long.MAX_VALUE);
Assert.assertFalse(queue.offer(RandomUtil.randomString(RandomUtil.randomInt(100))));
Assertions.assertFalse(queue.offer(RandomUtil.randomString(RandomUtil.randomInt(100))));
// 设定一个很小的值可以成功加入
queue.setMaxFreeMemory(10);
Assert.assertTrue(queue.offer(RandomUtil.randomString(RandomUtil.randomInt(100))));
Assertions.assertTrue(queue.offer(RandomUtil.randomString(RandomUtil.randomInt(100))));
}
}

View File

@ -4,8 +4,8 @@ import cn.hutool.core.collection.iter.LineIter;
import cn.hutool.core.collection.iter.PartitionIter;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.array.ArrayUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
@ -16,7 +16,7 @@ public class PartitionIterTest {
final LineIter lineIter = new LineIter(ResourceUtil.getUtf8Reader("test_lines.csv"));
final PartitionIter<String> iter = new PartitionIter<>(lineIter, 3);
for (final List<String> lines : iter) {
Assert.assertTrue(lines.size() > 0);
Assertions.assertTrue(lines.size() > 0);
}
}
@ -28,6 +28,6 @@ public class PartitionIterTest {
for (final List<Integer> lines : iter) {
max = ArrayUtil.max(max, ArrayUtil.max(lines.toArray(new Integer[0])));
}
Assert.assertEquals(45, max);
Assertions.assertEquals(45, max);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.collection;
import cn.hutool.core.thread.ThreadUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
@ -27,7 +27,7 @@ public class RingIndexUtilTest {
ThreadUtil.concurrencyTest(strList.size(), () -> {
final int index = RingIndexUtil.ringNextIntByObj(strList, atomicInteger);
final String s = strList.get(index);
Assert.assertNotNull(s);
Assertions.assertNotNull(s);
});
}

View File

@ -2,8 +2,8 @@ package cn.hutool.core.collection;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Set;
@ -18,7 +18,7 @@ public class UniqueKeySetTest {
set.add(new UniqueTestBean("id2", "王五", "木星"));
// 后两个ID重复
Assert.assertEquals(2, set.size());
Assertions.assertEquals(2, set.size());
}
@Data

View File

@ -1,7 +1,7 @@
package cn.hutool.core.collection.iter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* test for {@link ArrayIter}
@ -12,39 +12,39 @@ public class ArrayIterTest {
public void testHasNext() {
Integer[] arr = new Integer[]{ 1, 2, 3 };
ArrayIter<Integer> iter = new ArrayIter<>(arr);
Assert.assertTrue(iter.hasNext());
Assertions.assertTrue(iter.hasNext());
}
@Test
public void testNext() {
Integer[] arr = new Integer[]{ 1, 2, 3 };
ArrayIter<Integer> iter = new ArrayIter<>(arr);
Assert.assertEquals((Integer)1, iter.next());
Assert.assertEquals((Integer)2, iter.next());
Assert.assertEquals((Integer)3, iter.next());
Assertions.assertEquals((Integer)1, iter.next());
Assertions.assertEquals((Integer)2, iter.next());
Assertions.assertEquals((Integer)3, iter.next());
}
@Test
public void testRemove() {
Integer[] arr = new Integer[]{ 1, 2, 3 };
ArrayIter<Integer> iter = new ArrayIter<>(arr);
Assert.assertThrows(UnsupportedOperationException.class, iter::remove);
Assertions.assertThrows(UnsupportedOperationException.class, iter::remove);
}
@Test
public void testGetArray() {
Integer[] arr = new Integer[]{ 1, 2, 3 };
ArrayIter<Integer> iter = new ArrayIter<>(arr);
Assert.assertEquals(arr, iter.getArray());
Assertions.assertEquals(arr, iter.getArray());
}
@Test
public void testReset() {
Integer[] arr = new Integer[]{ 1, 2, 3 };
ArrayIter<Integer> iter = new ArrayIter<>(arr);
Assert.assertEquals((Integer)1, iter.next());
Assertions.assertEquals((Integer)1, iter.next());
iter.reset();
Assert.assertEquals((Integer)1, iter.next());
Assertions.assertEquals((Integer)1, iter.next());
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.collection.iter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@ -17,31 +17,31 @@ public class CopiedIterTest {
public void copyOf() {
List<Integer> list = Arrays.asList(1, 2, 3);
Iterator<Integer> iter = list.iterator();
Assert.assertEquals((Integer)1, iter.next());
Assertions.assertEquals((Integer)1, iter.next());
Assert.assertEquals((Integer)2, CopiedIter.copyOf(iter).next());
Assertions.assertEquals((Integer)2, CopiedIter.copyOf(iter).next());
}
@Test
public void hasNext() {
Assert.assertTrue(CopiedIter.copyOf(Arrays.asList(1, 2, 3).iterator()).hasNext());
Assert.assertFalse(CopiedIter.copyOf(Collections.emptyIterator()).hasNext());
Assertions.assertTrue(CopiedIter.copyOf(Arrays.asList(1, 2, 3).iterator()).hasNext());
Assertions.assertFalse(CopiedIter.copyOf(Collections.emptyIterator()).hasNext());
}
@Test
public void next() {
List<Integer> list = Arrays.asList(1, 2, 3);
Iterator<Integer> iter = CopiedIter.copyOf(list.iterator());
Assert.assertEquals((Integer)1, iter.next());
Assert.assertEquals((Integer)2, iter.next());
Assert.assertEquals((Integer)3, iter.next());
Assertions.assertEquals((Integer)1, iter.next());
Assertions.assertEquals((Integer)2, iter.next());
Assertions.assertEquals((Integer)3, iter.next());
}
@Test
public void remove() {
List<Integer> list = Arrays.asList(1, 2, 3);
Iterator<Integer> iter = CopiedIter.copyOf(list.iterator());
Assert.assertThrows(UnsupportedOperationException.class, iter::remove);
Assertions.assertThrows(UnsupportedOperationException.class, iter::remove);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.collection.iter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@ -16,31 +16,31 @@ public class EnumerationIterTest {
public void testHasNext() {
Enumeration<Integer> enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator());
EnumerationIter<Integer> iter = new EnumerationIter<>(enumeration);
Assert.assertTrue(iter.hasNext());
Assert.assertFalse(new EnumerationIter<>(new IteratorEnumeration<>(Collections.emptyIterator())).hasNext());
Assertions.assertTrue(iter.hasNext());
Assertions.assertFalse(new EnumerationIter<>(new IteratorEnumeration<>(Collections.emptyIterator())).hasNext());
}
@Test
public void testNext() {
Enumeration<Integer> enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator());
EnumerationIter<Integer> iter = new EnumerationIter<>(enumeration);
Assert.assertEquals((Integer)1, iter.next());
Assert.assertEquals((Integer)2, iter.next());
Assert.assertEquals((Integer)3, iter.next());
Assertions.assertEquals((Integer)1, iter.next());
Assertions.assertEquals((Integer)2, iter.next());
Assertions.assertEquals((Integer)3, iter.next());
}
@Test
public void testRemove() {
Enumeration<Integer> enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator());
EnumerationIter<Integer> iter = new EnumerationIter<>(enumeration);
Assert.assertThrows(UnsupportedOperationException.class, iter::remove);
Assertions.assertThrows(UnsupportedOperationException.class, iter::remove);
}
@Test
public void testIterator() {
Enumeration<Integer> enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator());
EnumerationIter<Integer> iter = new EnumerationIter<>(enumeration);
Assert.assertSame(iter, iter.iterator());
Assertions.assertSame(iter, iter.iterator());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.collection.iter;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@ -21,42 +21,42 @@ public class FilterIterTest {
count++;
}
}
Assert.assertEquals(2, count);
Assertions.assertEquals(2, count);
}
@Test
public void hasNext() {
Iterator<Integer> iter = new FilterIter<>(Arrays.asList(1, 2, 3).iterator(), i -> true);
Assert.assertTrue(iter.hasNext());
Assertions.assertTrue(iter.hasNext());
iter = new FilterIter<>(Collections.emptyIterator(), i -> true);
Assert.assertFalse(iter.hasNext());
Assertions.assertFalse(iter.hasNext());
}
@Test
public void next() {
// 只保留奇数
Iterator<Integer> iter = new FilterIter<>(Arrays.asList(1, 2, 3).iterator(), i -> (i & 1) == 1);
Assert.assertEquals((Integer)1, iter.next());
Assert.assertEquals((Integer)3, iter.next());
Assertions.assertEquals((Integer)1, iter.next());
Assertions.assertEquals((Integer)3, iter.next());
}
@Test
public void remove() {
Iterator<Integer> iter = new FilterIter<>(Collections.emptyIterator(), i -> true);
Assert.assertThrows(IllegalStateException.class, iter::remove);
Assertions.assertThrows(IllegalStateException.class, iter::remove);
}
@Test
public void getIterator() {
FilterIter<Integer> iter = new FilterIter<>(Collections.emptyIterator(), i -> true);
Assert.assertSame(Collections.emptyIterator(), iter.getIterator());
Assertions.assertSame(Collections.emptyIterator(), iter.getIterator());
}
@Test
public void getFilter() {
Predicate<Integer> predicate = i -> true;
FilterIter<Integer> iter = new FilterIter<>(Collections.emptyIterator(), predicate);
Assert.assertSame(predicate, iter.getFilter());
Assertions.assertSame(predicate, iter.getFilter());
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.collection.iter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@ -17,20 +17,20 @@ public class IterChainTest {
final Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
final Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
IterChain<Integer> iterChain = new IterChain<>();
Assert.assertSame(iterChain, iterChain.addChain(iter1));
Assert.assertSame(iterChain, iterChain.addChain(iter2));
Assert.assertEquals(2, iterChain.allIterators.size());
Assertions.assertSame(iterChain, iterChain.addChain(iter1));
Assertions.assertSame(iterChain, iterChain.addChain(iter2));
Assertions.assertEquals(2, iterChain.allIterators.size());
iterChain = new IterChain<>(iter1, iter2);
Assert.assertEquals(2, iterChain.allIterators.size());
Assertions.assertEquals(2, iterChain.allIterators.size());
}
@Test
public void testHasNext() {
final IterChain<Integer> iterChain = new IterChain<>();
Assert.assertFalse(iterChain.hasNext());
Assert.assertFalse(iterChain.addChain(Collections.emptyIterator()).hasNext());
Assert.assertTrue(iterChain.addChain(Arrays.asList(3, 4).iterator()).hasNext());
Assertions.assertFalse(iterChain.hasNext());
Assertions.assertFalse(iterChain.addChain(Collections.emptyIterator()).hasNext());
Assertions.assertTrue(iterChain.addChain(Arrays.asList(3, 4).iterator()).hasNext());
}
@Test
@ -38,19 +38,19 @@ public class IterChainTest {
final Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
final Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
final IterChain<Integer> iterChain = new IterChain<>();
Assert.assertSame(iterChain, iterChain.addChain(iter1));
Assert.assertSame(iterChain, iterChain.addChain(iter2));
Assert.assertEquals((Integer)1, iterChain.next());
Assert.assertEquals((Integer)2, iterChain.next());
Assert.assertEquals((Integer)3, iterChain.next());
Assert.assertEquals((Integer)4, iterChain.next());
Assertions.assertSame(iterChain, iterChain.addChain(iter1));
Assertions.assertSame(iterChain, iterChain.addChain(iter2));
Assertions.assertEquals((Integer)1, iterChain.next());
Assertions.assertEquals((Integer)2, iterChain.next());
Assertions.assertEquals((Integer)3, iterChain.next());
Assertions.assertEquals((Integer)4, iterChain.next());
}
@Test
public void testRemove() {
final IterChain<Integer> iterChain = new IterChain<>();
iterChain.addChain(Arrays.asList(1, 2).iterator());
Assert.assertThrows(IllegalStateException.class, iterChain::remove);
Assertions.assertThrows(IllegalStateException.class, iterChain::remove);
}
@Test
@ -58,12 +58,12 @@ public class IterChainTest {
final Iterator<Integer> iter1 = Arrays.asList(1, 2).iterator();
final Iterator<Integer> iter2 = Arrays.asList(3, 4).iterator();
final IterChain<Integer> iterChain = new IterChain<>();
Assert.assertSame(iterChain, iterChain.addChain(iter1));
Assert.assertSame(iterChain, iterChain.addChain(iter2));
Assertions.assertSame(iterChain, iterChain.addChain(iter1));
Assertions.assertSame(iterChain, iterChain.addChain(iter2));
final Iterator<Iterator<Integer>> iterators = iterChain.iterator();
Assert.assertSame(iter1, iterators.next());
Assert.assertSame(iter2, iterators.next());
Assertions.assertSame(iter1, iterators.next());
Assertions.assertSame(iter2, iterators.next());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.collection.iter;
import lombok.RequiredArgsConstructor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.w3c.dom.NodeList;
import java.util.*;
@ -15,51 +15,51 @@ public class IterUtilTest {
@Test
public void testGetIter() {
Assert.assertNull(IterUtil.getIter(null));
Assert.assertEquals(Collections.emptyIterator(), IterUtil.getIter(Collections.emptyList()));
Assertions.assertNull(IterUtil.getIter(null));
Assertions.assertEquals(Collections.emptyIterator(), IterUtil.getIter(Collections.emptyList()));
Assert.assertNull(IterUtil.getIter((Object)null));
Assert.assertNotNull(IterUtil.getIter(Collections.emptyIterator()));
Assert.assertNotNull(IterUtil.getIter((Object)Collections.emptyList()));
Assert.assertNotNull(IterUtil.getIter(new Integer[0]));
Assert.assertNotNull(IterUtil.getIter(Collections.emptyMap()));
Assert.assertNull(IterUtil.getIter((NodeList)null));
Assertions.assertNull(IterUtil.getIter((Object)null));
Assertions.assertNotNull(IterUtil.getIter(Collections.emptyIterator()));
Assertions.assertNotNull(IterUtil.getIter((Object)Collections.emptyList()));
Assertions.assertNotNull(IterUtil.getIter(new Integer[0]));
Assertions.assertNotNull(IterUtil.getIter(Collections.emptyMap()));
Assertions.assertNull(IterUtil.getIter((NodeList)null));
}
@Test
public void testIsEmpty() {
Assert.assertTrue(IterUtil.isEmpty(Collections.emptyIterator()));
Assert.assertFalse(IterUtil.isEmpty(Arrays.asList(1, 2).iterator()));
Assertions.assertTrue(IterUtil.isEmpty(Collections.emptyIterator()));
Assertions.assertFalse(IterUtil.isEmpty(Arrays.asList(1, 2).iterator()));
Assert.assertTrue(IterUtil.isEmpty(Collections.emptyList()));
Assert.assertFalse(IterUtil.isEmpty(Arrays.asList(1, 2)));
Assertions.assertTrue(IterUtil.isEmpty(Collections.emptyList()));
Assertions.assertFalse(IterUtil.isEmpty(Arrays.asList(1, 2)));
}
@Test
public void testIsNotEmpty() {
Assert.assertFalse(IterUtil.isNotEmpty(Collections.emptyIterator()));
Assert.assertTrue(IterUtil.isNotEmpty(Arrays.asList(1, 2).iterator()));
Assertions.assertFalse(IterUtil.isNotEmpty(Collections.emptyIterator()));
Assertions.assertTrue(IterUtil.isNotEmpty(Arrays.asList(1, 2).iterator()));
Assert.assertFalse(IterUtil.isNotEmpty(Collections.emptyList()));
Assert.assertTrue(IterUtil.isNotEmpty(Arrays.asList(1, 2)));
Assertions.assertFalse(IterUtil.isNotEmpty(Collections.emptyList()));
Assertions.assertTrue(IterUtil.isNotEmpty(Arrays.asList(1, 2)));
}
@Test
public void testHasNull() {
Assert.assertFalse(IterUtil.hasNull(Arrays.asList(1, 3, 2).iterator()));
Assert.assertTrue(IterUtil.hasNull(Arrays.asList(1, null, 2).iterator()));
Assert.assertFalse(IterUtil.hasNull(Collections.emptyIterator()));
Assert.assertTrue(IterUtil.hasNull(null));
Assertions.assertFalse(IterUtil.hasNull(Arrays.asList(1, 3, 2).iterator()));
Assertions.assertTrue(IterUtil.hasNull(Arrays.asList(1, null, 2).iterator()));
Assertions.assertFalse(IterUtil.hasNull(Collections.emptyIterator()));
Assertions.assertTrue(IterUtil.hasNull(null));
}
@Test
public void testIsAllNull() {
Assert.assertTrue(IterUtil.isAllNull(Arrays.asList(null, null)));
Assert.assertFalse(IterUtil.isAllNull(Arrays.asList(1, null)));
Assert.assertTrue(IterUtil.isAllNull((Iterable<?>)null));
Assert.assertTrue(IterUtil.isAllNull(Arrays.asList(null, null).iterator()));
Assert.assertFalse(IterUtil.isAllNull(Arrays.asList(1, null).iterator()));
Assert.assertTrue(IterUtil.isAllNull((Iterator<?>)null));
Assertions.assertTrue(IterUtil.isAllNull(Arrays.asList(null, null)));
Assertions.assertFalse(IterUtil.isAllNull(Arrays.asList(1, null)));
Assertions.assertTrue(IterUtil.isAllNull((Iterable<?>)null));
Assertions.assertTrue(IterUtil.isAllNull(Arrays.asList(null, null).iterator()));
Assertions.assertFalse(IterUtil.isAllNull(Arrays.asList(1, null).iterator()));
Assertions.assertTrue(IterUtil.isAllNull((Iterator<?>)null));
}
@Test
@ -67,8 +67,8 @@ public class IterUtilTest {
Object o1 = new Object();
Object o2 = new Object();
Map<Object, Integer> countMap = IterUtil.countMap(Arrays.asList(o1, o2, o1, o1).iterator());
Assert.assertEquals((Integer)3, countMap.get(o1));
Assert.assertEquals((Integer)1, countMap.get(o2));
Assertions.assertEquals((Integer)3, countMap.get(o1));
Assertions.assertEquals((Integer)1, countMap.get(o2));
}
@Test
@ -76,8 +76,8 @@ public class IterUtilTest {
Bean bean1 = new Bean(1, "A");
Bean bean2 = new Bean(2, "B");
Map<Integer, Bean> map = IterUtil.fieldValueMap(Arrays.asList(bean1, bean2).iterator(), "id");
Assert.assertEquals(bean1, map.get(1));
Assert.assertEquals(bean2, map.get(2));
Assertions.assertEquals(bean1, map.get(1));
Assertions.assertEquals(bean2, map.get(2));
}
@Test
@ -87,16 +87,16 @@ public class IterUtilTest {
Map<Integer, String> map = IterUtil.fieldValueAsMap(
Arrays.asList(bean1, bean2).iterator(), "id", "name"
);
Assert.assertEquals("A", map.get(1));
Assert.assertEquals("B", map.get(2));
Assertions.assertEquals("A", map.get(1));
Assertions.assertEquals("B", map.get(2));
}
@Test
public void testFieldValueList() {
Bean bean1 = new Bean(1, "A");
Bean bean2 = new Bean(2, "B");
Assert.assertEquals(Arrays.asList(1, 2), IterUtil.fieldValueList(Arrays.asList(bean1, bean2), "id"));
Assert.assertEquals(
Assertions.assertEquals(Arrays.asList(1, 2), IterUtil.fieldValueList(Arrays.asList(bean1, bean2), "id"));
Assertions.assertEquals(
Arrays.asList(1, 2),
IterUtil.fieldValueList(Arrays.asList(bean1, bean2).iterator(), "id")
);
@ -105,9 +105,9 @@ public class IterUtilTest {
@Test
public void testJoin() {
List<String> stringList = Arrays.asList("1", "2", "3");
Assert.assertEquals("123", IterUtil.join(stringList.iterator(), ""));
Assert.assertEquals("-1--2--3-", IterUtil.join(stringList.iterator(), "", "-", "-"));
Assert.assertEquals("123", IterUtil.join(stringList.iterator(), "", Function.identity()));
Assertions.assertEquals("123", IterUtil.join(stringList.iterator(), ""));
Assertions.assertEquals("-1--2--3-", IterUtil.join(stringList.iterator(), "", "-", "-"));
Assertions.assertEquals("123", IterUtil.join(stringList.iterator(), "", Function.identity()));
}
@Test
@ -115,28 +115,28 @@ public class IterUtilTest {
List<Integer> keys = Arrays.asList(1, 2, 3);
Map<Integer, Integer> map = IterUtil.toMap(keys, keys);
Assert.assertEquals(keys, new ArrayList<>(map.keySet()));
Assert.assertEquals(keys, new ArrayList<>(map.values()));
Assertions.assertEquals(keys, new ArrayList<>(map.keySet()));
Assertions.assertEquals(keys, new ArrayList<>(map.values()));
map = IterUtil.toMap(keys.iterator(), keys.iterator());
Assert.assertEquals(keys, new ArrayList<>(map.keySet()));
Assert.assertEquals(keys, new ArrayList<>(map.values()));
Assertions.assertEquals(keys, new ArrayList<>(map.keySet()));
Assertions.assertEquals(keys, new ArrayList<>(map.values()));
map = IterUtil.toMap(keys.iterator(), keys.iterator(), true);
Assert.assertEquals(keys, new ArrayList<>(map.keySet()));
Assert.assertEquals(keys, new ArrayList<>(map.values()));
Assertions.assertEquals(keys, new ArrayList<>(map.keySet()));
Assertions.assertEquals(keys, new ArrayList<>(map.values()));
map = IterUtil.toMap(keys, keys, true);
Assert.assertEquals(keys, new ArrayList<>(map.keySet()));
Assert.assertEquals(keys, new ArrayList<>(map.values()));
Assertions.assertEquals(keys, new ArrayList<>(map.keySet()));
Assertions.assertEquals(keys, new ArrayList<>(map.values()));
map = IterUtil.toMap(keys, Function.identity());
Assert.assertEquals(keys, new ArrayList<>(map.keySet()));
Assert.assertEquals(keys, new ArrayList<>(map.values()));
Assertions.assertEquals(keys, new ArrayList<>(map.keySet()));
Assertions.assertEquals(keys, new ArrayList<>(map.values()));
map = IterUtil.toMap(keys, Function.identity(), Function.identity());
Assert.assertEquals(keys, new ArrayList<>(map.keySet()));
Assert.assertEquals(keys, new ArrayList<>(map.values()));
Assertions.assertEquals(keys, new ArrayList<>(map.keySet()));
Assertions.assertEquals(keys, new ArrayList<>(map.values()));
}
@Test
@ -144,157 +144,157 @@ public class IterUtilTest {
List<Integer> keys = Arrays.asList(1, 2, 3, 4);
Map<Boolean, List<Integer>> map = IterUtil.toListMap(keys, i -> (i & 1) == 0, Function.identity());
Assert.assertEquals(Arrays.asList(2, 4), map.get(true));
Assert.assertEquals(Arrays.asList(1, 3), map.get(false));
Assertions.assertEquals(Arrays.asList(2, 4), map.get(true));
Assertions.assertEquals(Arrays.asList(1, 3), map.get(false));
map = IterUtil.toListMap(keys, i -> (i & 1) == 0);
Assert.assertEquals(Arrays.asList(2, 4), map.get(true));
Assert.assertEquals(Arrays.asList(1, 3), map.get(false));
Assertions.assertEquals(Arrays.asList(2, 4), map.get(true));
Assertions.assertEquals(Arrays.asList(1, 3), map.get(false));
map = new LinkedHashMap<>();
Map<Boolean, List<Integer>> rawMap = IterUtil.toListMap(map, keys, i -> (i & 1) == 0, Function.identity());
Assert.assertSame(rawMap, map);
Assert.assertEquals(Arrays.asList(2, 4), rawMap.get(true));
Assert.assertEquals(Arrays.asList(1, 3), rawMap.get(false));
Assertions.assertSame(rawMap, map);
Assertions.assertEquals(Arrays.asList(2, 4), rawMap.get(true));
Assertions.assertEquals(Arrays.asList(1, 3), rawMap.get(false));
}
@Test
public void testAsIterable() {
Iterator<Integer> iter = Arrays.asList(1, 2, 3).iterator();
Assert.assertEquals(iter, IterUtil.asIterable(iter).iterator());
Assert.assertNull(IterUtil.asIterable(null).iterator());
Assertions.assertEquals(iter, IterUtil.asIterable(iter).iterator());
Assertions.assertNull(IterUtil.asIterable(null).iterator());
Enumeration<Integer> enumeration = new IteratorEnumeration<>(iter);
Iterator<Integer> iter2 = IterUtil.asIterator(enumeration);
Assert.assertEquals((Integer)1, iter2.next());
Assert.assertEquals((Integer)2, iter2.next());
Assert.assertEquals((Integer)3, iter2.next());
Assertions.assertEquals((Integer)1, iter2.next());
Assertions.assertEquals((Integer)2, iter2.next());
Assertions.assertEquals((Integer)3, iter2.next());
}
@Test
public void testGet() {
Iterator<Integer> iter = Arrays.asList(1, 2, 3, 4).iterator();
Assert.assertEquals((Integer)3, IterUtil.get(iter, 2));
Assert.assertThrows(IllegalArgumentException.class, () -> IterUtil.get(iter, -1));
Assertions.assertEquals((Integer)3, IterUtil.get(iter, 2));
Assertions.assertThrows(IllegalArgumentException.class, () -> IterUtil.get(iter, -1));
}
@Test
public void testGetFirst() {
Iterator<Integer> iter = Arrays.asList(1, 2, 3, 4).iterator();
Assert.assertEquals((Integer)1, IterUtil.getFirst(iter));
Assert.assertNull(IterUtil.getFirst(null));
Assert.assertNull(IterUtil.getFirst(Collections.emptyIterator()));
Assertions.assertEquals((Integer)1, IterUtil.getFirst(iter));
Assertions.assertNull(IterUtil.getFirst(null));
Assertions.assertNull(IterUtil.getFirst(Collections.emptyIterator()));
Assert.assertEquals((Integer)2, IterUtil.getFirst(iter, t -> (t & 1) == 0));
Assert.assertNull(IterUtil.getFirst((Iterator<Integer>)null, t -> (t & 1) == 0));
Assert.assertNull(IterUtil.getFirst(Collections.emptyIterator(), Objects::nonNull));
Assertions.assertEquals((Integer)2, IterUtil.getFirst(iter, t -> (t & 1) == 0));
Assertions.assertNull(IterUtil.getFirst((Iterator<Integer>)null, t -> (t & 1) == 0));
Assertions.assertNull(IterUtil.getFirst(Collections.emptyIterator(), Objects::nonNull));
}
@Test
public void testGetFirstNoneNull() {
Iterator<Integer> iter = Arrays.asList(null, 2, null, 4).iterator();
Assert.assertEquals((Integer)2, IterUtil.getFirstNoneNull(iter));
Assert.assertNull(IterUtil.getFirstNoneNull(null));
Assert.assertNull(IterUtil.getFirstNoneNull(Collections.emptyIterator()));
Assertions.assertEquals((Integer)2, IterUtil.getFirstNoneNull(iter));
Assertions.assertNull(IterUtil.getFirstNoneNull(null));
Assertions.assertNull(IterUtil.getFirstNoneNull(Collections.emptyIterator()));
}
@Test
public void testGetElementType() {
List<Object> list = Arrays.asList(null, "str", null);
Assert.assertEquals(String.class, IterUtil.getElementType(list));
Assert.assertNull(IterUtil.getElementType((Iterable<?>)null));
Assert.assertNull(IterUtil.getElementType(Collections.emptyList()));
Assertions.assertEquals(String.class, IterUtil.getElementType(list));
Assertions.assertNull(IterUtil.getElementType((Iterable<?>)null));
Assertions.assertNull(IterUtil.getElementType(Collections.emptyList()));
Assert.assertEquals(String.class, IterUtil.getElementType(list.iterator()));
Assert.assertNull(IterUtil.getElementType((Iterator<?>)null));
Assert.assertNull(IterUtil.getElementType(Collections.emptyIterator()));
Assertions.assertEquals(String.class, IterUtil.getElementType(list.iterator()));
Assertions.assertNull(IterUtil.getElementType((Iterator<?>)null));
Assertions.assertNull(IterUtil.getElementType(Collections.emptyIterator()));
}
@Test
public void testEdit() {
Assert.assertEquals(
Assertions.assertEquals(
Collections.singletonList("str"),
IterUtil.edit(Arrays.asList(null, "str", null).iterator(), t -> t)
);
Assert.assertEquals(
Assertions.assertEquals(
Collections.singletonList("str"),
IterUtil.edit(Arrays.asList(null, "str", null).iterator(), null)
);
Assert.assertEquals(Collections.emptyList(), IterUtil.edit(null, t -> t));
Assertions.assertEquals(Collections.emptyList(), IterUtil.edit(null, t -> t));
}
@Test
public void testRemove() {
List<Integer> list = new ArrayList<>(Arrays.asList(1, null, null, 3));
IterUtil.remove(list.iterator(), Objects::isNull);
Assert.assertEquals(Arrays.asList(1, 3), list);
Assertions.assertEquals(Arrays.asList(1, 3), list);
}
@Test
public void testFilterToList() {
List<Integer> list1 = new ArrayList<>(Arrays.asList(1, null, null, 3));
List<Integer> list2 = IterUtil.filterToList(list1.iterator(), Objects::nonNull);
Assert.assertSame(list1, list1);
Assert.assertEquals(Arrays.asList(1, 3), list2);
Assertions.assertSame(list1, list1);
Assertions.assertEquals(Arrays.asList(1, 3), list2);
}
@Test
public void testFiltered() {
Assert.assertNotNull(IterUtil.filtered(Collections.emptyIterator(), t -> true));
Assertions.assertNotNull(IterUtil.filtered(Collections.emptyIterator(), t -> true));
}
@Test
public void testEmpty() {
Assert.assertSame(Collections.emptyIterator(), IterUtil.empty());
Assertions.assertSame(Collections.emptyIterator(), IterUtil.empty());
}
@Test
public void testTrans() {
Assert.assertNotNull(IterUtil.trans(Collections.emptyIterator(), t -> true));
Assertions.assertNotNull(IterUtil.trans(Collections.emptyIterator(), t -> true));
}
@Test
public void testSize() {
Assert.assertEquals(0, IterUtil.size((Iterator<?>)null));
Assert.assertEquals(0, IterUtil.size(Collections.emptyIterator()));
Assert.assertEquals(3, IterUtil.size(Arrays.asList(1, 2, 3).iterator()));
Assertions.assertEquals(0, IterUtil.size((Iterator<?>)null));
Assertions.assertEquals(0, IterUtil.size(Collections.emptyIterator()));
Assertions.assertEquals(3, IterUtil.size(Arrays.asList(1, 2, 3).iterator()));
Assert.assertEquals(0, IterUtil.size((Iterable<?>)null));
Assert.assertEquals(0, IterUtil.size(Collections.emptyList()));
Assert.assertEquals(3, IterUtil.size(Arrays.asList(1, 2, 3)));
Assertions.assertEquals(0, IterUtil.size((Iterable<?>)null));
Assertions.assertEquals(0, IterUtil.size(Collections.emptyList()));
Assertions.assertEquals(3, IterUtil.size(Arrays.asList(1, 2, 3)));
}
@Test
public void testIsEqualList() {
Assert.assertFalse(IterUtil.isEqualList(null, Collections.emptyList()));
Assert.assertFalse(IterUtil.isEqualList(Arrays.asList(1, 2, 3), Collections.emptyList()));
Assert.assertFalse(IterUtil.isEqualList(Arrays.asList(1, 2, 3), Arrays.asList(1, 2)));
Assert.assertTrue(IterUtil.isEqualList(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3)));
Assert.assertTrue(IterUtil.isEqualList(null, null));
Assert.assertTrue(IterUtil.isEqualList(Collections.emptyList(), Collections.emptyList()));
Assertions.assertFalse(IterUtil.isEqualList(null, Collections.emptyList()));
Assertions.assertFalse(IterUtil.isEqualList(Arrays.asList(1, 2, 3), Collections.emptyList()));
Assertions.assertFalse(IterUtil.isEqualList(Arrays.asList(1, 2, 3), Arrays.asList(1, 2)));
Assertions.assertTrue(IterUtil.isEqualList(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3)));
Assertions.assertTrue(IterUtil.isEqualList(null, null));
Assertions.assertTrue(IterUtil.isEqualList(Collections.emptyList(), Collections.emptyList()));
}
@Test
public void testClear() {
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3));
IterUtil.clear(list.iterator());
Assert.assertTrue(list.isEmpty());
Assert.assertThrows(UnsupportedOperationException.class, () -> IterUtil.clear(Arrays.asList(1, 2).iterator()));
Assertions.assertTrue(list.isEmpty());
Assertions.assertThrows(UnsupportedOperationException.class, () -> IterUtil.clear(Arrays.asList(1, 2).iterator()));
}
@Test
public void testToStr() {
List<Integer> list = Arrays.asList(1, 2, 3);
Assert.assertEquals("[1, 2, 3]", IterUtil.toStr(list.iterator()));
Assert.assertEquals("[1, 2, 3]", IterUtil.toStr(list.iterator(), Objects::toString));
Assert.assertEquals("{1:2:3}", IterUtil.toStr(list.iterator(), Objects::toString, ":", "{", "}"));
Assertions.assertEquals("[1, 2, 3]", IterUtil.toStr(list.iterator()));
Assertions.assertEquals("[1, 2, 3]", IterUtil.toStr(list.iterator(), Objects::toString));
Assertions.assertEquals("{1:2:3}", IterUtil.toStr(list.iterator(), Objects::toString, ":", "{", "}"));
}
@Test
public void testForEach() {
List<Integer> list = new ArrayList<>();
IterUtil.forEach(Arrays.asList(1, 2, 3, 4).iterator(), list::add);
Assert.assertEquals(Arrays.asList(1, 2, 3, 4), list);
Assertions.assertEquals(Arrays.asList(1, 2, 3, 4), list);
}
@RequiredArgsConstructor

View File

@ -1,7 +1,7 @@
package cn.hutool.core.collection.iter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@ -16,17 +16,17 @@ public class IteratorEnumerationTest {
public void testHasMoreElements() {
List<Integer> list = Arrays.asList(1, 2, 3);
IteratorEnumeration<Integer> enumeration = new IteratorEnumeration<>(list.iterator());
Assert.assertTrue(enumeration.hasMoreElements());
Assert.assertFalse(new IteratorEnumeration<>(Collections.emptyIterator()).hasMoreElements());
Assertions.assertTrue(enumeration.hasMoreElements());
Assertions.assertFalse(new IteratorEnumeration<>(Collections.emptyIterator()).hasMoreElements());
}
@Test
public void testNextElement() {
List<Integer> list = Arrays.asList(1, 2, 3);
IteratorEnumeration<Integer> enumeration = new IteratorEnumeration<>(list.iterator());
Assert.assertEquals((Integer)1, enumeration.nextElement());
Assert.assertEquals((Integer)2, enumeration.nextElement());
Assert.assertEquals((Integer)3, enumeration.nextElement());
Assertions.assertEquals((Integer)1, enumeration.nextElement());
Assertions.assertEquals((Integer)2, enumeration.nextElement());
Assertions.assertEquals((Integer)3, enumeration.nextElement());
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.collection.iter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.net.URL;
@ -16,45 +16,45 @@ public class LineIterTest {
@Test
public void testHasNext() {
LineIter iter = getItrFromClasspathFile();
Assert.assertTrue(iter.hasNext());
Assertions.assertTrue(iter.hasNext());
}
@Test
public void testNext() {
LineIter iter = getItrFromClasspathFile();
Assert.assertEquals("is first line", iter.next());
Assert.assertEquals("is second line", iter.next());
Assert.assertEquals("is third line", iter.next());
Assertions.assertEquals("is first line", iter.next());
Assertions.assertEquals("is second line", iter.next());
Assertions.assertEquals("is third line", iter.next());
}
@Test
public void testRemove() {
LineIter iter = getItrFromClasspathFile();
iter.next();
Assert.assertThrows(UnsupportedOperationException.class, iter::remove);
Assertions.assertThrows(UnsupportedOperationException.class, iter::remove);
}
@Test
public void testFinish() {
LineIter iter = getItrFromClasspathFile();
iter.finish();
Assert.assertThrows(NoSuchElementException.class, iter::next);
Assertions.assertThrows(NoSuchElementException.class, iter::next);
}
@Test
public void testClose() throws IOException {
URL url = LineIterTest.class.getClassLoader().getResource("text.txt");
Assert.assertNotNull(url);
Assertions.assertNotNull(url);
FileInputStream inputStream = new FileInputStream(url.getFile());
LineIter iter = new LineIter(inputStream, StandardCharsets.UTF_8);
iter.close();
Assert.assertThrows(NoSuchElementException.class, iter::next);
Assert.assertThrows(IOException.class, inputStream::read);
Assertions.assertThrows(NoSuchElementException.class, iter::next);
Assertions.assertThrows(IOException.class, inputStream::read);
}
private static LineIter getItrFromClasspathFile() {
URL url = LineIterTest.class.getClassLoader().getResource("text.txt");
Assert.assertNotNull(url);
Assertions.assertNotNull(url);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(url.getFile());

View File

@ -1,7 +1,7 @@
package cn.hutool.core.collection.iter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@ -16,16 +16,16 @@ public class PartitionIterTest {
public void testHasNext() {
Iterator<Integer> iter = Arrays.asList(1, 2, 3, 4).iterator();
PartitionIter<Integer> partitionIter = new PartitionIter<>(iter, 2);
Assert.assertTrue(partitionIter.hasNext());
Assert.assertFalse(new PartitionIter<>(Collections.emptyIterator(), 1).hasNext());
Assertions.assertTrue(partitionIter.hasNext());
Assertions.assertFalse(new PartitionIter<>(Collections.emptyIterator(), 1).hasNext());
}
@Test
public void testNext() {
Iterator<Integer> iter = Arrays.asList(1, 2, 3, 4).iterator();
PartitionIter<Integer> partitionIter = new PartitionIter<>(iter, 2);
Assert.assertEquals(Arrays.asList(1, 2), partitionIter.next());
Assert.assertEquals(Arrays.asList(3, 4), partitionIter.next());
Assertions.assertEquals(Arrays.asList(1, 2), partitionIter.next());
Assertions.assertEquals(Arrays.asList(3, 4), partitionIter.next());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.collection.iter;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
@ -17,16 +17,16 @@ public class TransIterTest {
@Test
public void testHasNext() {
TransIter<Integer, String> iter = new TransIter<>(Arrays.asList(1, 2, 3).iterator(), String::valueOf);
Assert.assertTrue(iter.hasNext());
Assert.assertFalse(new TransIter<>(Collections.emptyIterator(), Function.identity()).hasNext());
Assertions.assertTrue(iter.hasNext());
Assertions.assertFalse(new TransIter<>(Collections.emptyIterator(), Function.identity()).hasNext());
}
@Test
public void testNext() {
TransIter<Integer, String> iter = new TransIter<>(Arrays.asList(1, 2, 3).iterator(), String::valueOf);
Assert.assertEquals("1", iter.next());
Assert.assertEquals("2", iter.next());
Assert.assertEquals("3", iter.next());
Assertions.assertEquals("1", iter.next());
Assertions.assertEquals("2", iter.next());
Assertions.assertEquals("3", iter.next());
}
@Test
@ -39,6 +39,6 @@ public class TransIterTest {
iter.remove();
iter.next();
iter.remove();
Assert.assertTrue(list.isEmpty());
Assertions.assertTrue(list.isEmpty());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.collection.partition;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
@ -12,37 +12,37 @@ public class PartitionTest {
public void sizeTest() {
final List<Integer> list = ListUtil.of(1, 2, 3, 4, 5);
final Partition<Integer> partition = new Partition<>(list, 4);
Assert.assertEquals(2, partition.size());
Assertions.assertEquals(2, partition.size());
}
@Test
public void getSizeTest() {
List<Integer> mockedList = makingList(19);
Partition<Integer> partition = new Partition<>(mockedList, 10);
Assert.assertEquals(2, partition.size());
Assertions.assertEquals(2, partition.size());
mockedList = makingList(11);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(2, partition.size());
Assertions.assertEquals(2, partition.size());
mockedList = makingList(10);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(1, partition.size());
Assertions.assertEquals(1, partition.size());
mockedList = makingList(9);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(1, partition.size());
Assertions.assertEquals(1, partition.size());
mockedList = makingList(5);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(1, partition.size());
Assertions.assertEquals(1, partition.size());
}
@Test
public void getZeroSizeTest() {
final List<Integer> mockedList = makingList(0);
final Partition<Integer> partition = new Partition<>(mockedList, 10);
Assert.assertEquals(0, partition.size());
Assertions.assertEquals(0, partition.size());
}
private List<Integer> makingList(final int length) {
@ -59,11 +59,11 @@ public class PartitionTest {
final List<Integer> emptyList = Collections.emptyList();
Partition<Integer> partition = new Partition<>(emptyList, 10);
Assert.assertTrue(partition.isEmpty());
Assertions.assertTrue(partition.isEmpty());
final List<Integer> singletonList = Collections.singletonList(1);
partition = new Partition<>(singletonList, 10);
Assert.assertFalse(partition.isEmpty());
Assert.assertEquals(1, partition.size());
Assertions.assertFalse(partition.isEmpty());
Assertions.assertEquals(1, partition.size());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.comparator;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
@ -11,10 +11,10 @@ public class CompareUtilTest {
@Test
public void compareTest(){
int compare = CompareUtil.compare(null, "a", true);
Assert.assertTrue(compare > 0);
Assertions.assertTrue(compare > 0);
compare = CompareUtil.compare(null, "a", false);
Assert.assertTrue(compare < 0);
Assertions.assertTrue(compare < 0);
}
@Test
@ -26,11 +26,11 @@ public class CompareUtilTest {
// 正序
list.sort(CompareUtil.comparingPinyin(e -> e));
Assert.assertEquals(list, ascendingOrderResult);
Assertions.assertEquals(list, ascendingOrderResult);
// 反序
list.sort(CompareUtil.comparingPinyin(e -> e, true));
Assert.assertEquals(list, descendingOrderResult);
Assertions.assertEquals(list, descendingOrderResult);
}
@Test
@ -40,7 +40,7 @@ public class CompareUtilTest {
data.sort(CompareUtil.comparingIndexed(e -> e, index));
//[1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Assert.assertEquals(ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"), data);
Assertions.assertEquals(ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"), data);
}
@Test
@ -51,7 +51,7 @@ public class CompareUtilTest {
//正确排序index.toArray()
data.sort(CompareUtil.comparingIndexed(e -> e, index.toArray()));
//[5, 6, 7, 8, 9, 10, 2, 2, 1, 1, 3, 3, 4, 4]
Assert.assertEquals(ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"), data);
Assertions.assertEquals(ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"), data);
}
@Test
public void comparingIndexedTest3() {
@ -61,16 +61,16 @@ public class CompareUtilTest {
//正确排序array
data.sort(CompareUtil.comparingIndexed(e -> e, indexArray));
//[5, 6, 7, 8, 9, 10, 2, 2, 1, 1, 3, 3, 4, 4]
Assert.assertEquals(data, ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"));
Assertions.assertEquals(data, ListUtil.view("5", "6", "7", "8", "9", "10", "2", "2", "1", "1", "3", "3", "4", "4"));
}
@Test
public void compareNullTest() {
Assert.assertEquals(0, CompareUtil.compare(1, 1));
Assert.assertEquals(1, CompareUtil.compare(1, null));
Assert.assertEquals(-1, CompareUtil.compare(null, 1));
Assertions.assertEquals(0, CompareUtil.compare(1, 1));
Assertions.assertEquals(1, CompareUtil.compare(1, null));
Assertions.assertEquals(-1, CompareUtil.compare(null, 1));
Assert.assertEquals(-1, CompareUtil.compare(1, null, true));
Assert.assertEquals(1, CompareUtil.compare(null, 1, true));
Assertions.assertEquals(-1, CompareUtil.compare(1, null, true));
Assertions.assertEquals(1, CompareUtil.compare(null, 1, true));
}
}

View File

@ -3,8 +3,8 @@ package cn.hutool.core.comparator;
import cn.hutool.core.collection.ListUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
@ -21,15 +21,15 @@ public class PropertyComparatorTest {
// 默认null在末尾
final List<User> sortedList1 = ListUtil.sort(users, new PropertyComparator<>("b"));
Assert.assertEquals("a", sortedList1.get(0).getB());
Assert.assertEquals("d", sortedList1.get(1).getB());
Assert.assertNull(sortedList1.get(2).getB());
Assertions.assertEquals("a", sortedList1.get(0).getB());
Assertions.assertEquals("d", sortedList1.get(1).getB());
Assertions.assertNull(sortedList1.get(2).getB());
// null在首
final List<User> sortedList2 = ListUtil.sort(users, new PropertyComparator<>("b", false));
Assert.assertNull(sortedList2.get(0).getB());
Assert.assertEquals("a", sortedList2.get(1).getB());
Assert.assertEquals("d", sortedList2.get(2).getB());
Assertions.assertNull(sortedList2.get(0).getB());
Assertions.assertEquals("a", sortedList2.get(1).getB());
Assertions.assertEquals("d", sortedList2.get(2).getB());
}
@Test
@ -42,9 +42,9 @@ public class PropertyComparatorTest {
// 反序
final List<User> sortedList = ListUtil.sort(users, new PropertyComparator<>("b").reversed());
Assert.assertNull(sortedList.get(0).getB());
Assert.assertEquals("d", sortedList.get(1).getB());
Assert.assertEquals("a", sortedList.get(2).getB());
Assertions.assertNull(sortedList.get(0).getB());
Assertions.assertEquals("d", sortedList.get(1).getB());
Assertions.assertEquals("a", sortedList.get(2).getB());
}
@Data

View File

@ -1,7 +1,7 @@
package cn.hutool.core.comparator;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 版本比较单元测试
@ -14,43 +14,43 @@ public class VersionComparatorTest {
@Test
public void versionComparatorTest1() {
final int compare = VersionComparator.INSTANCE.compare("1.2.1", "1.12.1");
Assert.assertTrue(compare < 0);
Assertions.assertTrue(compare < 0);
}
@Test
public void versionComparatorTest2() {
final int compare = VersionComparator.INSTANCE.compare("1.12.1", "1.12.1c");
Assert.assertTrue(compare < 0);
Assertions.assertTrue(compare < 0);
}
@Test
public void versionComparatorTest3() {
final int compare = VersionComparator.INSTANCE.compare(null, "1.12.1c");
Assert.assertTrue(compare < 0);
Assertions.assertTrue(compare < 0);
}
@Test
public void versionComparatorTest4() {
final int compare = VersionComparator.INSTANCE.compare("1.13.0", "1.12.1c");
Assert.assertTrue(compare > 0);
Assertions.assertTrue(compare > 0);
}
@Test
public void versionComparatorTest5() {
final int compare = VersionComparator.INSTANCE.compare("V1.2", "V1.1");
Assert.assertTrue(compare > 0);
Assertions.assertTrue(compare > 0);
}
@Test
public void versionComparatorTes6() {
final int compare = VersionComparator.INSTANCE.compare("V0.0.20170102", "V0.0.20170101");
Assert.assertTrue(compare > 0);
Assertions.assertTrue(compare > 0);
}
@Test
public void equalsTest(){
final VersionComparator first = new VersionComparator();
final VersionComparator other = new VersionComparator();
Assert.assertNotEquals(first, other);
Assertions.assertNotEquals(first, other);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.compress;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
@ -9,7 +9,7 @@ import java.nio.file.StandardCopyOption;
public class IssueI5DRU0Test {
@Test
@Ignore
@Disabled
public void appendTest(){
// https://gitee.com/dromara/hutool/issues/I5DRU0
// 向zip中添加文件的时候如果添加的文件的父目录已经存在会报错实际中目录存在忽略即可

View File

@ -1,15 +1,15 @@
package cn.hutool.core.compress;
import cn.hutool.core.lang.Console;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.File;
public class ZipReaderTest {
@Test
@Ignore
@Disabled
public void unzipTest() {
final File unzip = ZipUtil.unzip("d:/java.zip", "d:/test/java");
Console.log(unzip);

View File

@ -3,21 +3,21 @@ package cn.hutool.core.compress;
import cn.hutool.core.io.file.FileUtil;
import cn.hutool.core.io.resource.FileResource;
import cn.hutool.core.util.CharsetUtil;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.File;
public class ZipWriterTest {
@Test
@Ignore
@Disabled
public void zipDirTest() {
ZipUtil.zip(new File("d:/test"));
}
@Test
@Ignore
@Disabled
public void addTest(){
final ZipWriter writer = ZipWriter.of(FileUtil.file("d:/test/test.zip"), CharsetUtil.UTF_8);
writer.add(new FileResource("d:/test/qr_c.png"));

View File

@ -1,33 +1,33 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class BasicTypeTest {
@Test
public void wrapTest(){
Assert.assertEquals(Integer.class, BasicType.wrap(int.class));
Assert.assertEquals(Integer.class, BasicType.wrap(Integer.class));
Assert.assertEquals(String.class, BasicType.wrap(String.class));
Assert.assertNull(BasicType.wrap(null));
Assertions.assertEquals(Integer.class, BasicType.wrap(int.class));
Assertions.assertEquals(Integer.class, BasicType.wrap(Integer.class));
Assertions.assertEquals(String.class, BasicType.wrap(String.class));
Assertions.assertNull(BasicType.wrap(null));
}
@Test
public void unWrapTest(){
Assert.assertEquals(int.class, BasicType.unWrap(int.class));
Assert.assertEquals(int.class, BasicType.unWrap(Integer.class));
Assert.assertEquals(String.class, BasicType.unWrap(String.class));
Assert.assertNull(BasicType.unWrap(null));
Assertions.assertEquals(int.class, BasicType.unWrap(int.class));
Assertions.assertEquals(int.class, BasicType.unWrap(Integer.class));
Assertions.assertEquals(String.class, BasicType.unWrap(String.class));
Assertions.assertNull(BasicType.unWrap(null));
}
@Test
public void getPrimitiveSetTest(){
Assert.assertEquals(8, BasicType.getPrimitiveSet().size());
Assertions.assertEquals(8, BasicType.getPrimitiveSet().size());
}
@Test
public void getWrapperSetTest(){
Assert.assertEquals(8, BasicType.getWrapperSet().size());
Assertions.assertEquals(8, BasicType.getWrapperSet().size());
}
}

View File

@ -2,8 +2,8 @@ package cn.hutool.core.convert;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.collection.SetUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.Serializable;
import java.util.Collection;
@ -23,24 +23,24 @@ public class CastUtilTest {
Collection<Number> collection2 = CastUtil.castUp(collection);
collection2.add(new Double("123.1"));
Assert.assertSame(collection, collection2);
Assertions.assertSame(collection, collection2);
Collection<Integer> collection3 = CastUtil.castDown(collection2);
Assert.assertSame(collection2, collection3);
Assertions.assertSame(collection2, collection3);
List<Number> list2 = CastUtil.castUp(list);
Assert.assertSame(list, list2);
Assertions.assertSame(list, list2);
List<Integer> list3 = CastUtil.castDown(list2);
Assert.assertSame(list2, list3);
Assertions.assertSame(list2, list3);
Set<Number> set2 = CastUtil.castUp(set);
Assert.assertSame(set, set2);
Assertions.assertSame(set, set2);
Set<Integer> set3 = CastUtil.castDown(set2);
Assert.assertSame(set2, set3);
Assertions.assertSame(set2, set3);
Map<Number, Serializable> map2 = CastUtil.castUp(map);
Assert.assertSame(map, map2);
Assertions.assertSame(map, map2);
Map<Integer, Number> map3 = CastUtil.castDown(map2);
Assert.assertSame(map2, map3);
Assertions.assertSame(map2, map3);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Type;
@ -15,7 +15,7 @@ public class CompositeConverterTest {
@Test
public void getConverterTest() {
final Converter converter = CompositeConverter.getInstance().getConverter(CharSequence.class, false);
Assert.assertNotNull(converter);
Assertions.assertNotNull(converter);
}
@Test
@ -24,13 +24,13 @@ public class CompositeConverterTest {
final CompositeConverter compositeConverter = CompositeConverter.getInstance();
CharSequence result = (CharSequence) compositeConverter.convert(CharSequence.class, a);
Assert.assertEquals("454553", result);
Assertions.assertEquals("454553", result);
//此处做为示例自定义CharSequence转换因为Hutool中已经提供CharSequence转换请尽量不要替换
//替换可能引发关联转换异常例如覆盖CharSequence转换会影响全局
compositeConverter.putCustom(CharSequence.class, new CustomConverter());
result = (CharSequence) compositeConverter.convert(CharSequence.class, a);
Assert.assertEquals("Custom: 454553", result);
Assertions.assertEquals("Custom: 454553", result);
}
public static class CustomConverter implements Converter{

View File

@ -1,8 +1,8 @@
package cn.hutool.core.convert;
import cn.hutool.core.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit;
@ -16,10 +16,10 @@ public class ConvertOtherTest {
public void hexTest() {
final String a = "我是一个小小的可爱的字符串";
final String hex = Convert.toHex(a, CharsetUtil.UTF_8);
Assert.assertEquals("e68891e698afe4b880e4b8aae5b08fe5b08fe79a84e58fafe788b1e79a84e5ad97e7aca6e4b8b2", hex);
Assertions.assertEquals("e68891e698afe4b880e4b8aae5b08fe5b08fe79a84e58fafe788b1e79a84e5ad97e7aca6e4b8b2", hex);
final String raw = Convert.hexToStr(hex, CharsetUtil.UTF_8);
Assert.assertEquals(a, raw);
Assertions.assertEquals(a, raw);
}
@Test
@ -27,18 +27,18 @@ public class ConvertOtherTest {
final String a = "我是一个小小的可爱的字符串";
final String unicode = Convert.strToUnicode(a);
Assert.assertEquals("\\u6211\\u662f\\u4e00\\u4e2a\\u5c0f\\u5c0f\\u7684\\u53ef\\u7231\\u7684\\u5b57\\u7b26\\u4e32", unicode);
Assertions.assertEquals("\\u6211\\u662f\\u4e00\\u4e2a\\u5c0f\\u5c0f\\u7684\\u53ef\\u7231\\u7684\\u5b57\\u7b26\\u4e32", unicode);
final String raw = Convert.unicodeToStr(unicode);
Assert.assertEquals(raw, a);
Assertions.assertEquals(raw, a);
// 针对有特殊空白符的Unicode
final String str = "你 好";
final String unicode2 = Convert.strToUnicode(str);
Assert.assertEquals("\\u4f60\\u00a0\\u597d", unicode2);
Assertions.assertEquals("\\u4f60\\u00a0\\u597d", unicode2);
final String str2 = Convert.unicodeToStr(unicode2);
Assert.assertEquals(str, str2);
Assertions.assertEquals(str, str2);
}
@Test
@ -47,14 +47,14 @@ public class ConvertOtherTest {
// 转换后result为乱码
final String result = Convert.convertCharset(a, CharsetUtil.NAME_UTF_8, CharsetUtil.NAME_ISO_8859_1);
final String raw = Convert.convertCharset(result, CharsetUtil.NAME_ISO_8859_1, "UTF-8");
Assert.assertEquals(raw, a);
Assertions.assertEquals(raw, a);
}
@Test
public void convertTimeTest() {
final long a = 4535345;
final long minutes = Convert.convertTime(a, TimeUnit.MILLISECONDS, TimeUnit.MINUTES);
Assert.assertEquals(75, minutes);
Assertions.assertEquals(75, minutes);
}
@Test
@ -62,11 +62,11 @@ public class ConvertOtherTest {
// 去包装
final Class<?> wrapClass = Integer.class;
final Class<?> unWraped = Convert.unWrap(wrapClass);
Assert.assertEquals(int.class, unWraped);
Assertions.assertEquals(int.class, unWraped);
// 包装
final Class<?> primitiveClass = long.class;
final Class<?> wraped = Convert.wrap(primitiveClass);
Assert.assertEquals(Long.class, wraped);
Assertions.assertEquals(Long.class, wraped);
}
}

View File

@ -10,8 +10,8 @@ import cn.hutool.core.util.ByteUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.Serializable;
import java.math.BigDecimal;
@ -39,7 +39,7 @@ public class ConvertTest {
@Test
public void toObjectTest() {
final Object result = Convert.convert(Object.class, "aaaa");
Assert.assertEquals("aaaa", result);
Assertions.assertEquals("aaaa", result);
}
/**
@ -58,25 +58,25 @@ public class ConvertTest {
final int a = 1;
final long[] b = { 1, 2, 3, 4, 5 };
Assert.assertEquals("[1, 2, 3, 4, 5]", Convert.convert(String.class, b));
Assertions.assertEquals("[1, 2, 3, 4, 5]", Convert.convert(String.class, b));
final String aStr = Convert.toStr(a);
Assert.assertEquals("1", aStr);
Assertions.assertEquals("1", aStr);
final String bStr = Convert.toStr(b);
Assert.assertEquals("[1, 2, 3, 4, 5]", Convert.toStr(bStr));
Assertions.assertEquals("[1, 2, 3, 4, 5]", Convert.toStr(bStr));
}
@Test
public void toStrTest2() {
final String result = Convert.convert(String.class, "aaaa");
Assert.assertEquals("aaaa", result);
Assertions.assertEquals("aaaa", result);
}
@Test
public void toStrTest3() {
final char a = 'a';
final String result = Convert.convert(String.class, a);
Assert.assertEquals("a", result);
Assertions.assertEquals("a", result);
}
@Test
@ -84,7 +84,7 @@ public class ConvertTest {
// 被当作八进制
@SuppressWarnings("OctalInteger")
final String result = Convert.toStr(001200);
Assert.assertEquals("640", result);
Assertions.assertEquals("640", result);
}
@Test
@ -93,118 +93,120 @@ public class ConvertTest {
final String a = "aaaa";
final String aDefaultValue = "aDefault";
final String aResult = Convert.toStr(a, aDefaultValue);
Assert.assertEquals(aResult, a);
Assertions.assertEquals(aResult, a);
// 被转化的对象为null返回默认值
final String b = null;
final String bDefaultValue = "bDefault";
final String bResult = Convert.toStr(b, bDefaultValue);
Assert.assertEquals(bResult, bDefaultValue);
Assertions.assertEquals(bResult, bDefaultValue);
// 转换失败返回默认值
final TestExceptionClass c = new TestExceptionClass();
final String cDefaultValue = "cDefault";
final String cResult = Convert.toStr(c, cDefaultValue);
Assert.assertEquals(cResult, cDefaultValue);
Assertions.assertEquals(cResult, cDefaultValue);
}
@Test
public void toIntTest() {
final String a = " 34232";
final Integer aInteger = Convert.toInt(a);
Assert.assertEquals(Integer.valueOf(34232), aInteger);
Assertions.assertEquals(Integer.valueOf(34232), aInteger);
final int aInt = (int) CompositeConverter.getInstance().convert(int.class, a);
Assert.assertEquals(34232, aInt);
Assertions.assertEquals(34232, aInt);
// 带小数测试
final String b = " 34232.00";
final Integer bInteger = Convert.toInt(b);
Assert.assertEquals(Integer.valueOf(34232), bInteger);
Assertions.assertEquals(Integer.valueOf(34232), bInteger);
final int bInt = (int) CompositeConverter.getInstance().convert(int.class, b);
Assert.assertEquals(34232, bInt);
Assertions.assertEquals(34232, bInt);
// boolean测试
final boolean c = true;
final Integer cInteger = Convert.toInt(c);
Assert.assertEquals(Integer.valueOf(1), cInteger);
Assertions.assertEquals(Integer.valueOf(1), cInteger);
final int cInt = (int) CompositeConverter.getInstance().convert(int.class, c);
Assert.assertEquals(1, cInt);
Assertions.assertEquals(1, cInt);
// boolean测试
final String d = "08";
final Integer dInteger = Convert.toInt(d);
Assert.assertEquals(Integer.valueOf(8), dInteger);
Assertions.assertEquals(Integer.valueOf(8), dInteger);
final int dInt = (int) CompositeConverter.getInstance().convert(int.class, d);
Assert.assertEquals(8, dInt);
Assertions.assertEquals(8, dInt);
}
@Test
public void toIntTest2() {
final ArrayList<String> array = new ArrayList<>();
final Integer aInt = Convert.convertQuietly(Integer.class, array, -1);
Assert.assertEquals(Integer.valueOf(-1), aInt);
Assertions.assertEquals(Integer.valueOf(-1), aInt);
}
@Test(expected = NumberFormatException.class)
@Test
public void toIntOfExceptionTest(){
final Integer d = Convert.convert(Integer.class, "d");
Assert.assertNotNull(d);
Assertions.assertThrows(NumberFormatException.class, ()->{
final Integer d = Convert.convert(Integer.class, "d");
Assertions.assertNotNull(d);
});
}
@Test
public void toLongTest() {
final String a = " 342324545435435";
final Long aLong = Convert.toLong(a);
Assert.assertEquals(Long.valueOf(342324545435435L), aLong);
Assertions.assertEquals(Long.valueOf(342324545435435L), aLong);
final long aLong2 = (long) CompositeConverter.getInstance().convert(long.class, a);
Assert.assertEquals(342324545435435L, aLong2);
Assertions.assertEquals(342324545435435L, aLong2);
// 带小数测试
final String b = " 342324545435435.245435435";
final Long bLong = Convert.toLong(b);
Assert.assertEquals(Long.valueOf(342324545435435L), bLong);
Assertions.assertEquals(Long.valueOf(342324545435435L), bLong);
final long bLong2 = (long) CompositeConverter.getInstance().convert(long.class, b);
Assert.assertEquals(342324545435435L, bLong2);
Assertions.assertEquals(342324545435435L, bLong2);
// boolean测试
final boolean c = true;
final Long cLong = Convert.toLong(c);
Assert.assertEquals(Long.valueOf(1), cLong);
Assertions.assertEquals(Long.valueOf(1), cLong);
final long cLong2 = (long) CompositeConverter.getInstance().convert(long.class, c);
Assert.assertEquals(1, cLong2);
Assertions.assertEquals(1, cLong2);
// boolean测试
final String d = "08";
final Long dLong = Convert.toLong(d);
Assert.assertEquals(Long.valueOf(8), dLong);
Assertions.assertEquals(Long.valueOf(8), dLong);
final long dLong2 = (long) CompositeConverter.getInstance().convert(long.class, d);
Assert.assertEquals(8, dLong2);
Assertions.assertEquals(8, dLong2);
}
@Test
public void toCharTest() {
final String str = "aadfdsfs";
final Character c = Convert.toChar(str);
Assert.assertEquals(Character.valueOf('a'), c);
Assertions.assertEquals(Character.valueOf('a'), c);
// 转换失败
final Object str2 = "";
final Character c2 = Convert.toChar(str2);
Assert.assertNull(c2);
Assertions.assertNull(c2);
}
@Test
public void toNumberTest() {
final Object a = "12.45";
final Number number = Convert.toNumber(a);
Assert.assertEquals(12.45D, number.doubleValue(), 0);
Assertions.assertEquals(12.45D, number.doubleValue(), 0);
}
@Test
public void emptyToNumberTest() {
final Object a = "";
final Number number = Convert.toNumber(a);
Assert.assertNull(number);
Assertions.assertNull(number);
}
@Test
@ -212,10 +214,10 @@ public class ConvertTest {
// 测试 int byte
final int int0 = 234;
final byte byte0 = Convert.intToByte(int0);
Assert.assertEquals(-22, byte0);
Assertions.assertEquals(-22, byte0);
final int int1 = Convert.byteToUnsignedInt(byte0);
Assert.assertEquals(int0, int1);
Assertions.assertEquals(int0, int1);
}
@Test
@ -226,7 +228,7 @@ public class ConvertTest {
// 测试 byte 数组转 int
final int int3 = Convert.bytesToInt(bytesInt);
Assert.assertEquals(int2, int3);
Assertions.assertEquals(int2, int3);
}
@Test
@ -237,7 +239,7 @@ public class ConvertTest {
final byte[] bytesLong = Convert.longToBytes(long1);
final long long2 = Convert.bytesToLong(bytesLong);
Assert.assertEquals(long1, long2);
Assertions.assertEquals(long1, long2);
}
@Test
@ -246,7 +248,7 @@ public class ConvertTest {
final byte[] bytes = Convert.shortToBytes(short1);
final short short2 = Convert.bytesToShort(bytes);
Assert.assertEquals(short2, short1);
Assertions.assertEquals(short2, short1);
}
@Test
@ -254,63 +256,63 @@ public class ConvertTest {
final List<String> list = Arrays.asList("1", "2");
final String str = Convert.toStr(list);
final List<String> list2 = Convert.toList(String.class, str);
Assert.assertEquals("1", list2.get(0));
Assert.assertEquals("2", list2.get(1));
Assertions.assertEquals("1", list2.get(0));
Assertions.assertEquals("2", list2.get(1));
final List<Integer> list3 = Convert.toList(Integer.class, str);
Assert.assertEquals(1, list3.get(0).intValue());
Assert.assertEquals(2, list3.get(1).intValue());
Assertions.assertEquals(1, list3.get(0).intValue());
Assertions.assertEquals(2, list3.get(1).intValue());
}
@Test
public void toListTest2(){
final String str = "1,2";
final List<String> list2 = Convert.toList(String.class, str);
Assert.assertEquals("1", list2.get(0));
Assert.assertEquals("2", list2.get(1));
Assertions.assertEquals("1", list2.get(0));
Assertions.assertEquals("2", list2.get(1));
final List<Integer> list3 = Convert.toList(Integer.class, str);
Assert.assertEquals(1, list3.get(0).intValue());
Assert.assertEquals(2, list3.get(1).intValue());
Assertions.assertEquals(1, list3.get(0).intValue());
Assertions.assertEquals(2, list3.get(1).intValue());
}
@Test
public void toByteArrayTest(){
// 测试Serializable转换为bytes调用序列化转换
final byte[] bytes = Convert.toPrimitiveByteArray(new Product("zhangsan", "张三", "5.1.1"));
Assert.assertNotNull(bytes);
Assertions.assertNotNull(bytes);
final Product product = Convert.convert(Product.class, bytes);
Assert.assertEquals("zhangsan", product.getName());
Assert.assertEquals("张三", product.getCName());
Assert.assertEquals("5.1.1", product.getVersion());
Assertions.assertEquals("zhangsan", product.getName());
Assertions.assertEquals("张三", product.getCName());
Assertions.assertEquals("5.1.1", product.getVersion());
}
@Test
public void numberToByteArrayTest(){
// 测试Serializable转换为bytes调用序列化转换
final byte[] bytes = Convert.toPrimitiveByteArray(12L);
Assert.assertArrayEquals(ByteUtil.toBytes(12L), bytes);
Assertions.assertArrayEquals(ByteUtil.toBytes(12L), bytes);
}
@Test
public void toAtomicIntegerArrayTest(){
final String str = "1,2";
final AtomicIntegerArray atomicIntegerArray = Convert.convert(AtomicIntegerArray.class, str);
Assert.assertEquals("[1, 2]", atomicIntegerArray.toString());
Assertions.assertEquals("[1, 2]", atomicIntegerArray.toString());
}
@Test
public void toAtomicLongArrayTest(){
final String str = "1,2";
final AtomicLongArray atomicLongArray = Convert.convert(AtomicLongArray.class, str);
Assert.assertEquals("[1, 2]", atomicLongArray.toString());
Assertions.assertEquals("[1, 2]", atomicLongArray.toString());
}
@Test
public void toClassTest(){
final Class<?> convert = Convert.convert(Class.class, "cn.hutool.core.convert.ConvertTest.Product");
Assert.assertSame(Product.class, convert);
Assertions.assertSame(Product.class, convert);
}
@Data
@ -326,14 +328,14 @@ public class ConvertTest {
@Test
public void enumToIntTest(){
final Integer integer = Convert.toInt(BuildingType.CUO);
Assert.assertEquals(1, integer.intValue());
Assertions.assertEquals(1, integer.intValue());
}
@Test
public void toSetTest(){
final Set<Integer> result = Convert.convert(new TypeReference<Set<Integer>>() {
}, "1,2,3");
Assert.assertEquals(SetUtil.of(1,2,3), result);
Assertions.assertEquals(SetUtil.of(1,2,3), result);
}
@Getter
@ -354,22 +356,24 @@ public class ConvertTest {
}
}
@Test(expected = DateException.class)
@Test
public void toDateTest(){
// 默认转换失败报错而不是返回null
Convert.convert(Date.class, "aaaa");
Assertions.assertThrows(DateException.class, ()->{
// 默认转换失败报错而不是返回null
Convert.convert(Date.class, "aaaa");
});
}
@Test
public void toDateTest2(){
final Date date = Convert.toDate("2021-01");
Assert.assertNull(date);
Assertions.assertNull(date);
}
@Test
public void toSqlDateTest(){
final java.sql.Date date = Convert.convert(java.sql.Date.class, DateUtil.parse("2021-07-28"));
Assert.assertEquals("2021-07-28", date.toString());
Assertions.assertEquals("2021-07-28", date.toString());
}
@Test
@ -381,9 +385,9 @@ public class ConvertTest {
@SuppressWarnings("unchecked")
final Hashtable<String, String> hashtable = Convert.convert(Hashtable.class, map);
Assert.assertEquals("v1", hashtable.get("a1"));
Assert.assertEquals("v2", hashtable.get("a2"));
Assert.assertEquals("v3", hashtable.get("a3"));
Assertions.assertEquals("v1", hashtable.get("a1"));
Assertions.assertEquals("v2", hashtable.get("a2"));
Assertions.assertEquals("v3", hashtable.get("a3"));
}
@Test
@ -391,9 +395,9 @@ public class ConvertTest {
// https://github.com/dromara/hutool/issues/1818
final String str = "33020000210909112800000124";
final BigDecimal bigDecimal = Convert.toBigDecimal(str);
Assert.assertEquals(str, bigDecimal.toPlainString());
Assertions.assertEquals(str, bigDecimal.toPlainString());
Assert.assertNull(Convert.toBigDecimal(" "));
Assertions.assertNull(Convert.toBigDecimal(" "));
}
@Test
@ -402,53 +406,53 @@ public class ConvertTest {
final String hex2 = "CD0CCB43";
final byte[] value = HexUtil.decodeHex(hex2);
final float f = Convert.toFloat(value);
Assert.assertEquals(406.1F, f, 0);
Assertions.assertEquals(406.1F, f, 0);
}
@Test
public void floatToDoubleTest(){
final float a = 0.45f;
final double b = Convert.toDouble(a);
Assert.assertEquals(0.45D, b, 0);
Assertions.assertEquals(0.45D, b, 0);
}
@Test
public void floatToDoubleAddrTest(){
final float a = 0.45f;
final DoubleAdder adder = Convert.convert(DoubleAdder.class, a);
Assert.assertEquals(0.45D, adder.doubleValue(), 0);
Assertions.assertEquals(0.45D, adder.doubleValue(), 0);
}
@Test
public void doubleToFloatTest(){
final double a = 0.45f;
final float b = Convert.toFloat(a);
Assert.assertEquals(a, b, 0);
Assertions.assertEquals(a, b, 0);
}
@Test
public void localDateTimeToLocalDateTest(){
final LocalDateTime localDateTime = LocalDateTime.now();
final LocalDate convert = Convert.convert(LocalDate.class, localDateTime);
Assert.assertEquals(localDateTime.toLocalDate(), convert);
Assertions.assertEquals(localDateTime.toLocalDate(), convert);
}
@Test
public void toSBCTest(){
final String s = Convert.toSBC(null);
Assert.assertNull(s);
Assertions.assertNull(s);
}
@Test
public void toDBCTest(){
final String s = Convert.toDBC(null);
Assert.assertNull(s);
Assertions.assertNull(s);
}
@Test
public void convertQuietlyTest(){
final String a = "12";
final Object s = Convert.convertQuietly(int.class, a, a);
Assert.assertEquals(12, s);
Assertions.assertEquals(12, s);
}
}

View File

@ -3,9 +3,9 @@ package cn.hutool.core.convert;
import cn.hutool.core.convert.impl.ArrayConverter;
import cn.hutool.core.io.file.FileUtil;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.URL;
@ -25,14 +25,14 @@ public class ConvertToArrayTest {
final String[] b = { "1", "2", "3", "4" };
final Integer[] integerArray = Convert.toIntArray(b);
Assert.assertArrayEquals(integerArray, new Integer[]{1,2,3,4});
Assertions.assertArrayEquals(integerArray, new Integer[]{1,2,3,4});
final int[] intArray = Convert.convert(int[].class, b);
Assert.assertArrayEquals(intArray, new int[]{1,2,3,4});
Assertions.assertArrayEquals(intArray, new int[]{1,2,3,4});
final long[] c = {1,2,3,4,5};
final Integer[] intArray2 = Convert.toIntArray(c);
Assert.assertArrayEquals(intArray2, new Integer[]{1,2,3,4,5});
Assertions.assertArrayEquals(intArray2, new Integer[]{1,2,3,4,5});
}
@Test
@ -41,7 +41,7 @@ public class ConvertToArrayTest {
final ArrayConverter arrayConverter = new ArrayConverter(true);
final Integer[] integerArray = arrayConverter.convert(Integer[].class, b, null);
Assert.assertArrayEquals(integerArray, new Integer[]{null, 1});
Assertions.assertArrayEquals(integerArray, new Integer[]{null, 1});
}
@Test
@ -49,14 +49,14 @@ public class ConvertToArrayTest {
final String[] b = { "1", "2", "3", "4" };
final Long[] longArray = Convert.toLongArray(b);
Assert.assertArrayEquals(longArray, new Long[]{1L,2L,3L,4L});
Assertions.assertArrayEquals(longArray, new Long[]{1L,2L,3L,4L});
final long[] longArray2 = Convert.convert(long[].class, b);
Assert.assertArrayEquals(longArray2, new long[]{1L,2L,3L,4L});
Assertions.assertArrayEquals(longArray2, new long[]{1L,2L,3L,4L});
final int[] c = {1,2,3,4,5};
final Long[] intArray2 = Convert.toLongArray(c);
Assert.assertArrayEquals(intArray2, new Long[]{1L,2L,3L,4L,5L});
Assertions.assertArrayEquals(intArray2, new Long[]{1L,2L,3L,4L,5L});
}
@Test
@ -64,14 +64,14 @@ public class ConvertToArrayTest {
final String[] b = { "1", "2", "3", "4" };
final Double[] doubleArray = Convert.toDoubleArray(b);
Assert.assertArrayEquals(doubleArray, new Double[]{1D,2D,3D,4D});
Assertions.assertArrayEquals(doubleArray, new Double[]{1D,2D,3D,4D});
final double[] doubleArray2 = Convert.convert(double[].class, b);
Assert.assertArrayEquals(doubleArray2, new double[]{1D,2D,3D,4D}, 2);
Assertions.assertArrayEquals(doubleArray2, new double[]{1D,2D,3D,4D}, 2);
final int[] c = {1,2,3,4,5};
final Double[] intArray2 = Convert.toDoubleArray(c);
Assert.assertArrayEquals(intArray2, new Double[]{1D,2D,3D,4D,5D});
Assertions.assertArrayEquals(intArray2, new Double[]{1D,2D,3D,4D,5D});
}
@Test
@ -80,18 +80,18 @@ public class ConvertToArrayTest {
//数组转数组测试
final int[] a = new int[]{1,2,3,4};
final long[] result = (long[]) CompositeConverter.getInstance().convert(long[].class, a);
Assert.assertArrayEquals(new long[]{1L, 2L, 3L, 4L}, result);
Assertions.assertArrayEquals(new long[]{1L, 2L, 3L, 4L}, result);
//数组转数组测试
final byte[] resultBytes = (byte[]) CompositeConverter.getInstance().convert(byte[].class, a);
Assert.assertArrayEquals(new byte[]{1, 2, 3, 4}, resultBytes);
Assertions.assertArrayEquals(new byte[]{1, 2, 3, 4}, resultBytes);
//字符串转数组
final String arrayStr = "1,2,3,4,5";
//获取Converter类的方法2自己实例化相应Converter对象
final ArrayConverter c3 = new ArrayConverter();
final int[] result3 = c3.convert(int[].class, arrayStr, null);
Assert.assertArrayEquals(new int[]{1,2,3,4,5}, result3);
Assertions.assertArrayEquals(new int[]{1,2,3,4,5}, result3);
}
@Test
@ -102,9 +102,9 @@ public class ConvertToArrayTest {
list.add("c");
final String[] result = Convert.toStrArray(list);
Assert.assertEquals(list.get(0), result[0]);
Assert.assertEquals(list.get(1), result[1]);
Assert.assertEquals(list.get(2), result[2]);
Assertions.assertEquals(list.get(0), result[0]);
Assertions.assertEquals(list.get(1), result[1]);
Assertions.assertEquals(list.get(2), result[2]);
}
@Test
@ -113,24 +113,24 @@ public class ConvertToArrayTest {
final Character[] array = Convert.toCharArray(testStr);
//包装类型数组
Assert.assertEquals(new Character('a'), array[0]);
Assert.assertEquals(new Character('b'), array[1]);
Assert.assertEquals(new Character('c'), array[2]);
Assert.assertEquals(new Character('d'), array[3]);
Assert.assertEquals(new Character('e'), array[4]);
Assertions.assertEquals(new Character('a'), array[0]);
Assertions.assertEquals(new Character('b'), array[1]);
Assertions.assertEquals(new Character('c'), array[2]);
Assertions.assertEquals(new Character('d'), array[3]);
Assertions.assertEquals(new Character('e'), array[4]);
//原始类型数组
final char[] array2 = Convert.convert(char[].class, testStr);
Assert.assertEquals('a', array2[0]);
Assert.assertEquals('b', array2[1]);
Assert.assertEquals('c', array2[2]);
Assert.assertEquals('d', array2[3]);
Assert.assertEquals('e', array2[4]);
Assertions.assertEquals('a', array2[0]);
Assertions.assertEquals('b', array2[1]);
Assertions.assertEquals('c', array2[2]);
Assertions.assertEquals('d', array2[3]);
Assertions.assertEquals('e', array2[4]);
}
@Test
@Ignore
@Disabled
public void toUrlArrayTest() {
final File[] files = FileUtil.file("D:\\workspace").listFiles();

View File

@ -3,8 +3,8 @@ package cn.hutool.core.convert;
import cn.hutool.core.bean.BeanUtilTest.SubPerson;
import cn.hutool.core.map.CaseInsensitiveMap;
import cn.hutool.core.reflect.TypeReference;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -28,9 +28,9 @@ public class ConvertToBeanTest {
person.setSubName("sub名字");
final Map<?, ?> map = Convert.convert(Map.class, person);
Assert.assertEquals(map.get("name"), "测试A11");
Assert.assertEquals(map.get("age"), 14);
Assert.assertEquals("11213232", map.get("openid"));
Assertions.assertEquals(map.get("name"), "测试A11");
Assertions.assertEquals(map.get("age"), 14);
Assertions.assertEquals("11213232", map.get("openid"));
}
@Test
@ -42,15 +42,15 @@ public class ConvertToBeanTest {
person.setSubName("sub名字");
final Map<String, String> map = Convert.toMap(String.class, String.class, person);
Assert.assertEquals("测试A11", map.get("name"));
Assert.assertEquals("14", map.get("age"));
Assert.assertEquals("11213232", map.get("openid"));
Assertions.assertEquals("测试A11", map.get("name"));
Assertions.assertEquals("14", map.get("age"));
Assertions.assertEquals("11213232", map.get("openid"));
final LinkedHashMap<String, String> map2 = Convert.convert(
new TypeReference<LinkedHashMap<String, String>>() {}, person);
Assert.assertEquals("测试A11", map2.get("name"));
Assert.assertEquals("14", map2.get("age"));
Assert.assertEquals("11213232", map2.get("openid"));
Assertions.assertEquals("测试A11", map2.get("name"));
Assertions.assertEquals("14", map2.get("age"));
Assertions.assertEquals("11213232", map2.get("openid"));
}
@Test
@ -63,10 +63,10 @@ public class ConvertToBeanTest {
final Map<String, String> map2 = Convert.toMap(String.class, String.class, map1);
Assert.assertEquals("1", map2.get("key1"));
Assert.assertEquals("2", map2.get("key2"));
Assert.assertEquals("3", map2.get("key3"));
Assert.assertEquals("4", map2.get("key4"));
Assertions.assertEquals("1", map2.get("key1"));
Assertions.assertEquals("2", map2.get("key2"));
Assertions.assertEquals("3", map2.get("key3"));
Assertions.assertEquals("4", map2.get("key4"));
}
@Test
@ -79,18 +79,18 @@ public class ConvertToBeanTest {
map.put("subName", "sub名字");
final SubPerson subPerson = Convert.convert(SubPerson.class, map);
Assert.assertEquals("88dc4b28-91b1-4a1a-bab5-444b795c7ecd", subPerson.getId().toString());
Assert.assertEquals(14, subPerson.getAge());
Assert.assertEquals("11213232", subPerson.getOpenid());
Assert.assertEquals("测试A11", subPerson.getName());
Assert.assertEquals("11213232", subPerson.getOpenid());
Assertions.assertEquals("88dc4b28-91b1-4a1a-bab5-444b795c7ecd", subPerson.getId().toString());
Assertions.assertEquals(14, subPerson.getAge());
Assertions.assertEquals("11213232", subPerson.getOpenid());
Assertions.assertEquals("测试A11", subPerson.getName());
Assertions.assertEquals("11213232", subPerson.getOpenid());
}
@Test
public void nullStrToBeanTest(){
final String nullStr = "null";
final SubPerson subPerson = Convert.convertQuietly(SubPerson.class, nullStr);
Assert.assertNull(subPerson);
Assertions.assertNull(subPerson);
}
@Test
@ -101,9 +101,9 @@ public class ConvertToBeanTest {
caseInsensitiveMap.put("tom", 3);
Map<String, String> map = Convert.toMap(String.class, String.class, caseInsensitiveMap);
Assert.assertEquals("2", map.get("jerry"));
Assert.assertEquals("2", map.get("Jerry"));
Assert.assertEquals("3", map.get("tom"));
Assertions.assertEquals("2", map.get("jerry"));
Assertions.assertEquals("2", map.get("Jerry"));
Assertions.assertEquals("3", map.get("tom"));
}
@Test
public void beanToSpecifyMapTest() {
@ -114,8 +114,8 @@ public class ConvertToBeanTest {
person.setSubName("sub名字");
Map<String, String> map = Convert.toMap(LinkedHashMap.class, String.class, String.class, person);
Assert.assertEquals("测试A11", map.get("name"));
Assert.assertEquals("14", map.get("age"));
Assert.assertEquals("11213232", map.get("openid"));
Assertions.assertEquals("测试A11", map.get("name"));
Assertions.assertEquals("14", map.get("age"));
Assertions.assertEquals("11213232", map.get("openid"));
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ConvertToBooleanTest {
@ -9,17 +9,17 @@ public class ConvertToBooleanTest {
public void intToBooleanTest() {
final int a = 100;
final Boolean aBoolean = Convert.toBoolean(a);
Assert.assertTrue(aBoolean);
Assertions.assertTrue(aBoolean);
final int b = 0;
final Boolean bBoolean = Convert.toBoolean(b);
Assert.assertFalse(bBoolean);
Assertions.assertFalse(bBoolean);
}
@Test
public void issueI65P8ATest() {
final Boolean bool = Convert.toBoolean("", Boolean.TRUE);
Assert.assertFalse(bool);
Assertions.assertFalse(bool);
}
}

View File

@ -2,8 +2,8 @@ package cn.hutool.core.convert;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.reflect.TypeReference;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.util.ArrayList;
@ -24,104 +24,104 @@ public class ConvertToCollectionTest {
public void toCollectionTest() {
final Object[] a = { "a", "", "", "", 1 };
final List<?> list = (List<?>) Convert.convert(Collection.class, a);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("", list.get(3));
Assert.assertEquals(1, list.get(4));
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("", list.get(3));
Assertions.assertEquals(1, list.get(4));
}
@Test
public void toListTest() {
final Object[] a = { "a", "", "", "", 1 };
final List<?> list = Convert.toList(a);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("", list.get(3));
Assert.assertEquals(1, list.get(4));
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("", list.get(3));
Assertions.assertEquals(1, list.get(4));
}
@Test
public void toListTest2() {
final Object[] a = { "a", "", "", "", 1 };
final List<String> list = Convert.toList(String.class, a);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("", list.get(3));
Assert.assertEquals("1", list.get(4));
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("", list.get(3));
Assertions.assertEquals("1", list.get(4));
}
@Test
public void toListTest3() {
final Object[] a = { "a", "", "", "", 1 };
final List<String> list = Convert.toList(String.class, a);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("", list.get(3));
Assert.assertEquals("1", list.get(4));
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("", list.get(3));
Assertions.assertEquals("1", list.get(4));
}
@Test
public void toListTest4() {
final Object[] a = { "a", "", "", "", 1 };
final List<String> list = Convert.convert(new TypeReference<List<String>>() {}, a);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("", list.get(3));
Assert.assertEquals("1", list.get(4));
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("", list.get(3));
Assertions.assertEquals("1", list.get(4));
}
@Test
public void strToListTest() {
final String a = "a,你,好,123";
final List<?> list = Convert.toList(a);
Assert.assertEquals(4, list.size());
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("123", list.get(3));
Assertions.assertEquals(4, list.size());
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("123", list.get(3));
final String b = "a";
final List<?> list2 = Convert.toList(b);
Assert.assertEquals(1, list2.size());
Assert.assertEquals("a", list2.get(0));
Assertions.assertEquals(1, list2.size());
Assertions.assertEquals("a", list2.get(0));
}
@Test
public void strToListTest2() {
final String a = "a,你,好,123";
final List<String> list = Convert.toList(String.class, a);
Assert.assertEquals(4, list.size());
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("123", list.get(3));
Assertions.assertEquals(4, list.size());
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("123", list.get(3));
}
@Test
public void numberToListTest() {
final Integer i = 1;
final ArrayList<?> list = Convert.convert(ArrayList.class, i);
Assert.assertSame(i, list.get(0));
Assertions.assertSame(i, list.get(0));
final BigDecimal b = BigDecimal.ONE;
final ArrayList<?> list2 = Convert.convert(ArrayList.class, b);
Assert.assertEquals(b, list2.get(0));
Assertions.assertEquals(b, list2.get(0));
}
@Test
public void toLinkedListTest() {
final Object[] a = { "a", "", "", "", 1 };
final List<?> list = Convert.convert(LinkedList.class, a);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("", list.get(3));
Assert.assertEquals(1, list.get(4));
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("", list.get(3));
Assertions.assertEquals(1, list.get(4));
}
@Test
@ -129,10 +129,10 @@ public class ConvertToCollectionTest {
final Object[] a = { "a", "", "", "", 1 };
final LinkedHashSet<?> set = Convert.convert(LinkedHashSet.class, a);
final ArrayList<?> list = ListUtil.of(set);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));
Assert.assertEquals("", list.get(3));
Assert.assertEquals(1, list.get(4));
Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2));
Assertions.assertEquals("", list.get(3));
Assertions.assertEquals(1, list.get(4));
}
}

View File

@ -2,8 +2,8 @@ package cn.hutool.core.convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.util.concurrent.atomic.AtomicLong;
@ -14,7 +14,7 @@ public class ConvertToNumberTest {
final DateTime date = DateUtil.parse("2020-05-17 12:32:00");
final Long dateLong = Convert.toLong(date);
assert date != null;
Assert.assertEquals(date.getTime(), dateLong.longValue());
Assertions.assertEquals(date.getTime(), dateLong.longValue());
}
@Test
@ -22,7 +22,7 @@ public class ConvertToNumberTest {
final DateTime date = DateUtil.parse("2020-05-17 12:32:00");
final Integer dateInt = Convert.toInt(date);
assert date != null;
Assert.assertEquals((int)date.getTime(), dateInt.intValue());
Assertions.assertEquals((int)date.getTime(), dateInt.intValue());
}
@Test
@ -30,22 +30,22 @@ public class ConvertToNumberTest {
final DateTime date = DateUtil.parse("2020-05-17 12:32:00");
final AtomicLong dateLong = Convert.convert(AtomicLong.class, date);
assert date != null;
Assert.assertEquals(date.getTime(), dateLong.longValue());
Assertions.assertEquals(date.getTime(), dateLong.longValue());
}
@Test
public void toBigDecimalTest(){
BigDecimal bigDecimal = Convert.toBigDecimal("1.1f");
Assert.assertEquals(1.1f, bigDecimal.floatValue(), 0);
Assertions.assertEquals(1.1f, bigDecimal.floatValue(), 0);
bigDecimal = Convert.toBigDecimal("1L");
Assert.assertEquals(1L, bigDecimal.longValue());
Assertions.assertEquals(1L, bigDecimal.longValue());
}
@Test
public void toNumberTest(){
// 直接转换为抽象Number默认使用BigDecimal实现
final Number number = Convert.toNumber("1");
Assert.assertEquals(BigDecimal.class, number.getClass());
Assertions.assertEquals(BigDecimal.class, number.getClass());
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 类型转换工具单元测试
@ -16,13 +16,13 @@ public class ConvertToSBCAndDBCTest {
public void toSBCTest() {
final String a = "123456789";
final String sbc = Convert.toSBC(a);
Assert.assertEquals("", sbc);
Assertions.assertEquals("", sbc);
}
@Test
public void toDBCTest() {
final String a = "";
final String dbc = Convert.toDBC(a);
Assert.assertEquals("123456789", dbc);
Assertions.assertEquals("123456789", dbc);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.convert;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
import java.time.LocalDateTime;
@ -15,42 +15,42 @@ public class DateConvertTest {
public void toDateTest() {
final String a = "2017-05-06";
final Date value = Convert.toDate(a);
Assert.assertEquals(a, DateUtil.formatDate(value));
Assertions.assertEquals(a, DateUtil.formatDate(value));
final long timeLong = DateUtil.now().getTime();
final Date value2 = Convert.toDate(timeLong);
Assert.assertEquals(timeLong, value2.getTime());
Assertions.assertEquals(timeLong, value2.getTime());
}
@Test
public void toDateFromIntTest() {
final int dateLong = -1497600000;
final Date value = Convert.toDate(dateLong);
Assert.assertNotNull(value);
Assert.assertEquals("Mon Dec 15 00:00:00 CST 1969", value.toString().replace("GMT+08:00", "CST"));
Assertions.assertNotNull(value);
Assertions.assertEquals("Mon Dec 15 00:00:00 CST 1969", value.toString().replace("GMT+08:00", "CST"));
final java.sql.Date sqlDate = Convert.convert(java.sql.Date.class, dateLong);
Assert.assertNotNull(sqlDate);
Assert.assertEquals("1969-12-15", sqlDate.toString());
Assertions.assertNotNull(sqlDate);
Assertions.assertEquals("1969-12-15", sqlDate.toString());
}
@Test
public void toDateFromLocalDateTimeTest() {
final LocalDateTime localDateTime = LocalDateTime.parse("2017-05-06T08:30:00", DateTimeFormatter.ISO_DATE_TIME);
final Date value = Convert.toDate(localDateTime);
Assert.assertNotNull(value);
Assert.assertEquals("2017-05-06", DateUtil.formatDate(value));
Assertions.assertNotNull(value);
Assertions.assertEquals("2017-05-06", DateUtil.formatDate(value));
}
@Test
public void toSqlDateTest() {
final String a = "2017-05-06";
final java.sql.Date value = Convert.convert(java.sql.Date.class, a);
Assert.assertEquals("2017-05-06", value.toString());
Assertions.assertEquals("2017-05-06", value.toString());
final long timeLong = DateUtil.now().getTime();
final java.sql.Date value2 = Convert.convert(java.sql.Date.class, timeLong);
Assert.assertEquals(timeLong, value2.getTime());
Assertions.assertEquals(timeLong, value2.getTime());
}
@Test
@ -58,14 +58,14 @@ public class DateConvertTest {
final Date src = new Date();
LocalDateTime ldt = Convert.toLocalDateTime(src);
Assert.assertEquals(ldt, DateUtil.toLocalDateTime(src));
Assertions.assertEquals(ldt, DateUtil.toLocalDateTime(src));
final Timestamp ts = Timestamp.from(src.toInstant());
ldt = Convert.toLocalDateTime(ts);
Assert.assertEquals(ldt, DateUtil.toLocalDateTime(src));
Assertions.assertEquals(ldt, DateUtil.toLocalDateTime(src));
final String str = "2020-12-12 12:12:12.0";
ldt = Convert.toLocalDateTime(str);
Assert.assertEquals(ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")), str);
Assertions.assertEquals(ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")), str);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* Enum转换单元测试
@ -11,19 +11,19 @@ public class EnumConvertTest {
@Test
public void convertTest(){
TestEnum bbb = Convert.convert(TestEnum.class, "BBB");
Assert.assertEquals(TestEnum.B, bbb);
Assertions.assertEquals(TestEnum.B, bbb);
bbb = Convert.convert(TestEnum.class, 22);
Assert.assertEquals(TestEnum.B, bbb);
Assertions.assertEquals(TestEnum.B, bbb);
}
@Test
public void toEnumTest(){
TestEnum ccc = Convert.toEnum(TestEnum.class, "CCC");
Assert.assertEquals(TestEnum.C, ccc);
Assertions.assertEquals(TestEnum.C, ccc);
ccc = Convert.toEnum(TestEnum.class, 33);
Assert.assertEquals(TestEnum.C, ccc);
Assertions.assertEquals(TestEnum.C, ccc);
}
enum TestEnum {

View File

@ -1,8 +1,8 @@
package cn.hutool.core.convert;
import cn.hutool.core.map.MapBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -23,8 +23,8 @@ public class MapConvertTest {
user.setAge(45);
final HashMap<?, ?> map = Convert.convert(HashMap.class, user);
Assert.assertEquals("AAA", map.get("name"));
Assert.assertEquals(45, map.get("age"));
Assertions.assertEquals("AAA", map.get("name"));
Assertions.assertEquals(45, map.get("age"));
}
@Test
@ -35,8 +35,8 @@ public class MapConvertTest {
.put("age", 45).map();
final LinkedHashMap<?, ?> map = Convert.convert(LinkedHashMap.class, srcMap);
Assert.assertEquals("AAA", map.get("name"));
Assert.assertEquals(45, map.get("age"));
Assertions.assertEquals("AAA", map.get("name"));
Assertions.assertEquals(45, map.get("age"));
}
public static class User {

View File

@ -1,290 +1,290 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class NumberChineseFormatterTest {
@Test
public void formatThousandTest(){
String f = NumberChineseFormatter.formatThousand(10, false);
Assert.assertEquals("", f);
Assertions.assertEquals("", f);
f = NumberChineseFormatter.formatThousand(11, false);
Assert.assertEquals("十一", f);
Assertions.assertEquals("十一", f);
f = NumberChineseFormatter.formatThousand(19, false);
Assert.assertEquals("十九", f);
Assertions.assertEquals("十九", f);
}
// 测试千
@Test
public void formatThousandLongTest(){
String f = NumberChineseFormatter.format(0, false);
Assert.assertEquals("", f);
Assertions.assertEquals("", f);
f = NumberChineseFormatter.format(1, false);
Assert.assertEquals("", f);
Assertions.assertEquals("", f);
f = NumberChineseFormatter.format(10, false);
Assert.assertEquals("一十", f);
Assertions.assertEquals("一十", f);
f = NumberChineseFormatter.format(12, false);
Assert.assertEquals("一十二", f);
Assertions.assertEquals("一十二", f);
f = NumberChineseFormatter.format(100, false);
Assert.assertEquals("一百", f);
Assertions.assertEquals("一百", f);
f = NumberChineseFormatter.format(101, false);
Assert.assertEquals("一百零一", f);
Assertions.assertEquals("一百零一", f);
f = NumberChineseFormatter.format(110, false);
Assert.assertEquals("一百一十", f);
Assertions.assertEquals("一百一十", f);
f = NumberChineseFormatter.format(112, false);
Assert.assertEquals("一百一十二", f);
Assertions.assertEquals("一百一十二", f);
f = NumberChineseFormatter.format(1000, false);
Assert.assertEquals("一千", f);
Assertions.assertEquals("一千", f);
f = NumberChineseFormatter.format(1001, false);
Assert.assertEquals("一千零一", f);
Assertions.assertEquals("一千零一", f);
f = NumberChineseFormatter.format(1010, false);
Assert.assertEquals("一千零一十", f);
Assertions.assertEquals("一千零一十", f);
f = NumberChineseFormatter.format(1100, false);
Assert.assertEquals("一千一百", f);
Assertions.assertEquals("一千一百", f);
f = NumberChineseFormatter.format(1101, false);
Assert.assertEquals("一千一百零一", f);
Assertions.assertEquals("一千一百零一", f);
f = NumberChineseFormatter.format(9999, false);
Assert.assertEquals("九千九百九十九", f);
Assertions.assertEquals("九千九百九十九", f);
}
// 测试万
@Test
public void formatTenThousandLongTest(){
String f = NumberChineseFormatter.format(1_0000, false);
Assert.assertEquals("一万", f);
Assertions.assertEquals("一万", f);
f = NumberChineseFormatter.format(1_0001, false);
Assert.assertEquals("一万零一", f);
Assertions.assertEquals("一万零一", f);
f = NumberChineseFormatter.format(1_0010, false);
Assert.assertEquals("一万零一十", f);
Assertions.assertEquals("一万零一十", f);
f = NumberChineseFormatter.format(1_0100, false);
Assert.assertEquals("一万零一百", f);
Assertions.assertEquals("一万零一百", f);
f = NumberChineseFormatter.format(1_1000, false);
Assert.assertEquals("一万一千", f);
Assertions.assertEquals("一万一千", f);
f = NumberChineseFormatter.format(10_1000, false);
Assert.assertEquals("一十万零一千", f);
Assertions.assertEquals("一十万零一千", f);
f = NumberChineseFormatter.format(10_0100, false);
Assert.assertEquals("一十万零一百", f);
Assertions.assertEquals("一十万零一百", f);
f = NumberChineseFormatter.format(100_1000, false);
Assert.assertEquals("一百万零一千", f);
Assertions.assertEquals("一百万零一千", f);
f = NumberChineseFormatter.format(100_0100, false);
Assert.assertEquals("一百万零一百", f);
Assertions.assertEquals("一百万零一百", f);
f = NumberChineseFormatter.format(1000_1000, false);
Assert.assertEquals("一千万零一千", f);
Assertions.assertEquals("一千万零一千", f);
f = NumberChineseFormatter.format(1000_0100, false);
Assert.assertEquals("一千万零一百", f);
Assertions.assertEquals("一千万零一百", f);
f = NumberChineseFormatter.format(9999_0000, false);
Assert.assertEquals("九千九百九十九万", f);
Assertions.assertEquals("九千九百九十九万", f);
}
// 测试亿
@Test
public void formatHundredMillionLongTest(){
String f = NumberChineseFormatter.format(1_0000_0000L, false);
Assert.assertEquals("一亿", f);
Assertions.assertEquals("一亿", f);
f = NumberChineseFormatter.format(1_0000_0001L, false);
Assert.assertEquals("一亿零一", f);
Assertions.assertEquals("一亿零一", f);
f = NumberChineseFormatter.format(1_0000_1000L, false);
Assert.assertEquals("一亿零一千", f);
Assertions.assertEquals("一亿零一千", f);
f = NumberChineseFormatter.format(1_0001_0000L, false);
Assert.assertEquals("一亿零一万", f);
Assertions.assertEquals("一亿零一万", f);
f = NumberChineseFormatter.format(1_0010_0000L, false);
Assert.assertEquals("一亿零一十万", f);
Assertions.assertEquals("一亿零一十万", f);
f = NumberChineseFormatter.format(1_0010_0000L, false);
Assert.assertEquals("一亿零一十万", f);
Assertions.assertEquals("一亿零一十万", f);
f = NumberChineseFormatter.format(1_0100_0000L, false);
Assert.assertEquals("一亿零一百万", f);
Assertions.assertEquals("一亿零一百万", f);
f = NumberChineseFormatter.format(1_1000_0000L, false);
Assert.assertEquals("一亿一千万", f);
Assertions.assertEquals("一亿一千万", f);
f = NumberChineseFormatter.format(10_1000_0000L, false);
Assert.assertEquals("一十亿零一千万", f);
Assertions.assertEquals("一十亿零一千万", f);
f = NumberChineseFormatter.format(100_1000_0000L, false);
Assert.assertEquals("一百亿零一千万", f);
Assertions.assertEquals("一百亿零一千万", f);
f = NumberChineseFormatter.format(1000_1000_0000L, false);
Assert.assertEquals("一千亿零一千万", f);
Assertions.assertEquals("一千亿零一千万", f);
f = NumberChineseFormatter.format(1100_1000_0000L, false);
Assert.assertEquals("一千一百亿零一千万", f);
Assertions.assertEquals("一千一百亿零一千万", f);
f = NumberChineseFormatter.format(9999_0000_0000L, false);
Assert.assertEquals("九千九百九十九亿", f);
Assertions.assertEquals("九千九百九十九亿", f);
}
// 测试万亿
@Test
public void formatTrillionsLongTest(){
String f = NumberChineseFormatter.format(1_0000_0000_0000L, false);
Assert.assertEquals("一万亿", f);
Assertions.assertEquals("一万亿", f);
f = NumberChineseFormatter.format(1_0000_1000_0000L, false);
Assert.assertEquals("一万亿零一千万", f);
Assertions.assertEquals("一万亿零一千万", f);
f = NumberChineseFormatter.format(1_0010_0000_0000L, false);
Assert.assertEquals("一万零一十亿", f);
Assertions.assertEquals("一万零一十亿", f);
}
@Test
public void formatTest() {
final String f0 = NumberChineseFormatter.format(5000_8000, false);
Assert.assertEquals("五千万零八千", f0);
Assertions.assertEquals("五千万零八千", f0);
String f1 = NumberChineseFormatter.format(1_0889.72356, false);
Assert.assertEquals("一万零八百八十九点七二", f1);
Assertions.assertEquals("一万零八百八十九点七二", f1);
f1 = NumberChineseFormatter.format(12653, false);
Assert.assertEquals("一万二千六百五十三", f1);
Assertions.assertEquals("一万二千六百五十三", f1);
f1 = NumberChineseFormatter.format(215.6387, false);
Assert.assertEquals("二百一十五点六四", f1);
Assertions.assertEquals("二百一十五点六四", f1);
f1 = NumberChineseFormatter.format(1024, false);
Assert.assertEquals("一千零二十四", f1);
Assertions.assertEquals("一千零二十四", f1);
f1 = NumberChineseFormatter.format(100350089, false);
Assert.assertEquals("一亿零三十五万零八十九", f1);
Assertions.assertEquals("一亿零三十五万零八十九", f1);
f1 = NumberChineseFormatter.format(1200, false);
Assert.assertEquals("一千二百", f1);
Assertions.assertEquals("一千二百", f1);
f1 = NumberChineseFormatter.format(12, false);
Assert.assertEquals("一十二", f1);
Assertions.assertEquals("一十二", f1);
f1 = NumberChineseFormatter.format(0.05, false);
Assert.assertEquals("零点零五", f1);
Assertions.assertEquals("零点零五", f1);
}
@Test
public void formatTest2() {
String f1 = NumberChineseFormatter.format(-0.3, false, false);
Assert.assertEquals("负零点三", f1);
Assertions.assertEquals("负零点三", f1);
f1 = NumberChineseFormatter.format(10, false, false);
Assert.assertEquals("一十", f1);
Assertions.assertEquals("一十", f1);
}
@Test
public void formatTest3() {
final String f1 = NumberChineseFormatter.format(5000_8000, false, false);
Assert.assertEquals("五千万零八千", f1);
Assertions.assertEquals("五千万零八千", f1);
final String f2 = NumberChineseFormatter.format(1_0035_0089, false, false);
Assert.assertEquals("一亿零三十五万零八十九", f2);
Assertions.assertEquals("一亿零三十五万零八十九", f2);
}
@Test
public void formatMaxTest() {
final String f3 = NumberChineseFormatter.format(99_9999_9999_9999L, false, false);
Assert.assertEquals("九十九万九千九百九十九亿九千九百九十九万九千九百九十九", f3);
Assertions.assertEquals("九十九万九千九百九十九亿九千九百九十九万九千九百九十九", f3);
}
@Test
public void formatTraditionalTest() {
String f1 = NumberChineseFormatter.format(10889.72356, true);
Assert.assertEquals("壹万零捌佰捌拾玖点柒贰", f1);
Assertions.assertEquals("壹万零捌佰捌拾玖点柒贰", f1);
f1 = NumberChineseFormatter.format(12653, true);
Assert.assertEquals("壹万贰仟陆佰伍拾叁", f1);
Assertions.assertEquals("壹万贰仟陆佰伍拾叁", f1);
f1 = NumberChineseFormatter.format(215.6387, true);
Assert.assertEquals("贰佰壹拾伍点陆肆", f1);
Assertions.assertEquals("贰佰壹拾伍点陆肆", f1);
f1 = NumberChineseFormatter.format(1024, true);
Assert.assertEquals("壹仟零贰拾肆", f1);
Assertions.assertEquals("壹仟零贰拾肆", f1);
f1 = NumberChineseFormatter.format(100350089, true);
Assert.assertEquals("壹亿零叁拾伍万零捌拾玖", f1);
Assertions.assertEquals("壹亿零叁拾伍万零捌拾玖", f1);
f1 = NumberChineseFormatter.format(1200, true);
Assert.assertEquals("壹仟贰佰", f1);
Assertions.assertEquals("壹仟贰佰", f1);
f1 = NumberChineseFormatter.format(12, true);
Assert.assertEquals("壹拾贰", f1);
Assertions.assertEquals("壹拾贰", f1);
f1 = NumberChineseFormatter.format(0.05, true);
Assert.assertEquals("零点零伍", f1);
Assertions.assertEquals("零点零伍", f1);
}
@Test
public void formatSimpleTest() {
String f1 = NumberChineseFormatter.formatSimple(1_2345);
Assert.assertEquals("1.23万", f1);
Assertions.assertEquals("1.23万", f1);
f1 = NumberChineseFormatter.formatSimple(-5_5555);
Assert.assertEquals("-5.56万", f1);
Assertions.assertEquals("-5.56万", f1);
f1 = NumberChineseFormatter.formatSimple(1_2345_6789);
Assert.assertEquals("1.23亿", f1);
Assertions.assertEquals("1.23亿", f1);
f1 = NumberChineseFormatter.formatSimple(-5_5555_5555);
Assert.assertEquals("-5.56亿", f1);
Assertions.assertEquals("-5.56亿", f1);
f1 = NumberChineseFormatter.formatSimple(1_2345_6789_1011L);
Assert.assertEquals("1.23万亿", f1);
Assertions.assertEquals("1.23万亿", f1);
f1 = NumberChineseFormatter.formatSimple(-5_5555_5555_5555L);
Assert.assertEquals("-5.56万亿", f1);
Assertions.assertEquals("-5.56万亿", f1);
f1 = NumberChineseFormatter.formatSimple(123);
Assert.assertEquals("123", f1);
Assertions.assertEquals("123", f1);
f1 = NumberChineseFormatter.formatSimple(-123);
Assert.assertEquals("-123", f1);
Assertions.assertEquals("-123", f1);
}
@Test
public void digitToChineseTest() {
String digitToChinese = Convert.digitToChinese(12_4124_1241_2421.12);
Assert.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元壹角贰分", digitToChinese);
Assertions.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元壹角贰分", digitToChinese);
digitToChinese = Convert.digitToChinese(12_0000_1241_2421L);
Assert.assertEquals("壹拾贰万亿零壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese);
Assertions.assertEquals("壹拾贰万亿零壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese);
digitToChinese = Convert.digitToChinese(12_0000_0000_2421L);
Assert.assertEquals("壹拾贰万亿零贰仟肆佰贰拾壹元整", digitToChinese);
Assertions.assertEquals("壹拾贰万亿零贰仟肆佰贰拾壹元整", digitToChinese);
digitToChinese = Convert.digitToChinese(12_4124_1241_2421D);
Assert.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese);
Assertions.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese);
digitToChinese = Convert.digitToChinese(2421.02);
Assert.assertEquals("贰仟肆佰贰拾壹元零贰分", digitToChinese);
Assertions.assertEquals("贰仟肆佰贰拾壹元零贰分", digitToChinese);
}
@Test
public void digitToChineseTest2() {
double a = 67556.32;
String digitUppercase = Convert.digitToChinese(a);
Assert.assertEquals("陆万柒仟伍佰伍拾陆元叁角贰分", digitUppercase);
Assertions.assertEquals("陆万柒仟伍佰伍拾陆元叁角贰分", digitUppercase);
a = 1024.00;
digitUppercase = Convert.digitToChinese(a);
Assert.assertEquals("壹仟零贰拾肆元整", digitUppercase);
Assertions.assertEquals("壹仟零贰拾肆元整", digitUppercase);
final double b = 1024;
digitUppercase = Convert.digitToChinese(b);
Assert.assertEquals("壹仟零贰拾肆元整", digitUppercase);
Assertions.assertEquals("壹仟零贰拾肆元整", digitUppercase);
}
@Test
public void digitToChineseTest3() {
String digitToChinese = Convert.digitToChinese(2_0000_0000.00);
Assert.assertEquals("贰亿元整", digitToChinese);
Assertions.assertEquals("贰亿元整", digitToChinese);
digitToChinese = Convert.digitToChinese(2_0000.00);
Assert.assertEquals("贰万元整", digitToChinese);
Assertions.assertEquals("贰万元整", digitToChinese);
digitToChinese = Convert.digitToChinese(2_0000_0000_0000.00);
Assert.assertEquals("贰万亿元整", digitToChinese);
Assertions.assertEquals("贰万亿元整", digitToChinese);
}
@Test
public void digitToChineseTest4() {
final String digitToChinese = Convert.digitToChinese(400_0000.00);
Assert.assertEquals("肆佰万元整", digitToChinese);
Assertions.assertEquals("肆佰万元整", digitToChinese);
}
@Test
public void numberCharToChineseTest(){
String s = NumberChineseFormatter.numberCharToChinese('1', false);
Assert.assertEquals("", s);
Assertions.assertEquals("", s);
s = NumberChineseFormatter.numberCharToChinese('2', false);
Assert.assertEquals("", s);
Assertions.assertEquals("", s);
s = NumberChineseFormatter.numberCharToChinese('0', false);
Assert.assertEquals("", s);
Assertions.assertEquals("", s);
// 非数字字符原样返回
s = NumberChineseFormatter.numberCharToChinese('A', false);
Assert.assertEquals("A", s);
Assertions.assertEquals("A", s);
}
@Test
public void chineseToNumberTest(){
Assert.assertEquals(0, NumberChineseFormatter.chineseToNumber(""));
Assert.assertEquals(102, NumberChineseFormatter.chineseToNumber("一百零二"));
Assert.assertEquals(112, NumberChineseFormatter.chineseToNumber("一百一十二"));
Assert.assertEquals(1012, NumberChineseFormatter.chineseToNumber("一千零一十二"));
Assert.assertEquals(1000000, NumberChineseFormatter.chineseToNumber("一百万"));
Assert.assertEquals(2000100112, NumberChineseFormatter.chineseToNumber("二十亿零一十万零一百一十二"));
Assertions.assertEquals(0, NumberChineseFormatter.chineseToNumber(""));
Assertions.assertEquals(102, NumberChineseFormatter.chineseToNumber("一百零二"));
Assertions.assertEquals(112, NumberChineseFormatter.chineseToNumber("一百一十二"));
Assertions.assertEquals(1012, NumberChineseFormatter.chineseToNumber("一千零一十二"));
Assertions.assertEquals(1000000, NumberChineseFormatter.chineseToNumber("一百万"));
Assertions.assertEquals(2000100112, NumberChineseFormatter.chineseToNumber("二十亿零一十万零一百一十二"));
}
@Test
public void chineseToNumberTest2(){
Assert.assertEquals(120, NumberChineseFormatter.chineseToNumber("一百二"));
Assert.assertEquals(1200, NumberChineseFormatter.chineseToNumber("一千二"));
Assert.assertEquals(22000, NumberChineseFormatter.chineseToNumber("两万二"));
Assert.assertEquals(22003, NumberChineseFormatter.chineseToNumber("两万二零三"));
Assert.assertEquals(22010, NumberChineseFormatter.chineseToNumber("两万二零一十"));
Assertions.assertEquals(120, NumberChineseFormatter.chineseToNumber("一百二"));
Assertions.assertEquals(1200, NumberChineseFormatter.chineseToNumber("一千二"));
Assertions.assertEquals(22000, NumberChineseFormatter.chineseToNumber("两万二"));
Assertions.assertEquals(22003, NumberChineseFormatter.chineseToNumber("两万二零三"));
Assertions.assertEquals(22010, NumberChineseFormatter.chineseToNumber("两万二零一十"));
}
@Test
@ -292,55 +292,59 @@ public class NumberChineseFormatterTest {
// issue#1726对于单位开头的数组默认赋予1
// 十二 -> 一十二
// 百二 -> 一百二
Assert.assertEquals(12, NumberChineseFormatter.chineseToNumber("十二"));
Assert.assertEquals(120, NumberChineseFormatter.chineseToNumber("百二"));
Assert.assertEquals(1300, NumberChineseFormatter.chineseToNumber("千三"));
Assertions.assertEquals(12, NumberChineseFormatter.chineseToNumber("十二"));
Assertions.assertEquals(120, NumberChineseFormatter.chineseToNumber("百二"));
Assertions.assertEquals(1300, NumberChineseFormatter.chineseToNumber("千三"));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void badNumberTest(){
// 连续数字检查
NumberChineseFormatter.chineseToNumber("一百一二三");
Assertions.assertThrows(IllegalArgumentException.class, ()->{
// 连续数字检查
NumberChineseFormatter.chineseToNumber("一百一二三");
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void badNumberTest2(){
// 非法字符
NumberChineseFormatter.chineseToNumber("一百你三");
Assertions.assertThrows(IllegalArgumentException.class, ()->{
// 非法字符
NumberChineseFormatter.chineseToNumber("一百你三");
});
}
@Test
public void singleMoneyTest(){
String format = NumberChineseFormatter.format(0.01, false, true);
Assert.assertEquals("一分", format);
Assertions.assertEquals("一分", format);
format = NumberChineseFormatter.format(0.10, false, true);
Assert.assertEquals("一角", format);
Assertions.assertEquals("一角", format);
format = NumberChineseFormatter.format(0.12, false, true);
Assert.assertEquals("一角二分", format);
Assertions.assertEquals("一角二分", format);
format = NumberChineseFormatter.format(1.00, false, true);
Assert.assertEquals("一元整", format);
Assertions.assertEquals("一元整", format);
format = NumberChineseFormatter.format(1.10, false, true);
Assert.assertEquals("一元一角", format);
Assertions.assertEquals("一元一角", format);
format = NumberChineseFormatter.format(1.02, false, true);
Assert.assertEquals("一元零二分", format);
Assertions.assertEquals("一元零二分", format);
}
@Test
public void singleNumberTest(){
String format = NumberChineseFormatter.format(0.01, false, false);
Assert.assertEquals("零点零一", format);
Assertions.assertEquals("零点零一", format);
format = NumberChineseFormatter.format(0.10, false, false);
Assert.assertEquals("零点一", format);
Assertions.assertEquals("零点一", format);
format = NumberChineseFormatter.format(0.12, false, false);
Assert.assertEquals("零点一二", format);
Assertions.assertEquals("零点一二", format);
format = NumberChineseFormatter.format(1.00, false, false);
Assert.assertEquals("", format);
Assertions.assertEquals("", format);
format = NumberChineseFormatter.format(1.10, false, false);
Assert.assertEquals("一点一", format);
Assertions.assertEquals("一点一", format);
format = NumberChineseFormatter.format(1.02, false, false);
Assert.assertEquals("一点零二", format);
Assertions.assertEquals("一点零二", format);
}
@SuppressWarnings("ConstantConditions")
@ -356,13 +360,13 @@ public class NumberChineseFormatterTest {
* s=叁角贰分, n=0.32
* s=陆万柒仟伍佰伍拾陆元叁角贰分, n=67556.32
*/
Assert.assertEquals(67556, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆圆").longValue());
Assert.assertEquals(67556, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元").longValue());
Assert.assertEquals(0.3D, NumberChineseFormatter.chineseMoneyToNumber("叁角").doubleValue(), 0);
Assert.assertEquals(0.02, NumberChineseFormatter.chineseMoneyToNumber("贰分").doubleValue(), 0);
Assert.assertEquals(67556.3, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元叁角").doubleValue(), 0);
Assert.assertEquals(67556.02, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元贰分").doubleValue(), 0);
Assert.assertEquals(0.32, NumberChineseFormatter.chineseMoneyToNumber("叁角贰分").doubleValue(), 0);
Assert.assertEquals(67556.32, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元叁角贰分").doubleValue(), 0);
Assertions.assertEquals(67556, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆圆").longValue());
Assertions.assertEquals(67556, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元").longValue());
Assertions.assertEquals(0.3D, NumberChineseFormatter.chineseMoneyToNumber("叁角").doubleValue(), 0);
Assertions.assertEquals(0.02, NumberChineseFormatter.chineseMoneyToNumber("贰分").doubleValue(), 0);
Assertions.assertEquals(67556.3, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元叁角").doubleValue(), 0);
Assertions.assertEquals(67556.02, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元贰分").doubleValue(), 0);
Assertions.assertEquals(0.32, NumberChineseFormatter.chineseMoneyToNumber("叁角贰分").doubleValue(), 0);
Assertions.assertEquals(67556.32, NumberChineseFormatter.chineseMoneyToNumber("陆万柒仟伍佰伍拾陆元叁角贰分").doubleValue(), 0);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.convert;
import cn.hutool.core.convert.impl.NumberConverter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class NumberConverterTest {
@ -10,13 +10,13 @@ public class NumberConverterTest {
public void toDoubleTest(){
final NumberConverter numberConverter = new NumberConverter();
final Number convert = numberConverter.convert(Double.class, "1,234.55", null);
Assert.assertEquals(1234.55D, convert);
Assertions.assertEquals(1234.55D, convert);
}
@Test
public void toIntegerTest(){
final NumberConverter numberConverter = new NumberConverter();
final Number convert = numberConverter.convert(Integer.class, "1,234.55", null);
Assert.assertEquals(1234, convert);
Assertions.assertEquals(1234, convert);
}
}

View File

@ -1,40 +1,40 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class NumberWordFormatTest {
@Test
public void formatTest() {
final String format = NumberWordFormatter.format(100.23);
Assert.assertEquals("ONE HUNDRED AND CENTS TWENTY THREE ONLY", format);
Assertions.assertEquals("ONE HUNDRED AND CENTS TWENTY THREE ONLY", format);
final String format2 = NumberWordFormatter.format("2100.00");
Assert.assertEquals("TWO THOUSAND ONE HUNDRED AND CENTS ONLY", format2);
Assertions.assertEquals("TWO THOUSAND ONE HUNDRED AND CENTS ONLY", format2);
}
@Test
public void formatSimpleTest() {
final String format1 = NumberWordFormatter.formatSimple(1200, false);
Assert.assertEquals("1.2k", format1);
Assertions.assertEquals("1.2k", format1);
final String format2 = NumberWordFormatter.formatSimple(4384324, false);
Assert.assertEquals("4.38m", format2);
Assertions.assertEquals("4.38m", format2);
final String format3 = NumberWordFormatter.formatSimple(4384324, true);
Assert.assertEquals("438.43w", format3);
Assertions.assertEquals("438.43w", format3);
final String format4 = NumberWordFormatter.formatSimple(4384324);
Assert.assertEquals("438.43w", format4);
Assertions.assertEquals("438.43w", format4);
final String format5 = NumberWordFormatter.formatSimple(438);
Assert.assertEquals("438", format5);
Assertions.assertEquals("438", format5);
}
@Test
public void formatSimpleTest2(){
final String s = NumberWordFormatter.formatSimple(1000);
Assert.assertEquals("1k", s);
Assertions.assertEquals("1k", s);
}
}

View File

@ -1,25 +1,27 @@
package cn.hutool.core.convert;
import cn.hutool.core.convert.impl.PrimitiveConverter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class PrimitiveConvertTest {
@Test
public void toIntTest(){
final int convert = Convert.convert(int.class, "123");
Assert.assertEquals(123, convert);
Assertions.assertEquals(123, convert);
}
@Test(expected = NumberFormatException.class)
@Test
public void toIntErrorTest(){
final int convert = Convert.convert(int.class, "aaaa");
Assertions.assertThrows(IllegalArgumentException.class, ()->{
Convert.convert(int.class, "aaaa");
});
}
@Test
public void toIntValueTest() {
final Object a = PrimitiveConverter.INSTANCE.convert(int.class, null);
Assert.assertNull(a);
Assertions.assertNull(a);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.TimeZone;
@ -10,6 +10,6 @@ public class StringConvertTest {
@Test
public void timezoneToStrTest(){
final String s = Convert.toStr(TimeZone.getTimeZone("Asia/Shanghai"));
Assert.assertEquals("Asia/Shanghai", s);
Assertions.assertEquals("Asia/Shanghai", s);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.convert;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.time.LocalDate;
@ -21,42 +21,42 @@ public class TemporalAccessorConverterTest {
// 通过转换获取的Instant为UTC时间
final Instant instant = Convert.convert(Instant.class, dateStr);
final Instant instant1 = DateUtil.parse(dateStr).toInstant();
Assert.assertEquals(instant1, instant);
Assertions.assertEquals(instant1, instant);
}
@Test
public void toLocalDateTimeTest(){
final LocalDateTime localDateTime = Convert.convert(LocalDateTime.class, "2019-02-18");
Assert.assertEquals("2019-02-18T00:00", localDateTime.toString());
Assertions.assertEquals("2019-02-18T00:00", localDateTime.toString());
}
@Test
public void toLocalDateTest(){
final LocalDate localDate = Convert.convert(LocalDate.class, "2019-02-18");
Assert.assertEquals("2019-02-18", localDate.toString());
Assertions.assertEquals("2019-02-18", localDate.toString());
}
@Test
public void toLocalTimeTest(){
final LocalTime localTime = Convert.convert(LocalTime.class, "2019-02-18");
Assert.assertEquals("00:00", localTime.toString());
Assertions.assertEquals("00:00", localTime.toString());
}
@Test
public void toZonedDateTimeTest(){
final ZonedDateTime zonedDateTime = Convert.convert(ZonedDateTime.class, "2019-02-18");
Assert.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString().substring(0, 22));
Assertions.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString().substring(0, 22));
}
@Test
public void toOffsetDateTimeTest(){
final OffsetDateTime zonedDateTime = Convert.convert(OffsetDateTime.class, "2019-02-18");
Assert.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString());
Assertions.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString());
}
@Test
public void toOffsetTimeTest(){
final OffsetTime offsetTime = Convert.convert(OffsetTime.class, "2019-02-18");
Assert.assertEquals("00:00+08:00", offsetTime.toString());
Assertions.assertEquals("00:00+08:00", offsetTime.toString());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.convert;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import javax.xml.datatype.XMLGregorianCalendar;
@ -11,6 +11,6 @@ public class XMLGregorianCalendarConverterTest {
@Test
public void convertTest(){
final XMLGregorianCalendar calendar = Convert.convert(XMLGregorianCalendar.class, DateUtil.parse("2022-01-03 04:00:00"));
Assert.assertNotNull(calendar);
Assertions.assertNotNull(calendar);
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.date;
import cn.hutool.core.date.BetweenFormatter.Level;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class BetweenFormatterTest {
@ -10,26 +10,26 @@ public class BetweenFormatterTest {
public void formatTest(){
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2017-01-01 22:59:59"), DateUtil.parse("2017-01-02 23:59:58"));
final BetweenFormatter formater = new BetweenFormatter(betweenMs, Level.MILLISECOND, 1);
Assert.assertEquals(formater.toString(), "1天");
Assertions.assertEquals(formater.toString(), "1天");
}
@Test
public void formatBetweenTest(){
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2018-07-16 11:23:19"), DateUtil.parse("2018-07-16 11:23:20"));
final BetweenFormatter formater = new BetweenFormatter(betweenMs, Level.SECOND, 1);
Assert.assertEquals(formater.toString(), "1秒");
Assertions.assertEquals(formater.toString(), "1秒");
}
@Test
public void formatBetweenTest2(){
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2018-07-16 12:25:23"), DateUtil.parse("2018-07-16 11:23:20"));
final BetweenFormatter formater = new BetweenFormatter(betweenMs, Level.SECOND, 5);
Assert.assertEquals(formater.toString(), "1小时2分3秒");
Assertions.assertEquals(formater.toString(), "1小时2分3秒");
}
@Test
public void formatTest2(){
final BetweenFormatter formater = new BetweenFormatter(584, Level.SECOND, 1);
Assert.assertEquals(formater.toString(), "0秒");
Assertions.assertEquals(formater.toString(), "0秒");
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.date;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Calendar;
import java.util.Objects;
@ -12,18 +12,20 @@ public class CalendarUtilTest {
public void formatChineseDate(){
final Calendar calendar = Objects.requireNonNull(DateUtil.parse("2018-02-24 12:13:14")).toCalendar();
final String chineseDate = CalendarUtil.formatChineseDate(calendar, false);
Assert.assertEquals("二〇一八年二月二十四日", chineseDate);
Assertions.assertEquals("二〇一八年二月二十四日", chineseDate);
final String chineseDateTime = CalendarUtil.formatChineseDate(calendar, true);
Assert.assertEquals("二〇一八年二月二十四日十二时十三分十四秒", chineseDateTime);
Assertions.assertEquals("二〇一八年二月二十四日十二时十三分十四秒", chineseDateTime);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void parseTest(){
final Calendar calendar = CalendarUtil.parse("2021-09-27 00:00:112323", false,
Assertions.assertThrows(IllegalArgumentException.class, ()->{
final Calendar calendar = CalendarUtil.parse("2021-09-27 00:00:112323", false,
DatePattern.NORM_DATETIME_FORMAT);
// https://github.com/dromara/hutool/issues/1849
// 在使用严格模式时秒不正确抛出异常
DateUtil.date(calendar);
// https://github.com/dromara/hutool/issues/1849
// 在使用严格模式时秒不正确抛出异常
DateUtil.date(calendar);
});
}
}

View File

@ -2,8 +2,8 @@ package cn.hutool.core.date;
import cn.hutool.core.date.chinese.ChineseDate;
import cn.hutool.core.text.StrUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Date;
import java.util.Objects;
@ -13,65 +13,65 @@ public class ChineseDateTest {
@Test
public void chineseDateTest() {
ChineseDate date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("2020-01-25")));
Assert.assertEquals("2020-01-25 00:00:00", date.getGregorianDate().toString());
Assert.assertEquals(2020, date.getChineseYear());
Assertions.assertEquals("2020-01-25 00:00:00", date.getGregorianDate().toString());
Assertions.assertEquals(2020, date.getChineseYear());
Assert.assertEquals(1, date.getMonth());
Assert.assertEquals("一月", date.getChineseMonth());
Assert.assertEquals("正月", date.getChineseMonthName());
Assertions.assertEquals(1, date.getMonth());
Assertions.assertEquals("一月", date.getChineseMonth());
Assertions.assertEquals("正月", date.getChineseMonthName());
Assert.assertEquals(1, date.getDay());
Assert.assertEquals("初一", date.getChineseDay());
Assertions.assertEquals(1, date.getDay());
Assertions.assertEquals("初一", date.getChineseDay());
Assert.assertEquals("庚子", date.getCyclical());
Assert.assertEquals("", date.getChineseZodiac());
Assert.assertEquals("春节", date.getFestivals());
Assert.assertEquals("庚子鼠年 正月初一", date.toString());
Assertions.assertEquals("庚子", date.getCyclical());
Assertions.assertEquals("", date.getChineseZodiac());
Assertions.assertEquals("春节", date.getFestivals());
Assertions.assertEquals("庚子鼠年 正月初一", date.toString());
date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("2020-01-14")));
Assert.assertEquals("己亥猪年 腊月二十", date.toString());
Assertions.assertEquals("己亥猪年 腊月二十", date.toString());
date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("2020-01-24")));
Assert.assertEquals("己亥猪年 腊月三十", date.toString());
Assertions.assertEquals("己亥猪年 腊月三十", date.toString());
Assert.assertEquals("2019-12-30", date.toStringNormal());
Assertions.assertEquals("2019-12-30", date.toStringNormal());
}
@Test
public void toStringNormalTest(){
final ChineseDate date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("2020-03-1")));
Assert.assertEquals("2020-02-08", date.toStringNormal());
Assertions.assertEquals("2020-02-08", date.toStringNormal());
}
@Test
public void parseTest(){
ChineseDate date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("1996-07-14")));
Assert.assertEquals("丙子鼠年 五月廿九", date.toString());
Assertions.assertEquals("丙子鼠年 五月廿九", date.toString());
date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("1996-07-15")));
Assert.assertEquals("丙子鼠年 五月三十", date.toString());
Assertions.assertEquals("丙子鼠年 五月三十", date.toString());
}
@Test
public void getChineseMonthTest(){
ChineseDate chineseDate = new ChineseDate(2020,6,15);
Assert.assertEquals("2020-08-04 00:00:00", chineseDate.getGregorianDate().toString());
Assert.assertEquals("六月", chineseDate.getChineseMonth());
Assertions.assertEquals("2020-08-04 00:00:00", chineseDate.getGregorianDate().toString());
Assertions.assertEquals("六月", chineseDate.getChineseMonth());
chineseDate = new ChineseDate(2020,4,15);
Assert.assertEquals("2020-06-06 00:00:00", chineseDate.getGregorianDate().toString());
Assert.assertEquals("闰四月", chineseDate.getChineseMonth());
Assertions.assertEquals("2020-06-06 00:00:00", chineseDate.getGregorianDate().toString());
Assertions.assertEquals("闰四月", chineseDate.getChineseMonth());
chineseDate = new ChineseDate(2020,5,15);
Assert.assertEquals("2020-07-05 00:00:00", chineseDate.getGregorianDate().toString());
Assert.assertEquals("五月", chineseDate.getChineseMonth());
Assertions.assertEquals("2020-07-05 00:00:00", chineseDate.getGregorianDate().toString());
Assertions.assertEquals("五月", chineseDate.getChineseMonth());
}
@Test
public void getFestivalsTest(){
// issue#I1XHSF@Gitee2023-01-20对应农历腊月29非除夕
final ChineseDate chineseDate = new ChineseDate(Objects.requireNonNull(DateUtil.parse("2023-01-20")));
Assert.assertTrue(StrUtil.isEmpty(chineseDate.getFestivals()));
Assertions.assertTrue(StrUtil.isEmpty(chineseDate.getFestivals()));
}
@Test
@ -79,23 +79,23 @@ public class ChineseDateTest {
// 修复这两个日期不正确的问题
// 问题出在计算与1900-01-31相差天数的问题上了相差天数非整天
ChineseDate date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("1991-09-14")));
Assert.assertEquals("辛未羊年 八月初七", date.toString());
Assertions.assertEquals("辛未羊年 八月初七", date.toString());
date = new ChineseDate(Objects.requireNonNull(DateUtil.parse("1991-09-15")));
Assert.assertEquals("辛未羊年 八月初八", date.toString());
Assertions.assertEquals("辛未羊年 八月初八", date.toString());
}
@Test
public void dateTest2(){
//noinspection ConstantConditions
final ChineseDate date = new ChineseDate(DateUtil.parse("2020-10-19"));
Assert.assertEquals("庚子鼠年 九月初三", date.toString());
Assertions.assertEquals("庚子鼠年 九月初三", date.toString());
}
@Test
public void dateTest2_2(){
//noinspection ConstantConditions
final ChineseDate date = new ChineseDate(DateUtil.parse("2020-07-20"));
Assert.assertEquals("庚子鼠年 五月三十", date.toString());
Assertions.assertEquals("庚子鼠年 五月三十", date.toString());
}
@Test
@ -103,7 +103,7 @@ public class ChineseDateTest {
// 初一offset为0测试
//noinspection ConstantConditions
final ChineseDate date = new ChineseDate(DateUtil.parse("2099-03-22"));
Assert.assertEquals("己未羊年 闰二月初一", date.toString());
Assertions.assertEquals("己未羊年 闰二月初一", date.toString());
}
@Test
@ -113,8 +113,8 @@ public class ChineseDateTest {
//noinspection ConstantConditions
final ChineseDate c2 = new ChineseDate(DateUtil.parse("2028-06-27"));
Assert.assertEquals("戊申猴年 五月初五", c1.toString());
Assert.assertEquals("戊申猴年 闰五月初五", c2.toString());
Assertions.assertEquals("戊申猴年 五月初五", c1.toString());
Assertions.assertEquals("戊申猴年 闰五月初五", c2.toString());
}
@Test
@ -122,7 +122,7 @@ public class ChineseDateTest {
//https://github.com/dromara/hutool/issues/2112
final ChineseDate springFestival = new ChineseDate(Objects.requireNonNull(DateUtil.parse("2022-02-01")));
final String chineseMonth = springFestival.getChineseMonth();
Assert.assertEquals("一月", chineseMonth);
Assertions.assertEquals("一月", chineseMonth);
}
@Test
@ -131,17 +131,17 @@ public class ChineseDateTest {
Date date = DateUtil.parse("1970-01-01");
//noinspection ConstantConditions
ChineseDate chineseDate = new ChineseDate(date);
Assert.assertEquals("己酉鸡年 冬月廿四", chineseDate.toString());
Assertions.assertEquals("己酉鸡年 冬月廿四", chineseDate.toString());
date = DateUtil.parse("1970-01-02");
//noinspection ConstantConditions
chineseDate = new ChineseDate(date);
Assert.assertEquals("己酉鸡年 冬月廿五", chineseDate.toString());
Assertions.assertEquals("己酉鸡年 冬月廿五", chineseDate.toString());
date = DateUtil.parse("1970-01-03");
//noinspection ConstantConditions
chineseDate = new ChineseDate(date);
Assert.assertEquals("己酉鸡年 冬月廿六", chineseDate.toString());
Assertions.assertEquals("己酉鸡年 冬月廿六", chineseDate.toString());
}
@Test
@ -150,16 +150,16 @@ public class ChineseDateTest {
final Date date = DateUtil.parse("1900-01-31");
//noinspection ConstantConditions
final ChineseDate chineseDate = new ChineseDate(date);
Assert.assertEquals("庚子鼠年 正月初一", chineseDate.toString());
Assertions.assertEquals("庚子鼠年 正月初一", chineseDate.toString());
}
@Test
public void getGregorianDateTest(){
// https://gitee.com/dromara/hutool/issues/I4ZSGJ
ChineseDate chineseDate = new ChineseDate(1998, 5, 1);
Assert.assertEquals("1998-06-24 00:00:00", chineseDate.getGregorianDate().toString());
Assertions.assertEquals("1998-06-24 00:00:00", chineseDate.getGregorianDate().toString());
chineseDate = new ChineseDate(1998, 5, 1, false);
Assert.assertEquals("1998-05-26 00:00:00", chineseDate.getGregorianDate().toString());
Assertions.assertEquals("1998-05-26 00:00:00", chineseDate.getGregorianDate().toString());
}
}

View File

@ -1,8 +1,8 @@
package cn.hutool.core.date;
import cn.hutool.core.date.BetweenFormatter.Level;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.time.temporal.ChronoUnit;
import java.util.Date;
@ -14,18 +14,18 @@ public class DateBetweenTest {
final Date start = DateUtil.parse("2017-02-01 12:23:46");
final Date end = DateUtil.parse("2018-02-01 12:23:46");
final long betweenYear = new DateBetween(start, end).betweenYear(false);
Assert.assertEquals(1, betweenYear);
Assertions.assertEquals(1, betweenYear);
final Date start1 = DateUtil.parse("2017-02-01 12:23:46");
final Date end1 = DateUtil.parse("2018-03-01 12:23:46");
final long betweenYear1 = new DateBetween(start1, end1).betweenYear(false);
Assert.assertEquals(1, betweenYear1);
Assertions.assertEquals(1, betweenYear1);
// 不足1年
final Date start2 = DateUtil.parse("2017-02-01 12:23:46");
final Date end2 = DateUtil.parse("2018-02-01 11:23:46");
final long betweenYear2 = new DateBetween(start2, end2).betweenYear(false);
Assert.assertEquals(0, betweenYear2);
Assertions.assertEquals(0, betweenYear2);
}
@Test
@ -33,7 +33,7 @@ public class DateBetweenTest {
final Date start = DateUtil.parse("2000-02-29");
final Date end = DateUtil.parse("2018-02-28");
final long betweenYear = new DateBetween(start, end).betweenYear(false);
Assert.assertEquals(18, betweenYear);
Assertions.assertEquals(18, betweenYear);
}
@Test
@ -41,18 +41,18 @@ public class DateBetweenTest {
final Date start = DateUtil.parse("2017-02-01 12:23:46");
final Date end = DateUtil.parse("2018-02-01 12:23:46");
final long betweenMonth = new DateBetween(start, end).betweenMonth(false);
Assert.assertEquals(12, betweenMonth);
Assertions.assertEquals(12, betweenMonth);
final Date start1 = DateUtil.parse("2017-02-01 12:23:46");
final Date end1 = DateUtil.parse("2018-03-01 12:23:46");
final long betweenMonth1 = new DateBetween(start1, end1).betweenMonth(false);
Assert.assertEquals(13, betweenMonth1);
Assertions.assertEquals(13, betweenMonth1);
// 不足
final Date start2 = DateUtil.parse("2017-02-01 12:23:46");
final Date end2 = DateUtil.parse("2018-02-01 11:23:46");
final long betweenMonth2 = new DateBetween(start2, end2).betweenMonth(false);
Assert.assertEquals(11, betweenMonth2);
Assertions.assertEquals(11, betweenMonth2);
}
@Test
@ -60,7 +60,7 @@ public class DateBetweenTest {
final Date date1 = DateUtil.parse("2017-03-01 20:33:23");
final Date date2 = DateUtil.parse("2017-03-01 23:33:23");
final String formatBetween = DateUtil.formatBetween(date1, date2, Level.SECOND);
Assert.assertEquals("3小时", formatBetween);
Assertions.assertEquals("3小时", formatBetween);
}
@Test
@ -73,6 +73,6 @@ public class DateBetweenTest {
TimeUtil.parse("2020-11-21", "yyy-MM-dd"),
TimeUtil.parse("2020-11-23", "yyy-MM-dd"),
ChronoUnit.WEEKS);
Assert.assertEquals(betweenWeek, betweenWeek2);
Assertions.assertEquals(betweenWeek, betweenWeek2);
}
}

View File

@ -1,15 +1,15 @@
package cn.hutool.core.date;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DateFieldTest {
@Test
public void ofTest() {
DateField field = DateField.of(11);
Assert.assertEquals(DateField.HOUR_OF_DAY, field);
Assertions.assertEquals(DateField.HOUR_OF_DAY, field);
field = DateField.of(12);
Assert.assertEquals(DateField.MINUTE, field);
Assertions.assertEquals(DateField.MINUTE, field);
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.date;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Date;
@ -14,47 +14,47 @@ public class DateModifierTest {
// 毫秒
DateTime begin = DateUtil.truncate(date, DateField.MILLISECOND);
Assert.assertEquals(dateStr, begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals(dateStr, begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.truncate(date, DateField.SECOND);
Assert.assertEquals("2017-03-01 22:33:23.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:33:23.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.truncate(date, DateField.MINUTE);
Assert.assertEquals("2017-03-01 22:33:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:33:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// 小时
begin = DateUtil.truncate(date, DateField.HOUR);
Assert.assertEquals("2017-03-01 22:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.truncate(date, DateField.HOUR_OF_DAY);
Assert.assertEquals("2017-03-01 22:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// 上下午原始日期是22点上下午的起始就是12点
begin = DateUtil.truncate(date, DateField.AM_PM);
Assert.assertEquals("2017-03-01 12:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 12:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// day of xxx按照day处理
begin = DateUtil.truncate(date, DateField.DAY_OF_WEEK_IN_MONTH);
Assert.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.truncate(date, DateField.DAY_OF_WEEK);
Assert.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.truncate(date, DateField.DAY_OF_MONTH);
Assert.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// 星期
begin = DateUtil.truncate(date, DateField.WEEK_OF_MONTH);
Assert.assertEquals("2017-02-27 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-02-27 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.truncate(date, DateField.WEEK_OF_YEAR);
Assert.assertEquals("2017-02-27 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-02-27 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.truncate(date, DateField.MONTH);
Assert.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.truncate(date, DateField.YEAR);
Assert.assertEquals("2017-01-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-01-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
}
@Test
@ -64,7 +64,7 @@ public class DateModifierTest {
// day of xxx按照day处理
final DateTime begin = DateUtil.truncate(date, DateField.DAY_OF_WEEK_IN_MONTH);
Assert.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 00:00:00.000", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
}
@Test
@ -74,47 +74,47 @@ public class DateModifierTest {
// 毫秒
DateTime begin = DateUtil.ceiling(date, DateField.MILLISECOND);
Assert.assertEquals(dateStr, begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals(dateStr, begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.ceiling(date, DateField.SECOND);
Assert.assertEquals("2017-03-01 22:33:23.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:33:23.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.ceiling(date, DateField.MINUTE);
Assert.assertEquals("2017-03-01 22:33:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:33:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// 小时
begin = DateUtil.ceiling(date, DateField.HOUR);
Assert.assertEquals("2017-03-01 22:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.ceiling(date, DateField.HOUR_OF_DAY);
Assert.assertEquals("2017-03-01 22:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 22:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// 上下午原始日期是22点上下午的结束就是23点
begin = DateUtil.ceiling(date, DateField.AM_PM);
Assert.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// day of xxx按照day处理
begin = DateUtil.ceiling(date, DateField.DAY_OF_WEEK_IN_MONTH);
Assert.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.ceiling(date, DateField.DAY_OF_WEEK);
Assert.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.ceiling(date, DateField.DAY_OF_MONTH);
Assert.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-01 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
// 星期
begin = DateUtil.ceiling(date, DateField.WEEK_OF_MONTH);
Assert.assertEquals("2017-03-05 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-05 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
begin = DateUtil.ceiling(date, DateField.WEEK_OF_YEAR);
Assert.assertEquals("2017-03-05 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-05 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.ceiling(date, DateField.MONTH);
Assert.assertEquals("2017-03-31 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-03-31 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
//
begin = DateUtil.ceiling(date, DateField.YEAR);
Assert.assertEquals("2017-12-31 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2017-12-31 23:59:59.999", begin.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
}
@Test
@ -124,6 +124,6 @@ public class DateModifierTest {
final Date date = DateUtil.parse(dateStr);
final DateTime dateTime = DateUtil.round(date, DateField.SECOND);
Assert.assertEquals("2022-08-12 14:59:21.999", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
Assertions.assertEquals("2022-08-12 14:59:21.999", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN));
}
}

View File

@ -1,7 +1,7 @@
package cn.hutool.core.date;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* DateTime单元测试
@ -17,19 +17,19 @@ public class DateTimeTest {
//
final int year = dateTime.year();
Assert.assertEquals(2017, year);
Assertions.assertEquals(2017, year);
// 季度非季节
final Quarter season = dateTime.quarterEnum();
Assert.assertEquals(Quarter.Q1, season);
Assertions.assertEquals(Quarter.Q1, season);
// 月份
final Month month = dateTime.monthEnum();
Assert.assertEquals(Month.JANUARY, month);
Assertions.assertEquals(Month.JANUARY, month);
//
final int day = dateTime.dayOfMonth();
Assert.assertEquals(5, day);
Assertions.assertEquals(5, day);
}
@Test
@ -38,48 +38,48 @@ public class DateTimeTest {
//
final int year = dateTime.year();
Assert.assertEquals(2017, year);
Assertions.assertEquals(2017, year);
// 季度非季节
final Quarter season = dateTime.quarterEnum();
Assert.assertEquals(Quarter.Q1, season);
Assertions.assertEquals(Quarter.Q1, season);
// 月份
final Month month = dateTime.monthEnum();
Assert.assertEquals(Month.JANUARY, month);
Assertions.assertEquals(Month.JANUARY, month);
//
final int day = dateTime.dayOfMonth();
Assert.assertEquals(5, day);
Assertions.assertEquals(5, day);
}
@Test
public void quarterTest() {
DateTime dateTime = new DateTime("2017-01-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
Quarter quarter = dateTime.quarterEnum();
Assert.assertEquals(Quarter.Q1, quarter);
Assertions.assertEquals(Quarter.Q1, quarter);
dateTime = new DateTime("2017-04-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
quarter = dateTime.quarterEnum();
Assert.assertEquals(Quarter.Q2, quarter);
Assertions.assertEquals(Quarter.Q2, quarter);
dateTime = new DateTime("2017-07-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
quarter = dateTime.quarterEnum();
Assert.assertEquals(Quarter.Q3, quarter);
Assertions.assertEquals(Quarter.Q3, quarter);
dateTime = new DateTime("2017-10-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
quarter = dateTime.quarterEnum();
Assert.assertEquals(Quarter.Q4, quarter);
Assertions.assertEquals(Quarter.Q4, quarter);
// 精确到毫秒
final DateTime beginTime = new DateTime("2017-10-01 00:00:00.000", DatePattern.NORM_DATETIME_MS_FORMAT);
dateTime = DateUtil.beginOfQuarter(dateTime);
Assert.assertEquals(beginTime, dateTime);
Assertions.assertEquals(beginTime, dateTime);
// 精确到毫秒
final DateTime endTime = new DateTime("2017-12-31 23:59:59.999", DatePattern.NORM_DATETIME_MS_FORMAT);
dateTime = DateUtil.endOfQuarter(dateTime);
Assert.assertEquals(endTime, dateTime);
Assertions.assertEquals(endTime, dateTime);
}
@Test
@ -88,21 +88,21 @@ public class DateTimeTest {
// 默认情况下DateTime为可变对象
DateTime offsite = dateTime.offset(DateField.YEAR, 0);
Assert.assertSame(offsite, dateTime);
Assertions.assertSame(offsite, dateTime);
// 设置为不可变对象后变动将返回新对象
dateTime.setMutable(false);
offsite = dateTime.offset(DateField.YEAR, 0);
Assert.assertNotSame(offsite, dateTime);
Assertions.assertNotSame(offsite, dateTime);
}
@Test
public void toStringTest() {
final DateTime dateTime = new DateTime("2017-01-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
Assert.assertEquals("2017-01-05 12:34:23", dateTime.toString());
Assertions.assertEquals("2017-01-05 12:34:23", dateTime.toString());
final String dateStr = dateTime.toString("yyyy/MM/dd");
Assert.assertEquals("2017/01/05", dateStr);
Assertions.assertEquals("2017/01/05", dateStr);
}
@Test
@ -110,35 +110,38 @@ public class DateTimeTest {
final DateTime dateTime = new DateTime("2017-01-05 12:34:23", DatePattern.NORM_DATETIME_FORMAT);
String dateStr = dateTime.toString(DatePattern.ISO8601_WITH_ZONE_OFFSET_PATTERN);
Assert.assertEquals("2017-01-05T12:34:23+0800", dateStr);
Assertions.assertEquals("2017-01-05T12:34:23+0800", dateStr);
dateStr = dateTime.toString(DatePattern.ISO8601_WITH_XXX_OFFSET_PATTERN);
Assert.assertEquals("2017-01-05T12:34:23+08:00", dateStr);
Assertions.assertEquals("2017-01-05T12:34:23+08:00", dateStr);
}
@Test
public void monthTest() {
//noinspection ConstantConditions
final int month = DateUtil.parse("2017-07-01").month();
Assert.assertEquals(6, month);
Assertions.assertEquals(6, month);
}
@Test
public void weekOfYearTest() {
final DateTime date = DateUtil.parse("2016-12-27");
//noinspection ConstantConditions
Assert.assertEquals(2016, date.year());
Assertions.assertEquals(2016, date.year());
//跨年的周返回的总是1
Assert.assertEquals(1, date.weekOfYear());
Assertions.assertEquals(1, date.weekOfYear());
}
/**
* 严格模式下不允许非常规的数字如秒部分最多5999则报错
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void ofTest(){
final String a = "2021-09-27 00:00:99";
new DateTime(a, DatePattern.NORM_DATETIME_FORMAT, false);
Assertions.assertThrows(IllegalArgumentException.class, ()->{
final String a = "2021-09-27 00:00:99";
new DateTime(a, DatePattern.NORM_DATETIME_FORMAT, false);
});
}
}

Some files were not shown because too many files have changed in this diff Show More