diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java index b6d69725b..7fac3d661 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotatedElementUtilTest.java @@ -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, 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, 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 ================= diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java index 0f8ef1dfe..ddac22646 100755 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java @@ -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 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) diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java index b4fb77fdc..328ee6414 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/CombinationAnnotationElementTest.java @@ -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) diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java index 6edb2f018..4fdd8d794 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/GenericAnnotationMappingTest.java @@ -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) diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java index 38a73bc71..6a27ea0f7 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/HierarchicalAnnotatedElementTest.java @@ -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 iterator = elements.iterator(); - Assert.assertNotNull(iterator); + Assertions.assertNotNull(iterator); final List 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 diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java index a5d3f0449..6a50714f8 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/MetaAnnotatedElementTest.java @@ -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 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 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 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 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 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 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 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) diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java index 098fe81f6..1b5bc3041 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableAnnotationCollectorTest.java @@ -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 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 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) diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java index 26afe079d..1d93cba3d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/RepeatableMetaAnnotatedElementTest.java @@ -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, 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, 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 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 diff --git a/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java b/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java index 7527a4c09..57b6954ef 100644 --- a/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/annotation/ResolvedAnnotationMappingTest.java @@ -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同名同类型的属性value、alias被覆写 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存在别名value1,value2因此也一并被覆写 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") diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/BeanCopyMappingTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/BeanCopyMappingTest.java index 151419e48..e91873a5e 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/BeanCopyMappingTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/BeanCopyMappingTest.java @@ -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 diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/BeanDescTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/BeanDescTest.java index e9e3d63b4..7fab1265d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/BeanDescTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/BeanDescTest.java @@ -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 { diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/BeanPathTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/BeanPathTest.java index 37261f5e5..555ec9687 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/BeanPathTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/BeanPathTest.java @@ -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 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 result = (Map)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 diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java index 0bd556c52..8459ca4c9 100755 --- a/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/BeanUtilTest.java @@ -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 map = new HashMap<>(); - map.put("age", "哈哈"); - BeanUtil.toBean(map, Person.class); + Assertions.assertThrows(NumberFormatException.class, ()->{ + final Map map = new HashMap<>(); + map.put("age", "哈哈"); + BeanUtil.toBean(map, Person.class); + }); } @Test @@ -184,11 +179,11 @@ public class BeanUtilTest { final Map 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 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 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 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 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 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 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 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 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 {} @@ -679,10 +674,10 @@ public class BeanUtilTest { final List studentList = ListUtil.view(student, student2); final List 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 studentList = ListUtil.view(student, student2); final List 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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/BeanWithReturnThisTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/BeanWithReturnThisTest.java index acec2d47c..b5ed14be8 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/BeanWithReturnThisTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/BeanWithReturnThisTest.java @@ -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{ diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/DynaBeanTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/DynaBeanTest.java index ba62aa397..d61d04cf5 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/DynaBeanTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/DynaBeanTest.java @@ -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 diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/Issue1687Test.java b/hutool-core/src/test/java/cn/hutool/core/bean/Issue1687Test.java index cfbddac83..9aeb435a5 100755 --- a/hutool-core/src/test/java/cn/hutool/core/bean/Issue1687Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/Issue1687Test.java @@ -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 diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2009Test.java b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2009Test.java index 2e4e5ae56..f2d56fafe 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2009Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2009Test.java @@ -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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2082Test.java b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2082Test.java index bd98dad16..9671ce34e 100755 --- a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2082Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2082Test.java @@ -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
@@ -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 diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2202Test.java b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2202Test.java index 6ffd5f6e1..7b0fdbe7b 100755 --- a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2202Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2202Test.java @@ -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 diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2649Test.java b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2649Test.java index 8fae58a90..ead645afe 100755 --- a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2649Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2649Test.java @@ -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 view1List = new ArrayList<>(); for (int i = 0; i < 200; i++) { diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2683Test.java b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2683Test.java index c18ce5426..9161ace1e 100755 --- a/hutool-core/src/test/java/cn/hutool/core/bean/Issue2683Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/Issue2683Test.java @@ -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 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())); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/IssueI5DDZXTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/IssueI5DDZXTest.java index 8fe56d143..b608f2d92 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/IssueI5DDZXTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/IssueI5DDZXTest.java @@ -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 diff --git a/hutool-core/src/test/java/cn/hutool/core/bean/copier/BeanCopierTest.java b/hutool-core/src/test/java/cn/hutool/core/bean/copier/BeanCopierTest.java index 3dcb07b35..20029bdc9 100644 --- a/hutool-core/src/test/java/cn/hutool/core/bean/copier/BeanCopierTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/bean/copier/BeanCopierTest.java @@ -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 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 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 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 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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/cache/CacheConcurrentTest.java b/hutool-core/src/test/java/cn/hutool/core/cache/CacheConcurrentTest.java index 75d6df3f7..eb74e3925 100755 --- a/hutool-core/src/test/java/cn/hutool/core/cache/CacheConcurrentTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/cache/CacheConcurrentTest.java @@ -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 cache = new FIFOCache<>(3); @@ -52,7 +52,7 @@ public class CacheConcurrentTest { } @Test - @Ignore + @Disabled public void lruCacheTest() { final int threadCount = 40000; final Cache 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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/cache/CacheTest.java b/hutool-core/src/test/java/cn/hutool/core/cache/CacheTest.java index 5f7f1ee6e..a9c3abcba 100755 --- a/hutool-core/src/test/java/cn/hutool/core/cache/CacheTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/cache/CacheTest.java @@ -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 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 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(); diff --git a/hutool-core/src/test/java/cn/hutool/core/cache/FileCacheTest.java b/hutool-core/src/test/java/cn/hutool/core/cache/FileCacheTest.java index 89641d7f2..f4860184a 100755 --- a/hutool-core/src/test/java/cn/hutool/core/cache/FileCacheTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/cache/FileCacheTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/cache/LRUCacheTest.java b/hutool-core/src/test/java/cn/hutool/core/cache/LRUCacheTest.java index 08243df95..0055a2d70 100755 --- a/hutool-core/src/test/java/cn/hutool/core/cache/LRUCacheTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/cache/LRUCacheTest.java @@ -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 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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/cache/WeakCacheTest.java b/hutool-core/src/test/java/cn/hutool/core/cache/WeakCacheTest.java index 946976e17..3a5ff4560 100755 --- a/hutool-core/src/test/java/cn/hutool/core/cache/WeakCacheTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/cache/WeakCacheTest.java @@ -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 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测试 diff --git a/hutool-core/src/test/java/cn/hutool/core/classloader/ClassLoaderUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/classloader/ClassLoaderUtilTest.java index 978f0afd2..97e17ad41 100644 --- a/hutool-core/src/test/java/cn/hutool/core/classloader/ClassLoaderUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/classloader/ClassLoaderUtilTest.java @@ -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 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") diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/Base32Test.java b/hutool-core/src/test/java/cn/hutool/core/codec/Base32Test.java index 1ac4015cc..ddd81e60c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/Base32Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/Base32Test.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/Base58Test.java b/hutool-core/src/test/java/cn/hutool/core/codec/Base58Test.java index 23256a084..341b79abe 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/Base58Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/Base58Test.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/Base62Test.java b/hutool-core/src/test/java/cn/hutool/core/codec/Base62Test.java index b3e22526b..6da0e00cf 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/Base62Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/Base62Test.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/Base64Test.java b/hutool-core/src/test/java/cn/hutool/core/codec/Base64Test.java index fe88cddee..21dfe0807 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/Base64Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/Base64Test.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/CaesarTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/CaesarTest.java index e0544093b..210c12c01 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/CaesarTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/CaesarTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/HashidsTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/HashidsTest.java index c9332b7fa..85bb777a3 100755 --- a/hutool-core/src/test/java/cn/hutool/core/codec/HashidsTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/HashidsTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/MorseTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/MorseTest.java index 86c8c5049..0554824b5 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/MorseTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/MorseTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/PercentCodecTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/PercentCodecTest.java index edfa2cefa..22476ecfd 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/PercentCodecTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/PercentCodecTest.java @@ -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')); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/PunyCodeTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/PunyCodeTest.java index 3193ade29..e51126b10 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/PunyCodeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/PunyCodeTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/RotTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/RotTest.java index a50521a3e..94a1acd3b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/RotTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/RotTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/hash/CityHashTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/hash/CityHashTest.java index 84230909f..8d4a5fe05 100755 --- a/hutool-core/src/test/java/cn/hutool/core/codec/hash/CityHashTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/hash/CityHashTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/hash/MurmurHashTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/hash/MurmurHashTest.java index bf965d118..6796b23da 100755 --- a/hutool-core/src/test/java/cn/hutool/core/codec/hash/MurmurHashTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/hash/MurmurHashTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/hash/SimhashTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/hash/SimhashTest.java index 0c7703c7b..93c4c1db8 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/hash/SimhashTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/hash/SimhashTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash128Test.java b/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash128Test.java index a66418905..f01ab1fab 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash128Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash128Test.java @@ -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) { diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash64Test.java b/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash64Test.java index b1fa2c42b..eb64f6cf5 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash64Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHash64Test.java @@ -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) { diff --git a/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHashTest.java b/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHashTest.java index 5f15ba817..7bf449bc1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHashTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/codec/hash/metro/MetroHashTest.java @@ -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(); diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/CollStreamUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/CollStreamUtilTest.java index 951bc8454..8364ca5a4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/CollStreamUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/CollStreamUtilTest.java @@ -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 map = CollStreamUtil.toIdentityMap(null, Student::getStudentId); - Assert.assertEquals(map, Collections.EMPTY_MAP); + Assertions.assertEquals(map, Collections.EMPTY_MAP); final List 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 map = CollStreamUtil.toMap(null, Student::getStudentId, Student::getName); - Assert.assertEquals(map, Collections.EMPTY_MAP); + Assertions.assertEquals(map, Collections.EMPTY_MAP); final List 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> map = CollStreamUtil.groupByKey(null, Student::getClassId); - Assert.assertEquals(map, Collections.EMPTY_MAP); + Assertions.assertEquals(map, Collections.EMPTY_MAP); final List 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 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>> map = CollStreamUtil.groupBy2Key(null, Student::getTermId, Student::getClassId); - Assert.assertEquals(map, Collections.EMPTY_MAP); + Assertions.assertEquals(map, Collections.EMPTY_MAP); final List 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> map = CollStreamUtil.group2Map(null, Student::getTermId, Student::getClassId); - Assert.assertEquals(map, Collections.EMPTY_MAP); + Assertions.assertEquals(map, Collections.EMPTY_MAP); final List 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 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> 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> map = CollStreamUtil.groupKeyValue(null, Student::getTermId, Student::getClassId); - Assert.assertEquals(map, Collections.EMPTY_MAP); + Assertions.assertEquals(map, Collections.EMPTY_MAP); final List 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> 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> map = CollStreamUtil.groupBy(null, Student::getTermId, Collectors.toList()); - Assert.assertEquals(map, Collections.EMPTY_MAP); + Assertions.assertEquals(map, Collections.EMPTY_MAP); // 参数空数组测试 final List 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> 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 final Map> 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> 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 termIdCountMap = CollStreamUtil.groupBy(students, Student::getTermId, Collectors.counting()); final Map termIdCountCompareMap = new HashMap<>(); termIdCountCompareMap.put(null, 2L); termIdCountCompareMap.put(1L, 2L); - Assert.assertEquals(termIdCountCompareMap, termIdCountMap); + Assertions.assertEquals(termIdCountCompareMap, termIdCountMap); } @Test public void testTranslate2List() { List list = CollStreamUtil.toList(null, Student::getName); - Assert.assertEquals(list, Collections.EMPTY_LIST); + Assertions.assertEquals(list, Collections.EMPTY_LIST); final List 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 set = CollStreamUtil.toSet(null, Student::getName); - Assert.assertEquals(set, Collections.EMPTY_SET); + Assertions.assertEquals(set, Collections.EMPTY_SET); final List 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 map1 = null; Map map2 = Collections.emptyMap(); Map 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 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 compare = new HashMap<>(); compare.put(1L, "张三李四"); - Assert.assertEquals(map, compare); + Assertions.assertEquals(map, compare); } private String merge(final Student student1, final Student student2) { diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java index 4c1abd8e4..443d4c5fd 100755 --- a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java @@ -12,8 +12,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; 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.ArrayDeque; import java.util.ArrayList; @@ -47,49 +47,49 @@ public class CollUtilTest { public void emptyIfNullTest() { final Set set = null; final Set set1 = CollUtil.emptyIfNull(set); - Assert.assertEquals(SetUtil.empty(), set1); + Assertions.assertEquals(SetUtil.empty(), set1); final List list = null; final List list1 = CollUtil.emptyIfNull(list); - Assert.assertEquals(ListUtil.empty(), list1); + Assertions.assertEquals(ListUtil.empty(), list1); } @SuppressWarnings("ConstantConditions") @Test public void hasNullTest() { List list = null; - Assert.assertTrue(CollUtil.hasNull(list)); + Assertions.assertTrue(CollUtil.hasNull(list)); list = ListUtil.of(); - Assert.assertFalse(CollUtil.hasNull(list)); + Assertions.assertFalse(CollUtil.hasNull(list)); list = ListUtil.of(""); - Assert.assertFalse(CollUtil.hasNull(list)); + Assertions.assertFalse(CollUtil.hasNull(list)); list = ListUtil.of("", null); - Assert.assertTrue(CollUtil.hasNull(list)); + Assertions.assertTrue(CollUtil.hasNull(list)); } @Test public void defaultIfEmpty() { List strings = CollUtil.defaultIfEmpty(ListUtil.of(), ListUtil.of("1")); - Assert.assertEquals(ListUtil.of("1"), strings); + Assertions.assertEquals(ListUtil.of("1"), strings); strings = CollUtil.defaultIfEmpty(null, ListUtil.of("1")); - Assert.assertEquals(ListUtil.of("1"), strings); + Assertions.assertEquals(ListUtil.of("1"), strings); } @Test public void defaultIfEmpty2() { final List strings = CollUtil.defaultIfEmpty(ListUtil.of(), Function.identity(), () -> ListUtil.of("1")); - Assert.assertEquals(ListUtil.of("1"), strings); + Assertions.assertEquals(ListUtil.of("1"), strings); } @Test public void testPredicateContains() { final List list = ListUtil.of("bbbbb", "aaaaa", "ccccc"); - Assert.assertTrue(CollUtil.contains(list, s -> s.startsWith("a"))); - Assert.assertFalse(CollUtil.contains(list, s -> s.startsWith("d"))); + Assertions.assertTrue(CollUtil.contains(list, s -> s.startsWith("a"))); + Assertions.assertFalse(CollUtil.contains(list, s -> s.startsWith("d"))); } @Test @@ -99,14 +99,14 @@ public class CollUtilTest { final List exceptResultList = ListUtil.of(1); List resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele); - Assert.assertEquals(list, exceptRemovedList); - Assert.assertEquals(resultList, exceptResultList); + Assertions.assertEquals(list, exceptRemovedList); + Assertions.assertEquals(resultList, exceptResultList); list = ListUtil.of(1, 2, 3); resultList = new ArrayList<>(); CollUtil.removeWithAddIf(list, resultList, ele -> 1 == ele); - Assert.assertEquals(list, exceptRemovedList); - Assert.assertEquals(resultList, exceptResultList); + Assertions.assertEquals(list, exceptRemovedList); + Assertions.assertEquals(resultList, exceptResultList); } @Test @@ -115,17 +115,17 @@ public class CollUtilTest { List answerList = ListUtil.of("a", "b"); CollUtil.padLeft(srcList, 1, "b"); CollUtil.padLeft(srcList, 2, "a"); - Assert.assertEquals(srcList, answerList); + Assertions.assertEquals(srcList, answerList); srcList = ListUtil.of("a", "b"); answerList = ListUtil.of("a", "b"); CollUtil.padLeft(srcList, 2, "a"); - Assert.assertEquals(srcList, answerList); + Assertions.assertEquals(srcList, answerList); srcList = ListUtil.of("c"); answerList = ListUtil.of("a", "a", "c"); CollUtil.padLeft(srcList, 3, "a"); - Assert.assertEquals(srcList, answerList); + Assertions.assertEquals(srcList, answerList); } @Test @@ -133,18 +133,18 @@ public class CollUtilTest { final List srcList = ListUtil.of("a"); final List answerList = ListUtil.of("a", "b", "b", "b", "b"); CollUtil.padRight(srcList, 5, "b"); - Assert.assertEquals(srcList, answerList); + Assertions.assertEquals(srcList, answerList); } @Test public void isNotEmptyTest() { - Assert.assertFalse(CollUtil.isNotEmpty((Collection) null)); + Assertions.assertFalse(CollUtil.isNotEmpty((Collection) null)); } @Test public void newHashSetTest() { final Set set = SetUtil.of((String[]) null); - Assert.assertNotNull(set); + Assertions.assertNotNull(set); } @Test @@ -154,7 +154,7 @@ public class CollUtilTest { final Collection union = CollUtil.union(list1, list2); - Assert.assertEquals(3, CollUtil.count(union, "b"::equals)); + Assertions.assertEquals(3, CollUtil.count(union, "b"::equals)); } @Test @@ -163,8 +163,8 @@ public class CollUtilTest { final List list2 = ListUtil.of("a", "b", "b", "b", "c", "d"); final Collection intersection = CollUtil.intersection(list1, list2); - Assert.assertEquals(2, CollUtil.count(intersection, "b"::equals)); - Assert.assertEquals(0, CollUtil.count(intersection, "x"::equals)); + Assertions.assertEquals(2, CollUtil.count(intersection, "b"::equals)); + Assertions.assertEquals(0, CollUtil.count(intersection, "x"::equals)); } @Test @@ -174,11 +174,11 @@ public class CollUtilTest { final List list3 = ListUtil.of(); final Collection intersectionDistinct = CollUtil.intersectionDistinct(list1, list2); - Assert.assertEquals(SetUtil.ofLinked("a", "b", "c", "d"), intersectionDistinct); + Assertions.assertEquals(SetUtil.ofLinked("a", "b", "c", "d"), intersectionDistinct); final Collection intersectionDistinct2 = CollUtil.intersectionDistinct(list1, list2, list3); Console.log(intersectionDistinct2); - Assert.assertTrue(intersectionDistinct2.isEmpty()); + Assertions.assertTrue(intersectionDistinct2.isEmpty()); } @Test @@ -187,14 +187,14 @@ public class CollUtilTest { final List list2 = ListUtil.of("a", "b", "b", "b", "c", "d", "x2"); final Collection disjunction = CollUtil.disjunction(list1, list2); - Assert.assertTrue(disjunction.contains("b")); - Assert.assertTrue(disjunction.contains("x2")); - Assert.assertTrue(disjunction.contains("x")); + Assertions.assertTrue(disjunction.contains("b")); + Assertions.assertTrue(disjunction.contains("x2")); + Assertions.assertTrue(disjunction.contains("x")); final Collection disjunction2 = CollUtil.disjunction(list2, list1); - Assert.assertTrue(disjunction2.contains("b")); - Assert.assertTrue(disjunction2.contains("x2")); - Assert.assertTrue(disjunction2.contains("x")); + Assertions.assertTrue(disjunction2.contains("b")); + Assertions.assertTrue(disjunction2.contains("x2")); + Assertions.assertTrue(disjunction2.contains("x")); } @Test @@ -204,9 +204,9 @@ public class CollUtilTest { final List list2 = ListUtil.of("a", "b", "b", "b", "c", "d", "x2"); final Collection disjunction = CollUtil.disjunction(list1, list2); - Assert.assertEquals(list2, disjunction); + Assertions.assertEquals(list2, disjunction); final Collection disjunction2 = CollUtil.disjunction(list2, list1); - Assert.assertEquals(list2, disjunction2); + Assertions.assertEquals(list2, disjunction2); } @Test @@ -216,19 +216,19 @@ public class CollUtilTest { final List list2 = ListUtil.of("a", "b", "c"); final Collection disjunction = CollUtil.disjunction(list1, list2); - Assert.assertTrue(disjunction.contains("1")); - Assert.assertTrue(disjunction.contains("2")); - Assert.assertTrue(disjunction.contains("3")); - Assert.assertTrue(disjunction.contains("a")); - Assert.assertTrue(disjunction.contains("b")); - Assert.assertTrue(disjunction.contains("c")); + Assertions.assertTrue(disjunction.contains("1")); + Assertions.assertTrue(disjunction.contains("2")); + Assertions.assertTrue(disjunction.contains("3")); + Assertions.assertTrue(disjunction.contains("a")); + Assertions.assertTrue(disjunction.contains("b")); + Assertions.assertTrue(disjunction.contains("c")); final Collection disjunction2 = CollUtil.disjunction(list2, list1); - Assert.assertTrue(disjunction2.contains("1")); - Assert.assertTrue(disjunction2.contains("2")); - Assert.assertTrue(disjunction2.contains("3")); - Assert.assertTrue(disjunction2.contains("a")); - Assert.assertTrue(disjunction2.contains("b")); - Assert.assertTrue(disjunction2.contains("c")); + Assertions.assertTrue(disjunction2.contains("1")); + Assertions.assertTrue(disjunction2.contains("2")); + Assertions.assertTrue(disjunction2.contains("3")); + Assertions.assertTrue(disjunction2.contains("a")); + Assertions.assertTrue(disjunction2.contains("b")); + Assertions.assertTrue(disjunction2.contains("c")); } @Test @@ -236,8 +236,8 @@ public class CollUtilTest { final List list1 = ListUtil.of("a", "b", "b", "c", "d", "x"); final List list2 = ListUtil.of("a", "b", "b", "b", "c", "d", "x2"); final Collection subtract = CollUtil.subtract(list1, list2); - Assert.assertEquals(1, subtract.size()); - Assert.assertEquals("x", subtract.iterator().next()); + Assertions.assertEquals(1, subtract.size()); + Assertions.assertEquals("x", subtract.iterator().next()); } @Test @@ -248,7 +248,7 @@ public class CollUtilTest { map1.put("2", "v2"); map2.put("2", "v2"); final Collection r2 = CollUtil.subtract(map1.keySet(), map2.keySet()); - Assert.assertEquals("[1]", r2.toString()); + Assertions.assertEquals("[1]", r2.toString()); } @Test @@ -259,7 +259,7 @@ public class CollUtilTest { map1.put("2", "v2"); map2.put("2", "v2"); final List r2 = CollUtil.subtractToList(map1.keySet(), map2.keySet()); - Assert.assertEquals("[1]", r2.toString()); + Assertions.assertEquals("[1]", r2.toString()); } @Test @@ -275,13 +275,13 @@ public class CollUtilTest { // ---------------------------------------------------------------------------------------- final List> list = ListUtil.of(map1, map2); final Map> map = CollUtil.toListMap(list); - Assert.assertEquals("值1", map.get("a").get(0)); - Assert.assertEquals("值2", map.get("a").get(1)); + Assertions.assertEquals("值1", map.get("a").get(0)); + Assertions.assertEquals("值2", map.get("a").get(1)); // ---------------------------------------------------------------------------------------- final List> listMap = CollUtil.toMapList(map); - Assert.assertEquals("值1", listMap.get(0).get("a")); - Assert.assertEquals("值2", listMap.get(1).get("a")); + Assertions.assertEquals("值1", listMap.get(0).get("a")); + Assertions.assertEquals("值2", listMap.get(1).get("a")); } @Test @@ -292,24 +292,24 @@ public class CollUtilTest { final List fieldValues = (List) CollUtil.getFieldValues(list, "name"); - Assert.assertEquals("张三", fieldValues.get(0)); - Assert.assertEquals("李四", fieldValues.get(1)); + Assertions.assertEquals("张三", fieldValues.get(0)); + Assertions.assertEquals("李四", fieldValues.get(1)); } @Test public void partitionTest() { final List list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9); final List> split = CollUtil.partition(list, 3); - Assert.assertEquals(3, split.size()); - Assert.assertEquals(3, split.get(0).size()); + Assertions.assertEquals(3, split.size()); + Assertions.assertEquals(3, split.get(0).size()); } @Test public void partitionTest2() { final ArrayList list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9); final List> split = CollUtil.partition(list, Integer.MAX_VALUE); - Assert.assertEquals(1, split.size()); - Assert.assertEquals(9, split.get(0).size()); + Assertions.assertEquals(1, split.size()); + Assertions.assertEquals(9, split.get(0).size()); } @Test @@ -326,7 +326,7 @@ public class CollUtilTest { result[0] = value; } }); - Assert.assertEquals("1", result[0]); + Assertions.assertEquals("1", result[0]); } @Test @@ -335,7 +335,7 @@ public class CollUtilTest { final Collection filtered = CollUtil.edit(list, t -> t + 1); - Assert.assertEquals(ListUtil.of("a1", "b1", "c1"), filtered); + Assertions.assertEquals(ListUtil.of("a1", "b1", "c1"), filtered); } @Test @@ -345,8 +345,8 @@ public class CollUtilTest { final List filtered = CollUtil.remove(list, "a"::equals); // 原地过滤 - Assert.assertSame(list, filtered); - Assert.assertEquals(ListUtil.of("b", "c"), filtered); + Assertions.assertSame(list, filtered); + Assertions.assertEquals(ListUtil.of("b", "c"), filtered); } @Test @@ -354,7 +354,7 @@ public class CollUtilTest { final Set set = SetUtil.ofLinked("a", "b", "", " ", "c"); final Set filtered = CollUtil.remove(set, StrUtil::isBlank); - Assert.assertEquals(SetUtil.ofLinked("a", "b", "c"), filtered); + Assertions.assertEquals(SetUtil.ofLinked("a", "b", "c"), filtered); } @Test @@ -370,12 +370,12 @@ public class CollUtilTest { return false; }); - Assert.assertEquals(1, removed.size()); - Assert.assertEquals("a", removed.get(0)); + Assertions.assertEquals(1, removed.size()); + Assertions.assertEquals("a", removed.get(0)); // 原地过滤 - Assert.assertSame(list, filtered); - Assert.assertEquals(ListUtil.of("b", "c"), filtered); + Assertions.assertSame(list, filtered); + Assertions.assertEquals(ListUtil.of("b", "c"), filtered); } @Test @@ -385,8 +385,8 @@ public class CollUtilTest { final List filtered = CollUtil.removeNull(list); // 原地过滤 - Assert.assertSame(list, filtered); - Assert.assertEquals(ListUtil.of("a", "b", "c", "", " "), filtered); + Assertions.assertSame(list, filtered); + Assertions.assertEquals(ListUtil.of("a", "b", "c", "", " "), filtered); } @Test @@ -396,8 +396,8 @@ public class CollUtilTest { final List filtered = CollUtil.removeEmpty(list); // 原地过滤 - Assert.assertSame(list, filtered); - Assert.assertEquals(ListUtil.of("a", "b", "c", " "), filtered); + Assertions.assertSame(list, filtered); + Assertions.assertEquals(ListUtil.of("a", "b", "c", " "), filtered); } @Test @@ -407,52 +407,52 @@ public class CollUtilTest { final List filtered = CollUtil.removeBlank(list); // 原地过滤 - Assert.assertSame(list, filtered); - Assert.assertEquals(ListUtil.of("a", "b", "c"), filtered); + Assertions.assertSame(list, filtered); + Assertions.assertEquals(ListUtil.of("a", "b", "c"), filtered); } @Test public void groupTest() { final List list = ListUtil.of("1", "2", "3", "4", "5", "6"); final List> group = CollUtil.group(list, null); - Assert.assertTrue(group.size() > 0); + Assertions.assertTrue(group.size() > 0); final List> group2 = CollUtil.group(list, t -> { // 按照奇数偶数分类 return Integer.parseInt(t) % 2; }); - Assert.assertEquals(ListUtil.of("2", "4", "6"), group2.get(0)); - Assert.assertEquals(ListUtil.of("1", "3", "5"), group2.get(1)); + Assertions.assertEquals(ListUtil.of("2", "4", "6"), group2.get(0)); + Assertions.assertEquals(ListUtil.of("1", "3", "5"), group2.get(1)); } @Test public void groupByFieldTest() { final List list = ListUtil.of(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12)); final List> groupByField = CollUtil.groupByField(list, "age"); - Assert.assertEquals("张三", groupByField.get(0).get(0).getName()); - Assert.assertEquals("王五", groupByField.get(0).get(1).getName()); + Assertions.assertEquals("张三", groupByField.get(0).get(0).getName()); + Assertions.assertEquals("王五", groupByField.get(0).get(1).getName()); - Assert.assertEquals("李四", groupByField.get(1).get(0).getName()); + Assertions.assertEquals("李四", groupByField.get(1).get(0).getName()); } @Test public void groupByFuncTest() { final List list = ListUtil.of(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12)); final List> groupByField = CollUtil.groupByFunc(list, TestBean::getAge); - Assert.assertEquals("张三", groupByField.get(0).get(0).getName()); - Assert.assertEquals("王五", groupByField.get(0).get(1).getName()); + Assertions.assertEquals("张三", groupByField.get(0).get(0).getName()); + Assertions.assertEquals("王五", groupByField.get(0).get(1).getName()); - Assert.assertEquals("李四", groupByField.get(1).get(0).getName()); + Assertions.assertEquals("李四", groupByField.get(1).get(0).getName()); } @Test public void groupByFunc2Test() { final List list = ListUtil.of(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12)); final List> groupByField = CollUtil.groupByFunc(list, a -> a.getAge() > 12); - Assert.assertEquals("张三", groupByField.get(0).get(0).getName()); - Assert.assertEquals("王五", groupByField.get(0).get(1).getName()); + Assertions.assertEquals("张三", groupByField.get(0).get(0).getName()); + Assertions.assertEquals("王五", groupByField.get(0).get(1).getName()); - Assert.assertEquals("李四", groupByField.get(1).get(0).getName()); + Assertions.assertEquals("李四", groupByField.get(1).get(0).getName()); } @Test @@ -464,9 +464,9 @@ public class CollUtilTest { ); CollUtil.sortByProperty(list, "createTime"); - Assert.assertEquals("李四", list.get(0).getName()); - Assert.assertEquals("王五", list.get(1).getName()); - Assert.assertEquals("张三", list.get(2).getName()); + Assertions.assertEquals("李四", list.get(0).getName()); + Assertions.assertEquals("王五", list.get(1).getName()); + Assertions.assertEquals("张三", list.get(2).getName()); } @Test @@ -478,9 +478,9 @@ public class CollUtilTest { ); CollUtil.sortByProperty(list, "age"); - Assert.assertEquals("李四", list.get(0).getName()); - Assert.assertEquals("张三", list.get(1).getName()); - Assert.assertEquals("王五", list.get(2).getName()); + Assertions.assertEquals("李四", list.get(0).getName()); + Assertions.assertEquals("张三", list.get(1).getName()); + Assertions.assertEquals("王五", list.get(2).getName()); } @Test @@ -491,9 +491,9 @@ public class CollUtilTest { ); final Map map = CollUtil.fieldValueMap(list, "name"); - Assert.assertEquals("李四", map.get("李四").getName()); - Assert.assertEquals("王五", map.get("王五").getName()); - Assert.assertEquals("张三", map.get("张三").getName()); + Assertions.assertEquals("李四", map.get("李四").getName()); + Assertions.assertEquals("王五", map.get("王五").getName()); + Assertions.assertEquals("张三", map.get("张三").getName()); } @Test @@ -504,21 +504,21 @@ public class CollUtilTest { ); final Map map = CollUtil.fieldValueAsMap(list, "name", "age"); - Assert.assertEquals(new Integer(12), map.get("张三")); - Assert.assertEquals(new Integer(13), map.get("李四")); - Assert.assertEquals(new Integer(14), map.get("王五")); + Assertions.assertEquals(new Integer(12), map.get("张三")); + Assertions.assertEquals(new Integer(13), map.get("李四")); + Assertions.assertEquals(new Integer(14), map.get("王五")); } @Test public void emptyTest() { final SortedSet emptySortedSet = CollUtil.empty(SortedSet.class); - Assert.assertEquals(Collections.emptySortedSet(), emptySortedSet); + Assertions.assertEquals(Collections.emptySortedSet(), emptySortedSet); final Set emptySet = CollUtil.empty(Set.class); - Assert.assertEquals(Collections.emptySet(), emptySet); + Assertions.assertEquals(Collections.emptySet(), emptySet); final List emptyList = CollUtil.empty(List.class); - Assert.assertEquals(Collections.emptyList(), emptyList); + Assertions.assertEquals(Collections.emptyList(), emptyList); } @Data @@ -539,16 +539,16 @@ public class CollUtilTest { final List list1 = ListUtil.of(false); final List list2 = ListUtil.of(true); - Assert.assertTrue(list1 instanceof ArrayList); - Assert.assertTrue(list2 instanceof LinkedList); + Assertions.assertTrue(list1 instanceof ArrayList); + Assertions.assertTrue(list2 instanceof LinkedList); } @Test public void listTest2() { final List list1 = ListUtil.of("a", "b", "c"); final List list2 = ListUtil.ofLinked("a", "b", "c"); - Assert.assertEquals("[a, b, c]", list1.toString()); - Assert.assertEquals("[a, b, c]", list2.toString()); + Assertions.assertEquals("[a, b, c]", list1.toString()); + Assertions.assertEquals("[a, b, c]", list2.toString()); } @Test @@ -560,18 +560,18 @@ public class CollUtilTest { final List list1 = ListUtil.of(false, set); final List list2 = ListUtil.of(true, set); - Assert.assertEquals("[a, b, c]", list1.toString()); - Assert.assertEquals("[a, b, c]", list2.toString()); + Assertions.assertEquals("[a, b, c]", list1.toString()); + Assertions.assertEquals("[a, b, c]", list2.toString()); } @Test public void getTest() { final HashSet set = SetUtil.ofLinked("A", "B", "C", "D"); String str = CollUtil.get(set, 2); - Assert.assertEquals("C", str); + Assertions.assertEquals("C", str); str = CollUtil.get(set, -1); - Assert.assertEquals("D", str); + Assertions.assertEquals("D", str); } @Test @@ -587,7 +587,7 @@ public class CollUtilTest { // Assert result final List arrayList = new ArrayList<>(); arrayList.add(null); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } @Test @@ -604,7 +604,7 @@ public class CollUtilTest { // Assert result final List arrayList = new ArrayList<>(); arrayList.add(null); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } @Test @@ -619,7 +619,7 @@ public class CollUtilTest { // Assert result final List arrayList = new ArrayList<>(); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } @Test @@ -632,7 +632,7 @@ public class CollUtilTest { // Act final List retval = CollUtil.sub(list, start, end, step); // Assert result - Assert.assertTrue(retval.isEmpty()); + Assertions.assertTrue(retval.isEmpty()); } @Test @@ -647,7 +647,7 @@ public class CollUtilTest { final List retval = CollUtil.sub(list, start, end, step); // Assert result final List arrayList = new ArrayList<>(); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } @Test @@ -662,21 +662,23 @@ public class CollUtilTest { final List retval = CollUtil.sub(list, start, end, step); // Assert result final List arrayList = new ArrayList<>(); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void subInput1PositiveNegativePositiveOutputArrayIndexOutOfBoundsException() { - // Arrange - final List list = new ArrayList<>(); - list.add(null); - final int start = 2_147_483_643; - final int end = -2_147_483_648; - final int step = 2; + Assertions.assertThrows(IndexOutOfBoundsException.class, ()->{ + // Arrange + final List list = new ArrayList<>(); + list.add(null); + final int start = 2_147_483_643; + final int end = -2_147_483_648; + final int step = 2; - // Act - CollUtil.sub(list, start, end, step); - // Method is not expected to return due to exception thrown + // Act + CollUtil.sub(list, start, end, step); + // Method is not expected to return due to exception thrown + }); } @Test @@ -689,7 +691,7 @@ public class CollUtilTest { // Act final List retval = CollUtil.sub(list, start, end, step); // Assert result - Assert.assertTrue(retval.isEmpty()); + Assertions.assertTrue(retval.isEmpty()); } @Test @@ -704,7 +706,7 @@ public class CollUtilTest { final List retval = CollUtil.sub(list, start, end, step); // Assert result final List arrayList = new ArrayList<>(); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } @Test @@ -719,7 +721,7 @@ public class CollUtilTest { final List retval = CollUtil.sub(list, start, end, step); // Assert result final List arrayList = new ArrayList<>(); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } @Test @@ -734,7 +736,7 @@ public class CollUtilTest { final List retval = CollUtil.sub(list, start, end, step); // Assert result final List arrayList = new ArrayList<>(); - Assert.assertEquals(arrayList, retval); + Assertions.assertEquals(arrayList, retval); } @Test @@ -746,7 +748,7 @@ public class CollUtilTest { // Act final List retval = CollUtil.sub(list, start, end); // Assert result - Assert.assertTrue(retval.isEmpty()); + Assertions.assertTrue(retval.isEmpty()); } @Test @@ -754,7 +756,7 @@ public class CollUtilTest { final List list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9); final List sortPageAll = CollUtil.sortPageAll(1, 5, Comparator.reverseOrder(), list); - Assert.assertEquals(ListUtil.of(4, 3, 2, 1), sortPageAll); + Assertions.assertEquals(ListUtil.of(4, 3, 2, 1), sortPageAll); } @Test @@ -762,18 +764,18 @@ public class CollUtilTest { final List list1 = ListUtil.of(1, 2, 3, 4, 5); final List list2 = ListUtil.of(5, 3, 1, 9, 11); - Assert.assertTrue(CollUtil.containsAny(list1, list2)); + Assertions.assertTrue(CollUtil.containsAny(list1, list2)); } @Test public void containsAllTest() { final List list1 = ListUtil.of(1, 2, 3, 4, 5); final List list2 = ListUtil.of(5, 3, 1); - Assert.assertTrue(CollUtil.containsAll(list1, list2)); + Assertions.assertTrue(CollUtil.containsAll(list1, list2)); final List list3 = ListUtil.of(1); final List list4 = ListUtil.of(); - Assert.assertTrue(CollUtil.containsAll(list3, list4)); + Assertions.assertTrue(CollUtil.containsAll(list3, list4)); } @Test @@ -781,7 +783,7 @@ public class CollUtilTest { // 测试:空数组返回null而不是报错 final List test = ListUtil.of(); final String last = CollUtil.getLast(test); - Assert.assertNull(last); + Assertions.assertNull(last); } @Test @@ -791,22 +793,22 @@ public class CollUtilTest { final Map map = CollUtil.zip(keys, values); - Assert.assertEquals(4, Objects.requireNonNull(map).size()); + Assertions.assertEquals(4, Objects.requireNonNull(map).size()); - Assert.assertEquals(1, map.get("a").intValue()); - Assert.assertEquals(2, map.get("b").intValue()); - Assert.assertEquals(3, map.get("c").intValue()); - Assert.assertEquals(4, map.get("d").intValue()); + Assertions.assertEquals(1, map.get("a").intValue()); + Assertions.assertEquals(2, map.get("b").intValue()); + Assertions.assertEquals(3, map.get("c").intValue()); + Assertions.assertEquals(4, map.get("d").intValue()); } @Test public void toMapTest() { final Collection keys = ListUtil.of("a", "b", "c", "d"); final Map map = IterUtil.toMap(keys, (value) -> "key" + value); - Assert.assertEquals("a", map.get("keya")); - Assert.assertEquals("b", map.get("keyb")); - Assert.assertEquals("c", map.get("keyc")); - Assert.assertEquals("d", map.get("keyd")); + Assertions.assertEquals("a", map.get("keya")); + Assertions.assertEquals("b", map.get("keyb")); + Assertions.assertEquals("c", map.get("keyc")); + Assertions.assertEquals("d", map.get("keyd")); } @Test @@ -820,9 +822,9 @@ public class CollUtilTest { Map.Entry::getKey, entry -> Long.parseLong(entry.getValue())); - Assert.assertEquals(1L, (long) map.get("a")); - Assert.assertEquals(12L, (long) map.get("b")); - Assert.assertEquals(134L, (long) map.get("c")); + Assertions.assertEquals(1L, (long) map.get("a")); + Assertions.assertEquals(12L, (long) map.get("b")); + Assertions.assertEquals(134L, (long) map.get("c")); } @Test @@ -830,17 +832,17 @@ public class CollUtilTest { final List list = ListUtil.of("a", "b", "c", "c", "a", "b", "d"); final Map countMap = CollUtil.countMap(list); - Assert.assertEquals(Integer.valueOf(2), countMap.get("a")); - Assert.assertEquals(Integer.valueOf(2), countMap.get("b")); - Assert.assertEquals(Integer.valueOf(2), countMap.get("c")); - Assert.assertEquals(Integer.valueOf(1), countMap.get("d")); + Assertions.assertEquals(Integer.valueOf(2), countMap.get("a")); + Assertions.assertEquals(Integer.valueOf(2), countMap.get("b")); + Assertions.assertEquals(Integer.valueOf(2), countMap.get("c")); + Assertions.assertEquals(Integer.valueOf(1), countMap.get("d")); } @Test public void indexOfTest() { final List list = ListUtil.of("a", "b", "c", "c", "a", "b", "d"); final int i = CollUtil.indexOf(list, (str) -> str.charAt(0) == 'c'); - Assert.assertEquals(2, i); + Assertions.assertEquals(2, i); } @Test @@ -848,13 +850,13 @@ public class CollUtilTest { // List有优化 final List list = ListUtil.of("a", "b", "c", "c", "a", "b", "d"); final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'a'); - Assert.assertEquals(4, i); + Assertions.assertEquals(4, i); final Queue set = new ArrayDeque<>(Arrays.asList(1, 2, 3, 3, 2, 1)); - Assert.assertEquals(5, CollUtil.lastIndexOf(set, num -> num.equals(1))); - Assert.assertEquals(4, CollUtil.lastIndexOf(set, num -> num.equals(2))); - Assert.assertEquals(3, CollUtil.lastIndexOf(set, num -> num.equals(3))); - Assert.assertEquals(-1, CollUtil.lastIndexOf(set, num -> num.equals(4))); + Assertions.assertEquals(5, CollUtil.lastIndexOf(set, num -> num.equals(1))); + Assertions.assertEquals(4, CollUtil.lastIndexOf(set, num -> num.equals(2))); + Assertions.assertEquals(3, CollUtil.lastIndexOf(set, num -> num.equals(3))); + Assertions.assertEquals(-1, CollUtil.lastIndexOf(set, num -> num.equals(4))); } @Test @@ -862,7 +864,7 @@ public class CollUtilTest { final Set list = SetUtil.ofLinked("a", "b", "c", "c", "a", "b", "d"); // 去重后c排第三 final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'c'); - Assert.assertEquals(2, i); + Assertions.assertEquals(2, i); } @Test @@ -872,7 +874,7 @@ public class CollUtilTest { objects.add(Dict.of().set("name", "姓名:" + i)); } - Assert.assertEquals(0, ListUtil.page(objects, 3, 5).size()); + Assertions.assertEquals(0, ListUtil.page(objects, 3, 5).size()); } @Test @@ -881,15 +883,15 @@ public class CollUtilTest { final List list2 = Arrays.asList(2L, 3L); final List result = CollUtil.subtractToList(list1, list2); - Assert.assertEquals(1, result.size()); - Assert.assertEquals(1L, (long) result.get(0)); + Assertions.assertEquals(1, result.size()); + Assertions.assertEquals(1L, (long) result.get(0)); } @Test public void sortNaturalTest() { final List of = ListUtil.of("a", "c", "b"); final List sort = CollUtil.sort(of, CompareUtil.natural()); - Assert.assertEquals("a,b,c", CollUtil.join(sort, ",")); + Assertions.assertEquals("a,b,c", CollUtil.join(sort, ",")); } @Test @@ -912,9 +914,9 @@ public class CollUtilTest { genderMap.put(5, "小孩"); genderMap.put(6, "男"); - Assert.assertEquals(people.get(1).getGender(), "woman"); + Assertions.assertEquals(people.get(1).getGender(), "woman"); CollUtil.setValueByMap(people, genderMap, Person::getId, Person::setGender); - Assert.assertEquals(people.get(1).getGender(), "妇女"); + Assertions.assertEquals(people.get(1).getGender(), "妇女"); final Map personMap = new HashMap<>(); personMap.put(1, new Person("AA", 21, "男", 1)); @@ -930,13 +932,13 @@ public class CollUtilTest { x.setAge(y.getAge()); }); - Assert.assertEquals(people.get(1).getGender(), "小孩"); + Assertions.assertEquals(people.get(1).getGender(), "小孩"); } @Test public void distinctTest() { final List distinct = CollUtil.distinct(ListUtil.view(5, 3, 10, 9, 0, 5, 10, 9)); - Assert.assertEquals(ListUtil.view(5, 3, 10, 9, 0), distinct); + Assertions.assertEquals(ListUtil.view(5, 3, 10, 9, 0), distinct); } @Test @@ -952,15 +954,15 @@ public class CollUtilTest { // 覆盖模式下ff覆盖了aa,ee覆盖了bb List distinct = CollUtil.distinct(people, Person::getGender, true); - Assert.assertEquals(2, distinct.size()); - Assert.assertEquals("ff", distinct.get(0).getName()); - Assert.assertEquals("ee", distinct.get(1).getName()); + Assertions.assertEquals(2, distinct.size()); + Assertions.assertEquals("ff", distinct.get(0).getName()); + Assertions.assertEquals("ee", distinct.get(1).getName()); // 非覆盖模式下,保留了最早加入的aa和bb distinct = CollUtil.distinct(people, Person::getGender, false); - Assert.assertEquals(2, distinct.size()); - Assert.assertEquals("aa", distinct.get(0).getName()); - Assert.assertEquals("bb", distinct.get(1).getName()); + Assertions.assertEquals(2, distinct.size()); + Assertions.assertEquals("aa", distinct.get(0).getName()); + Assertions.assertEquals("bb", distinct.get(1).getName()); } @Data @@ -976,7 +978,7 @@ public class CollUtilTest { public void mapTest() { final List list = ListUtil.of("a", "b", "c"); final List extract = CollUtil.map(list, (e) -> e + "_1"); - Assert.assertEquals(ListUtil.of("a_1", "b_1", "c_1"), extract); + Assertions.assertEquals(ListUtil.of("a_1", "b_1", "c_1"), extract); } @Test @@ -989,14 +991,14 @@ public class CollUtilTest { ); final List extract = CollUtil.map(people, Person::getName); - Assert.assertEquals(ListUtil.of("aa", "bb", "cc", "dd"), extract); + Assertions.assertEquals(ListUtil.of("aa", "bb", "cc", "dd"), extract); } @Test public void createTest() { final Collection collection = CollUtil.create(Collections.emptyList().getClass()); Console.log(collection.getClass()); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); } @Test @@ -1009,7 +1011,7 @@ public class CollUtilTest { ); final Collection trans = CollUtil.trans(people, Person::getName); - Assert.assertEquals("[aa, bb, cc, dd]", trans.toString()); + Assertions.assertEquals("[aa, bb, cc, dd]", trans.toString()); } @SuppressWarnings("ConstantConditions") @@ -1019,7 +1021,7 @@ public class CollUtilTest { final List list2 = null; final List list3 = null; final Collection union = CollUtil.union(list1, list2, list3); - Assert.assertNotNull(union); + Assertions.assertNotNull(union); } @SuppressWarnings("ConstantConditions") @@ -1029,7 +1031,7 @@ public class CollUtilTest { final List list2 = null; final List list3 = null; final Set set = CollUtil.unionDistinct(list1, list2, list3); - Assert.assertNotNull(set); + Assertions.assertNotNull(set); } @SuppressWarnings("ConstantConditions") @@ -1039,9 +1041,9 @@ public class CollUtilTest { final List list2 = null; final List list3 = null; final List list = CollUtil.unionAll(list1, list2, list3); - Assert.assertNotNull(list); + Assertions.assertNotNull(list); - Assert.assertEquals( + Assertions.assertEquals( ListUtil.of(1, 2, 3, 4), CollUtil.unionAll(ListUtil.of(1), ListUtil.of(2), ListUtil.of(3), ListUtil.of(4)) ); @@ -1056,7 +1058,7 @@ public class CollUtilTest { list2.add("aa"); final List list3 = null; final Collection collection = CollUtil.intersection(list1, list2, list3); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); } @SuppressWarnings("ConstantConditions") @@ -1068,24 +1070,24 @@ public class CollUtilTest { // list2.add("aa"); final List list3 = null; final Collection collection = CollUtil.intersectionDistinct(list1, list2, list3); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); } @Test public void addIfAbsentTest() { // 为false的情况 - Assert.assertFalse(CollUtil.addIfAbsent(null, null)); - Assert.assertFalse(CollUtil.addIfAbsent(ListUtil.of(), null)); - Assert.assertFalse(CollUtil.addIfAbsent(null, "123")); - Assert.assertFalse(CollUtil.addIfAbsent(ListUtil.of("123"), "123")); - Assert.assertFalse(CollUtil.addIfAbsent(ListUtil.of(new Animal("jack", 20)), + Assertions.assertFalse(CollUtil.addIfAbsent(null, null)); + Assertions.assertFalse(CollUtil.addIfAbsent(ListUtil.of(), null)); + Assertions.assertFalse(CollUtil.addIfAbsent(null, "123")); + Assertions.assertFalse(CollUtil.addIfAbsent(ListUtil.of("123"), "123")); + Assertions.assertFalse(CollUtil.addIfAbsent(ListUtil.of(new Animal("jack", 20)), new Animal("jack", 20))); // 正常情况 - Assert.assertTrue(CollUtil.addIfAbsent(ListUtil.of("456"), "123")); - Assert.assertTrue(CollUtil.addIfAbsent(ListUtil.of(new Animal("jack", 20)), + Assertions.assertTrue(CollUtil.addIfAbsent(ListUtil.of("456"), "123")); + Assertions.assertTrue(CollUtil.addIfAbsent(ListUtil.of(new Animal("jack", 20)), new Dog("jack", 20))); - Assert.assertTrue(CollUtil.addIfAbsent(ListUtil.of(new Animal("jack", 20)), + Assertions.assertTrue(CollUtil.addIfAbsent(ListUtil.of(new Animal("jack", 20)), new Animal("tom", 20))); } @@ -1108,14 +1110,14 @@ public class CollUtilTest { @Test public void getFirstTest() { - Assert.assertNull(CollUtil.getFirst(null)); - Assert.assertNull(CollUtil.getFirst(ListUtil.of())); + Assertions.assertNull(CollUtil.getFirst(null)); + Assertions.assertNull(CollUtil.getFirst(ListUtil.of())); - Assert.assertEquals("1", CollUtil.getFirst(ListUtil.of("1", "2", "3"))); + Assertions.assertEquals("1", CollUtil.getFirst(ListUtil.of("1", "2", "3"))); final ArrayDeque deque = new ArrayDeque<>(); deque.add("3"); deque.add("4"); - Assert.assertEquals("3", CollUtil.getFirst(deque)); + Assertions.assertEquals("3", CollUtil.getFirst(deque)); } @Test @@ -1125,29 +1127,29 @@ public class CollUtilTest { stack.push(i); } final List popPart1 = CollUtil.popPart(stack, 3); - Assert.assertEquals(ListUtil.of(9, 8, 7), popPart1); - Assert.assertEquals(7, stack.size()); + Assertions.assertEquals(ListUtil.of(9, 8, 7), popPart1); + Assertions.assertEquals(7, stack.size()); final ArrayDeque queue = new ArrayDeque<>(); for (int i = 0; i < 10; i++) { queue.push(i); } final List popPart2 = CollUtil.popPart(queue, 3); - Assert.assertEquals(ListUtil.of(9, 8, 7), popPart2); - Assert.assertEquals(7, queue.size()); + Assertions.assertEquals(ListUtil.of(9, 8, 7), popPart2); + Assertions.assertEquals(7, queue.size()); } @Test public void isEqualListTest() { final List list = ListUtil.of(1, 2, 3, 4); - Assert.assertTrue(CollUtil.isEqualList(null, null)); - Assert.assertTrue(CollUtil.isEqualList(ListUtil.of(), ListUtil.of())); - Assert.assertTrue(CollUtil.isEqualList(list, list)); - Assert.assertTrue(CollUtil.isEqualList(list, ListUtil.of(1, 2, 3, 4))); + Assertions.assertTrue(CollUtil.isEqualList(null, null)); + Assertions.assertTrue(CollUtil.isEqualList(ListUtil.of(), ListUtil.of())); + Assertions.assertTrue(CollUtil.isEqualList(list, list)); + Assertions.assertTrue(CollUtil.isEqualList(list, ListUtil.of(1, 2, 3, 4))); - Assert.assertFalse(CollUtil.isEqualList(null, ListUtil.of())); - Assert.assertFalse(CollUtil.isEqualList(list, ListUtil.of(1, 2, 3, 3))); - Assert.assertFalse(CollUtil.isEqualList(list, ListUtil.of(1, 2, 3))); - Assert.assertFalse(CollUtil.isEqualList(list, ListUtil.of(4, 3, 2, 1))); + Assertions.assertFalse(CollUtil.isEqualList(null, ListUtil.of())); + Assertions.assertFalse(CollUtil.isEqualList(list, ListUtil.of(1, 2, 3, 3))); + Assertions.assertFalse(CollUtil.isEqualList(list, ListUtil.of(1, 2, 3))); + Assertions.assertFalse(CollUtil.isEqualList(list, ListUtil.of(4, 3, 2, 1))); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/IterUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/IterUtilTest.java index 4835f593a..dbeeaa224 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/IterUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/IterUtilTest.java @@ -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 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 carList = ListUtil.of(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎")); final Map 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 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 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 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 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 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> 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 testMap = IterUtil.toMap(Arrays.asList(bmw, benz), Car::getCarNumber); - Assert.assertEquals(expectedMap, testMap); + Assertions.assertEquals(expectedMap, testMap); } @Test public void getElementTypeTest() { final List 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 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 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 set = SetUtil.ofLinked("A", "B", "C", "D"); final String str = IterUtil.get(set.iterator(), 2); - Assert.assertEquals("C", str); + Assertions.assertEquals("C", str); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/ListUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/ListUtilTest.java index bfdea2fa9..01a9477ce 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/ListUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/ListUtilTest.java @@ -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> 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 list = new ArrayList<>(); CollUtil.padRight(list, RandomUtil.randomInt(1000_0000, 1_0000_0000), "test"); @@ -51,7 +51,7 @@ public class ListUtilTest { final List> 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> 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 a = ListUtil.ofLinked("1", "2", "3"); final List 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 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 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> 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 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 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> list = Arrays.asList(map1, map2, map3); ListUtil.swapElement(list, map2, map3); Map 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 strings = ListUtil.ofCopyOnWrite(ListUtil.of("a", "b")); - Assert.assertEquals(2, strings.size()); + Assertions.assertEquals(2, strings.size()); } @Test public void ofCopyOnWriteTest2(){ final CopyOnWriteArrayList strings = ListUtil.ofCopyOnWrite("a", "b"); - Assert.assertEquals(2, strings.size()); + Assertions.assertEquals(2, strings.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/MapProxyTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/MapProxyTest.java index d799d1cd7..3568f1313 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/MapProxyTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/MapProxyTest.java @@ -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 keys = mapProxy.keySet(); - Assert.assertFalse(keys.isEmpty()); + Assertions.assertFalse(keys.isEmpty()); final Set> 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(), "小明"); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueueTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueueTest.java index fc9ff9533..cbef27ba8 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueueTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueueTest.java @@ -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 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)))); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/PartitionIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/PartitionIterTest.java index a1bc70e18..fea83cbfb 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/PartitionIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/PartitionIterTest.java @@ -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 iter = new PartitionIter<>(lineIter, 3); for (final List lines : iter) { - Assert.assertTrue(lines.size() > 0); + Assertions.assertTrue(lines.size() > 0); } } @@ -28,6 +28,6 @@ public class PartitionIterTest { for (final List lines : iter) { max = ArrayUtil.max(max, ArrayUtil.max(lines.toArray(new Integer[0]))); } - Assert.assertEquals(45, max); + Assertions.assertEquals(45, max); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/RingIndexUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/RingIndexUtilTest.java index 7ce717aa3..06193dbdf 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/RingIndexUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/RingIndexUtilTest.java @@ -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); }); } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/UniqueKeySetTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/UniqueKeySetTest.java index 71b43fe7a..7f9089945 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/UniqueKeySetTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/UniqueKeySetTest.java @@ -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 diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/ArrayIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/ArrayIterTest.java index 48aef57a1..c33a8fa01 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/ArrayIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/ArrayIterTest.java @@ -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 iter = new ArrayIter<>(arr); - Assert.assertTrue(iter.hasNext()); + Assertions.assertTrue(iter.hasNext()); } @Test public void testNext() { Integer[] arr = new Integer[]{ 1, 2, 3 }; ArrayIter 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 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 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 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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/CopiedIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/CopiedIterTest.java index 76e86a7c2..a40a6009c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/CopiedIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/CopiedIterTest.java @@ -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 list = Arrays.asList(1, 2, 3); Iterator 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 list = Arrays.asList(1, 2, 3); Iterator 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 list = Arrays.asList(1, 2, 3); Iterator iter = CopiedIter.copyOf(list.iterator()); - Assert.assertThrows(UnsupportedOperationException.class, iter::remove); + Assertions.assertThrows(UnsupportedOperationException.class, iter::remove); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/EnumerationIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/EnumerationIterTest.java index 8c2b6b0c3..de41487ad 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/EnumerationIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/EnumerationIterTest.java @@ -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 enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator()); EnumerationIter 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 enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator()); EnumerationIter 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 enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator()); EnumerationIter iter = new EnumerationIter<>(enumeration); - Assert.assertThrows(UnsupportedOperationException.class, iter::remove); + Assertions.assertThrows(UnsupportedOperationException.class, iter::remove); } @Test public void testIterator() { Enumeration enumeration = new IteratorEnumeration<>(Arrays.asList(1, 2, 3).iterator()); EnumerationIter iter = new EnumerationIter<>(enumeration); - Assert.assertSame(iter, iter.iterator()); + Assertions.assertSame(iter, iter.iterator()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/FilterIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/FilterIterTest.java index 4778a320d..a9362a6d0 100755 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/FilterIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/FilterIterTest.java @@ -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 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 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 iter = new FilterIter<>(Collections.emptyIterator(), i -> true); - Assert.assertThrows(IllegalStateException.class, iter::remove); + Assertions.assertThrows(IllegalStateException.class, iter::remove); } @Test public void getIterator() { FilterIter iter = new FilterIter<>(Collections.emptyIterator(), i -> true); - Assert.assertSame(Collections.emptyIterator(), iter.getIterator()); + Assertions.assertSame(Collections.emptyIterator(), iter.getIterator()); } @Test public void getFilter() { Predicate predicate = i -> true; FilterIter iter = new FilterIter<>(Collections.emptyIterator(), predicate); - Assert.assertSame(predicate, iter.getFilter()); + Assertions.assertSame(predicate, iter.getFilter()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterChainTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterChainTest.java index 5565437e4..c533f97c1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterChainTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterChainTest.java @@ -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 iter1 = Arrays.asList(1, 2).iterator(); final Iterator iter2 = Arrays.asList(3, 4).iterator(); IterChain 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 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 iter1 = Arrays.asList(1, 2).iterator(); final Iterator iter2 = Arrays.asList(3, 4).iterator(); final IterChain 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 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 iter1 = Arrays.asList(1, 2).iterator(); final Iterator iter2 = Arrays.asList(3, 4).iterator(); final IterChain 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> iterators = iterChain.iterator(); - Assert.assertSame(iter1, iterators.next()); - Assert.assertSame(iter2, iterators.next()); + Assertions.assertSame(iter1, iterators.next()); + Assertions.assertSame(iter2, iterators.next()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterUtilTest.java index be901e74d..de9631656 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/IterUtilTest.java @@ -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 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 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 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 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 keys = Arrays.asList(1, 2, 3); Map 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 keys = Arrays.asList(1, 2, 3, 4); Map> 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> 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 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 enumeration = new IteratorEnumeration<>(iter); Iterator 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 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 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)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)null, t -> (t & 1) == 0)); + Assertions.assertNull(IterUtil.getFirst(Collections.emptyIterator(), Objects::nonNull)); } @Test public void testGetFirstNoneNull() { Iterator 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 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 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 list1 = new ArrayList<>(Arrays.asList(1, null, null, 3)); List 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 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 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 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 diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/IteratorEnumerationTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/IteratorEnumerationTest.java index 273579188..6abcfdc71 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/IteratorEnumerationTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/IteratorEnumerationTest.java @@ -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 list = Arrays.asList(1, 2, 3); IteratorEnumeration 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 list = Arrays.asList(1, 2, 3); IteratorEnumeration 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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/LineIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/LineIterTest.java index 27c13d7cd..5cc171f86 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/LineIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/LineIterTest.java @@ -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()); diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/PartitionIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/PartitionIterTest.java index cacc8f8ce..928a379d6 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/PartitionIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/PartitionIterTest.java @@ -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 iter = Arrays.asList(1, 2, 3, 4).iterator(); PartitionIter 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 iter = Arrays.asList(1, 2, 3, 4).iterator(); PartitionIter 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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/iter/TransIterTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/iter/TransIterTest.java index 3651b59be..c00de7e17 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/iter/TransIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/iter/TransIterTest.java @@ -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 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 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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/partition/PartitionTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/partition/PartitionTest.java index 3ecf70dfe..a8d4b3a21 100755 --- a/hutool-core/src/test/java/cn/hutool/core/collection/partition/PartitionTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/partition/PartitionTest.java @@ -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 list = ListUtil.of(1, 2, 3, 4, 5); final Partition partition = new Partition<>(list, 4); - Assert.assertEquals(2, partition.size()); + Assertions.assertEquals(2, partition.size()); } @Test public void getSizeTest() { List mockedList = makingList(19); Partition 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 mockedList = makingList(0); final Partition partition = new Partition<>(mockedList, 10); - Assert.assertEquals(0, partition.size()); + Assertions.assertEquals(0, partition.size()); } private List makingList(final int length) { @@ -59,11 +59,11 @@ public class PartitionTest { final List emptyList = Collections.emptyList(); Partition partition = new Partition<>(emptyList, 10); - Assert.assertTrue(partition.isEmpty()); + Assertions.assertTrue(partition.isEmpty()); final List 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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/comparator/CompareUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/comparator/CompareUtilTest.java index 962a34c42..99b9023ca 100644 --- a/hutool-core/src/test/java/cn/hutool/core/comparator/CompareUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/comparator/CompareUtilTest.java @@ -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)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/comparator/PropertyComparatorTest.java b/hutool-core/src/test/java/cn/hutool/core/comparator/PropertyComparatorTest.java index 4336ad8f0..2de08d9bf 100644 --- a/hutool-core/src/test/java/cn/hutool/core/comparator/PropertyComparatorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/comparator/PropertyComparatorTest.java @@ -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 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 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 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 diff --git a/hutool-core/src/test/java/cn/hutool/core/comparator/VersionComparatorTest.java b/hutool-core/src/test/java/cn/hutool/core/comparator/VersionComparatorTest.java index caaeca694..5a287a75b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/comparator/VersionComparatorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/comparator/VersionComparatorTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/compress/IssueI5DRU0Test.java b/hutool-core/src/test/java/cn/hutool/core/compress/IssueI5DRU0Test.java index 9d3a79340..b75b26893 100644 --- a/hutool-core/src/test/java/cn/hutool/core/compress/IssueI5DRU0Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/compress/IssueI5DRU0Test.java @@ -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中添加文件的时候,如果添加的文件的父目录已经存在,会报错。实际中目录存在忽略即可。 diff --git a/hutool-core/src/test/java/cn/hutool/core/compress/ZipReaderTest.java b/hutool-core/src/test/java/cn/hutool/core/compress/ZipReaderTest.java index 7a97d33e1..f33708a99 100755 --- a/hutool-core/src/test/java/cn/hutool/core/compress/ZipReaderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/compress/ZipReaderTest.java @@ -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); diff --git a/hutool-core/src/test/java/cn/hutool/core/compress/ZipWriterTest.java b/hutool-core/src/test/java/cn/hutool/core/compress/ZipWriterTest.java index c38f5a213..198aff383 100755 --- a/hutool-core/src/test/java/cn/hutool/core/compress/ZipWriterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/compress/ZipWriterTest.java @@ -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")); diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/BasicTypeTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/BasicTypeTest.java index 778174172..9c6d77efd 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/BasicTypeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/BasicTypeTest.java @@ -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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/CastUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/CastUtilTest.java index d67aaebad..415f8c205 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/CastUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/CastUtilTest.java @@ -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 collection2 = CastUtil.castUp(collection); collection2.add(new Double("123.1")); - Assert.assertSame(collection, collection2); + Assertions.assertSame(collection, collection2); Collection collection3 = CastUtil.castDown(collection2); - Assert.assertSame(collection2, collection3); + Assertions.assertSame(collection2, collection3); List list2 = CastUtil.castUp(list); - Assert.assertSame(list, list2); + Assertions.assertSame(list, list2); List list3 = CastUtil.castDown(list2); - Assert.assertSame(list2, list3); + Assertions.assertSame(list2, list3); Set set2 = CastUtil.castUp(set); - Assert.assertSame(set, set2); + Assertions.assertSame(set, set2); Set set3 = CastUtil.castDown(set2); - Assert.assertSame(set2, set3); + Assertions.assertSame(set2, set3); Map map2 = CastUtil.castUp(map); - Assert.assertSame(map, map2); + Assertions.assertSame(map, map2); Map map3 = CastUtil.castDown(map2); - Assert.assertSame(map2, map3); + Assertions.assertSame(map2, map3); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/CompositeConverterTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/CompositeConverterTest.java index 8cf80ae89..b2b73939e 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/CompositeConverterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/CompositeConverterTest.java @@ -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{ diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertOtherTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertOtherTest.java index f13fcb60c..8baee843f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertOtherTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertOtherTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertTest.java index 013da7b41..8f2c13cc1 100755 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertTest.java @@ -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 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 list = Arrays.asList("1", "2"); final String str = Convert.toStr(list); final List 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 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 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 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 result = Convert.convert(new TypeReference>() { }, "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 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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToArrayTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToArrayTest.java index bee7c8a4b..45ba8ac77 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToArrayTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToArrayTest.java @@ -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(); diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBeanTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBeanTest.java index c62c06030..97eb621c0 100755 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBeanTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBeanTest.java @@ -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 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 map2 = Convert.convert( new TypeReference>() {}, 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 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 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 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")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBooleanTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBooleanTest.java index 75aa3c1cf..389e8b468 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBooleanTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToBooleanTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToCollectionTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToCollectionTest.java index b3b1b6622..b135d1471 100755 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToCollectionTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToCollectionTest.java @@ -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 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 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 list = Convert.convert(new TypeReference>() {}, 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 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)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToNumberTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToNumberTest.java index 313ac08cc..90b5765e1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToNumberTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToNumberTest.java @@ -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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToSBCAndDBCTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToSBCAndDBCTest.java index 170157de2..619acce04 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToSBCAndDBCTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/ConvertToSBCAndDBCTest.java @@ -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("123456789", sbc); + Assertions.assertEquals("123456789", sbc); } @Test public void toDBCTest() { final String a = "123456789"; final String dbc = Convert.toDBC(a); - Assert.assertEquals("123456789", dbc); + Assertions.assertEquals("123456789", dbc); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/DateConvertTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/DateConvertTest.java index eaf59f93e..914384144 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/DateConvertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/DateConvertTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/EnumConvertTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/EnumConvertTest.java index 1a37cdc6e..a6b20631b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/EnumConvertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/EnumConvertTest.java @@ -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 { diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/MapConvertTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/MapConvertTest.java index 05665c397..c62501c84 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/MapConvertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/MapConvertTest.java @@ -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 { diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/NumberChineseFormatterTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/NumberChineseFormatterTest.java index 429c7de15..f98c1f384 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/NumberChineseFormatterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/NumberChineseFormatterTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/NumberConverterTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/NumberConverterTest.java index 3ed82e6a9..685a7145d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/NumberConverterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/NumberConverterTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java index 7b39d1a9f..dadbd5f1a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/PrimitiveConvertTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/PrimitiveConvertTest.java index 88c4e5fd7..6d7123081 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/PrimitiveConvertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/PrimitiveConvertTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/StringConvertTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/StringConvertTest.java index 5a990e77b..2aeaefcd4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/StringConvertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/StringConvertTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/TemporalAccessorConverterTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/TemporalAccessorConverterTest.java index 82011a344..07dcc8066 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/TemporalAccessorConverterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/TemporalAccessorConverterTest.java @@ -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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/XMLGregorianCalendarConverterTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/XMLGregorianCalendarConverterTest.java index f3aafb8f9..ed92ab356 100755 --- a/hutool-core/src/test/java/cn/hutool/core/convert/XMLGregorianCalendarConverterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/XMLGregorianCalendarConverterTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/BetweenFormatterTest.java b/hutool-core/src/test/java/cn/hutool/core/date/BetweenFormatterTest.java index a6503904c..89526d6aa 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/BetweenFormatterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/BetweenFormatterTest.java @@ -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秒"); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/CalendarUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/CalendarUtilTest.java index a1452c149..fd11e3b8f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/CalendarUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/CalendarUtilTest.java @@ -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); + }); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java b/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java index a87a00021..adb9f2ee3 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/ChineseDateTest.java @@ -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@Gitee,2023-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()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/DateBetweenTest.java b/hutool-core/src/test/java/cn/hutool/core/date/DateBetweenTest.java index cd18bd251..6224c5a18 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/DateBetweenTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/DateBetweenTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/DateFieldTest.java b/hutool-core/src/test/java/cn/hutool/core/date/DateFieldTest.java index 88310c2ef..9b4aaf8c6 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/DateFieldTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/DateFieldTest.java @@ -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); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/DateModifierTest.java b/hutool-core/src/test/java/cn/hutool/core/date/DateModifierTest.java index 56f4a1d16..1b5f0105b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/DateModifierTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/DateModifierTest.java @@ -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)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/DateTimeTest.java b/hutool-core/src/test/java/cn/hutool/core/date/DateTimeTest.java index 4a9122342..dfb390911 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/DateTimeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/DateTimeTest.java @@ -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()); } /** * 严格模式下,不允许非常规的数字,如秒部分最多59,99则报错 */ - @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); + }); + } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java index 167c59c8e..b0566609a 100755 --- a/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/DateUtilTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.date.BetweenFormatter.Level; import cn.hutool.core.date.format.FastDateFormat; import cn.hutool.core.lang.Console; 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; import java.text.SimpleDateFormat; import java.time.Instant; @@ -31,26 +31,26 @@ public class DateUtilTest { public void nowTest() { // 当前时间 final Date date = DateUtil.now(); - Assert.assertNotNull(date); + Assertions.assertNotNull(date); // 当前时间 final Date date2 = DateUtil.date(Calendar.getInstance()); - Assert.assertNotNull(date2); + Assertions.assertNotNull(date2); // 当前时间 final Date date3 = DateUtil.date(System.currentTimeMillis()); - Assert.assertNotNull(date3); + Assertions.assertNotNull(date3); // 当前日期字符串,格式:yyyy-MM-dd HH:mm:ss final String now = DateUtil.formatNow(); - Assert.assertNotNull(now); + Assertions.assertNotNull(now); // 当前日期字符串,格式:yyyy-MM-dd final String today = DateUtil.formatToday(); - Assert.assertNotNull(today); + Assertions.assertNotNull(today); } @Test public void todayTest() { final String s = DateUtil.today().toString(); - Assert.assertTrue(s.endsWith("00:00:00")); + Assertions.assertTrue(s.endsWith("00:00:00")); } @Test @@ -59,15 +59,15 @@ public class DateUtilTest { final Date date = DateUtil.parse(dateStr); final String format = DateUtil.format(date, "yyyy/MM/dd"); - Assert.assertEquals("2017/03/01", format); + Assertions.assertEquals("2017/03/01", format); // 常用格式的格式化 final String formatDate = DateUtil.formatDate(date); - Assert.assertEquals("2017-03-01", formatDate); + Assertions.assertEquals("2017-03-01", formatDate); final String formatDateTime = DateUtil.formatDateTime(date); - Assert.assertEquals("2017-03-01 00:00:00", formatDateTime); + Assertions.assertEquals("2017-03-01 00:00:00", formatDateTime); final String formatTime = DateUtil.formatTime(date); - Assert.assertEquals("00:00:00", formatTime); + Assertions.assertEquals("00:00:00", formatTime); } @Test @@ -76,10 +76,10 @@ public class DateUtilTest { final Date date = DateUtil.parse(dateStr); final String format = DateUtil.format(date, "#sss"); - Assert.assertEquals("1488297600", format); + Assertions.assertEquals("1488297600", format); final DateTime parse = DateUtil.parse(format, "#sss"); - Assert.assertEquals(date, parse); + Assertions.assertEquals(date, parse); } @Test @@ -88,10 +88,10 @@ public class DateUtilTest { final Date date = DateUtil.parse(dateStr); final String format = DateUtil.format(date, "#SSS"); - Assert.assertEquals("1488297600000", format); + Assertions.assertEquals("1488297600000", format); final DateTime parse = DateUtil.parse(format, "#SSS"); - Assert.assertEquals(date, parse); + Assertions.assertEquals(date, parse); } @Test @@ -101,16 +101,16 @@ public class DateUtilTest { // 一天的开始 final Date beginOfDay = DateUtil.beginOfDay(date); - Assert.assertEquals("2017-03-01 00:00:00", beginOfDay.toString()); + Assertions.assertEquals("2017-03-01 00:00:00", beginOfDay.toString()); // 一天的结束 final Date endOfDay = DateUtil.endOfDay(date); - Assert.assertEquals("2017-03-01 23:59:59", endOfDay.toString()); + Assertions.assertEquals("2017-03-01 23:59:59", endOfDay.toString()); } @Test public void endOfDayTest() { final DateTime parse = DateUtil.parse("2020-05-31 00:00:00"); - Assert.assertEquals("2020-05-31 23:59:59", DateUtil.endOfDay(parse).toString()); + Assertions.assertEquals("2020-05-31 23:59:59", DateUtil.endOfDay(parse).toString()); } @Test @@ -118,7 +118,7 @@ public class DateUtilTest { final String dateStr2 = "2020-02-29 12:59:34"; final Date date2 = DateUtil.parse(dateStr2); final DateTime dateTime = DateUtil.truncate(date2, DateField.MINUTE); - Assert.assertEquals("2020-02-29 12:59:00", dateTime.toString()); + Assertions.assertEquals("2020-02-29 12:59:00", dateTime.toString()); } @Test @@ -128,10 +128,10 @@ public class DateUtilTest { DateTime dateTime = DateUtil.ceiling(date2, DateField.MINUTE); - Assert.assertEquals("2020-02-29 12:59:59.999", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertEquals("2020-02-29 12:59:59.999", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); dateTime = DateUtil.ceiling(date2, DateField.MINUTE, true); - Assert.assertEquals("2020-02-29 12:59:59.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertEquals("2020-02-29 12:59:59.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); } @Test @@ -141,10 +141,10 @@ public class DateUtilTest { DateTime dateTime = DateUtil.ceiling(date2, DateField.DAY_OF_MONTH); - Assert.assertEquals("2020-02-29 23:59:59.999", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertEquals("2020-02-29 23:59:59.999", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); dateTime = DateUtil.ceiling(date2, DateField.DAY_OF_MONTH, true); - Assert.assertEquals("2020-02-29 23:59:59.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertEquals("2020-02-29 23:59:59.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); } @Test @@ -155,18 +155,18 @@ public class DateUtilTest { // 一周的开始 final Date beginOfWeek = DateUtil.beginOfWeek(date); - Assert.assertEquals("2017-02-27 00:00:00", beginOfWeek.toString()); + Assertions.assertEquals("2017-02-27 00:00:00", beginOfWeek.toString()); // 一周的结束 final Date endOfWeek = DateUtil.endOfWeek(date); - Assert.assertEquals("2017-03-05 23:59:59", endOfWeek.toString()); + Assertions.assertEquals("2017-03-05 23:59:59", endOfWeek.toString()); final Calendar calendar = DateUtil.calendar(date); // 一周的开始 final Calendar begin = DateUtil.beginOfWeek(calendar); - Assert.assertEquals("2017-02-27 00:00:00", DateUtil.date(begin).toString()); + Assertions.assertEquals("2017-02-27 00:00:00", DateUtil.date(begin).toString()); // 一周的结束 final Calendar end = DateUtil.endOfWeek(calendar); - Assert.assertEquals("2017-03-05 23:59:59", DateUtil.date(end).toString()); + Assertions.assertEquals("2017-03-05 23:59:59", DateUtil.date(end).toString()); } @Test @@ -175,11 +175,11 @@ public class DateUtilTest { final DateTime date = DateUtil.parse(beginStr); final Calendar calendar = Objects.requireNonNull(date).toCalendar(); final Calendar begin = DateUtil.beginOfWeek(calendar, false); - Assert.assertEquals("2020-03-08 00:00:00", DateUtil.date(begin).toString()); + Assertions.assertEquals("2020-03-08 00:00:00", DateUtil.date(begin).toString()); final Calendar calendar2 = date.toCalendar(); final Calendar end = DateUtil.endOfWeek(calendar2, false); - Assert.assertEquals("2020-03-14 23:59:59", DateUtil.date(end).toString()); + Assertions.assertEquals("2020-03-14 23:59:59", DateUtil.date(end).toString()); } @Test @@ -188,19 +188,19 @@ public class DateUtilTest { final Date date = DateUtil.parse(dateStr); final Date newDate = DateUtil.offset(date, DateField.DAY_OF_MONTH, 2); - Assert.assertEquals("2017-03-03 22:33:23", newDate.toString()); + Assertions.assertEquals("2017-03-03 22:33:23", newDate.toString()); // 偏移天 final DateTime newDate2 = DateUtil.offsetDay(date, 3); - Assert.assertEquals("2017-03-04 22:33:23", newDate2.toString()); + Assertions.assertEquals("2017-03-04 22:33:23", newDate2.toString()); // 偏移小时 final DateTime newDate3 = DateUtil.offsetHour(date, -3); - Assert.assertEquals("2017-03-01 19:33:23", newDate3.toString()); + Assertions.assertEquals("2017-03-01 19:33:23", newDate3.toString()); // 偏移月 final DateTime offsetMonth = DateUtil.offsetMonth(date, -1); - Assert.assertEquals("2017-02-01 22:33:23", offsetMonth.toString()); + Assertions.assertEquals("2017-02-01 22:33:23", offsetMonth.toString()); } @Test @@ -210,10 +210,10 @@ public class DateUtilTest { for (int i = 0; i < 4; i++) { list.add(DateUtil.offsetMonth(st, i)); } - Assert.assertEquals("2018-05-31 00:00:00", list.get(0).toString()); - Assert.assertEquals("2018-06-30 00:00:00", list.get(1).toString()); - Assert.assertEquals("2018-07-31 00:00:00", list.get(2).toString()); - Assert.assertEquals("2018-08-31 00:00:00", list.get(3).toString()); + Assertions.assertEquals("2018-05-31 00:00:00", list.get(0).toString()); + Assertions.assertEquals("2018-06-30 00:00:00", list.get(1).toString()); + Assertions.assertEquals("2018-07-31 00:00:00", list.get(2).toString()); + Assertions.assertEquals("2018-08-31 00:00:00", list.get(3).toString()); } @Test @@ -226,75 +226,75 @@ public class DateUtilTest { // 相差月 long betweenMonth = DateUtil.betweenMonth(date1, date2, false); - Assert.assertEquals(1, betweenMonth);// 相差一个月 + Assertions.assertEquals(1, betweenMonth);// 相差一个月 // 反向 betweenMonth = DateUtil.betweenMonth(date2, date1, false); - Assert.assertEquals(1, betweenMonth);// 相差一个月 + Assertions.assertEquals(1, betweenMonth);// 相差一个月 // 相差天 long betweenDay = DateUtil.between(date1, date2, DateUnit.DAY); - Assert.assertEquals(31, betweenDay);// 相差一个月,31天 + Assertions.assertEquals(31, betweenDay);// 相差一个月,31天 // 反向 betweenDay = DateUtil.between(date2, date1, DateUnit.DAY); - Assert.assertEquals(31, betweenDay);// 相差一个月,31天 + Assertions.assertEquals(31, betweenDay);// 相差一个月,31天 // 相差小时 long betweenHour = DateUtil.between(date1, date2, DateUnit.HOUR); - Assert.assertEquals(745, betweenHour); + Assertions.assertEquals(745, betweenHour); // 反向 betweenHour = DateUtil.between(date2, date1, DateUnit.HOUR); - Assert.assertEquals(745, betweenHour); + Assertions.assertEquals(745, betweenHour); // 相差分 long betweenMinute = DateUtil.between(date1, date2, DateUnit.MINUTE); - Assert.assertEquals(44721, betweenMinute); + Assertions.assertEquals(44721, betweenMinute); // 反向 betweenMinute = DateUtil.between(date2, date1, DateUnit.MINUTE); - Assert.assertEquals(44721, betweenMinute); + Assertions.assertEquals(44721, betweenMinute); // 相差秒 long betweenSecond = DateUtil.between(date1, date2, DateUnit.SECOND); - Assert.assertEquals(2683311, betweenSecond); + Assertions.assertEquals(2683311, betweenSecond); // 反向 betweenSecond = DateUtil.between(date2, date1, DateUnit.SECOND); - Assert.assertEquals(2683311, betweenSecond); + Assertions.assertEquals(2683311, betweenSecond); // 相差秒 long betweenMS = DateUtil.between(date1, date2, DateUnit.MS); - Assert.assertEquals(2683311000L, betweenMS); + Assertions.assertEquals(2683311000L, betweenMS); // 反向 betweenMS = DateUtil.between(date2, date1, DateUnit.MS); - Assert.assertEquals(2683311000L, betweenMS); + Assertions.assertEquals(2683311000L, betweenMS); } @Test public void betweenTest2() { final long between = DateUtil.between(DateUtil.parse("2019-05-06 02:15:00"), DateUtil.parse("2019-05-06 02:20:00"), DateUnit.HOUR); - Assert.assertEquals(0, between); + Assertions.assertEquals(0, between); } @Test public void betweenTest3() { final long between = DateUtil.between(DateUtil.parse("2020-03-31 23:59:59"), DateUtil.parse("2020-04-01 00:00:00"), DateUnit.SECOND); - Assert.assertEquals(1, between); + Assertions.assertEquals(1, between); } @Test public void formatChineseDateTest() { String formatChineseDate = DateUtil.formatChineseDate(DateUtil.parse("2018-02-24"), true, false); - Assert.assertEquals("二〇一八年二月二十四日", formatChineseDate); + Assertions.assertEquals("二〇一八年二月二十四日", formatChineseDate); formatChineseDate = DateUtil.formatChineseDate(DateUtil.parse("2018-02-14"), true, false); - Assert.assertEquals("二〇一八年二月十四日", formatChineseDate); + Assertions.assertEquals("二〇一八年二月十四日", formatChineseDate); } @Test public void formatChineseDateTimeTest() { String formatChineseDateTime = DateUtil.formatChineseDate(DateUtil.parse("2018-02-24 12:13:14"), true, true); - Assert.assertEquals("二〇一八年二月二十四日十二时十三分十四秒", formatChineseDateTime); + Assertions.assertEquals("二〇一八年二月二十四日十二时十三分十四秒", formatChineseDateTime); formatChineseDateTime = DateUtil.formatChineseDate(DateUtil.parse("2022-01-18 12:00:00"), true, true); - Assert.assertEquals("二〇二二年一月十八日十二时零分零秒", formatChineseDateTime); + Assertions.assertEquals("二〇二二年一月十八日十二时零分零秒", formatChineseDateTime); } @Test @@ -307,53 +307,53 @@ public class DateUtilTest { final long between = DateUtil.between(date1, date2, DateUnit.MS); final String formatBetween = DateUtil.formatBetween(between, Level.MINUTE); - Assert.assertEquals("31天1小时21分", formatBetween); + Assertions.assertEquals("31天1小时21分", formatBetween); } @Test public void currentTest() { final long current = DateUtil.current(); final String currentStr = String.valueOf(current); - Assert.assertEquals(13, currentStr.length()); + Assertions.assertEquals(13, currentStr.length()); final long currentNano = DateUtil.current(); final String currentNanoStr = String.valueOf(currentNano); - Assert.assertNotNull(currentNanoStr); + Assertions.assertNotNull(currentNanoStr); } @Test public void weekOfYearTest() { // 第一周周日 final int weekOfYear1 = DateUtil.weekOfYear(DateUtil.parse("2016-01-03")); - Assert.assertEquals(1, weekOfYear1); + Assertions.assertEquals(1, weekOfYear1); // 第二周周四 final int weekOfYear2 = DateUtil.weekOfYear(DateUtil.parse("2016-01-07")); - Assert.assertEquals(2, weekOfYear2); + Assertions.assertEquals(2, weekOfYear2); } @Test public void timeToSecondTest() { int second = DateUtil.timeToSecond("00:01:40"); - Assert.assertEquals(100, second); + Assertions.assertEquals(100, second); second = DateUtil.timeToSecond("00:00:40"); - Assert.assertEquals(40, second); + Assertions.assertEquals(40, second); second = DateUtil.timeToSecond("01:00:00"); - Assert.assertEquals(3600, second); + Assertions.assertEquals(3600, second); second = DateUtil.timeToSecond("00:00:00"); - Assert.assertEquals(0, second); + Assertions.assertEquals(0, second); } @Test public void secondToTimeTest() { String time = DateUtil.secondToTime(3600); - Assert.assertEquals("01:00:00", time); + Assertions.assertEquals("01:00:00", time); time = DateUtil.secondToTime(3800); - Assert.assertEquals("01:03:20", time); + Assertions.assertEquals("01:03:20", time); time = DateUtil.secondToTime(0); - Assert.assertEquals("00:00:00", time); + Assertions.assertEquals("00:00:00", time); time = DateUtil.secondToTime(30); - Assert.assertEquals("00:00:30", time); + Assertions.assertEquals("00:00:30", time); } @Test @@ -362,7 +362,7 @@ public class DateUtilTest { final String s2 = "55:00:50"; final int i = DateUtil.timeToSecond(s1) + DateUtil.timeToSecond(s2); final String s = DateUtil.secondToTime(i); - Assert.assertEquals("110:03:08", s); + Assertions.assertEquals("110:03:08", s); } @Test @@ -372,7 +372,7 @@ public class DateUtilTest { final Date birthDate = DateUtil.parse(birthday, "yyMMdd"); // 获取出生年(完全表现形式,如:2010) final int sYear = DateUtil.year(birthDate); - Assert.assertEquals(1970, sYear); + Assertions.assertEquals(1970, sYear); } @Test @@ -380,13 +380,13 @@ public class DateUtilTest { final String dateStr = "2018-10-10 12:11:11"; final Date date = DateUtil.parse(dateStr); final String format = DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN); - Assert.assertEquals(dateStr, format); + Assertions.assertEquals(dateStr, format); } @Test public void parseTest4() { final String ymd = DateUtil.parse("2019-3-21 12:20:15", "yyyy-MM-dd").toString(DatePattern.PURE_DATE_PATTERN); - Assert.assertEquals("20190321", ymd); + Assertions.assertEquals("20190321", ymd); } @Test @@ -394,33 +394,33 @@ public class DateUtilTest { // 测试时间解析 //noinspection ConstantConditions String time = DateUtil.parse("22:12:12").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("22:12:12", time); + Assertions.assertEquals("22:12:12", time); //noinspection ConstantConditions time = DateUtil.parse("2:12:12").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("02:12:12", time); + Assertions.assertEquals("02:12:12", time); //noinspection ConstantConditions time = DateUtil.parse("2:2:12").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("02:02:12", time); + Assertions.assertEquals("02:02:12", time); //noinspection ConstantConditions time = DateUtil.parse("2:2:1").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("02:02:01", time); + Assertions.assertEquals("02:02:01", time); //noinspection ConstantConditions time = DateUtil.parse("22:2:1").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("22:02:01", time); + Assertions.assertEquals("22:02:01", time); //noinspection ConstantConditions time = DateUtil.parse("2:22:1").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("02:22:01", time); + Assertions.assertEquals("02:22:01", time); // 测试两位时间解析 //noinspection ConstantConditions time = DateUtil.parse("2:22").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("02:22:00", time); + Assertions.assertEquals("02:22:00", time); //noinspection ConstantConditions time = DateUtil.parse("12:22").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("12:22:00", time); + Assertions.assertEquals("12:22:00", time); //noinspection ConstantConditions time = DateUtil.parse("12:2").toString(DatePattern.NORM_TIME_FORMAT); - Assert.assertEquals("12:02:00", time); + Assertions.assertEquals("12:02:00", time); } @@ -429,7 +429,7 @@ public class DateUtilTest { final String str = "Tue Jun 4 16:25:15 +0800 2019"; final DateTime dateTime = DateUtil.parse(str); assert dateTime != null; - Assert.assertEquals("2019-06-04 16:25:15", dateTime.toString()); + Assertions.assertEquals("2019-06-04 16:25:15", dateTime.toString()); } @Test @@ -437,12 +437,12 @@ public class DateUtilTest { String str = "2019-06-01T19:45:43.000 +0800"; DateTime dateTime = DateUtil.parse(str); assert dateTime != null; - Assert.assertEquals("2019-06-01 19:45:43", dateTime.toString()); + Assertions.assertEquals("2019-06-01 19:45:43", dateTime.toString()); str = "2019-06-01T19:45:43 +08:00"; dateTime = DateUtil.parse(str); assert dateTime != null; - Assert.assertEquals("2019-06-01 19:45:43", dateTime.toString()); + Assertions.assertEquals("2019-06-01 19:45:43", dateTime.toString()); } @Test @@ -450,7 +450,7 @@ public class DateUtilTest { final String str = "2020-06-28T02:14:13.000Z"; final DateTime dateTime = DateUtil.parse(str); assert dateTime != null; - Assert.assertEquals("2020-06-28 02:14:13", dateTime.toString()); + Assertions.assertEquals("2020-06-28 02:14:13", dateTime.toString()); } /** @@ -460,23 +460,23 @@ public class DateUtilTest { public void parseNormFullTest() { String str = "2020-02-06 01:58:00.000020"; DateTime dateTime = DateUtil.parse(str); - Assert.assertNotNull(dateTime); - Assert.assertEquals("2020-02-06 01:58:00.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertNotNull(dateTime); + Assertions.assertEquals("2020-02-06 01:58:00.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); str = "2020-02-06 01:58:00.00002"; dateTime = DateUtil.parse(str); - Assert.assertNotNull(dateTime); - Assert.assertEquals("2020-02-06 01:58:00.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertNotNull(dateTime); + Assertions.assertEquals("2020-02-06 01:58:00.000", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); str = "2020-02-06 01:58:00.111000"; dateTime = DateUtil.parse(str); - Assert.assertNotNull(dateTime); - Assert.assertEquals("2020-02-06 01:58:00.111", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertNotNull(dateTime); + Assertions.assertEquals("2020-02-06 01:58:00.111", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); str = "2020-02-06 01:58:00.111"; dateTime = DateUtil.parse(str); - Assert.assertNotNull(dateTime); - Assert.assertEquals("2020-02-06 01:58:00.111", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); + Assertions.assertNotNull(dateTime); + Assertions.assertEquals("2020-02-06 01:58:00.111", dateTime.toString(DatePattern.NORM_DATETIME_MS_PATTERN)); } /** @@ -486,7 +486,7 @@ public class DateUtilTest { public void parseEmptyTest() { final String str = " "; final DateTime dateTime = DateUtil.parse(str); - Assert.assertNull(dateTime); + Assertions.assertNull(dateTime); } @Test @@ -495,12 +495,12 @@ public class DateUtilTest { String str = "2019-06-01T19:45:43+08:00"; DateTime dateTime = DateUtil.parse(str); assert dateTime != null; - Assert.assertEquals("2019-06-01 19:45:43", dateTime.toString()); + Assertions.assertEquals("2019-06-01 19:45:43", dateTime.toString()); str = "2019-06-01T19:45:43 +08:00"; dateTime = DateUtil.parse(str); assert dateTime != null; - Assert.assertEquals("2019-06-01 19:45:43", dateTime.toString()); + Assertions.assertEquals("2019-06-01 19:45:43", dateTime.toString()); } @Test @@ -509,10 +509,10 @@ public class DateUtilTest { final String str = "2019-09-17T13:26:17.948Z"; final DateTime dateTime = DateUtil.parse(str); assert dateTime != null; - Assert.assertEquals("2019-09-17 13:26:17", dateTime.toString()); + Assertions.assertEquals("2019-09-17 13:26:17", dateTime.toString()); final DateTime offset = DateUtil.offsetHour(dateTime, 8); - Assert.assertEquals("2019-09-17 21:26:17", offset.toString()); + Assertions.assertEquals("2019-09-17 21:26:17", offset.toString()); } @Test @@ -520,7 +520,7 @@ public class DateUtilTest { final String dateStr = "2018-4-10"; final Date date = DateUtil.parse(dateStr); final String format = DateUtil.format(date, DatePattern.NORM_DATE_PATTERN); - Assert.assertEquals("2018-04-10", format); + Assertions.assertEquals("2018-04-10", format); } @Test @@ -534,9 +534,9 @@ public class DateUtilTest { final DateTime dt2 = DateUtil.parse(dateStr2); final DateTime dt3 = DateUtil.parse(dateStr3); final DateTime dt4 = DateUtil.parse(dateStr4); - Assert.assertEquals(dt1, dt2); - Assert.assertEquals(dt2, dt3); - Assert.assertEquals(dt3, dt4); + Assertions.assertEquals(dt1, dt2); + Assertions.assertEquals(dt2, dt3); + Assertions.assertEquals(dt3, dt4); } @Test @@ -550,9 +550,9 @@ public class DateUtilTest { final DateTime dt2 = DateUtil.parse(dateStr2); final DateTime dt3 = DateUtil.parse(dateStr3); final DateTime dt4 = DateUtil.parse(dateStr4); - Assert.assertEquals(dt1, dt2); - Assert.assertEquals(dt2, dt3); - Assert.assertEquals(dt3, dt4); + Assertions.assertEquals(dt1, dt2); + Assertions.assertEquals(dt2, dt3); + Assertions.assertEquals(dt3, dt4); } @Test @@ -566,9 +566,9 @@ public class DateUtilTest { final DateTime dt2 = DateUtil.parse(dateStr2); final DateTime dt3 = DateUtil.parse(dateStr3); final DateTime dt4 = DateUtil.parse(dateStr4); - Assert.assertEquals(dt1, dt2); - Assert.assertEquals(dt2, dt3); - Assert.assertEquals(dt3, dt4); + Assertions.assertEquals(dt1, dt2); + Assertions.assertEquals(dt2, dt3); + Assertions.assertEquals(dt3, dt4); } @Test @@ -578,7 +578,7 @@ public class DateUtilTest { final DateTime dt1 = DateUtil.parse(dateStr1); final DateTime dt2 = DateUtil.parse(dateStr2); - Assert.assertEquals(dt1, dt2); + Assertions.assertEquals(dt1, dt2); } @Test @@ -588,7 +588,7 @@ public class DateUtilTest { final DateTime dt1 = DateUtil.parse(dateStr1); final DateTime dt2 = DateUtil.parse(dateStr2); - Assert.assertEquals(dt1, dt2); + Assertions.assertEquals(dt1, dt2); } @Test @@ -598,68 +598,68 @@ public class DateUtilTest { // parse方法支持UTC格式测试 final DateTime dt2 = DateUtil.parse(dateStr1); - Assert.assertEquals(dt, dt2); + Assertions.assertEquals(dt, dt2); // 默认使用Pattern对应的时区,即UTC时区 String dateStr = Objects.requireNonNull(dt).toString(); - Assert.assertEquals("2018-09-13 05:34:31", dateStr); + Assertions.assertEquals("2018-09-13 05:34:31", dateStr); // 使用当前(上海)时区 dateStr = dt.toString(TimeZone.getTimeZone("GMT+8:00")); - Assert.assertEquals("2018-09-13 13:34:31", dateStr); + Assertions.assertEquals("2018-09-13 13:34:31", dateStr); dateStr1 = "2018-09-13T13:34:32+0800"; dt = DateUtil.parse(dateStr1); dateStr = Objects.requireNonNull(dt).toString(TimeZone.getTimeZone("GMT+8:00")); - Assert.assertEquals("2018-09-13 13:34:32", dateStr); + Assertions.assertEquals("2018-09-13 13:34:32", dateStr); dateStr1 = "2018-09-13T13:34:33+08:00"; dt = DateUtil.parse(dateStr1); dateStr = Objects.requireNonNull(dt).toString(TimeZone.getTimeZone("GMT+8:00")); - Assert.assertEquals("2018-09-13 13:34:33", dateStr); + Assertions.assertEquals("2018-09-13 13:34:33", dateStr); dateStr1 = "2018-09-13T13:34:34+0800"; dt = DateUtil.parse(dateStr1); assert dt != null; dateStr = dt.toString(TimeZone.getTimeZone("GMT+8:00")); - Assert.assertEquals("2018-09-13 13:34:34", dateStr); + Assertions.assertEquals("2018-09-13 13:34:34", dateStr); dateStr1 = "2018-09-13T13:34:35+08:00"; dt = DateUtil.parse(dateStr1); assert dt != null; dateStr = dt.toString(TimeZone.getTimeZone("GMT+8:00")); - Assert.assertEquals("2018-09-13 13:34:35", dateStr); + Assertions.assertEquals("2018-09-13 13:34:35", dateStr); dateStr1 = "2018-09-13T13:34:36.999+0800"; dt = DateUtil.parse(dateStr1); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DatePattern.NORM_DATETIME_MS_PATTERN); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); dateStr = Objects.requireNonNull(dt).toString(simpleDateFormat); - Assert.assertEquals("2018-09-13 13:34:36.999", dateStr); + Assertions.assertEquals("2018-09-13 13:34:36.999", dateStr); dateStr1 = "2018-09-13T13:34:37.999+08:00"; dt = DateUtil.parse(dateStr1); dateStr = Objects.requireNonNull(dt).toString(simpleDateFormat); - Assert.assertEquals("2018-09-13 13:34:37.999", dateStr); + Assertions.assertEquals("2018-09-13 13:34:37.999", dateStr); dateStr1 = "2018-09-13T13:34:38.999+0800"; dt = DateUtil.parse(dateStr1); assert dt != null; dateStr = dt.toString(simpleDateFormat); - Assert.assertEquals("2018-09-13 13:34:38.999", dateStr); + Assertions.assertEquals("2018-09-13 13:34:38.999", dateStr); dateStr1 = "2018-09-13T13:34:39.999+08:00"; dt = DateUtil.parse(dateStr1); assert dt != null; dateStr = dt.toString(simpleDateFormat); - Assert.assertEquals("2018-09-13 13:34:39.999", dateStr); + Assertions.assertEquals("2018-09-13 13:34:39.999", dateStr); // 使用UTC时区 dateStr1 = "2018-09-13T13:34:39.99"; dt = DateUtil.parse(dateStr1); assert dt != null; dateStr = dt.toString(); - Assert.assertEquals("2018-09-13 13:34:39", dateStr); + Assertions.assertEquals("2018-09-13 13:34:39", dateStr); } @Test @@ -668,15 +668,15 @@ public class DateUtilTest { // 检查不同毫秒长度都可以正常匹配 String utcTime = "2021-03-30T12:56:51.3Z"; DateTime parse = DateUtil.parse(utcTime); - Assert.assertEquals("2021-03-30 12:56:51", Objects.requireNonNull(parse).toString()); + Assertions.assertEquals("2021-03-30 12:56:51", Objects.requireNonNull(parse).toString()); utcTime = "2021-03-30T12:56:51.34Z"; parse = DateUtil.parse(utcTime); - Assert.assertEquals("2021-03-30 12:56:51", Objects.requireNonNull(parse).toString()); + Assertions.assertEquals("2021-03-30 12:56:51", Objects.requireNonNull(parse).toString()); utcTime = "2021-03-30T12:56:51.345Z"; parse = DateUtil.parse(utcTime); - Assert.assertEquals("2021-03-30 12:56:51", Objects.requireNonNull(parse).toString()); + Assertions.assertEquals("2021-03-30 12:56:51", Objects.requireNonNull(parse).toString()); } @Test @@ -684,8 +684,8 @@ public class DateUtilTest { // issue#I5M6DP final String dateStr = "2022-08-13T09:30"; final DateTime dateTime = DateUtil.parse(dateStr); - Assert.assertNotNull(dateTime); - Assert.assertEquals("2022-08-13 09:30:00", dateTime.toString()); + Assertions.assertNotNull(dateTime); + Assertions.assertEquals("2022-08-13 09:30:00", dateTime.toString()); } @Test @@ -698,10 +698,10 @@ public class DateUtilTest { final DateTime parse = DateUtil.parse(dateStr, sdf); DateTime dateTime = DateUtil.parse(dateStr); - Assert.assertEquals(parse, dateTime); + Assertions.assertEquals(parse, dateTime); dateTime = DateUtil.parse(dateStr); - Assert.assertEquals(parse, dateTime); + Assertions.assertEquals(parse, dateTime); } @Test @@ -715,21 +715,21 @@ public class DateUtilTest { final FastDateFormat fdf = FastDateFormat.getInstance(DatePattern.JDK_DATETIME_PATTERN, TimeZone.getTimeZone("America/Chicago"), Locale.US); final DateTime parse2 = DateUtil.parse(dateStr, fdf); - Assert.assertEquals(parse, parse2); + Assertions.assertEquals(parse, parse2); } @Test public void parseJDkTest() { final String dateStr = "Thu May 16 17:57:18 GMT+08:00 2019"; final DateTime time = DateUtil.parse(dateStr); - Assert.assertEquals("2019-05-16 17:57:18", Objects.requireNonNull(time).toString()); + Assertions.assertEquals("2019-05-16 17:57:18", Objects.requireNonNull(time).toString()); } @Test public void parseISOTest() { final String dateStr = "2020-04-23T02:31:00.000Z"; final DateTime time = DateUtil.parse(dateStr); - Assert.assertEquals("2020-04-23 02:31:00", Objects.requireNonNull(time).toString()); + Assertions.assertEquals("2020-04-23 02:31:00", Objects.requireNonNull(time).toString()); } @Test @@ -737,7 +737,7 @@ public class DateUtilTest { final DateTime date = DateUtil.now(); date.setField(DateField.YEAR, 2019); final DateTime endOfYear = DateUtil.endOfYear(date); - Assert.assertEquals("2019-12-31 23:59:59", endOfYear.toString()); + Assertions.assertEquals("2019-12-31 23:59:59", endOfYear.toString()); } @Test @@ -745,7 +745,7 @@ public class DateUtilTest { final Date date = DateUtil.endOfQuarter( DateUtil.parse("2020-05-31 00:00:00")); - Assert.assertEquals("2020-06-30 23:59:59", DateUtil.format(date, "yyyy-MM-dd HH:mm:ss")); + Assertions.assertEquals("2020-06-30 23:59:59", DateUtil.format(date, "yyyy-MM-dd HH:mm:ss")); } @Test @@ -754,21 +754,21 @@ public class DateUtilTest { final DateTime now = DateUtil.parse("2019-09-15 13:00"); final DateTime startOfWeek = DateUtil.beginOfWeek(now); - Assert.assertEquals("2019-09-09 00:00:00", startOfWeek.toString()); + Assertions.assertEquals("2019-09-09 00:00:00", startOfWeek.toString()); final DateTime endOfWeek = DateUtil.endOfWeek(now); - Assert.assertEquals("2019-09-15 23:59:59", endOfWeek.toString()); + Assertions.assertEquals("2019-09-15 23:59:59", endOfWeek.toString()); final long between = DateUtil.between(endOfWeek, startOfWeek, DateUnit.DAY); // 周一和周日相距6天 - Assert.assertEquals(6, between); + Assertions.assertEquals(6, between); } @Test public void dayOfWeekTest() { final int dayOfWeek = DateUtil.dayOfWeek(DateUtil.parse("2018-03-07")); - Assert.assertEquals(Calendar.WEDNESDAY, dayOfWeek); + Assertions.assertEquals(Calendar.WEDNESDAY, dayOfWeek); final Week week = DateUtil.dayOfWeekEnum(DateUtil.parse("2018-03-07")); - Assert.assertEquals(Week.WEDNESDAY, week); + Assertions.assertEquals(Week.WEDNESDAY, week); } @Test @@ -776,36 +776,36 @@ public class DateUtilTest { final Date date1 = DateUtil.parse("2021-04-13 23:59:59.999"); final Date date2 = DateUtil.parse("2021-04-13 23:59:10"); - Assert.assertEquals(1, DateUtil.compare(date1, date2)); - Assert.assertEquals(1, DateUtil.compare(date1, date2, DatePattern.NORM_DATETIME_PATTERN)); - Assert.assertEquals(0, DateUtil.compare(date1, date2, DatePattern.NORM_DATE_PATTERN)); - Assert.assertEquals(0, DateUtil.compare(date1, date2, DatePattern.NORM_DATETIME_MINUTE_PATTERN)); + Assertions.assertEquals(1, DateUtil.compare(date1, date2)); + Assertions.assertEquals(1, DateUtil.compare(date1, date2, DatePattern.NORM_DATETIME_PATTERN)); + Assertions.assertEquals(0, DateUtil.compare(date1, date2, DatePattern.NORM_DATE_PATTERN)); + Assertions.assertEquals(0, DateUtil.compare(date1, date2, DatePattern.NORM_DATETIME_MINUTE_PATTERN)); final Date date11 = DateUtil.parse("2021-04-13 23:59:59.999"); final Date date22 = DateUtil.parse("2021-04-11 23:10:10"); - Assert.assertEquals(0, DateUtil.compare(date11, date22, DatePattern.NORM_MONTH_PATTERN)); + Assertions.assertEquals(0, DateUtil.compare(date11, date22, DatePattern.NORM_MONTH_PATTERN)); } @Test public void formatHttpDateTest() { final String formatHttpDate = DateUtil.formatHttpDate(DateUtil.parse("2019-01-02 22:32:01")); - Assert.assertEquals("Wed, 02 Jan 2019 14:32:01 GMT", formatHttpDate); + Assertions.assertEquals("Wed, 02 Jan 2019 14:32:01 GMT", formatHttpDate); } @Test public void toInstantTest() { final LocalDateTime localDateTime = LocalDateTime.parse("2017-05-06T08:30:00", DateTimeFormatter.ISO_DATE_TIME); Instant instant = DateUtil.toInstant(localDateTime); - Assert.assertEquals("2017-05-06T00:30:00Z", instant.toString()); + Assertions.assertEquals("2017-05-06T00:30:00Z", instant.toString()); final LocalDate localDate = localDateTime.toLocalDate(); instant = DateUtil.toInstant(localDate); - Assert.assertNotNull(instant); + Assertions.assertNotNull(instant); final LocalTime localTime = localDateTime.toLocalTime(); instant = DateUtil.toInstant(localTime); - Assert.assertNotNull(instant); + Assertions.assertNotNull(instant); } @Test @@ -813,12 +813,12 @@ public class DateUtilTest { //LocalDateTime ==> date final LocalDateTime localDateTime = LocalDateTime.parse("2017-05-06T08:30:00", DateTimeFormatter.ISO_DATE_TIME); final DateTime date = DateUtil.date(localDateTime); - Assert.assertEquals("2017-05-06 08:30:00", date.toString()); + Assertions.assertEquals("2017-05-06 08:30:00", date.toString()); //LocalDate ==> date final LocalDate localDate = localDateTime.toLocalDate(); final DateTime date2 = DateUtil.date(localDate); - Assert.assertEquals("2017-05-06", + Assertions.assertEquals("2017-05-06", DateUtil.format(date2, DatePattern.NORM_DATE_PATTERN)); } @@ -827,7 +827,7 @@ public class DateUtilTest { // 测试负数日期 final long dateLong = -1497600000; final DateTime date = DateUtil.date(dateLong); - Assert.assertEquals("1969-12-15 00:00:00", date.toString()); + Assertions.assertEquals("1969-12-15 00:00:00", date.toString()); } @Test @@ -835,14 +835,16 @@ public class DateUtilTest { final String d1 = "2000-02-29"; final String d2 = "2018-02-28"; final int age = DateUtil.age(DateUtil.parse(d1), DateUtil.parse(d2)); - Assert.assertEquals(18, age); + Assertions.assertEquals(18, age); } - @Test(expected = IllegalArgumentException.class) + @Test public void ageTest2() { - final String d1 = "2019-02-29"; - final String d2 = "2018-02-28"; - DateUtil.age(DateUtil.parse(d1), DateUtil.parse(d2)); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + final String d1 = "2019-02-29"; + final String d2 = "2018-02-28"; + DateUtil.age(DateUtil.parse(d1), DateUtil.parse(d2)); + }); } @Test @@ -851,12 +853,12 @@ public class DateUtilTest { final String strDate = "2019-12-01 17:02:30"; LocalDateTime ldt = TimeUtil.parseByISO(strDate); String strDate1 = DateUtil.formatLocalDateTime(ldt); - Assert.assertEquals(strDate, strDate1); + Assertions.assertEquals(strDate, strDate1); final String strDate2 = "2019-12-01 17:02:30.111"; ldt = TimeUtil.parse(strDate2, DatePattern.NORM_DATETIME_MS_PATTERN); strDate1 = DateUtil.format(ldt, DatePattern.NORM_DATETIME_PATTERN); - Assert.assertEquals(strDate, strDate1); + Assertions.assertEquals(strDate, strDate1); } @Test @@ -864,7 +866,7 @@ public class DateUtilTest { // 测试字符串与LocalDateTime的互相转换 final String strDate = "2019-12-01"; final LocalDateTime localDateTime = TimeUtil.parse(strDate, "yyyy-MM-dd"); - Assert.assertEquals(strDate, DateUtil.format(localDateTime, DatePattern.NORM_DATE_PATTERN)); + Assertions.assertEquals(strDate, DateUtil.format(localDateTime, DatePattern.NORM_DATE_PATTERN)); } @Test @@ -873,7 +875,7 @@ public class DateUtilTest { final DateTime end = DateUtil.parse("2019-10-05"); final long weekCount = DateUtil.betweenWeek(start, end, true); - Assert.assertEquals(30L, weekCount); + Assertions.assertEquals(30L, weekCount); } @Test @@ -883,38 +885,38 @@ public class DateUtilTest { final long betweenDay = DateUtil.betweenDay( DateUtil.parse("1970-01-01"), DateUtil.parse(datr), false); - Assert.assertEquals(Math.abs(LocalDate.parse(datr).toEpochDay()), betweenDay); + Assertions.assertEquals(Math.abs(LocalDate.parse(datr).toEpochDay()), betweenDay); } } @Test public void dayOfYearTest() { final int dayOfYear = DateUtil.dayOfYear(DateUtil.parse("2020-01-01")); - Assert.assertEquals(1, dayOfYear); + Assertions.assertEquals(1, dayOfYear); final int lengthOfYear = DateUtil.lengthOfYear(2020); - Assert.assertEquals(366, lengthOfYear); + Assertions.assertEquals(366, lengthOfYear); } @SuppressWarnings("ConstantConditions") @Test public void parseSingleNumberTest() { DateTime dateTime = DateUtil.parse("2020-5-08"); - Assert.assertEquals("2020-05-08 00:00:00", dateTime.toString()); + Assertions.assertEquals("2020-05-08 00:00:00", dateTime.toString()); dateTime = DateUtil.parse("2020-5-8"); - Assert.assertEquals("2020-05-08 00:00:00", dateTime.toString()); + Assertions.assertEquals("2020-05-08 00:00:00", dateTime.toString()); dateTime = DateUtil.parse("2020-05-8"); - Assert.assertEquals("2020-05-08 00:00:00", dateTime.toString()); + Assertions.assertEquals("2020-05-08 00:00:00", dateTime.toString()); //datetime dateTime = DateUtil.parse("2020-5-8 3:12:3"); - Assert.assertEquals("2020-05-08 03:12:03", dateTime.toString()); + Assertions.assertEquals("2020-05-08 03:12:03", dateTime.toString()); dateTime = DateUtil.parse("2020-5-8 3:2:3"); - Assert.assertEquals("2020-05-08 03:02:03", dateTime.toString()); + Assertions.assertEquals("2020-05-08 03:02:03", dateTime.toString()); dateTime = DateUtil.parse("2020-5-8 3:12:13"); - Assert.assertEquals("2020-05-08 03:12:13", dateTime.toString()); + Assertions.assertEquals("2020-05-08 03:12:13", dateTime.toString()); dateTime = DateUtil.parse("2020-5-8 4:12:26.223"); - Assert.assertEquals("2020-05-08 04:12:26", dateTime.toString()); + Assertions.assertEquals("2020-05-08 04:12:26", dateTime.toString()); } @SuppressWarnings("ConstantConditions") @@ -922,14 +924,16 @@ public class DateUtilTest { public void parseISO8601Test() { final String dt = "2020-06-03 12:32:12,333"; final DateTime parse = DateUtil.parse(dt); - Assert.assertEquals("2020-06-03 12:32:12", parse.toString()); + Assertions.assertEquals("2020-06-03 12:32:12", parse.toString()); } - @Test(expected = DateException.class) + @Test public void parseNotFitTest() { - //https://github.com/dromara/hutool/issues/1332 - // 在日期格式不匹配的时候,测试是否正常报错 - DateUtil.parse("2020-12-23", DatePattern.PURE_DATE_PATTERN); + Assertions.assertThrows(DateException.class, ()->{ + //https://github.com/dromara/hutool/issues/1332 + // 在日期格式不匹配的时候,测试是否正常报错 + DateUtil.parse("2020-12-23", DatePattern.PURE_DATE_PATTERN); + }); } @Test @@ -938,60 +942,60 @@ public class DateUtilTest { calendar.set(2021, Calendar.JULY, 14, 23, 59, 59); final Date date = new DateTime(calendar); - Assert.assertEquals("2021-07-14 23:59:59", DateUtil.format(date, DatePattern.NORM_DATETIME_FORMATTER)); - Assert.assertEquals("2021-07-14 23:59:59", DateUtil.format(date, DatePattern.NORM_DATETIME_FORMAT)); - Assert.assertEquals("2021-07-14 23:59:59", DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN)); + Assertions.assertEquals("2021-07-14 23:59:59", DateUtil.format(date, DatePattern.NORM_DATETIME_FORMATTER)); + Assertions.assertEquals("2021-07-14 23:59:59", DateUtil.format(date, DatePattern.NORM_DATETIME_FORMAT)); + Assertions.assertEquals("2021-07-14 23:59:59", DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN)); } @Test public void formatNormDateTimeFormatterTest() { String format = DateUtil.format(DateUtil.parse("2021-07-14 10:05:38"), DatePattern.NORM_DATETIME_FORMATTER); - Assert.assertEquals("2021-07-14 10:05:38", format); + Assertions.assertEquals("2021-07-14 10:05:38", format); format = DateUtil.format(TimeUtil.parseByISO("2021-07-14T10:05:38"), "yyyy-MM-dd HH:mm:ss"); - Assert.assertEquals("2021-07-14 10:05:38", format); + Assertions.assertEquals("2021-07-14 10:05:38", format); } @Test public void isWeekendTest() { DateTime parse = DateUtil.parse("2021-07-28"); - Assert.assertFalse(DateUtil.isWeekend(parse)); + Assertions.assertFalse(DateUtil.isWeekend(parse)); parse = DateUtil.parse("2021-07-25"); - Assert.assertTrue(DateUtil.isWeekend(parse)); + Assertions.assertTrue(DateUtil.isWeekend(parse)); parse = DateUtil.parse("2021-07-24"); - Assert.assertTrue(DateUtil.isWeekend(parse)); + Assertions.assertTrue(DateUtil.isWeekend(parse)); } @Test public void parseSingleMonthAndDayTest() { DateTime parse = DateUtil.parse("2021-1-1"); - Assert.assertNotNull(parse); - Assert.assertEquals("2021-01-01 00:00:00", parse.toString()); + Assertions.assertNotNull(parse); + Assertions.assertEquals("2021-01-01 00:00:00", parse.toString()); parse = DateUtil.parse("2021-1-22 00:00:00"); - Assert.assertNotNull(parse); - Assert.assertEquals("2021-01-22 00:00:00", parse.toString()); + Assertions.assertNotNull(parse); + Assertions.assertEquals("2021-01-22 00:00:00", parse.toString()); } @Test public void parseByDateTimeFormatterTest() { final DateTime parse = DateUtil.parse("2021-12-01", DatePattern.NORM_DATE_FORMATTER); - Assert.assertEquals("2021-12-01 00:00:00", parse.toString()); + Assertions.assertEquals("2021-12-01 00:00:00", parse.toString()); } @Test public void isSameWeekTest() { // 周六与周日比较 final boolean isSameWeek = DateUtil.isSameWeek(DateTime.of("2022-01-01", "yyyy-MM-dd"), DateTime.of("2022-01-02", "yyyy-MM-dd"), true); - Assert.assertTrue(isSameWeek); + Assertions.assertTrue(isSameWeek); // 周日与周一比较 final boolean isSameWeek1 = DateUtil.isSameWeek(DateTime.of("2022-01-02", "yyyy-MM-dd"), DateTime.of("2022-01-03", "yyyy-MM-dd"), false); - Assert.assertTrue(isSameWeek1); + Assertions.assertTrue(isSameWeek1); // 跨月比较 final boolean isSameWeek2 = DateUtil.isSameWeek(DateTime.of("2021-12-29", "yyyy-MM-dd"), DateTime.of("2022-01-01", "yyyy-MM-dd"), true); - Assert.assertTrue(isSameWeek2); + Assertions.assertTrue(isSameWeek2); } @Test @@ -1022,17 +1026,17 @@ public class DateUtilTest { final DateTime startTime = DateUtil.parse("2022-03-23 05:00:00"); final DateTime endTime = DateUtil.parse("2022-03-23 13:00:00"); - Assert.assertFalse(DateUtil.isOverlap(oneStartTime, oneEndTime, realStartTime, realEndTime)); - Assert.assertFalse(DateUtil.isOverlap(oneStartTime2, oneEndTime2, realStartTime, realEndTime)); - Assert.assertTrue(DateUtil.isOverlap(oneStartTime3, oneEndTime3, realStartTime, realEndTime)); + Assertions.assertFalse(DateUtil.isOverlap(oneStartTime, oneEndTime, realStartTime, realEndTime)); + Assertions.assertFalse(DateUtil.isOverlap(oneStartTime2, oneEndTime2, realStartTime, realEndTime)); + Assertions.assertTrue(DateUtil.isOverlap(oneStartTime3, oneEndTime3, realStartTime, realEndTime)); - Assert.assertFalse(DateUtil.isOverlap(realStartTime1,realEndTime1,startTime,endTime)); - Assert.assertFalse(DateUtil.isOverlap(startTime,endTime,realStartTime1,realEndTime1)); + Assertions.assertFalse(DateUtil.isOverlap(realStartTime1,realEndTime1,startTime,endTime)); + Assertions.assertFalse(DateUtil.isOverlap(startTime,endTime,realStartTime1,realEndTime1)); - Assert.assertTrue(DateUtil.isOverlap(startTime,startTime,startTime,startTime)); - Assert.assertTrue(DateUtil.isOverlap(startTime,startTime,startTime,endTime)); - Assert.assertFalse(DateUtil.isOverlap(startTime,startTime,endTime,endTime)); - Assert.assertTrue(DateUtil.isOverlap(startTime,endTime,endTime,endTime)); + Assertions.assertTrue(DateUtil.isOverlap(startTime,startTime,startTime,startTime)); + Assertions.assertTrue(DateUtil.isOverlap(startTime,startTime,startTime,endTime)); + Assertions.assertFalse(DateUtil.isOverlap(startTime,startTime,endTime,endTime)); + Assertions.assertTrue(DateUtil.isOverlap(startTime,endTime,endTime,endTime)); } @Test @@ -1043,15 +1047,15 @@ public class DateUtilTest { final boolean between = DateUtil.isIn(DateUtil.parse(startTimeStr), DateUtil.parse(endTimeStr), DateUtil.parse(sourceStr)); - Assert.assertTrue(between); + Assertions.assertTrue(between); } @Test public void isLastDayTest(){ final DateTime dateTime = DateUtil.parse("2022-09-30"); final int dayOfMonth = DateUtil.getLastDayOfMonth(dateTime); - Assert.assertEquals(dayOfMonth, Objects.requireNonNull(dateTime).dayOfMonth()); - Assert.assertTrue("not is last day of this month !!",DateUtil.isLastDayOfMonth(dateTime)); + Assertions.assertEquals(dayOfMonth, Objects.requireNonNull(dateTime).dayOfMonth()); + Assertions.assertTrue(DateUtil.isLastDayOfMonth(dateTime), "not is last day of this month !!"); } /** @@ -1061,18 +1065,18 @@ public class DateUtilTest { public void parseUTCTest4() { final String dateStr = "2023-02-07T00:02:16.12345+08:00"; final DateTime dateTime = DateUtil.parse(dateStr); - Assert.assertNotNull(dateTime); - Assert.assertEquals("2023-02-07 00:02:16", dateTime.toString()); + Assertions.assertNotNull(dateTime); + Assertions.assertEquals("2023-02-07 00:02:16", dateTime.toString()); final String dateStr2 = "2023-02-07T00:02:16.12345-08:00"; final DateTime dateTime2 = DateUtil.parse(dateStr2); - Assert.assertNotNull(dateTime2); - Assert.assertEquals("2023-02-07 00:02:16", dateTime2.toString()); + Assertions.assertNotNull(dateTime2); + Assertions.assertEquals("2023-02-07 00:02:16", dateTime2.toString()); final String dateStr3 = "2021-03-17T06:31:33.9999"; final DateTime dateTime3 = DateUtil.parse(dateStr3); - Assert.assertNotNull(dateTime3); - Assert.assertEquals("2021-03-17 06:31:33", dateTime3.toString()); + Assertions.assertNotNull(dateTime3); + Assertions.assertEquals("2021-03-17 06:31:33", dateTime3.toString()); } /** @@ -1081,8 +1085,8 @@ public class DateUtilTest { @Test public void issueI6E6ZGTest() { // issue#I6E6ZG,法定生日当天不算年龄,从第二天开始计算 - Assert.assertEquals(70, DateUtil.age(DateUtil.parse("1952-02-14"), DateUtil.parse("2023-02-14"))); - Assert.assertEquals(71, DateUtil.age(DateUtil.parse("1952-02-13"), DateUtil.parse("2023-02-14"))); - Assert.assertEquals(0, DateUtil.age(DateUtil.parse("2023-02-14"), DateUtil.parse("2023-02-14"))); + Assertions.assertEquals(70, DateUtil.age(DateUtil.parse("1952-02-14"), DateUtil.parse("2023-02-14"))); + Assertions.assertEquals(71, DateUtil.age(DateUtil.parse("1952-02-13"), DateUtil.parse("2023-02-14"))); + Assertions.assertEquals(0, DateUtil.age(DateUtil.parse("2023-02-14"), DateUtil.parse("2023-02-14"))); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/GanzhiTest.java b/hutool-core/src/test/java/cn/hutool/core/date/GanzhiTest.java index 06380a4d3..b13324318 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/GanzhiTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/GanzhiTest.java @@ -2,14 +2,14 @@ package cn.hutool.core.date; import cn.hutool.core.date.chinese.ChineseDate; import cn.hutool.core.date.chinese.GanZhi; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class GanzhiTest { @Test public void getGanzhiOfYearTest(){ - Assert.assertEquals("庚子", GanZhi.getGanzhiOfYear(2020)); + Assertions.assertEquals("庚子", GanZhi.getGanzhiOfYear(2020)); } @Test @@ -17,7 +17,7 @@ public class GanzhiTest { //通过公历构建 final ChineseDate chineseDate = new ChineseDate(DateUtil.parse("1993-01-06")); final String cyclicalYMD = chineseDate.getCyclicalYMD(); - Assert.assertEquals("壬申年癸丑月丁亥日",cyclicalYMD); + Assertions.assertEquals("壬申年癸丑月丁亥日",cyclicalYMD); } @Test @@ -25,7 +25,7 @@ public class GanzhiTest { //通过农历构建 final ChineseDate chineseDate = new ChineseDate(1992,12,14); final String cyclicalYMD = chineseDate.getCyclicalYMD(); - Assert.assertEquals("壬申年癸丑月丁亥日",cyclicalYMD); + Assertions.assertEquals("壬申年癸丑月丁亥日",cyclicalYMD); } @Test @@ -33,7 +33,7 @@ public class GanzhiTest { //通过公历构建 final ChineseDate chineseDate = new ChineseDate(DateUtil.parse("2020-08-28")); final String cyclicalYMD = chineseDate.getCyclicalYMD(); - Assert.assertEquals("庚子年甲申月癸卯日",cyclicalYMD); + Assertions.assertEquals("庚子年甲申月癸卯日",cyclicalYMD); } @Test @@ -41,6 +41,6 @@ public class GanzhiTest { //通过公历构建 final ChineseDate chineseDate = new ChineseDate(DateUtil.parse("1905-08-28")); final String cyclicalYMD = chineseDate.getCyclicalYMD(); - Assert.assertEquals("乙巳年甲申月己亥日",cyclicalYMD); + Assertions.assertEquals("乙巳年甲申月己亥日",cyclicalYMD); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/Issue2612Test.java b/hutool-core/src/test/java/cn/hutool/core/date/Issue2612Test.java index 9f285eb00..b0a9d0351 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/Issue2612Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/Issue2612Test.java @@ -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.Objects; @@ -9,10 +9,10 @@ public class Issue2612Test { @Test public void parseTest(){ - Assert.assertEquals("2022-09-14 23:59:00", + Assertions.assertEquals("2022-09-14 23:59:00", Objects.requireNonNull(DateUtil.parse("2022-09-14T23:59:00-08:00")).toString()); - Assert.assertEquals("2022-09-14 23:59:00", + Assertions.assertEquals("2022-09-14 23:59:00", Objects.requireNonNull(DateUtil.parse("2022-09-14T23:59:00-0800")).toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/Issue2981Test.java b/hutool-core/src/test/java/cn/hutool/core/date/Issue2981Test.java index 432459ff0..e2cf549aa 100755 --- a/hutool-core/src/test/java/cn/hutool/core/date/Issue2981Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/Issue2981Test.java @@ -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; public class Issue2981Test { /** @@ -15,8 +15,8 @@ public class Issue2981Test { final String str2 = "2019-01-01T00:00:00.000"; final String str3 = "2019-01-01 00:00:00.000"; - Assert.assertEquals(1546300800000L, DateUtil.parse(str1).getTime()); - Assert.assertEquals(1546272000000L, DateUtil.parse(str2).getTime()); - Assert.assertEquals(1546272000000L, DateUtil.parse(str3).getTime()); + Assertions.assertEquals(1546300800000L, DateUtil.parse(str1).getTime()); + Assertions.assertEquals(1546272000000L, DateUtil.parse(str2).getTime()); + Assertions.assertEquals(1546272000000L, DateUtil.parse(str3).getTime()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/Issue3011Test.java b/hutool-core/src/test/java/cn/hutool/core/date/Issue3011Test.java index d28f81f76..92007abba 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/Issue3011Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/Issue3011Test.java @@ -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; @@ -18,6 +18,6 @@ public class Issue3011Test { calendar2.set(2021, Calendar.FEBRUARY, 12); - Assert.assertFalse(DateUtil.isSameMonth(calendar1, calendar2)); + Assertions.assertFalse(DateUtil.isSameMonth(calendar1, calendar2)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/MonthTest.java b/hutool-core/src/test/java/cn/hutool/core/date/MonthTest.java index 3700ea6d3..27bb9e561 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/MonthTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/MonthTest.java @@ -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; @@ -11,59 +11,59 @@ public class MonthTest { @Test public void getLastDayTest(){ int lastDay = Month.of(Calendar.JANUARY).getLastDay(false); - Assert.assertEquals(31, lastDay); + Assertions.assertEquals(31, lastDay); lastDay = Month.of(Calendar.FEBRUARY).getLastDay(false); - Assert.assertEquals(28, lastDay); + Assertions.assertEquals(28, lastDay); lastDay = Month.of(Calendar.FEBRUARY).getLastDay(true); - Assert.assertEquals(29, lastDay); + Assertions.assertEquals(29, lastDay); lastDay = Month.of(Calendar.MARCH).getLastDay(true); - Assert.assertEquals(31, lastDay); + Assertions.assertEquals(31, lastDay); lastDay = Month.of(Calendar.APRIL).getLastDay(true); - Assert.assertEquals(30, lastDay); + Assertions.assertEquals(30, lastDay); lastDay = Month.of(Calendar.MAY).getLastDay(true); - Assert.assertEquals(31, lastDay); + Assertions.assertEquals(31, lastDay); lastDay = Month.of(Calendar.JUNE).getLastDay(true); - Assert.assertEquals(30, lastDay); + Assertions.assertEquals(30, lastDay); lastDay = Month.of(Calendar.JULY).getLastDay(true); - Assert.assertEquals(31, lastDay); + Assertions.assertEquals(31, lastDay); lastDay = Month.of(Calendar.AUGUST).getLastDay(true); - Assert.assertEquals(31, lastDay); + Assertions.assertEquals(31, lastDay); lastDay = Month.of(Calendar.SEPTEMBER).getLastDay(true); - Assert.assertEquals(30, lastDay); + Assertions.assertEquals(30, lastDay); lastDay = Month.of(Calendar.OCTOBER).getLastDay(true); - Assert.assertEquals(31, lastDay); + Assertions.assertEquals(31, lastDay); lastDay = Month.of(Calendar.NOVEMBER).getLastDay(true); - Assert.assertEquals(30, lastDay); + Assertions.assertEquals(30, lastDay); lastDay = Month.of(Calendar.DECEMBER).getLastDay(true); - Assert.assertEquals(31, lastDay); + Assertions.assertEquals(31, lastDay); } @Test public void toJdkMonthTest(){ final java.time.Month month = Month.AUGUST.toJdkMonth(); - Assert.assertEquals(java.time.Month.AUGUST, month); + Assertions.assertEquals(java.time.Month.AUGUST, month); } - @Test(expected = IllegalArgumentException.class) + @Test public void toJdkMonthTest2(){ - Month.UNDECIMBER.toJdkMonth(); + Assertions.assertThrows(IllegalArgumentException.class, Month.UNDECIMBER::toJdkMonth); } @Test public void ofTest(){ Month month = Month.of("Jan"); - Assert.assertEquals(Month.JANUARY, month); + Assertions.assertEquals(Month.JANUARY, month); month = Month.of("JAN"); - Assert.assertEquals(Month.JANUARY, month); + Assertions.assertEquals(Month.JANUARY, month); month = Month.of("FEBRUARY"); - Assert.assertEquals(Month.FEBRUARY, month); + Assertions.assertEquals(Month.FEBRUARY, month); month = Month.of("February"); - Assert.assertEquals(Month.FEBRUARY, month); + Assertions.assertEquals(Month.FEBRUARY, month); month = Month.of(java.time.Month.FEBRUARY); - Assert.assertEquals(Month.FEBRUARY, month); + Assertions.assertEquals(Month.FEBRUARY, month); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/StopWatchTest.java b/hutool-core/src/test/java/cn/hutool/core/date/StopWatchTest.java index 93d945d1d..87d96ef28 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/StopWatchTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/StopWatchTest.java @@ -2,7 +2,7 @@ package cn.hutool.core.date; import cn.hutool.core.lang.Console; import cn.hutool.core.thread.ThreadUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; diff --git a/hutool-core/src/test/java/cn/hutool/core/date/TemporalAccessorUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/TemporalAccessorUtilTest.java index 28d726bf8..f52a1b145 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/TemporalAccessorUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/TemporalAccessorUtilTest.java @@ -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.time.LocalDate; import java.time.LocalTime; @@ -11,25 +11,25 @@ public class TemporalAccessorUtilTest { @Test public void formatLocalDateTest(){ final String format = TemporalAccessorUtil.format(LocalDate.of(2020, 12, 7), DatePattern.NORM_DATETIME_PATTERN); - Assert.assertEquals("2020-12-07 00:00:00", format); + Assertions.assertEquals("2020-12-07 00:00:00", format); } @Test public void formatLocalTimeTest(){ final String today = TemporalAccessorUtil.format(LocalDate.now(), DatePattern.NORM_DATE_PATTERN); final String format = TemporalAccessorUtil.format(LocalTime.MIN, DatePattern.NORM_DATETIME_PATTERN); - Assert.assertEquals(today + " 00:00:00", format); + Assertions.assertEquals(today + " 00:00:00", format); } @Test public void formatCustomTest(){ final String today = TemporalAccessorUtil.format( LocalDate.of(2021, 6, 26), "#sss"); - Assert.assertEquals("1624636800", today); + Assertions.assertEquals("1624636800", today); final String today2 = TemporalAccessorUtil.format( LocalDate.of(2021, 6, 26), "#SSS"); - Assert.assertEquals("1624636800000", today2); + Assertions.assertEquals("1624636800000", today2); } @Test @@ -41,6 +41,6 @@ public class TemporalAccessorUtilTest { TimeUtil.parse(sourceStr, DatePattern.NORM_DATETIME_FORMATTER), TimeUtil.parse(startTimeStr, DatePattern.NORM_DATETIME_FORMATTER), TimeUtil.parse(endTimeStr, DatePattern.NORM_DATETIME_FORMATTER)); - Assert.assertTrue(between); + Assertions.assertTrue(between); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/TimeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/TimeUtilTest.java index 3ff41ae9f..3608671d9 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/TimeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/TimeUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.date; import cn.hutool.core.lang.Console; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.time.Duration; import java.time.Instant; @@ -19,7 +19,7 @@ public class TimeUtilTest { @Test public void nowTest() { - Assert.assertNotNull(TimeUtil.now()); + Assertions.assertNotNull(TimeUtil.now()); } @Test @@ -28,8 +28,8 @@ public class TimeUtilTest { final DateTime dt = DateUtil.parse(dateStr); final LocalDateTime of = TimeUtil.of(dt); - Assert.assertNotNull(of); - Assert.assertEquals(dateStr, of.toString()); + Assertions.assertNotNull(of); + Assertions.assertEquals(dateStr, of.toString()); } @SuppressWarnings("DataFlowIssue") @@ -40,95 +40,95 @@ public class TimeUtilTest { final LocalDateTime of = TimeUtil.of(dt); final LocalDateTime of2 = TimeUtil.ofUTC(dt.getTime()); - Assert.assertNotNull(of); - Assert.assertNotNull(of2); - Assert.assertEquals(of, of2); + Assertions.assertNotNull(of); + Assertions.assertNotNull(of2); + Assertions.assertEquals(of, of2); } @Test public void parseOffsetTest() { final LocalDateTime localDateTime = TimeUtil.parse("2021-07-30T16:27:27+08:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); - Assert.assertEquals("2021-07-30T16:27:27", Objects.requireNonNull(localDateTime).toString()); + Assertions.assertEquals("2021-07-30T16:27:27", Objects.requireNonNull(localDateTime).toString()); } @Test public void parseTest() { final LocalDateTime localDateTime = TimeUtil.parse("2020-01-23T12:23:56", DateTimeFormatter.ISO_DATE_TIME); - Assert.assertEquals("2020-01-23T12:23:56", Objects.requireNonNull(localDateTime).toString()); + Assertions.assertEquals("2020-01-23T12:23:56", Objects.requireNonNull(localDateTime).toString()); } @Test public void parseTest2() { final LocalDateTime localDateTime = TimeUtil.parse("2020-01-23", DatePattern.NORM_DATE_PATTERN); - Assert.assertEquals("2020-01-23T00:00", Objects.requireNonNull(localDateTime).toString()); + Assertions.assertEquals("2020-01-23T00:00", Objects.requireNonNull(localDateTime).toString()); } @Test public void parseTest3() { final LocalDateTime localDateTime = TimeUtil.parse("12:23:56", DatePattern.NORM_TIME_PATTERN); - Assert.assertEquals("12:23:56", Objects.requireNonNull(localDateTime).toLocalTime().toString()); + Assertions.assertEquals("12:23:56", Objects.requireNonNull(localDateTime).toLocalTime().toString()); } @Test public void parseTest4() { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); - Assert.assertEquals("2020-01-23T12:23:56", localDateTime.toString()); + Assertions.assertEquals("2020-01-23T12:23:56", localDateTime.toString()); } @Test public void parseTest5() { final LocalDateTime localDateTime = TimeUtil.parse("19940121183604", "yyyyMMddHHmmss"); - Assert.assertEquals("1994-01-21T18:36:04", Objects.requireNonNull(localDateTime).toString()); + Assertions.assertEquals("1994-01-21T18:36:04", Objects.requireNonNull(localDateTime).toString()); } @Test public void parseTest6() { LocalDateTime localDateTime = TimeUtil.parse("19940121183604682", "yyyyMMddHHmmssSSS"); - Assert.assertEquals("1994-01-21T18:36:04.682", Objects.requireNonNull(localDateTime).toString()); + Assertions.assertEquals("1994-01-21T18:36:04.682", Objects.requireNonNull(localDateTime).toString()); localDateTime = TimeUtil.parse("1994012118360468", "yyyyMMddHHmmssSS"); - Assert.assertEquals("1994-01-21T18:36:04.680", Objects.requireNonNull(localDateTime).toString()); + Assertions.assertEquals("1994-01-21T18:36:04.680", Objects.requireNonNull(localDateTime).toString()); localDateTime = TimeUtil.parse("199401211836046", "yyyyMMddHHmmssS"); - Assert.assertEquals("1994-01-21T18:36:04.600", Objects.requireNonNull(localDateTime).toString()); + Assertions.assertEquals("1994-01-21T18:36:04.600", Objects.requireNonNull(localDateTime).toString()); } @Test public void parseDateTest() { LocalDate localDate = TimeUtil.parseDateByISO("2020-01-23"); - Assert.assertEquals("2020-01-23", localDate.toString()); + Assertions.assertEquals("2020-01-23", localDate.toString()); localDate = TimeUtil.parseDate("2020-01-23T12:23:56", DateTimeFormatter.ISO_DATE_TIME); - Assert.assertEquals("2020-01-23", localDate.toString()); + Assertions.assertEquals("2020-01-23", localDate.toString()); } @Test public void parseSingleMonthAndDayTest() { final LocalDate localDate = TimeUtil.parseDate("2020-1-1", "yyyy-M-d"); - Assert.assertEquals("2020-01-01", localDate.toString()); + Assertions.assertEquals("2020-01-01", localDate.toString()); } @Test public void formatTest() { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); String format = TimeUtil.format(localDateTime, DatePattern.NORM_DATETIME_PATTERN); - Assert.assertEquals("2020-01-23 12:23:56", format); + Assertions.assertEquals("2020-01-23 12:23:56", format); format = TimeUtil.formatNormal(localDateTime); - Assert.assertEquals("2020-01-23 12:23:56", format); + Assertions.assertEquals("2020-01-23 12:23:56", format); format = TimeUtil.format(localDateTime, DatePattern.NORM_DATE_PATTERN); - Assert.assertEquals("2020-01-23", format); + Assertions.assertEquals("2020-01-23", format); } @Test public void formatLocalDateTest() { final LocalDate date = LocalDate.parse("2020-01-23"); String format = TimeUtil.format(date, DatePattern.NORM_DATE_PATTERN); - Assert.assertEquals("2020-01-23", format); + Assertions.assertEquals("2020-01-23", format); format = TimeUtil.formatNormal(date); - Assert.assertEquals("2020-01-23", format); + Assertions.assertEquals("2020-01-23", format); } @Test @@ -136,12 +136,12 @@ public class TimeUtilTest { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); LocalDateTime offset = TimeUtil.offset(localDateTime, 1, ChronoUnit.DAYS); // 非同一对象 - Assert.assertNotSame(localDateTime, offset); + Assertions.assertNotSame(localDateTime, offset); - Assert.assertEquals("2020-01-24T12:23:56", offset.toString()); + Assertions.assertEquals("2020-01-24T12:23:56", offset.toString()); offset = TimeUtil.offset(localDateTime, -1, ChronoUnit.DAYS); - Assert.assertEquals("2020-01-22T12:23:56", offset.toString()); + Assertions.assertEquals("2020-01-22T12:23:56", offset.toString()); } @Test @@ -149,14 +149,14 @@ public class TimeUtilTest { final Duration between = TimeUtil.between( TimeUtil.parseByISO("2019-02-02T00:00:00"), TimeUtil.parseByISO("2020-02-02T00:00:00")); - Assert.assertEquals(365, between.toDays()); + Assertions.assertEquals(365, between.toDays()); } @Test public void beginOfDayTest() { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); final LocalDateTime beginOfDay = TimeUtil.beginOfDay(localDateTime); - Assert.assertEquals("2020-01-23T00:00", beginOfDay.toString()); + Assertions.assertEquals("2020-01-23T00:00", beginOfDay.toString()); } @Test @@ -164,17 +164,17 @@ public class TimeUtilTest { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); LocalDateTime endOfDay = TimeUtil.endOfDay(localDateTime, false); - Assert.assertEquals("2020-01-23T23:59:59.999999999", endOfDay.toString()); + Assertions.assertEquals("2020-01-23T23:59:59.999999999", endOfDay.toString()); endOfDay = TimeUtil.endOfDay(localDateTime, true); - Assert.assertEquals("2020-01-23T23:59:59", endOfDay.toString()); + Assertions.assertEquals("2020-01-23T23:59:59", endOfDay.toString()); } @Test public void beginOfMonthTest() { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); final LocalDateTime begin = TimeUtil.beginOfMonth(localDateTime); - Assert.assertEquals("2020-01-01T00:00", begin.toString()); + Assertions.assertEquals("2020-01-01T00:00", begin.toString()); } @Test @@ -182,17 +182,17 @@ public class TimeUtilTest { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); LocalDateTime end = TimeUtil.endOfMonth(localDateTime, false); - Assert.assertEquals("2020-01-31T23:59:59.999999999", end.toString()); + Assertions.assertEquals("2020-01-31T23:59:59.999999999", end.toString()); end = TimeUtil.endOfMonth(localDateTime, true); - Assert.assertEquals("2020-01-31T23:59:59", end.toString()); + Assertions.assertEquals("2020-01-31T23:59:59", end.toString()); } @Test public void beginOfYearTest() { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); final LocalDateTime begin = TimeUtil.beginOfMonth(localDateTime); - Assert.assertEquals("2020-01-01T00:00", begin.toString()); + Assertions.assertEquals("2020-01-01T00:00", begin.toString()); } @Test @@ -200,34 +200,34 @@ public class TimeUtilTest { final LocalDateTime localDateTime = TimeUtil.parseByISO("2020-01-23T12:23:56"); LocalDateTime end = TimeUtil.endOfYear(localDateTime, false); - Assert.assertEquals("2020-12-31T23:59:59.999999999", end.toString()); + Assertions.assertEquals("2020-12-31T23:59:59.999999999", end.toString()); end = TimeUtil.endOfYear(localDateTime, true); - Assert.assertEquals("2020-12-31T23:59:59", end.toString()); + Assertions.assertEquals("2020-12-31T23:59:59", end.toString()); } @Test public void dayOfWeekTest() { final Week one = TimeUtil.dayOfWeek(LocalDate.of(2021, 9, 20)); - Assert.assertEquals(Week.MONDAY, one); + Assertions.assertEquals(Week.MONDAY, one); final Week two = TimeUtil.dayOfWeek(LocalDate.of(2021, 9, 21)); - Assert.assertEquals(Week.TUESDAY, two); + Assertions.assertEquals(Week.TUESDAY, two); final Week three = TimeUtil.dayOfWeek(LocalDate.of(2021, 9, 22)); - Assert.assertEquals(Week.WEDNESDAY, three); + Assertions.assertEquals(Week.WEDNESDAY, three); final Week four = TimeUtil.dayOfWeek(LocalDate.of(2021, 9, 23)); - Assert.assertEquals(Week.THURSDAY, four); + Assertions.assertEquals(Week.THURSDAY, four); final Week five = TimeUtil.dayOfWeek(LocalDate.of(2021, 9, 24)); - Assert.assertEquals(Week.FRIDAY, five); + Assertions.assertEquals(Week.FRIDAY, five); final Week six = TimeUtil.dayOfWeek(LocalDate.of(2021, 9, 25)); - Assert.assertEquals(Week.SATURDAY, six); + Assertions.assertEquals(Week.SATURDAY, six); final Week seven = TimeUtil.dayOfWeek(LocalDate.of(2021, 9, 26)); - Assert.assertEquals(Week.SUNDAY, seven); + Assertions.assertEquals(Week.SUNDAY, seven); } @Test @@ -251,37 +251,37 @@ public class TimeUtilTest { final LocalDateTime startTime = TimeUtil.parseByISO("2022-03-23 05:00:00"); final LocalDateTime endTime = TimeUtil.parseByISO("2022-03-23 13:00:00"); - Assert.assertFalse(TimeUtil.isOverlap(oneStartTime,oneEndTime,realStartTime,realEndTime)); - Assert.assertFalse(TimeUtil.isOverlap(oneStartTime2,oneEndTime2,realStartTime,realEndTime)); - Assert.assertTrue(TimeUtil.isOverlap(oneStartTime3,oneEndTime3,realStartTime,realEndTime)); + Assertions.assertFalse(TimeUtil.isOverlap(oneStartTime,oneEndTime,realStartTime,realEndTime)); + Assertions.assertFalse(TimeUtil.isOverlap(oneStartTime2,oneEndTime2,realStartTime,realEndTime)); + Assertions.assertTrue(TimeUtil.isOverlap(oneStartTime3,oneEndTime3,realStartTime,realEndTime)); - Assert.assertFalse(TimeUtil.isOverlap(realStartTime1,realEndTime1,startTime,endTime)); - Assert.assertFalse(TimeUtil.isOverlap(startTime,endTime,realStartTime1,realEndTime1)); + Assertions.assertFalse(TimeUtil.isOverlap(realStartTime1,realEndTime1,startTime,endTime)); + Assertions.assertFalse(TimeUtil.isOverlap(startTime,endTime,realStartTime1,realEndTime1)); - Assert.assertTrue(TimeUtil.isOverlap(startTime,startTime,startTime,startTime)); - Assert.assertTrue(TimeUtil.isOverlap(startTime,startTime,startTime,endTime)); - Assert.assertFalse(TimeUtil.isOverlap(startTime,startTime,endTime,endTime)); - Assert.assertTrue(TimeUtil.isOverlap(startTime,endTime,endTime,endTime)); + Assertions.assertTrue(TimeUtil.isOverlap(startTime,startTime,startTime,startTime)); + Assertions.assertTrue(TimeUtil.isOverlap(startTime,startTime,startTime,endTime)); + Assertions.assertFalse(TimeUtil.isOverlap(startTime,startTime,endTime,endTime)); + Assertions.assertTrue(TimeUtil.isOverlap(startTime,endTime,endTime,endTime)); } @Test public void weekOfYearTest(){ final LocalDate date1 = LocalDate.of(2021, 12, 31); final int weekOfYear1 = TimeUtil.weekOfYear(date1); - Assert.assertEquals(52, weekOfYear1); + Assertions.assertEquals(52, weekOfYear1); final int weekOfYear2 = TimeUtil.weekOfYear(date1.atStartOfDay()); - Assert.assertEquals(52, weekOfYear2); + Assertions.assertEquals(52, weekOfYear2); } @Test public void weekOfYearTest2(){ final LocalDate date1 = LocalDate.of(2022, 1, 31); final int weekOfYear1 = TimeUtil.weekOfYear(date1); - Assert.assertEquals(5, weekOfYear1); + Assertions.assertEquals(5, weekOfYear1); final int weekOfYear2 = TimeUtil.weekOfYear(date1.atStartOfDay()); - Assert.assertEquals(5, weekOfYear2); + Assertions.assertEquals(5, weekOfYear2); } @Test @@ -299,38 +299,38 @@ public class TimeUtilTest { final LocalDateTime end = LocalDateTime.parse("2019-02-02T09:00:00"); // 不在时间范围内 用例 - Assert.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T06:00:00"), begin, end)); - Assert.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T13:00:00"), begin, end)); - Assert.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-01T08:00:00"), begin, end)); - Assert.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-03T09:00:00"), begin, end)); + Assertions.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T06:00:00"), begin, end)); + Assertions.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T13:00:00"), begin, end)); + Assertions.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-01T08:00:00"), begin, end)); + Assertions.assertFalse(TimeUtil.isIn(LocalDateTime.parse("2019-02-03T09:00:00"), begin, end)); // 在时间范围内 用例 - Assert.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:00:00"), begin, end)); - Assert.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:00:01"), begin, end)); - Assert.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:11:00"), begin, end)); - Assert.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:22:00"), begin, end)); - Assert.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:59:59"), begin, end)); - Assert.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T09:00:00"), begin, end)); + Assertions.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:00:00"), begin, end)); + Assertions.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:00:01"), begin, end)); + Assertions.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:11:00"), begin, end)); + Assertions.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:22:00"), begin, end)); + Assertions.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T08:59:59"), begin, end)); + Assertions.assertTrue(TimeUtil.isIn(LocalDateTime.parse("2019-02-02T09:00:00"), begin, end)); // 测试边界条件 - Assert.assertTrue(TimeUtil.isIn(begin, begin, end, true, false)); - Assert.assertFalse(TimeUtil.isIn(begin, begin, end, false, false)); - Assert.assertTrue(TimeUtil.isIn(end, begin, end, false, true)); - Assert.assertFalse(TimeUtil.isIn(end, begin, end, false, false)); + Assertions.assertTrue(TimeUtil.isIn(begin, begin, end, true, false)); + Assertions.assertFalse(TimeUtil.isIn(begin, begin, end, false, false)); + Assertions.assertTrue(TimeUtil.isIn(end, begin, end, false, true)); + Assertions.assertFalse(TimeUtil.isIn(end, begin, end, false, false)); // begin、end互换 - Assert.assertTrue(TimeUtil.isIn(begin, end, begin, true, true)); + Assertions.assertTrue(TimeUtil.isIn(begin, end, begin, true, true)); // 比较当前时间范围 final LocalDateTime now = LocalDateTime.now(); - Assert.assertTrue(TimeUtil.isIn(now, now.minusHours(1L), now.plusHours(1L))); - Assert.assertFalse(TimeUtil.isIn(now, now.minusHours(1L), now.minusHours(2L))); - Assert.assertFalse(TimeUtil.isIn(now, now.plusHours(1L), now.plusHours(2L))); + Assertions.assertTrue(TimeUtil.isIn(now, now.minusHours(1L), now.plusHours(1L))); + Assertions.assertFalse(TimeUtil.isIn(now, now.minusHours(1L), now.minusHours(2L))); + Assertions.assertFalse(TimeUtil.isIn(now, now.plusHours(1L), now.plusHours(2L))); // 异常入参 - Assert.assertThrows(IllegalArgumentException.class, () -> TimeUtil.isIn(null, begin, end, false, false)); - Assert.assertThrows(IllegalArgumentException.class, () -> TimeUtil.isIn(begin, null, end, false, false)); - Assert.assertThrows(IllegalArgumentException.class, () -> TimeUtil.isIn(begin, begin, null, false, false)); + Assertions.assertThrows(IllegalArgumentException.class, () -> TimeUtil.isIn(null, begin, end, false, false)); + Assertions.assertThrows(IllegalArgumentException.class, () -> TimeUtil.isIn(begin, null, end, false, false)); + Assertions.assertThrows(IllegalArgumentException.class, () -> TimeUtil.isIn(begin, begin, null, false, false)); } @@ -340,8 +340,8 @@ public class TimeUtilTest { .map(LocalDate::parse) .map(TimeUtil.formatFunc(DatePattern.CHINESE_DATE_FORMATTER)) .collect(Collectors.toList()); - Assert.assertEquals("2023年03月01日", dateStrList.get(0)); - Assert.assertEquals("2023年03月02日", dateStrList.get(1)); + Assertions.assertEquals("2023年03月01日", dateStrList.get(0)); + Assertions.assertEquals("2023年03月02日", dateStrList.get(1)); } @Test @@ -350,7 +350,7 @@ public class TimeUtilTest { .map(LocalDateTime::parse) .map(TimeUtil.formatFunc(DatePattern.CHINESE_DATE_FORMATTER)) .collect(Collectors.toList()); - Assert.assertEquals("2023年03月01日", dateStrList.get(0)); - Assert.assertEquals("2023年03月02日", dateStrList.get(1)); + Assertions.assertEquals("2023年03月01日", dateStrList.get(0)); + Assertions.assertEquals("2023年03月02日", dateStrList.get(1)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/TimeZoneTest.java b/hutool-core/src/test/java/cn/hutool/core/date/TimeZoneTest.java index 26c18af12..e084c063e 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/TimeZoneTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/TimeZoneTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.date; import java.util.TimeZone; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import cn.hutool.core.date.format.FastDateFormat; @@ -13,11 +13,11 @@ public class TimeZoneTest { public void timeZoneConvertTest() { final DateTime dt = DateUtil.parse("2018-07-10 21:44:32", // FastDateFormat.getInstance(DatePattern.NORM_DATETIME_PATTERN, TimeZone.getTimeZone("GMT+8:00"))); - Assert.assertEquals("2018-07-10 21:44:32", dt.toString()); + Assertions.assertEquals("2018-07-10 21:44:32", dt.toString()); dt.setTimeZone(TimeZone.getTimeZone("Europe/London")); final int hour = dt.getField(DateField.HOUR_OF_DAY); - Assert.assertEquals(14, hour); - Assert.assertEquals("2018-07-10 14:44:32", dt.toString()); + Assertions.assertEquals(14, hour); + Assertions.assertEquals("2018-07-10 14:44:32", dt.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java b/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java index 90d158bf8..cf1b2661e 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/WeekTest.java @@ -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.time.DayOfWeek; import java.util.Calendar; @@ -11,68 +11,68 @@ public class WeekTest { @Test public void ofTest(){ //测试别名及大小写 - Assert.assertEquals(Week.SUNDAY, Week.of("sun")); - Assert.assertEquals(Week.SUNDAY, Week.of("SUN")); - Assert.assertEquals(Week.SUNDAY, Week.of("Sun")); + Assertions.assertEquals(Week.SUNDAY, Week.of("sun")); + Assertions.assertEquals(Week.SUNDAY, Week.of("SUN")); + Assertions.assertEquals(Week.SUNDAY, Week.of("Sun")); //测试全名及大小写 - Assert.assertEquals(Week.SUNDAY, Week.of("sunday")); - Assert.assertEquals(Week.SUNDAY, Week.of("Sunday")); - Assert.assertEquals(Week.SUNDAY, Week.of("SUNDAY")); + Assertions.assertEquals(Week.SUNDAY, Week.of("sunday")); + Assertions.assertEquals(Week.SUNDAY, Week.of("Sunday")); + Assertions.assertEquals(Week.SUNDAY, Week.of("SUNDAY")); - Assert.assertEquals(Week.MONDAY, Week.of("Mon")); - Assert.assertEquals(Week.MONDAY, Week.of("Monday")); + Assertions.assertEquals(Week.MONDAY, Week.of("Mon")); + Assertions.assertEquals(Week.MONDAY, Week.of("Monday")); - Assert.assertEquals(Week.TUESDAY, Week.of("tue")); - Assert.assertEquals(Week.TUESDAY, Week.of("tuesday")); + Assertions.assertEquals(Week.TUESDAY, Week.of("tue")); + Assertions.assertEquals(Week.TUESDAY, Week.of("tuesday")); - Assert.assertEquals(Week.WEDNESDAY, Week.of("wed")); - Assert.assertEquals(Week.WEDNESDAY, Week.of("WEDNESDAY")); + Assertions.assertEquals(Week.WEDNESDAY, Week.of("wed")); + Assertions.assertEquals(Week.WEDNESDAY, Week.of("WEDNESDAY")); - Assert.assertEquals(Week.THURSDAY, Week.of("thu")); - Assert.assertEquals(Week.THURSDAY, Week.of("THURSDAY")); + Assertions.assertEquals(Week.THURSDAY, Week.of("thu")); + Assertions.assertEquals(Week.THURSDAY, Week.of("THURSDAY")); - Assert.assertEquals(Week.FRIDAY, Week.of("fri")); - Assert.assertEquals(Week.FRIDAY, Week.of("FRIDAY")); + Assertions.assertEquals(Week.FRIDAY, Week.of("fri")); + Assertions.assertEquals(Week.FRIDAY, Week.of("FRIDAY")); - Assert.assertEquals(Week.SATURDAY, Week.of("sat")); - Assert.assertEquals(Week.SATURDAY, Week.of("SATURDAY")); + Assertions.assertEquals(Week.SATURDAY, Week.of("sat")); + Assertions.assertEquals(Week.SATURDAY, Week.of("SATURDAY")); } @Test public void ofTest2(){ - Assert.assertEquals(Week.SUNDAY, Week.of(DayOfWeek.SUNDAY)); - Assert.assertEquals(Week.MONDAY, Week.of(DayOfWeek.MONDAY)); - Assert.assertEquals(Week.TUESDAY, Week.of(DayOfWeek.TUESDAY)); - Assert.assertEquals(Week.WEDNESDAY, Week.of(DayOfWeek.WEDNESDAY)); - Assert.assertEquals(Week.THURSDAY, Week.of(DayOfWeek.THURSDAY)); - Assert.assertEquals(Week.FRIDAY, Week.of(DayOfWeek.FRIDAY)); - Assert.assertEquals(Week.SATURDAY, Week.of(DayOfWeek.SATURDAY)); - Assert.assertEquals(Week.SATURDAY, Week.of(Calendar.SATURDAY)); - Assert.assertNull(Week.of(10)); - Assert.assertNull(Week.of(-1)); + Assertions.assertEquals(Week.SUNDAY, Week.of(DayOfWeek.SUNDAY)); + Assertions.assertEquals(Week.MONDAY, Week.of(DayOfWeek.MONDAY)); + Assertions.assertEquals(Week.TUESDAY, Week.of(DayOfWeek.TUESDAY)); + Assertions.assertEquals(Week.WEDNESDAY, Week.of(DayOfWeek.WEDNESDAY)); + Assertions.assertEquals(Week.THURSDAY, Week.of(DayOfWeek.THURSDAY)); + Assertions.assertEquals(Week.FRIDAY, Week.of(DayOfWeek.FRIDAY)); + Assertions.assertEquals(Week.SATURDAY, Week.of(DayOfWeek.SATURDAY)); + Assertions.assertEquals(Week.SATURDAY, Week.of(Calendar.SATURDAY)); + Assertions.assertNull(Week.of(10)); + Assertions.assertNull(Week.of(-1)); } @Test public void toJdkDayOfWeekTest(){ - Assert.assertEquals(DayOfWeek.MONDAY, Week.MONDAY.toJdkDayOfWeek()); - Assert.assertEquals(DayOfWeek.TUESDAY, Week.TUESDAY.toJdkDayOfWeek()); - Assert.assertEquals(DayOfWeek.WEDNESDAY, Week.WEDNESDAY.toJdkDayOfWeek()); - Assert.assertEquals(DayOfWeek.THURSDAY, Week.THURSDAY.toJdkDayOfWeek()); - Assert.assertEquals(DayOfWeek.FRIDAY, Week.FRIDAY.toJdkDayOfWeek()); - Assert.assertEquals(DayOfWeek.SATURDAY, Week.SATURDAY.toJdkDayOfWeek()); - Assert.assertEquals(DayOfWeek.SUNDAY, Week.SUNDAY.toJdkDayOfWeek()); + Assertions.assertEquals(DayOfWeek.MONDAY, Week.MONDAY.toJdkDayOfWeek()); + Assertions.assertEquals(DayOfWeek.TUESDAY, Week.TUESDAY.toJdkDayOfWeek()); + Assertions.assertEquals(DayOfWeek.WEDNESDAY, Week.WEDNESDAY.toJdkDayOfWeek()); + Assertions.assertEquals(DayOfWeek.THURSDAY, Week.THURSDAY.toJdkDayOfWeek()); + Assertions.assertEquals(DayOfWeek.FRIDAY, Week.FRIDAY.toJdkDayOfWeek()); + Assertions.assertEquals(DayOfWeek.SATURDAY, Week.SATURDAY.toJdkDayOfWeek()); + Assertions.assertEquals(DayOfWeek.SUNDAY, Week.SUNDAY.toJdkDayOfWeek()); } @Test public void toChineseTest(){ - Assert.assertEquals("周一",Week.MONDAY.toChinese("周")); - Assert.assertEquals("星期一",Week.MONDAY.toChinese("星期")); - Assert.assertEquals("星期二",Week.TUESDAY.toChinese("星期")); - Assert.assertEquals("星期三",Week.WEDNESDAY.toChinese("星期")); - Assert.assertEquals("星期四",Week.THURSDAY.toChinese("星期")); - Assert.assertEquals("星期五",Week.FRIDAY.toChinese("星期")); - Assert.assertEquals("星期六",Week.SATURDAY.toChinese("星期")); - Assert.assertEquals("星期日",Week.SUNDAY.toChinese("星期")); - Assert.assertEquals("星期一",Week.MONDAY.toChinese()); + Assertions.assertEquals("周一",Week.MONDAY.toChinese("周")); + Assertions.assertEquals("星期一",Week.MONDAY.toChinese("星期")); + Assertions.assertEquals("星期二",Week.TUESDAY.toChinese("星期")); + Assertions.assertEquals("星期三",Week.WEDNESDAY.toChinese("星期")); + Assertions.assertEquals("星期四",Week.THURSDAY.toChinese("星期")); + Assertions.assertEquals("星期五",Week.FRIDAY.toChinese("星期")); + Assertions.assertEquals("星期六",Week.SATURDAY.toChinese("星期")); + Assertions.assertEquals("星期日",Week.SUNDAY.toChinese("星期")); + Assertions.assertEquals("星期一",Week.MONDAY.toChinese()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java b/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java index 07479928e..7b31b0924 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/ZodiacTest.java @@ -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; @@ -9,26 +9,26 @@ public class ZodiacTest { @Test public void getZodiacTest() { - Assert.assertEquals("摩羯座", Zodiac.getZodiac(Month.JANUARY, 19)); - Assert.assertEquals("水瓶座", Zodiac.getZodiac(Month.JANUARY, 20)); - Assert.assertEquals("巨蟹座", Zodiac.getZodiac(6, 17)); + Assertions.assertEquals("摩羯座", Zodiac.getZodiac(Month.JANUARY, 19)); + Assertions.assertEquals("水瓶座", Zodiac.getZodiac(Month.JANUARY, 20)); + Assertions.assertEquals("巨蟹座", Zodiac.getZodiac(6, 17)); final Calendar calendar = Calendar.getInstance(); calendar.set(2022, Calendar.JULY, 17); - Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar.getTime())); - Assert.assertEquals("巨蟹座", Zodiac.getZodiac(calendar)); - Assert.assertNull(Zodiac.getZodiac((Calendar) null)); + Assertions.assertEquals("巨蟹座", Zodiac.getZodiac(calendar.getTime())); + Assertions.assertEquals("巨蟹座", Zodiac.getZodiac(calendar)); + Assertions.assertNull(Zodiac.getZodiac((Calendar) null)); } @Test public void getChineseZodiacTest() { - Assert.assertEquals("狗", Zodiac.getChineseZodiac(1994)); - Assert.assertEquals("狗", Zodiac.getChineseZodiac(2018)); - Assert.assertEquals("猪", Zodiac.getChineseZodiac(2019)); + Assertions.assertEquals("狗", Zodiac.getChineseZodiac(1994)); + Assertions.assertEquals("狗", Zodiac.getChineseZodiac(2018)); + Assertions.assertEquals("猪", Zodiac.getChineseZodiac(2019)); final Calendar calendar = Calendar.getInstance(); calendar.set(2022, Calendar.JULY, 17); - Assert.assertEquals("虎", Zodiac.getChineseZodiac(calendar.getTime())); - Assert.assertEquals("虎", Zodiac.getChineseZodiac(calendar)); - Assert.assertNull(Zodiac.getChineseZodiac(1899)); - Assert.assertNull(Zodiac.getChineseZodiac((Calendar) null)); + Assertions.assertEquals("虎", Zodiac.getChineseZodiac(calendar.getTime())); + Assertions.assertEquals("虎", Zodiac.getChineseZodiac(calendar)); + Assertions.assertNull(Zodiac.getChineseZodiac(1899)); + Assertions.assertNull(Zodiac.getChineseZodiac((Calendar) null)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/ZoneUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/date/ZoneUtilTest.java index c9a3f14ea..50432cf7f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/ZoneUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/ZoneUtilTest.java @@ -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.time.ZoneId; import java.util.TimeZone; @@ -10,7 +10,7 @@ public class ZoneUtilTest { @Test public void test() { - Assert.assertEquals(ZoneId.systemDefault(), ZoneUtil.toZoneId(null)); - Assert.assertEquals(TimeZone.getDefault(), ZoneUtil.toTimeZone(null)); + Assertions.assertEquals(ZoneId.systemDefault(), ZoneUtil.toZoneId(null)); + Assertions.assertEquals(TimeZone.getDefault(), ZoneUtil.toTimeZone(null)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueI5YB1ATest.java b/hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueI5YB1ATest.java index 347cd8588..72b8fc17e 100755 --- a/hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueI5YB1ATest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/chinese/IssueI5YB1ATest.java @@ -1,13 +1,13 @@ package cn.hutool.core.date.chinese; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class IssueI5YB1ATest { @Test public void chineseDateTest() { // 四月非闰月,因此isLeapMonth参数无效 final ChineseDate date = new ChineseDate(2023, 4, 8, true); - Assert.assertEquals("2023-05-26 00:00:00", date.getGregorianDate().toString()); + Assertions.assertEquals("2023-05-26 00:00:00", date.getGregorianDate().toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/date/chinese/SolarTermsTest.java b/hutool-core/src/test/java/cn/hutool/core/date/chinese/SolarTermsTest.java index ab3a6dc8c..263a316ca 100644 --- a/hutool-core/src/test/java/cn/hutool/core/date/chinese/SolarTermsTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/date/chinese/SolarTermsTest.java @@ -1,80 +1,80 @@ package cn.hutool.core.date.chinese; 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; public class SolarTermsTest { @Test public void getTermTest1(){ final int term = SolarTerms.getTerm(1987, 3); - Assert.assertEquals(4, term); + Assertions.assertEquals(4, term); } @Test public void getTermTest() { - Assert.assertEquals("小寒", SolarTerms.getTerm(2021, 1, 5)); + Assertions.assertEquals("小寒", SolarTerms.getTerm(2021, 1, 5)); - Assert.assertEquals("大寒", SolarTerms.getTerm(2021, 1, 20)); + Assertions.assertEquals("大寒", SolarTerms.getTerm(2021, 1, 20)); - Assert.assertEquals("立春", SolarTerms.getTerm(2021, 2, 3)); + Assertions.assertEquals("立春", SolarTerms.getTerm(2021, 2, 3)); - Assert.assertEquals("雨水", SolarTerms.getTerm(2021, 2, 18)); + Assertions.assertEquals("雨水", SolarTerms.getTerm(2021, 2, 18)); - Assert.assertEquals("惊蛰", SolarTerms.getTerm(2021, 3, 5)); + Assertions.assertEquals("惊蛰", SolarTerms.getTerm(2021, 3, 5)); - Assert.assertEquals("春分", SolarTerms.getTerm(2021, 3, 20)); + Assertions.assertEquals("春分", SolarTerms.getTerm(2021, 3, 20)); - Assert.assertEquals("清明", SolarTerms.getTerm(2021, 4, 4)); + Assertions.assertEquals("清明", SolarTerms.getTerm(2021, 4, 4)); - Assert.assertEquals("谷雨", SolarTerms.getTerm(2021, 4, 20)); + Assertions.assertEquals("谷雨", SolarTerms.getTerm(2021, 4, 20)); - Assert.assertEquals("立夏", SolarTerms.getTerm(2021, 5, 5)); + Assertions.assertEquals("立夏", SolarTerms.getTerm(2021, 5, 5)); - Assert.assertEquals("小满", SolarTerms.getTerm(2021, 5, 21)); + Assertions.assertEquals("小满", SolarTerms.getTerm(2021, 5, 21)); - Assert.assertEquals("芒种", SolarTerms.getTerm(2021, 6, 5)); + Assertions.assertEquals("芒种", SolarTerms.getTerm(2021, 6, 5)); - Assert.assertEquals("夏至", SolarTerms.getTerm(2021, 6, 21)); + Assertions.assertEquals("夏至", SolarTerms.getTerm(2021, 6, 21)); - Assert.assertEquals("小暑", SolarTerms.getTerm(2021, 7, 7)); + Assertions.assertEquals("小暑", SolarTerms.getTerm(2021, 7, 7)); - Assert.assertEquals("大暑", SolarTerms.getTerm(2021, 7, 22)); + Assertions.assertEquals("大暑", SolarTerms.getTerm(2021, 7, 22)); - Assert.assertEquals("立秋", SolarTerms.getTerm(2021, 8, 7)); + Assertions.assertEquals("立秋", SolarTerms.getTerm(2021, 8, 7)); - Assert.assertEquals("处暑", SolarTerms.getTerm(2021, 8, 23)); + Assertions.assertEquals("处暑", SolarTerms.getTerm(2021, 8, 23)); - Assert.assertEquals("白露", SolarTerms.getTerm(2021, 9, 7)); + Assertions.assertEquals("白露", SolarTerms.getTerm(2021, 9, 7)); - Assert.assertEquals("秋分", SolarTerms.getTerm(2021, 9, 23)); + Assertions.assertEquals("秋分", SolarTerms.getTerm(2021, 9, 23)); - Assert.assertEquals("寒露", SolarTerms.getTerm(2021, 10, 8)); + Assertions.assertEquals("寒露", SolarTerms.getTerm(2021, 10, 8)); - Assert.assertEquals("霜降", SolarTerms.getTerm(2021, 10, 23)); + Assertions.assertEquals("霜降", SolarTerms.getTerm(2021, 10, 23)); - Assert.assertEquals("立冬", SolarTerms.getTerm(2021, 11, 7)); + Assertions.assertEquals("立冬", SolarTerms.getTerm(2021, 11, 7)); - Assert.assertEquals("小雪", SolarTerms.getTerm(2021, 11, 22)); + Assertions.assertEquals("小雪", SolarTerms.getTerm(2021, 11, 22)); - Assert.assertEquals("大雪", SolarTerms.getTerm(2021, 12, 7)); + Assertions.assertEquals("大雪", SolarTerms.getTerm(2021, 12, 7)); - Assert.assertEquals("冬至", SolarTerms.getTerm(2021, 12, 21)); + Assertions.assertEquals("冬至", SolarTerms.getTerm(2021, 12, 21)); } @Test public void getTermByDateTest() { - Assert.assertEquals("春分", SolarTerms.getTerm(DateUtil.parse("2021-03-20"))); - Assert.assertEquals("处暑", SolarTerms.getTerm(DateUtil.parse("2022-08-23"))); + Assertions.assertEquals("春分", SolarTerms.getTerm(DateUtil.parse("2021-03-20"))); + Assertions.assertEquals("处暑", SolarTerms.getTerm(DateUtil.parse("2022-08-23"))); } @Test public void getTermByChineseDateTest() { - Assert.assertEquals("清明", SolarTerms.getTerm(new ChineseDate(2021, 2, 23))); - Assert.assertEquals("秋分", SolarTerms.getTerm(new ChineseDate(2022, 8, 28))); + Assertions.assertEquals("清明", SolarTerms.getTerm(new ChineseDate(2021, 2, 23))); + Assertions.assertEquals("秋分", SolarTerms.getTerm(new ChineseDate(2022, 8, 28))); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/exceptions/ExceptionUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/exceptions/ExceptionUtilTest.java index 1c001db89..736b3db8f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/exceptions/ExceptionUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/exceptions/ExceptionUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.exceptions; import cn.hutool.core.convert.Convert; import cn.hutool.core.io.IORuntimeException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -17,14 +17,14 @@ public class ExceptionUtilTest { @Test public void wrapTest() { final IORuntimeException e = ExceptionUtil.wrap(new IOException(), IORuntimeException.class); - Assert.assertNotNull(e); + Assertions.assertNotNull(e); } @Test public void getRootTest() { // 查找入口方法 final StackTraceElement ele = ExceptionUtil.getRootStackElement(); - Assert.assertEquals("main", ele.getMethodName()); + Assertions.assertEquals("main", ele.getMethodName()); } @Test @@ -33,17 +33,17 @@ public class ExceptionUtilTest { final IOException ioException = new IOException(); final IllegalArgumentException argumentException = new IllegalArgumentException(ioException); final IOException ioException1 = ExceptionUtil.convertFromOrSuppressedThrowable(argumentException, IOException.class, true); - Assert.assertNotNull(ioException1); + Assertions.assertNotNull(ioException1); } @Test public void bytesIntConvertTest(){ final String s = Convert.toStr(12); final int integer = Convert.toInt(s); - Assert.assertEquals(12, integer); + Assertions.assertEquals(12, integer); final byte[] bytes = Convert.intToBytes(12); final int i = Convert.bytesToInt(bytes); - Assert.assertEquals(12, i); + Assertions.assertEquals(12, i); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/BomReaderTest.java b/hutool-core/src/test/java/cn/hutool/core/io/BomReaderTest.java index 42c2acc50..7b33922a5 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/BomReaderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/BomReaderTest.java @@ -1,14 +1,14 @@ package cn.hutool.core.io; import cn.hutool.core.io.file.FileUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BomReaderTest { @Test public void readTest() { final BomReader bomReader = FileUtil.getBOMReader(FileUtil.file("with_bom.txt")); final String read = IoUtil.read(bomReader, true); - Assert.assertEquals("此文本包含BOM头信息,用于测试BOM头读取", read); + Assertions.assertEquals("此文本包含BOM头信息,用于测试BOM头读取", read); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/BufferUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/BufferUtilTest.java index b3968aff4..0663e8c89 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/BufferUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/BufferUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.io; import java.nio.ByteBuffer; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.text.StrUtil; @@ -22,7 +22,7 @@ public class BufferUtilTest { final ByteBuffer buffer = ByteBuffer.wrap(bytes); final ByteBuffer buffer2 = BufferUtil.copy(buffer, ByteBuffer.allocate(5)); - Assert.assertEquals("AAABB", StrUtil.utf8Str(buffer2)); + Assertions.assertEquals("AAABB", StrUtil.utf8Str(buffer2)); } @Test @@ -31,7 +31,7 @@ public class BufferUtilTest { final ByteBuffer buffer = ByteBuffer.wrap(bytes); final byte[] bs = BufferUtil.readBytes(buffer, 5); - Assert.assertEquals("AAABB", StrUtil.utf8Str(bs)); + Assertions.assertEquals("AAABB", StrUtil.utf8Str(bs)); } @Test @@ -40,7 +40,7 @@ public class BufferUtilTest { final ByteBuffer buffer = ByteBuffer.wrap(bytes); final byte[] bs = BufferUtil.readBytes(buffer, 5); - Assert.assertEquals("AAABB", StrUtil.utf8Str(bs)); + Assertions.assertEquals("AAABB", StrUtil.utf8Str(bs)); } @Test @@ -50,17 +50,17 @@ public class BufferUtilTest { // 第一行 String line = BufferUtil.readLine(buffer, CharsetUtil.UTF_8); - Assert.assertEquals("aa", line); + Assertions.assertEquals("aa", line); // 第二行 line = BufferUtil.readLine(buffer, CharsetUtil.UTF_8); - Assert.assertEquals("bbb", line); + Assertions.assertEquals("bbb", line); // 第三行因为没有行结束标志,因此返回null line = BufferUtil.readLine(buffer, CharsetUtil.UTF_8); - Assert.assertNull(line); + Assertions.assertNull(line); // 读取剩余部分 - Assert.assertEquals("cc", StrUtil.utf8Str(BufferUtil.readBytes(buffer))); + Assertions.assertEquals("cc", StrUtil.utf8Str(BufferUtil.readBytes(buffer))); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/CharsetDetectorTest.java b/hutool-core/src/test/java/cn/hutool/core/io/CharsetDetectorTest.java index e487e40ed..be4075f23 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/CharsetDetectorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/CharsetDetectorTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.io; import cn.hutool.core.io.resource.ResourceUtil; 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.nio.charset.Charset; @@ -14,6 +14,6 @@ public class CharsetDetectorTest { // 测试多个Charset对同一个流的处理是否有问题 final Charset detect = CharsetDetector.detect(ResourceUtil.getStream("test.xml"), CharsetUtil.GBK, CharsetUtil.UTF_8); - Assert.assertEquals(CharsetUtil.UTF_8, detect); + Assertions.assertEquals(CharsetUtil.UTF_8, detect); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/ClassPathResourceTest.java b/hutool-core/src/test/java/cn/hutool/core/io/ClassPathResourceTest.java index f98042480..1e12ce858 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/ClassPathResourceTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/ClassPathResourceTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.io; import cn.hutool.core.io.resource.ClassPathResource; 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.io.IOException; import java.util.Properties; @@ -19,7 +19,7 @@ public class ClassPathResourceTest { public void readStringTest() { final ClassPathResource resource = new ClassPathResource("test.properties"); final String content = resource.readUtf8Str(); - Assert.assertTrue(StrUtil.isNotEmpty(content)); + Assertions.assertTrue(StrUtil.isNotEmpty(content)); } @Test @@ -27,7 +27,7 @@ public class ClassPathResourceTest { // 读取classpath根目录测试 final ClassPathResource resource = new ClassPathResource("/"); final String content = resource.readUtf8Str(); - Assert.assertTrue(StrUtil.isNotEmpty(content)); + Assertions.assertTrue(StrUtil.isNotEmpty(content)); } @Test @@ -36,27 +36,27 @@ public class ClassPathResourceTest { final Properties properties = new Properties(); properties.load(resource.getStream()); - Assert.assertEquals("1", properties.get("a")); - Assert.assertEquals("2", properties.get("b")); + Assertions.assertEquals("1", properties.get("a")); + Assertions.assertEquals("2", properties.get("b")); } @Test public void readFromJarTest() { //测试读取junit的jar包下的LICENSE-junit.txt文件 - final ClassPathResource resource = new ClassPathResource("LICENSE-junit.txt"); + final ClassPathResource resource = new ClassPathResource("META-INF/LICENSE.md"); String result = resource.readUtf8Str(); - Assert.assertNotNull(result); + Assertions.assertNotNull(result); //二次读取测试,用于测试关闭流对再次读取的影响 result = resource.readUtf8Str(); - Assert.assertNotNull(result); + Assertions.assertNotNull(result); } @Test public void getAbsTest() { - final ClassPathResource resource = new ClassPathResource("LICENSE-junit.txt"); + final ClassPathResource resource = new ClassPathResource("META-INF/LICENSE.md"); final String absPath = resource.getAbsolutePath(); - Assert.assertTrue(absPath.contains("LICENSE-junit.txt")); + Assertions.assertTrue(absPath.contains("LICENSE")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/FastStringWriterTest.java b/hutool-core/src/test/java/cn/hutool/core/io/FastStringWriterTest.java index c9fa99a44..e77673c80 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/FastStringWriterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/FastStringWriterTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.io; 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; public class FastStringWriterTest { @@ -12,6 +12,6 @@ public class FastStringWriterTest { final FastStringWriter fastStringWriter = new FastStringWriter(IoUtil.DEFAULT_BUFFER_SIZE); fastStringWriter.write(StrUtil.repeat("hutool", 2)); - Assert.assertEquals("hutoolhutool", fastStringWriter.toString()); + Assertions.assertEquals("hutoolhutool", fastStringWriter.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/FileReaderTest.java b/hutool-core/src/test/java/cn/hutool/core/io/FileReaderTest.java index b698b5ecf..827af2770 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/FileReaderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/FileReaderTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.io; import cn.hutool.core.io.file.FileUtil; 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 cn.hutool.core.io.file.FileReader; @@ -21,20 +21,20 @@ public class FileReaderTest { public void fileReaderTest(){ final FileReader fileReader = FileReader.of(FileUtil.file("test.properties")); final String result = fileReader.readString(); - Assert.assertNotNull(result); + Assertions.assertNotNull(result); } @Test public void readLinesTest() { final FileReader fileReader = FileReader.of(FileUtil.file("test.properties")); final List strings = fileReader.readLines(); - Assert.assertEquals(6, strings.size()); + Assertions.assertEquals(6, strings.size()); } @Test public void readLinesTest2() { final FileReader fileReader = FileReader.of(FileUtil.file("test.properties")); final List strings = fileReader.readLines(new ArrayList<>(), StrUtil::isNotBlank); - Assert.assertEquals(5, strings.size()); + Assertions.assertEquals(5, strings.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/FileTypeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/FileTypeUtilTest.java index 3c6da37ff..a90417e73 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/FileTypeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/FileTypeUtilTest.java @@ -4,9 +4,9 @@ import cn.hutool.core.io.file.FileTypeUtil; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.resource.ResourceUtil; 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.BufferedInputStream; import java.io.File; @@ -22,28 +22,28 @@ public class FileTypeUtilTest { @Test public void getTypeTest() { final String type = FileTypeUtil.getType(ResourceUtil.getStream("hutool.jpg")); - Assert.assertEquals("jpg", type); + Assertions.assertEquals("jpg", type); } @Test public void customTypeTest() { final File file = FileUtil.file("hutool.jpg"); final String type = FileTypeUtil.getType(file); - Assert.assertEquals("jpg", type); + Assertions.assertEquals("jpg", type); final String oldType = FileTypeUtil.putFileType("ffd8ffe000104a464946", "new_jpg"); - Assert.assertNull(oldType); + Assertions.assertNull(oldType); final String newType = FileTypeUtil.getType(file); - Assert.assertEquals("new_jpg", newType); + Assertions.assertEquals("new_jpg", newType); FileTypeUtil.removeFileType("ffd8ffe000104a464946"); final String type2 = FileTypeUtil.getType(file); - Assert.assertEquals("jpg", type2); + Assertions.assertEquals("jpg", type2); } @Test - @Ignore + @Disabled public void emptyTest() { final File file = FileUtil.file("d:/empty.txt"); final String type = FileTypeUtil.getType(file); @@ -51,7 +51,7 @@ public class FileTypeUtilTest { } @Test - @Ignore + @Disabled public void docTest() { final File file = FileUtil.file("f:/test/test.doc"); final String type = FileTypeUtil.getType(file); @@ -59,27 +59,27 @@ public class FileTypeUtilTest { } @Test - @Ignore + @Disabled public void inputStreamAndFilenameTest() { final File file = FileUtil.file("e:/laboratory/test.xlsx"); final String type = FileTypeUtil.getType(file); - Assert.assertEquals("xlsx", type); + Assertions.assertEquals("xlsx", type); } @Test - @Ignore + @Disabled public void getTypeFromInputStream() throws IOException { final File file = FileUtil.file("d:/test/pic.jpg"); final BufferedInputStream inputStream = FileUtil.getInputStream(file); inputStream.mark(0); final String type = FileTypeUtil.getType(inputStream); - Assert.assertEquals("jpg", type); + Assertions.assertEquals("jpg", type); inputStream.reset(); } @Test - @Ignore + @Disabled public void webpTest() { // https://gitee.com/dromara/hutool/issues/I5BGTF final File file = FileUtil.file("d:/test/a.webp"); @@ -92,6 +92,6 @@ public class FileTypeUtilTest { public void issueI6MACITest() { final File file = FileUtil.file("1.txt"); final String type = FileTypeUtil.getType(file); - Assert.assertEquals("txt", type); + Assertions.assertEquals("txt", type); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/FileUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/FileUtilTest.java index b5aac3796..f8418c82a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/FileUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/FileUtilTest.java @@ -7,9 +7,9 @@ import cn.hutool.core.io.file.LineSeparator; import cn.hutool.core.lang.Console; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.SystemUtil; -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.nio.file.Path; @@ -23,46 +23,48 @@ import java.util.List; */ public class FileUtilTest { - @Test(expected = IllegalArgumentException.class) + @Test public void fileTest() { - final File file = FileUtil.file("d:/aaa", "bbb"); - Assert.assertNotNull(file); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + final File file = FileUtil.file("d:/aaa", "bbb"); + Assertions.assertNotNull(file); - // 构建目录中出现非子目录抛出异常 - FileUtil.file(file, "../ccc"); + // 构建目录中出现非子目录抛出异常 + FileUtil.file(file, "../ccc"); - FileUtil.file("E:/"); + FileUtil.file("E:/"); + }); } @Test public void getAbsolutePathTest() { final String absolutePath = FileUtil.getAbsolutePath("LICENSE-junit.txt"); - Assert.assertNotNull(absolutePath); + Assertions.assertNotNull(absolutePath); final String absolutePath2 = FileUtil.getAbsolutePath(absolutePath); - Assert.assertNotNull(absolutePath2); - Assert.assertEquals(absolutePath, absolutePath2); + Assertions.assertNotNull(absolutePath2); + Assertions.assertEquals(absolutePath, absolutePath2); String path = FileUtil.getAbsolutePath("中文.xml"); - Assert.assertTrue(path.contains("中文.xml")); + Assertions.assertTrue(path.contains("中文.xml")); path = FileUtil.getAbsolutePath("d:"); - Assert.assertEquals("d:", path); + Assertions.assertEquals("d:", path); } @Test - @Ignore + @Disabled public void touchTest() { FileUtil.touch("d:\\tea\\a.jpg"); } @Test - @Ignore + @Disabled public void renameTest() { FileUtil.rename(FileUtil.file("d:/test/3.jpg"), "2.jpg", false); } @Test - @Ignore + @Disabled public void renameTest2() { FileUtil.move(FileUtil.file("d:/test/a"), FileUtil.file("d:/test/b"), false); } @@ -74,12 +76,12 @@ public class FileUtilTest { FileUtil.copy(srcFile, destFile, true); - Assert.assertTrue(destFile.exists()); - Assert.assertEquals(srcFile.length(), destFile.length()); + Assertions.assertTrue(destFile.exists()); + Assertions.assertEquals(srcFile.length(), destFile.length()); } @Test - @Ignore + @Disabled public void copyDirTest() { final File srcFile = FileUtil.file("D:\\test"); final File destFile = FileUtil.file("E:\\"); @@ -88,7 +90,7 @@ public class FileUtilTest { } @Test - @Ignore + @Disabled public void moveDirTest() { final File srcFile = FileUtil.file("E:\\test2"); final File destFile = FileUtil.file("D:\\"); @@ -103,18 +105,18 @@ public class FileUtilTest { final File destFile = FileUtil.file("d:/hutool.jpg"); final boolean equals = FileUtil.equals(srcFile, destFile); - Assert.assertTrue(equals); + Assertions.assertTrue(equals); // 源文件存在,目标文件不存在 final File srcFile1 = FileUtil.file("hutool.jpg"); final File destFile1 = FileUtil.file("d:/hutool.jpg"); final boolean notEquals = FileUtil.equals(srcFile1, destFile1); - Assert.assertFalse(notEquals); + Assertions.assertFalse(notEquals); } @Test - @Ignore + @Disabled public void convertLineSeparatorTest() { FileUtil.convertLineSeparator(FileUtil.file("d:/aaa.txt"), CharsetUtil.UTF_8, LineSeparator.WINDOWS); } @@ -122,33 +124,33 @@ public class FileUtilTest { @Test public void normalizeHomePathTest() { final String home = SystemUtil.getUserHomePath().replace('\\', '/'); - Assert.assertEquals(home + "/bar/", FileUtil.normalize("~/foo/../bar/")); + Assertions.assertEquals(home + "/bar/", FileUtil.normalize("~/foo/../bar/")); } @Test public void normalizeHomePathTest2() { final String home = SystemUtil.getUserHomePath().replace('\\', '/'); // 多个~应该只替换开头的 - Assert.assertEquals(home + "/~bar/", FileUtil.normalize("~/foo/../~bar/")); + Assertions.assertEquals(home + "/~bar/", FileUtil.normalize("~/foo/../~bar/")); } @Test public void normalizeClassPathTest() { - Assert.assertEquals("", FileUtil.normalize("classpath:")); + Assertions.assertEquals("", FileUtil.normalize("classpath:")); } @Test public void normalizeClassPathTest2() { - Assert.assertEquals("../a/b.csv", FileUtil.normalize("../a/b.csv")); - Assert.assertEquals("../../../a/b.csv", FileUtil.normalize("../../../a/b.csv")); + Assertions.assertEquals("../a/b.csv", FileUtil.normalize("../a/b.csv")); + Assertions.assertEquals("../../../a/b.csv", FileUtil.normalize("../../../a/b.csv")); } @Test public void doubleNormalizeTest() { final String normalize = FileUtil.normalize("/aa/b:/c"); final String normalize2 = FileUtil.normalize(normalize); - Assert.assertEquals("/aa/b:/c", normalize); - Assert.assertEquals(normalize, normalize2); + Assertions.assertEquals("/aa/b:/c", normalize); + Assertions.assertEquals(normalize, normalize2); } @Test @@ -156,45 +158,45 @@ public class FileUtilTest { final Path path = Paths.get("/aaa/bbb/ccc/ddd/eee/fff"); Path subPath = FileUtil.subPath(path, 5, 4); - Assert.assertEquals("eee", subPath.toString()); + Assertions.assertEquals("eee", subPath.toString()); subPath = FileUtil.subPath(path, 0, 1); - Assert.assertEquals("aaa", subPath.toString()); + Assertions.assertEquals("aaa", subPath.toString()); subPath = FileUtil.subPath(path, 1, 0); - Assert.assertEquals("aaa", subPath.toString()); + Assertions.assertEquals("aaa", subPath.toString()); // 负数 subPath = FileUtil.subPath(path, -1, 0); - Assert.assertEquals("aaa/bbb/ccc/ddd/eee", subPath.toString().replace('\\', '/')); + Assertions.assertEquals("aaa/bbb/ccc/ddd/eee", subPath.toString().replace('\\', '/')); subPath = FileUtil.subPath(path, -1, Integer.MAX_VALUE); - Assert.assertEquals("fff", subPath.toString()); + Assertions.assertEquals("fff", subPath.toString()); subPath = FileUtil.subPath(path, -1, path.getNameCount()); - Assert.assertEquals("fff", subPath.toString()); + Assertions.assertEquals("fff", subPath.toString()); subPath = FileUtil.subPath(path, -2, -3); - Assert.assertEquals("ddd", subPath.toString()); + Assertions.assertEquals("ddd", subPath.toString()); } @Test public void subPathTest2() { String subPath = FileUtil.subPath("d:/aaa/bbb/", "d:/aaa/bbb/ccc/"); - Assert.assertEquals("ccc/", subPath); + Assertions.assertEquals("ccc/", subPath); subPath = FileUtil.subPath("d:/aaa/bbb", "d:/aaa/bbb/ccc/"); - Assert.assertEquals("ccc/", subPath); + Assertions.assertEquals("ccc/", subPath); subPath = FileUtil.subPath("d:/aaa/bbb", "d:/aaa/bbb/ccc/test.txt"); - Assert.assertEquals("ccc/test.txt", subPath); + Assertions.assertEquals("ccc/test.txt", subPath); subPath = FileUtil.subPath("d:/aaa/bbb/", "d:/aaa/bbb/ccc"); - Assert.assertEquals("ccc", subPath); + Assertions.assertEquals("ccc", subPath); subPath = FileUtil.subPath("d:/aaa/bbb", "d:/aaa/bbb/ccc"); - Assert.assertEquals("ccc", subPath); + Assertions.assertEquals("ccc", subPath); subPath = FileUtil.subPath("d:/aaa/bbb", "d:/aaa/bbb"); - Assert.assertEquals("", subPath); + Assertions.assertEquals("", subPath); subPath = FileUtil.subPath("d:/aaa/bbb/", "d:/aaa/bbb"); - Assert.assertEquals("", subPath); + Assertions.assertEquals("", subPath); } @Test @@ -202,29 +204,29 @@ public class FileUtilTest { final Path path = Paths.get("/aaa/bbb/ccc/ddd/eee/fff"); Path ele = FileUtil.getPathEle(path, -1); - Assert.assertEquals("fff", ele.toString()); + Assertions.assertEquals("fff", ele.toString()); ele = FileUtil.getPathEle(path, 0); - Assert.assertEquals("aaa", ele.toString()); + Assertions.assertEquals("aaa", ele.toString()); ele = FileUtil.getPathEle(path, -5); - Assert.assertEquals("bbb", ele.toString()); + Assertions.assertEquals("bbb", ele.toString()); ele = FileUtil.getPathEle(path, -6); - Assert.assertEquals("aaa", ele.toString()); + Assertions.assertEquals("aaa", ele.toString()); } @Test public void listFileNamesTest() { List names = FileUtil.listFileNames("classpath:"); - Assert.assertTrue(names.contains("hutool.jpg")); + Assertions.assertTrue(names.contains("hutool.jpg")); names = FileUtil.listFileNames(""); - Assert.assertTrue(names.contains("hutool.jpg")); + Assertions.assertTrue(names.contains("hutool.jpg")); names = FileUtil.listFileNames("."); - Assert.assertTrue(names.contains("hutool.jpg")); + Assertions.assertTrue(names.contains("hutool.jpg")); } @Test - @Ignore + @Disabled public void listFileNamesInJarTest() { final List names = FileUtil.listFileNames("d:/test/hutool-core-5.1.0.jar!/cn/hutool/core/util "); for (final String name : names) { @@ -233,7 +235,7 @@ public class FileUtilTest { } @Test - @Ignore + @Disabled public void listFileNamesTest2() { final List names = FileUtil.listFileNames("D:\\m2_repo\\commons-cli\\commons-cli\\1.0\\commons-cli-1.0.jar!org/apache/commons/cli/"); for (final String string : names) { @@ -242,7 +244,7 @@ public class FileUtilTest { } @Test - @Ignore + @Disabled public void loopFilesTest() { final List files = FileUtil.loopFiles("d:/"); for (final File file : files) { @@ -251,13 +253,13 @@ public class FileUtilTest { } @Test - @Ignore + @Disabled public void loopFilesTest2() { FileUtil.loopFiles("").forEach(Console::log); } @Test - @Ignore + @Disabled public void loopFilesWithDepthTest() { final List files = FileUtil.loopFiles(FileUtil.file("d:/m2_repo"), 2, null); for (final File file : files) { @@ -270,22 +272,22 @@ public class FileUtilTest { // 只在Windows下测试 if (FileUtil.isWindows()) { File parent = FileUtil.getParent(FileUtil.file("d:/aaa/bbb/cc/ddd"), 0); - Assert.assertEquals(FileUtil.file("d:\\aaa\\bbb\\cc\\ddd"), parent); + Assertions.assertEquals(FileUtil.file("d:\\aaa\\bbb\\cc\\ddd"), parent); parent = FileUtil.getParent(FileUtil.file("d:/aaa/bbb/cc/ddd"), 1); - Assert.assertEquals(FileUtil.file("d:\\aaa\\bbb\\cc"), parent); + Assertions.assertEquals(FileUtil.file("d:\\aaa\\bbb\\cc"), parent); parent = FileUtil.getParent(FileUtil.file("d:/aaa/bbb/cc/ddd"), 2); - Assert.assertEquals(FileUtil.file("d:\\aaa\\bbb"), parent); + Assertions.assertEquals(FileUtil.file("d:\\aaa\\bbb"), parent); parent = FileUtil.getParent(FileUtil.file("d:/aaa/bbb/cc/ddd"), 4); - Assert.assertEquals(FileUtil.file("d:\\"), parent); + Assertions.assertEquals(FileUtil.file("d:\\"), parent); parent = FileUtil.getParent(FileUtil.file("d:/aaa/bbb/cc/ddd"), 5); - Assert.assertNull(parent); + Assertions.assertNull(parent); parent = FileUtil.getParent(FileUtil.file("d:/aaa/bbb/cc/ddd"), 10); - Assert.assertNull(parent); + Assertions.assertNull(parent); } } @@ -293,164 +295,164 @@ public class FileUtilTest { public void lastIndexOfSeparatorTest() { final String dir = "d:\\aaa\\bbb\\cc\\ddd"; final int index = FileUtil.lastIndexOfSeparator(dir); - Assert.assertEquals(13, index); + Assertions.assertEquals(13, index); final String file = "ddd.jpg"; final int index2 = FileUtil.lastIndexOfSeparator(file); - Assert.assertEquals(-1, index2); + Assertions.assertEquals(-1, index2); } @Test public void getNameTest() { String path = "d:\\aaa\\bbb\\cc\\ddd\\"; String name = FileNameUtil.getName(path); - Assert.assertEquals("ddd", name); + Assertions.assertEquals("ddd", name); path = "d:\\aaa\\bbb\\cc\\ddd.jpg"; name = FileNameUtil.getName(path); - Assert.assertEquals("ddd.jpg", name); + Assertions.assertEquals("ddd.jpg", name); } @Test public void mainNameTest() { String path = "d:\\aaa\\bbb\\cc\\ddd\\"; String mainName = FileNameUtil.mainName(path); - Assert.assertEquals("ddd", mainName); + Assertions.assertEquals("ddd", mainName); path = "d:\\aaa\\bbb\\cc\\ddd"; mainName = FileNameUtil.mainName(path); - Assert.assertEquals("ddd", mainName); + Assertions.assertEquals("ddd", mainName); path = "d:\\aaa\\bbb\\cc\\ddd.jpg"; mainName = FileNameUtil.mainName(path); - Assert.assertEquals("ddd", mainName); + Assertions.assertEquals("ddd", mainName); } @Test public void extNameTest() { String path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\ddd\\" : "~/Desktop/hutool/ddd/"; String mainName = FileNameUtil.extName(path); - Assert.assertEquals("", mainName); + Assertions.assertEquals("", mainName); path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\ddd" : "~/Desktop/hutool/ddd"; mainName = FileNameUtil.extName(path); - Assert.assertEquals("", mainName); + Assertions.assertEquals("", mainName); path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\ddd.jpg" : "~/Desktop/hutool/ddd.jpg"; mainName = FileNameUtil.extName(path); - Assert.assertEquals("jpg", mainName); + Assertions.assertEquals("jpg", mainName); path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.xlsx" : "~/Desktop/hutool/fff.xlsx"; mainName = FileNameUtil.extName(path); - Assert.assertEquals("xlsx", mainName); + Assertions.assertEquals("xlsx", mainName); path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.gz" : "~/Desktop/hutool/fff.tar.gz"; mainName = FileNameUtil.extName(path); - Assert.assertEquals("tar.gz", mainName); + Assertions.assertEquals("tar.gz", mainName); path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.Z" : "~/Desktop/hutool/fff.tar.Z"; mainName = FileNameUtil.extName(path); - Assert.assertEquals("tar.Z", mainName); + Assertions.assertEquals("tar.Z", mainName); path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.bz2" : "~/Desktop/hutool/fff.tar.bz2"; mainName = FileNameUtil.extName(path); - Assert.assertEquals("tar.bz2", mainName); + Assertions.assertEquals("tar.bz2", mainName); path = FileUtil.isWindows() ? "d:\\aaa\\bbb\\cc\\fff.tar.xz" : "~/Desktop/hutool/fff.tar.xz"; mainName = FileNameUtil.extName(path); - Assert.assertEquals("tar.xz", mainName); + Assertions.assertEquals("tar.xz", mainName); } @Test public void getWebRootTest() { final File webRoot = FileUtil.getWebRoot(); - Assert.assertNotNull(webRoot); - Assert.assertEquals("hutool-core", webRoot.getName()); + Assertions.assertNotNull(webRoot); + Assertions.assertEquals("hutool-core", webRoot.getName()); } @Test public void getMimeTypeTest() { String mimeType = FileUtil.getMimeType("test2Write.jpg"); - Assert.assertEquals("image/jpeg", mimeType); + Assertions.assertEquals("image/jpeg", mimeType); mimeType = FileUtil.getMimeType("test2Write.html"); - Assert.assertEquals("text/html", mimeType); + Assertions.assertEquals("text/html", mimeType); mimeType = FileUtil.getMimeType("main.css"); - Assert.assertEquals("text/css", mimeType); + Assertions.assertEquals("text/css", mimeType); mimeType = FileUtil.getMimeType("test.js"); - Assert.assertEquals("application/x-javascript", mimeType); + Assertions.assertEquals("application/x-javascript", mimeType); // office03 mimeType = FileUtil.getMimeType("test.doc"); - Assert.assertEquals("application/msword", mimeType); + Assertions.assertEquals("application/msword", mimeType); mimeType = FileUtil.getMimeType("test.xls"); - Assert.assertEquals("application/vnd.ms-excel", mimeType); + Assertions.assertEquals("application/vnd.ms-excel", mimeType); mimeType = FileUtil.getMimeType("test.ppt"); - Assert.assertEquals("application/vnd.ms-powerpoint", mimeType); + Assertions.assertEquals("application/vnd.ms-powerpoint", mimeType); // office07+ mimeType = FileUtil.getMimeType("test.docx"); - Assert.assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", mimeType); + Assertions.assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", mimeType); mimeType = FileUtil.getMimeType("test.xlsx"); - Assert.assertEquals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", mimeType); + Assertions.assertEquals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", mimeType); mimeType = FileUtil.getMimeType("test.pptx"); - Assert.assertEquals("application/vnd.openxmlformats-officedocument.presentationml.presentation", mimeType); + Assertions.assertEquals("application/vnd.openxmlformats-officedocument.presentationml.presentation", mimeType); // pr#2617@Github mimeType = FileUtil.getMimeType("test.wgt"); - Assert.assertEquals("application/widget", mimeType); + Assertions.assertEquals("application/widget", mimeType); } @Test public void isSubTest() { final File file = new File("d:/test"); final File file2 = new File("d:/test2/aaa"); - Assert.assertFalse(FileUtil.isSub(file, file2)); + Assertions.assertFalse(FileUtil.isSub(file, file2)); } @Test public void isSubRelativeTest() { final File file = new File(".."); final File file2 = new File("."); - Assert.assertTrue(FileUtil.isSub(file, file2)); + Assertions.assertTrue(FileUtil.isSub(file, file2)); } @Test - @Ignore + @Disabled public void appendLinesTest(){ final List list = ListUtil.of("a", "b", "c"); FileUtil.appendLines(list, FileUtil.file("d:/test/appendLines.txt"), CharsetUtil.UTF_8); } @Test - @Ignore + @Disabled public void createTempFileTest(){ final File nullDirTempFile = FileUtil.createTempFile(); - Assert.assertTrue(nullDirTempFile.exists()); + Assertions.assertTrue(nullDirTempFile.exists()); final File suffixDirTempFile = FileUtil.createTempFile(".xlsx",true); - Assert.assertEquals("xlsx", FileNameUtil.getSuffix(suffixDirTempFile)); + Assertions.assertEquals("xlsx", FileNameUtil.getSuffix(suffixDirTempFile)); final File prefixDirTempFile = FileUtil.createTempFile("prefix",".xlsx",true); - Assert.assertTrue(FileNameUtil.getPrefix(prefixDirTempFile).startsWith("prefix")); + Assertions.assertTrue(FileNameUtil.getPrefix(prefixDirTempFile).startsWith("prefix")); } @Test - @Ignore + @Disabled public void getTotalLinesTest() { // 千万行秒级内返回 final int totalLines = FileUtil.getTotalLines(FileUtil.file("")); - Assert.assertEquals(10000000, totalLines); + Assertions.assertEquals(10000000, totalLines); } @Test public void isAbsolutePathTest(){ String path = "d:/test\\aaa.txt"; - Assert.assertTrue(FileUtil.isAbsolutePath(path)); + Assertions.assertTrue(FileUtil.isAbsolutePath(path)); path = "test\\aaa.txt"; - Assert.assertFalse(FileUtil.isAbsolutePath(path)); + Assertions.assertFalse(FileUtil.isAbsolutePath(path)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/IoUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/IoUtilTest.java index b5117c06d..4365ef94a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/IoUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/IoUtilTest.java @@ -8,8 +8,8 @@ import cn.hutool.core.io.stream.StrInputStream; import cn.hutool.core.lang.func.SerConsumer; 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; import java.io.*; import java.util.List; @@ -19,7 +19,7 @@ public class IoUtilTest { @Test public void readBytesTest() { final byte[] bytes = IoUtil.readBytes(ResourceUtil.getStream("hutool.jpg")); - Assert.assertEquals(22807, bytes.length); + Assertions.assertEquals(22807, bytes.length); } @Test @@ -27,13 +27,13 @@ public class IoUtilTest { // 读取固定长度 final int limit = RandomUtil.randomInt(22807); final byte[] bytes = IoUtil.readBytes(ResourceUtil.getStream("hutool.jpg"), limit); - Assert.assertEquals(limit, bytes.length); + Assertions.assertEquals(limit, bytes.length); } @Test public void readLinesTest() { try (final BufferedReader reader = ResourceUtil.getUtf8Reader("test_lines.csv")) { - IoUtil.readLines(reader, (SerConsumer) Assert::assertNotNull); + IoUtil.readLines(reader, (SerConsumer) Assertions::assertNotNull); } catch (final IOException e) { throw new IORuntimeException(e); } @@ -42,12 +42,13 @@ public class IoUtilTest { @Test public void readUtf8LinesTest() { final List strings = IoUtil.readUtf8Lines(ResourceUtil.getStream("text.txt"), ListUtil.of()); - Assert.assertEquals(3, strings.size()); + Assertions.assertEquals(3, strings.size()); } @Test public void readUtf8LinesTest2() { - IoUtil.readUtf8Lines(ResourceUtil.getStream("text.txt"), (SerConsumer) Assert::assertNotNull); + IoUtil.readUtf8Lines(ResourceUtil.getStream("text.txt"), + (SerConsumer) Assertions::assertNotNull); } @Test @@ -55,8 +56,8 @@ public class IoUtilTest { final BufferedInputStream stream = IoUtil.toBuffered( new ByteArrayInputStream("hutool".getBytes()), IoUtil.DEFAULT_BUFFER_SIZE); - Assert.assertNotNull(stream); - Assert.assertEquals("hutool", IoUtil.readUtf8(stream)); + Assertions.assertNotNull(stream); + Assertions.assertEquals("hutool", IoUtil.readUtf8(stream)); } @Test @@ -64,7 +65,7 @@ public class IoUtilTest { final BufferedOutputStream stream = IoUtil.toBuffered( EmptyOutputStream.INSTANCE, 512); - Assert.assertNotNull(stream); + Assertions.assertNotNull(stream); } @Test @@ -72,9 +73,9 @@ public class IoUtilTest { final BufferedReader reader = IoUtil.toBuffered( new StringReader("hutool"), 512); - Assert.assertNotNull(reader); + Assertions.assertNotNull(reader); - Assert.assertEquals("hutool", IoUtil.read(reader)); + Assertions.assertEquals("hutool", IoUtil.read(reader)); } @Test @@ -83,11 +84,11 @@ public class IoUtilTest { final BufferedWriter writer = IoUtil.toBuffered( stringWriter, 512); - Assert.assertNotNull(writer); + Assertions.assertNotNull(writer); writer.write("hutool"); writer.flush(); - Assert.assertEquals("hutool", stringWriter.toString()); + Assertions.assertEquals("hutool", stringWriter.toString()); } @Test @@ -95,28 +96,28 @@ public class IoUtilTest { final StringWriter stringWriter = new StringWriter(); final BufferedWriter writer = IoUtil.toBuffered(stringWriter); - Assert.assertNotNull(writer); + Assertions.assertNotNull(writer); writer.write("hutool"); writer.flush(); - Assert.assertEquals("hutool", stringWriter.toString()); + Assertions.assertEquals("hutool", stringWriter.toString()); } @Test public void toPushBackReaderTest() throws IOException { final PushbackReader reader = IoUtil.toPushBackReader(new StringReader("hutool"), 12); final int read = reader.read(); - Assert.assertEquals('h', read); + Assertions.assertEquals('h', read); reader.unread(read); - Assert.assertEquals("hutool", IoUtil.read(reader)); + Assertions.assertEquals("hutool", IoUtil.read(reader)); } @Test public void toAvailableStreamTest() { final InputStream in = IoUtil.toAvailableStream(StrInputStream.ofUtf8("hutool")); final String read = IoUtil.readUtf8(in); - Assert.assertEquals("hutool", read); + Assertions.assertEquals("hutool", read); } @Test @@ -137,12 +138,12 @@ public class IoUtilTest { @Test public void contentEqualsTest() { final boolean b = IoUtil.contentEquals(new StringReader("hutool"), new StringReader("hutool")); - Assert.assertTrue(b); + Assertions.assertTrue(b); } @Test public void lineIterTest() { final LineIter strings = IoUtil.lineIter(ResourceUtil.getStream("text.txt"), CharsetUtil.UTF_8); - strings.forEach(Assert::assertNotNull); + strings.forEach(Assertions::assertNotNull); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/LineReaderTest.java b/hutool-core/src/test/java/cn/hutool/core/io/LineReaderTest.java index 01bdfdc39..c188c6b4a 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/LineReaderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/LineReaderTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.io; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.resource.ResourceUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -12,19 +12,19 @@ public class LineReaderTest { public void readLfTest() { final LineReader lineReader = new LineReader(ResourceUtil.getUtf8Reader("multi_line.properties")); final ArrayList list = ListUtil.of(lineReader); - Assert.assertEquals(3, list.size()); - Assert.assertEquals("test1", list.get(0)); - Assert.assertEquals("test2=abcd\\e", list.get(1)); - Assert.assertEquals("test3=abc", list.get(2)); + Assertions.assertEquals(3, list.size()); + Assertions.assertEquals("test1", list.get(0)); + Assertions.assertEquals("test2=abcd\\e", list.get(1)); + Assertions.assertEquals("test3=abc", list.get(2)); } @Test public void readCrLfTest() { final LineReader lineReader = new LineReader(ResourceUtil.getUtf8Reader("multi_line_crlf.properties")); final ArrayList list = ListUtil.of(lineReader); - Assert.assertEquals(3, list.size()); - Assert.assertEquals("test1", list.get(0)); - Assert.assertEquals("test2=abcd\\e", list.get(1)); - Assert.assertEquals("test3=abc", list.get(2)); + Assertions.assertEquals(3, list.size()); + Assertions.assertEquals("test1", list.get(0)); + Assertions.assertEquals("test2=abcd\\e", list.get(1)); + Assertions.assertEquals("test3=abc", list.get(2)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/ManifestUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/ManifestUtilTest.java index cfa6b33f6..788857fb5 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/ManifestUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/ManifestUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.io; import cn.hutool.core.util.ManifestUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.jar.Manifest; @@ -11,6 +11,6 @@ public class ManifestUtilTest { @Test public void getManiFestTest(){ final Manifest manifest = ManifestUtil.getManifest(Test.class); - Assert.assertNotNull(manifest); + Assertions.assertNotNull(manifest); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/NioUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/NioUtilTest.java index 8a15c9f3b..94576d827 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/NioUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/NioUtilTest.java @@ -5,9 +5,9 @@ import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.io.stream.EmptyOutputStream; import cn.hutool.core.lang.Console; import cn.hutool.core.text.StrUtil; -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.BufferedInputStream; import java.io.BufferedOutputStream; @@ -22,12 +22,12 @@ public class NioUtilTest { final long size = NioUtil.copyByNIO(ResourceUtil.getStream("hutool.jpg"), EmptyOutputStream.INSTANCE, NioUtil.DEFAULT_MIDDLE_BUFFER_SIZE, null); // 确认写出 - Assert.assertEquals(file.length(), size); - Assert.assertEquals(22807, size); + Assertions.assertEquals(file.length(), size); + Assertions.assertEquals(22807, size); } @Test - @Ignore + @Disabled public void copyByNIOTest2() { final File file = FileUtil.file("d:/test/logo.jpg"); final BufferedInputStream in = FileUtil.getInputStream(file); @@ -49,12 +49,12 @@ public class NioUtilTest { Console.log("finish"); } }); - Assert.assertEquals(file.length(), copySize); + Assertions.assertEquals(file.length(), copySize); } @Test public void readUtf8Test() throws IOException { final String s = NioUtil.readUtf8(FileChannel.open(FileUtil.file("text.txt").toPath())); - Assert.assertTrue(StrUtil.isNotBlank(s)); + Assertions.assertTrue(StrUtil.isNotBlank(s)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/checksum/CRC16Test.java b/hutool-core/src/test/java/cn/hutool/core/io/checksum/CRC16Test.java index d0b9e5684..349f717a0 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/checksum/CRC16Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/checksum/CRC16Test.java @@ -10,8 +10,8 @@ import cn.hutool.core.io.checksum.crc16.CRC16Modbus; import cn.hutool.core.io.checksum.crc16.CRC16USB; import cn.hutool.core.io.checksum.crc16.CRC16X25; import cn.hutool.core.io.checksum.crc16.CRC16XModem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CRC16Test { @@ -21,74 +21,74 @@ public class CRC16Test { public void ccittTest(){ final CRC16CCITT crc16 = new CRC16CCITT(); crc16.update(data.getBytes()); - Assert.assertEquals("c852", crc16.getHexValue()); + Assertions.assertEquals("c852", crc16.getHexValue()); } @Test public void ccittFalseTest(){ final CRC16CCITTFalse crc16 = new CRC16CCITTFalse(); crc16.update(data.getBytes()); - Assert.assertEquals("a5e4", crc16.getHexValue()); + Assertions.assertEquals("a5e4", crc16.getHexValue()); } @Test public void xmodemTest(){ final CRC16XModem crc16 = new CRC16XModem(); crc16.update(data.getBytes()); - Assert.assertEquals("5a8d", crc16.getHexValue()); + Assertions.assertEquals("5a8d", crc16.getHexValue()); } @Test public void x25Test(){ final CRC16X25 crc16 = new CRC16X25(); crc16.update(data.getBytes()); - Assert.assertEquals("a152", crc16.getHexValue()); + Assertions.assertEquals("a152", crc16.getHexValue()); } @Test public void modbusTest(){ final CRC16Modbus crc16 = new CRC16Modbus(); crc16.update(data.getBytes()); - Assert.assertEquals("25fb", crc16.getHexValue()); + Assertions.assertEquals("25fb", crc16.getHexValue()); } @Test public void ibmTest(){ final CRC16IBM crc16 = new CRC16IBM(); crc16.update(data.getBytes()); - Assert.assertEquals("18c", crc16.getHexValue()); + Assertions.assertEquals("18c", crc16.getHexValue()); } @Test public void maximTest(){ final CRC16Maxim crc16 = new CRC16Maxim(); crc16.update(data.getBytes()); - Assert.assertEquals("fe73", crc16.getHexValue()); + Assertions.assertEquals("fe73", crc16.getHexValue()); } @Test public void usbTest(){ final CRC16USB crc16 = new CRC16USB(); crc16.update(data.getBytes()); - Assert.assertEquals("da04", crc16.getHexValue()); + Assertions.assertEquals("da04", crc16.getHexValue()); } @Test public void dnpTest(){ final CRC16DNP crc16 = new CRC16DNP(); crc16.update(data.getBytes()); - Assert.assertEquals("3d1a", crc16.getHexValue()); + Assertions.assertEquals("3d1a", crc16.getHexValue()); } @Test public void ansiTest(){ final CRC16Ansi crc16 = new CRC16Ansi(); crc16.update(data.getBytes()); - Assert.assertEquals("1e00", crc16.getHexValue()); + Assertions.assertEquals("1e00", crc16.getHexValue()); crc16.reset(); final String str2 = "QN=20160801085857223;ST=32;CN=1062;PW=100000;MN=010000A8900016F000169DC0;Flag=5;CP=&&RtdInterval=30&&"; crc16.update(str2.getBytes()); - Assert.assertEquals("1c80", crc16.getHexValue()); + Assertions.assertEquals("1c80", crc16.getHexValue()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/checksum/CrcTest.java b/hutool-core/src/test/java/cn/hutool/core/io/checksum/CrcTest.java index d411fd1f2..7b9350fc2 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/checksum/CrcTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/checksum/CrcTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.io.checksum; import cn.hutool.core.codec.HexUtil; import cn.hutool.core.io.checksum.crc16.CRC16XModem; 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; /** * CRC校验单元测试 @@ -23,7 +23,7 @@ public class CrcTest { -46, -128, 4, 48, 52, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 1, -32, -80, 0, 98, -5, 71, 0, 64, 0, 0, 0, 0, -116, 1, 104, 2 }; final CRC8 crc8 = new CRC8(CRC_POLYNOM, CRC_INITIAL); crc8.update(data, 0, data.length); - Assert.assertEquals(29, crc8.getValue()); + Assertions.assertEquals(29, crc8.getValue()); } @Test @@ -31,7 +31,7 @@ public class CrcTest { final CRC16 crc = new CRC16(); crc.update(12); crc.update(16); - Assert.assertEquals("cc04", HexUtil.toHex(crc.getValue())); + Assertions.assertEquals("cc04", HexUtil.toHex(crc.getValue())); } @Test @@ -40,7 +40,7 @@ public class CrcTest { final CRC16 crc = new CRC16(); crc.update(str.getBytes(), 0, str.getBytes().length); final String crc16 = HexUtil.toHex(crc.getValue()); - Assert.assertEquals("18c", crc16); + Assertions.assertEquals("18c", crc16); } @Test @@ -50,6 +50,6 @@ public class CrcTest { final CRC16XModem crc16 = new CRC16XModem(); crc16.update(ByteUtil.toUtf8Bytes(text)); final String hexValue = crc16.getHexValue(true); - Assert.assertEquals("0e04", hexValue); + Assertions.assertEquals("0e04", hexValue); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/FileNameUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/FileNameUtilTest.java index be66ac71a..2ec58257b 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/FileNameUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/FileNameUtilTest.java @@ -1,48 +1,48 @@ package cn.hutool.core.io.file; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class FileNameUtilTest { @Test public void cleanInvalidTest(){ String name = FileNameUtil.cleanInvalid("1\n2\n"); - Assert.assertEquals("12", name); + Assertions.assertEquals("12", name); name = FileNameUtil.cleanInvalid("\r1\r\n2\n"); - Assert.assertEquals("12", name); + Assertions.assertEquals("12", name); } @Test public void mainNameTest() { final String s = FileNameUtil.mainName("abc.tar.gz"); - Assert.assertEquals("abc", s); + Assertions.assertEquals("abc", s); } @Test public void normalizeTest() { - Assert.assertEquals("/foo/", FileNameUtil.normalize("/foo//")); - Assert.assertEquals("/foo/", FileNameUtil.normalize("/foo/./")); - Assert.assertEquals("/bar", FileNameUtil.normalize("/foo/../bar")); - Assert.assertEquals("/bar/", FileNameUtil.normalize("/foo/../bar/")); - Assert.assertEquals("/baz", FileNameUtil.normalize("/foo/../bar/../baz")); - Assert.assertEquals("/", FileNameUtil.normalize("/../")); - Assert.assertEquals("foo", FileNameUtil.normalize("foo/bar/..")); - Assert.assertEquals("../bar", FileNameUtil.normalize("foo/../../bar")); - Assert.assertEquals("bar", FileNameUtil.normalize("foo/../bar")); - Assert.assertEquals("/server/bar", FileNameUtil.normalize("//server/foo/../bar")); - Assert.assertEquals("/bar", FileNameUtil.normalize("//server/../bar")); - Assert.assertEquals("C:/bar", FileNameUtil.normalize("C:\\foo\\..\\bar")); + Assertions.assertEquals("/foo/", FileNameUtil.normalize("/foo//")); + Assertions.assertEquals("/foo/", FileNameUtil.normalize("/foo/./")); + Assertions.assertEquals("/bar", FileNameUtil.normalize("/foo/../bar")); + Assertions.assertEquals("/bar/", FileNameUtil.normalize("/foo/../bar/")); + Assertions.assertEquals("/baz", FileNameUtil.normalize("/foo/../bar/../baz")); + Assertions.assertEquals("/", FileNameUtil.normalize("/../")); + Assertions.assertEquals("foo", FileNameUtil.normalize("foo/bar/..")); + Assertions.assertEquals("../bar", FileNameUtil.normalize("foo/../../bar")); + Assertions.assertEquals("bar", FileNameUtil.normalize("foo/../bar")); + Assertions.assertEquals("/server/bar", FileNameUtil.normalize("//server/foo/../bar")); + Assertions.assertEquals("/bar", FileNameUtil.normalize("//server/../bar")); + Assertions.assertEquals("C:/bar", FileNameUtil.normalize("C:\\foo\\..\\bar")); // - Assert.assertEquals("C:/bar", FileNameUtil.normalize("C:\\..\\bar")); - Assert.assertEquals("../../bar", FileNameUtil.normalize("../../bar")); - Assert.assertEquals("C:/bar", FileNameUtil.normalize("/C:/bar")); - Assert.assertEquals("C:", FileNameUtil.normalize("C:")); - Assert.assertEquals("\\/192.168.1.1/Share/", FileNameUtil.normalize("\\\\192.168.1.1\\Share\\")); + Assertions.assertEquals("C:/bar", FileNameUtil.normalize("C:\\..\\bar")); + Assertions.assertEquals("../../bar", FileNameUtil.normalize("../../bar")); + Assertions.assertEquals("C:/bar", FileNameUtil.normalize("/C:/bar")); + Assertions.assertEquals("C:", FileNameUtil.normalize("C:")); + Assertions.assertEquals("\\/192.168.1.1/Share/", FileNameUtil.normalize("\\\\192.168.1.1\\Share\\")); } @Test public void normalizeBlankTest() { - Assert.assertEquals("C:/aaa ", FileNameUtil.normalize("C:\\aaa ")); + Assertions.assertEquals("C:/aaa ", FileNameUtil.normalize("C:\\aaa ")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/FileSystemUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/FileSystemUtilTest.java index 9469efe37..8ff8ac9ad 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/FileSystemUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/FileSystemUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.io.file; import cn.hutool.core.lang.Console; 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.nio.file.FileSystem; import java.nio.file.FileVisitResult; @@ -14,7 +14,7 @@ import java.nio.file.attribute.BasicFileAttributes; public class FileSystemUtilTest { @Test - @Ignore + @Disabled public void listTest(){ final FileSystem fileSystem = FileSystemUtil.createZip("d:/test/test.zip", CharsetUtil.GBK); diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/IssueI666HBTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/IssueI666HBTest.java index 934daef76..3a882c5dd 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/IssueI666HBTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/IssueI666HBTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.io.file; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * 移动情况测试,环境: @@ -13,7 +13,7 @@ import org.junit.Test; public class IssueI666HBTest { @Test - @Ignore + @Disabled public void moveDirToDirTest() { // 目录移动到目录,将整个目录移动 // 会将dir1及其内容移动到dir2下,变成dir2/dir1 @@ -21,7 +21,7 @@ public class IssueI666HBTest { } @Test - @Ignore + @Disabled public void moveContentDirToDirTest() { // 目录内容移动到目录 // 移动内容,不移除目录本身 @@ -31,7 +31,7 @@ public class IssueI666HBTest { } @Test - @Ignore + @Disabled public void moveFileToDirTest() { // 文件移动到目录 // 会将test1.txt移动到dir2下,变成dir2/test1.txt @@ -39,7 +39,7 @@ public class IssueI666HBTest { } @Test - @Ignore + @Disabled public void moveContentFileToDirTest() { // 文件移动到目录 // 会将test1.txt移动到dir2下,变成dir2/test1.txt @@ -49,7 +49,7 @@ public class IssueI666HBTest { } @Test - @Ignore + @Disabled public void moveDirToDirNotExistTest() { // 目录移动到目标,dir3不存在,将整个目录移动 // 会将目录dir1变成目录dir3 @@ -57,7 +57,7 @@ public class IssueI666HBTest { } @Test - @Ignore + @Disabled public void moveContentDirToDirNotExistTest() { // 目录移动到目标,dir3不存在 // 会将目录dir1内容移动到dir3,但是dir1目录不删除 @@ -67,7 +67,7 @@ public class IssueI666HBTest { } @Test - @Ignore + @Disabled public void moveFileToTargetNotExistTest() { // 文件移动到不存在的路径 // 会将test1.txt重命名为test2 @@ -75,7 +75,7 @@ public class IssueI666HBTest { } @Test - @Ignore + @Disabled public void moveContentFileToTargetNotExistTest() { // 目录移动到目录,将整个目录移动 // 会将test1.txt重命名为test2 diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/PathCopyTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/PathCopyTest.java index cf14871f9..bf2e38c6c 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/PathCopyTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/PathCopyTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.io.file; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.nio.file.Path; import java.nio.file.Paths; @@ -12,7 +12,7 @@ import java.nio.file.Paths; public class PathCopyTest { @Test - @Ignore + @Disabled public void copySameFileTest() { final Path path = Paths.get("d:/test/dir1/test1.txt"); //src路径和target路径相同时,不执行操作 @@ -22,7 +22,7 @@ public class PathCopyTest { } @Test - @Ignore + @Disabled public void copySameDirTest() { final Path path = Paths.get("d:/test/dir1"); //src路径和target路径相同时,不执行操作 @@ -32,7 +32,7 @@ public class PathCopyTest { } @Test - @Ignore + @Disabled public void copyFileToDirTest() { // src为文件,target为已存在目录,则拷贝到目录下,文件名不变。 PathUtil.copy( @@ -41,7 +41,7 @@ public class PathCopyTest { } @Test - @Ignore + @Disabled public void copyFileToPathNotExistTest() { // src为文件,target为不存在路径,则目标以文件对待(自动创建父级目录) // 相当于拷贝后重命名 @@ -51,7 +51,7 @@ public class PathCopyTest { } @Test - @Ignore + @Disabled public void copyFileToFileTest() { //src为文件,target是一个已存在的文件,则当{@link CopyOption}设为覆盖时会被覆盖,默认不覆盖。 PathUtil.copy( @@ -60,7 +60,7 @@ public class PathCopyTest { } @Test - @Ignore + @Disabled public void copyDirToDirTest() { //src为目录,target为已存在目录,整个src目录连同其目录拷贝到目标目录中 PathUtil.copy( @@ -69,7 +69,7 @@ public class PathCopyTest { } @Test - @Ignore + @Disabled public void copyDirToPathNotExistTest() { //src为目录,target为不存在路径,则自动创建目标为新目录,整个src目录连同其目录拷贝到目标目录中 PathUtil.copy( @@ -78,7 +78,7 @@ public class PathCopyTest { } @Test - @Ignore + @Disabled public void copyDirToFileTest() { //src为目录,target为文件,抛出IllegalArgumentException PathUtil.copy( diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/PathDeleterTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/PathDeleterTest.java index 32e9a7f1e..e4be2dee3 100755 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/PathDeleterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/PathDeleterTest.java @@ -1,26 +1,26 @@ package cn.hutool.core.io.file; -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; public class PathDeleterTest { @Test - @Ignore + @Disabled public void delFileTest() { FileUtil.touch("d:/test/exist.txt"); PathUtil.del(Paths.get("d:/test/exist.txt")); } @Test - @Ignore + @Disabled public void delDirTest() { PathUtil.del(Paths.get("d:/test/dir1")); } @Test - @Ignore + @Disabled public void cleanDirTest() { PathUtil.clean(Paths.get("d:/test/dir1")); } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java index 62fb093d2..5ade407a2 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.io.file; -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.nio.file.Paths; import java.nio.file.StandardCopyOption; @@ -10,7 +10,7 @@ import java.nio.file.StandardCopyOption; public class PathUtilTest { @Test - @Ignore + @Disabled public void copyFileTest(){ PathUtil.copy( Paths.get("d:/test/1595232240113.jpg"), @@ -21,7 +21,7 @@ public class PathUtilTest { } @Test - @Ignore + @Disabled public void copyTest(){ PathUtil.copy( Paths.get("d:/Red2_LYY"), @@ -30,7 +30,7 @@ public class PathUtilTest { } @Test - @Ignore + @Disabled public void copyContentTest(){ PathUtil.copyContent( Paths.get("d:/Red2_LYY"), @@ -39,50 +39,50 @@ public class PathUtilTest { } @Test - @Ignore + @Disabled public void moveTest(){ PathUtil.move(Paths.get("d:/lombok.jar"), Paths.get("d:/test/"), false); } @Test - @Ignore + @Disabled public void moveDirTest(){ PathUtil.move(Paths.get("c:\\aaa"), Paths.get("d:/test/looly"), false); } @Test - @Ignore + @Disabled public void delDirTest(){ PathUtil.del(Paths.get("d:/test/looly")); } @Test - @Ignore + @Disabled public void getMimeTypeTest(){ String mimeType = PathUtil.getMimeType(Paths.get("d:/test/test.jpg")); - Assert.assertEquals("image/jpeg", mimeType); + Assertions.assertEquals("image/jpeg", mimeType); mimeType = PathUtil.getMimeType(Paths.get("d:/test/test.mov")); - Assert.assertEquals("video/quicktime", mimeType); + Assertions.assertEquals("video/quicktime", mimeType); } @Test public void getMimeOfRarTest(){ final String contentType = FileUtil.getMimeType("a001.rar"); - Assert.assertEquals("application/x-rar-compressed", contentType); + Assertions.assertEquals("application/x-rar-compressed", contentType); } @Test public void getMimeOf7zTest(){ final String contentType = FileUtil.getMimeType("a001.7z"); - Assert.assertEquals("application/x-7z-compressed", contentType); + Assertions.assertEquals("application/x-7z-compressed", contentType); } /** * issue#2893 target不存在空导致异常 */ @Test - @Ignore + @Disabled public void moveTest2(){ PathUtil.move(Paths.get("D:\\project\\test1.txt"), Paths.get("D:\\project\\test2.txt"), false); } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/TailerTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/TailerTest.java index 7a365555d..107086c2d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/TailerTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/TailerTest.java @@ -1,20 +1,19 @@ package cn.hutool.core.io.file; -import org.junit.Ignore; -import org.junit.Test; - import cn.hutool.core.util.CharsetUtil; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class TailerTest { @Test - @Ignore + @Disabled public void tailTest() { FileUtil.tail(FileUtil.file("d:/test/tail.txt"), CharsetUtil.GBK); } @Test - @Ignore + @Disabled public void tailWithLinesTest() { final Tailer tailer = new Tailer(FileUtil.file("f:/test/test.log"), Tailer.CONSOLE_HANDLER, 2); tailer.start(); diff --git a/hutool-core/src/test/java/cn/hutool/core/io/resource/ResourceUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/resource/ResourceUtilTest.java index 45981ce6e..c0da16e76 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/resource/ResourceUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/resource/ResourceUtilTest.java @@ -3,34 +3,34 @@ package cn.hutool.core.io.resource; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.IoUtil; 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; public class ResourceUtilTest { @Test public void readXmlTest(){ final String str = ResourceUtil.readUtf8Str("test.xml"); - Assert.assertNotNull(str); + Assertions.assertNotNull(str); final Resource resource = new ClassPathResource("test.xml"); final String xmlStr = resource.readUtf8Str(); - Assert.assertEquals(str, xmlStr); + Assertions.assertEquals(str, xmlStr); } @Test public void stringResourceTest(){ final StringResource stringResource = new StringResource("testData", "test"); - Assert.assertEquals("test", stringResource.getName()); - Assert.assertArrayEquals("testData".getBytes(), stringResource.readBytes()); - Assert.assertArrayEquals("testData".getBytes(), IoUtil.readBytes(stringResource.getStream())); + Assertions.assertEquals("test", stringResource.getName()); + Assertions.assertArrayEquals("testData".getBytes(), stringResource.readBytes()); + Assertions.assertArrayEquals("testData".getBytes(), IoUtil.readBytes(stringResource.getStream())); } @Test public void fileResourceTest(){ final FileResource resource = new FileResource(FileUtil.file("test.xml")); - Assert.assertEquals("test.xml", resource.getName()); - Assert.assertTrue(StrUtil.isNotEmpty(resource.readUtf8Str())); + Assertions.assertEquals("test.xml", resource.getName()); + Assertions.assertTrue(StrUtil.isNotEmpty(resource.readUtf8Str())); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/unit/DataSizeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/unit/DataSizeUtilTest.java index f1ab26cca..ed8602f7d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/unit/DataSizeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/unit/DataSizeUtilTest.java @@ -1,49 +1,49 @@ package cn.hutool.core.io.unit; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DataSizeUtilTest { @Test public void parseTest(){ long parse = DataSizeUtil.parse("3M"); - Assert.assertEquals(3145728, parse); + Assertions.assertEquals(3145728, parse); parse = DataSizeUtil.parse("3m"); - Assert.assertEquals(3145728, parse); + Assertions.assertEquals(3145728, parse); parse = DataSizeUtil.parse("3MB"); - Assert.assertEquals(3145728, parse); + Assertions.assertEquals(3145728, parse); parse = DataSizeUtil.parse("3mb"); - Assert.assertEquals(3145728, parse); + Assertions.assertEquals(3145728, parse); parse = DataSizeUtil.parse("3.1M"); - Assert.assertEquals(3250585, parse); + Assertions.assertEquals(3250585, parse); parse = DataSizeUtil.parse("3.1m"); - Assert.assertEquals(3250585, parse); + Assertions.assertEquals(3250585, parse); parse = DataSizeUtil.parse("3.1MB"); - Assert.assertEquals(3250585, parse); + Assertions.assertEquals(3250585, parse); parse = DataSizeUtil.parse("-3.1MB"); - Assert.assertEquals(-3250585, parse); + Assertions.assertEquals(-3250585, parse); parse = DataSizeUtil.parse("+3.1MB"); - Assert.assertEquals(3250585, parse); + Assertions.assertEquals(3250585, parse); parse = DataSizeUtil.parse("3.1mb"); - Assert.assertEquals(3250585, parse); + Assertions.assertEquals(3250585, parse); parse = DataSizeUtil.parse("3.1"); - Assert.assertEquals(3, parse); + Assertions.assertEquals(3, parse); try { DataSizeUtil.parse("3.1.3"); } catch (final IllegalArgumentException ie) { - Assert.assertEquals("'3.1.3' is not a valid data size", ie.getMessage()); + Assertions.assertEquals("'3.1.3' is not a valid data size", ie.getMessage()); } @@ -52,12 +52,12 @@ public class DataSizeUtilTest { @Test public void formatTest(){ String format = DataSizeUtil.format(Long.MAX_VALUE); - Assert.assertEquals("8 EB", format); + Assertions.assertEquals("8 EB", format); format = DataSizeUtil.format(1024L * 1024 * 1024 * 1024 * 1024); - Assert.assertEquals("1 PB", format); + Assertions.assertEquals("1 PB", format); format = DataSizeUtil.format(1024L * 1024 * 1024 * 1024); - Assert.assertEquals("1 TB", format); + Assertions.assertEquals("1 TB", format); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java index 82ddf0bfa..21b401a0d 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/AssertTest.java @@ -3,7 +3,8 @@ package cn.hutool.core.lang; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.text.StrUtil; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.List; @@ -29,7 +30,7 @@ public class AssertTest { public void notEmptyTest() { final String a = " "; final String s = Assert.notEmpty(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); } @Test @@ -37,11 +38,11 @@ public class AssertTest { // 虽然包含空字符串或者null,但是这大概数组由于有元素,则认定为非empty String[] a = new String[]{""}; String[] s = Assert.notEmpty(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); a = new String[]{null}; s = Assert.notEmpty(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); } @Test @@ -49,11 +50,11 @@ public class AssertTest { // 虽然包含空字符串或者null,但是这大概数组由于有元素,则认定为非empty List a = ListUtil.of(""); List s = Assert.notEmpty(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); - a = ListUtil.of((String)null); + a = ListUtil.of((String) null); s = Assert.notEmpty(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); } @Test @@ -61,58 +62,68 @@ public class AssertTest { // 虽然包含空字符串或者null,但是这大概数组由于有元素,则认定为非empty Map a = MapUtil.of("", ""); Map s = Assert.notEmpty(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); a = MapUtil.of(null, null); s = Assert.notEmpty(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); } @Test public void noNullElementsTest() { final String[] a = new String[]{""}; final String[] s = Assert.noNullElements(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); } - @Test(expected = IllegalArgumentException.class) + @Test public void noNullElementsTest2() { - final String[] a = new String[]{null}; - Assert.noNullElements(a); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + final String[] a = new String[]{null}; + Assert.noNullElements(a); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void noNullElementsTest3() { - final String[] a = new String[]{"a", null}; - Assert.noNullElements(a); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + final String[] a = new String[]{"a", null}; + Assert.noNullElements(a); + }); } @Test public void notBlankTest() { final String a = "a"; final String s = Assert.notBlank(a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); } - @Test(expected = IllegalArgumentException.class) + @Test public void isTrueTest() { - final int i = 0; - //noinspection ConstantConditions - Assert.isTrue(i > 0, IllegalArgumentException::new); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + final int i = 0; + //noinspection ConstantConditions + Assert.isTrue(i > 0, IllegalArgumentException::new); + }); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void isTrueTest2() { - final int i = -1; - //noinspection ConstantConditions - Assert.isTrue(i >= 0, IndexOutOfBoundsException::new); + Assertions.assertThrows(IndexOutOfBoundsException.class, ()->{ + final int i = -1; + //noinspection ConstantConditions + Assert.isTrue(i >= 0, IndexOutOfBoundsException::new); + }); } - @Test(expected = IndexOutOfBoundsException.class) + @Test public void isTrueTest3() { - final int i = -1; - //noinspection ConstantConditions - Assert.isTrue(i > 0, () -> new IndexOutOfBoundsException("relation message to return")); + Assertions.assertThrows(IndexOutOfBoundsException.class, ()->{ + final int i = -1; + //noinspection ConstantConditions + Assert.isTrue(i > 0, () -> new IndexOutOfBoundsException("relation message to return")); + }); } @SuppressWarnings("ConstantValue") @@ -146,42 +157,44 @@ public class AssertTest { public void checkBetweenTest() { final int a = 12; final int i = Assert.checkBetween(a, 1, 12); - org.junit.Assert.assertSame(a, i); + Assertions.assertSame(a, i); } @Test public void checkBetweenTest2() { final double a = 12; final double i = Assert.checkBetween(a, 1, 12); - org.junit.Assert.assertEquals(a, i, 0.00); + Assertions.assertEquals(a, i, 0.00); } @Test public void checkBetweenTest3() { final Number a = 12; final Number i = Assert.checkBetween(a, 1, 12); - org.junit.Assert.assertSame(a, i); + Assertions.assertSame(a, i); } - @Test(expected = IllegalArgumentException.class) + @Test public void notContainTest() { - final String sub = "a"; - final String a = Assert.notContain("abc", sub); - org.junit.Assert.assertSame(sub, a); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + final String sub = "a"; + final String a = Assert.notContain("abc", sub); + Assertions.assertSame(sub, a); + }); } @Test public void notContainTest2() { final String sub = "d"; final String a = Assert.notContain("abc", sub); - org.junit.Assert.assertSame(sub, a); + Assertions.assertSame(sub, a); } @Test public void isInstanceOfTest() { final String a = "a"; final String s = Assert.isInstanceOf(String.class, a); - org.junit.Assert.assertSame(a, s); + Assertions.assertSame(a, s); } @Test @@ -192,6 +205,6 @@ public class AssertTest { @Test public void checkIndexTest() { final int i = Assert.checkIndex(1, 10); - org.junit.Assert.assertEquals(1, i); + Assertions.assertEquals(1, i); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTableTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTableTest.java index fac3aca66..81d1e9e7b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTableTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTableTest.java @@ -1,12 +1,12 @@ package cn.hutool.core.lang; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class ConsoleTableTest { @Test - @Ignore + @Disabled public void printSBCTest() { ConsoleTable t = ConsoleTable.of(); t.addHeader("姓名", "年龄"); @@ -34,7 +34,7 @@ public class ConsoleTableTest { } @Test - @Ignore + @Disabled public void printDBCTest() { ConsoleTable t = ConsoleTable.of().setSBCMode(false); t.addHeader("姓名", "年龄"); diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTest.java index 4315c2311..aea871106 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/ConsoleTest.java @@ -1,9 +1,8 @@ package cn.hutool.core.lang; -import org.junit.Ignore; -import org.junit.Test; - import cn.hutool.core.thread.ThreadUtil; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * 控制台单元测试 @@ -59,7 +58,7 @@ public class ConsoleTest { } @Test - @Ignore + @Disabled public void inputTest() { Console.log("Please input something: "); final String input = Console.input(); @@ -67,7 +66,7 @@ public class ConsoleTest { } @Test - @Ignore + @Disabled public void printProgressTest() { for(int i = 0; i < 100; i++) { Console.printProgress('#', 100, i / 100D); diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/DictTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/DictTest.java index 109675521..b209b391b 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/DictTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/DictTest.java @@ -6,8 +6,8 @@ import cn.hutool.core.map.Dict; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -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; @@ -21,7 +21,7 @@ public class DictTest { .set("key3", DateTime.now());//Date final Long v2 = dict.getLong("key2"); - Assert.assertEquals(Long.valueOf(1000L), v2); + Assertions.assertEquals(Long.valueOf(1000L), v2); } @Test @@ -32,8 +32,8 @@ public class DictTest { dict.putAll(map); - Assert.assertEquals(1, dict.get("A")); - Assert.assertEquals(1, dict.get("a")); + Assertions.assertEquals(1, dict.get("A")); + Assertions.assertEquals(1, dict.get("a")); } @Test @@ -44,9 +44,9 @@ public class DictTest { "BLUE", "#0000FF" ); - Assert.assertEquals("#FF0000", dict.get("RED")); - Assert.assertEquals("#00FF00", dict.get("GREEN")); - Assert.assertEquals("#0000FF", dict.get("BLUE")); + Assertions.assertEquals("#FF0000", dict.get("RED")); + Assertions.assertEquals("#00FF00", dict.get("GREEN")); + Assertions.assertEquals("#0000FF", dict.get("BLUE")); } @Test @@ -61,7 +61,7 @@ public class DictTest { dict.removeEqual(dict2); - Assert.assertTrue(dict.isEmpty()); + Assertions.assertTrue(dict.isEmpty()); } @Test @@ -69,11 +69,11 @@ public class DictTest { final User user = GenericBuilder.of(User::new).with(User::setUsername, "hutool").build(); final Dict dict = Dict.of(); dict.setFields(user::getNickname, user::getUsername); - Assert.assertEquals("hutool", dict.get("username")); - Assert.assertNull(dict.get("nickname")); + Assertions.assertEquals("hutool", dict.get("username")); + Assertions.assertNull(dict.get("nickname")); // get by lambda - Assert.assertEquals("hutool", dict.get(User::getUsername)); + Assertions.assertEquals("hutool", dict.get(User::getUsername)); } @Data diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/NanoIdTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/NanoIdTest.java index bfac066f1..023c1ab86 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/NanoIdTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/NanoIdTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.lang; import cn.hutool.core.lang.id.NanoId; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.security.SecureRandom; import java.util.HashMap; @@ -32,7 +32,7 @@ public class NanoIdTest { if (ids.contains(id) == false) { ids.add(id); } else { - Assert.fail("Non-unique ID generated: " + id); + Assertions.fail("Non-unique ID generated: " + id); } } @@ -55,7 +55,7 @@ public class NanoIdTest { for (final String expectedId : expectedIds) { final String generatedId = NanoId.randomNanoId(random, alphabet, size); - Assert.assertEquals(expectedId, generatedId); + Assertions.assertEquals(expectedId, generatedId); } } @@ -82,7 +82,7 @@ public class NanoIdTest { } patternBuilder.append("]+$"); - Assert.assertTrue(id.matches(patternBuilder.toString())); + Assertions.assertTrue(id.matches(patternBuilder.toString())); } } @@ -95,7 +95,7 @@ public class NanoIdTest { final String id = NanoId.randomNanoId(size); - Assert.assertEquals(size, id.length()); + Assertions.assertEquals(size, id.length()); } } @@ -131,36 +131,43 @@ public class NanoIdTest { //Verify the distribution of characters is pretty even for (final Long charCount : charCounts.values()) { final double distribution = (charCount * alphabet.length / (double) (idCount * idSize)); - Assert.assertTrue(distribution >= 0.95 && distribution <= 1.05); + Assertions.assertTrue(distribution >= 0.95 && distribution <= 1.05); } } - @Test(expected = IllegalArgumentException.class) + @Test public void randomNanoIdEmptyAlphabetExceptionThrownTest() { - NanoId.randomNanoId(new SecureRandom(), new char[]{}, 10); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + NanoId.randomNanoId(new SecureRandom(), new char[]{}, 10); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void randomNanoId256AlphabetExceptionThrownTest() { + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + //The alphabet is composed of 256 unique characters + final char[] largeAlphabet = new char[256]; + for (int i = 0; i < 256; i++) { + largeAlphabet[i] = (char) i; + } + NanoId.randomNanoId(new SecureRandom(), largeAlphabet, 20); + }); - //The alphabet is composed of 256 unique characters - final char[] largeAlphabet = new char[256]; - for (int i = 0; i < 256; i++) { - largeAlphabet[i] = (char) i; - } - - NanoId.randomNanoId(new SecureRandom(), largeAlphabet, 20); } - @Test(expected = IllegalArgumentException.class) + @Test public void randomNanoIdNegativeSizeExceptionThrown() { - NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, -10); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, -10); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void randomNanoIdZeroSizeExceptionThrown() { - NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, 0); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, 0); + }); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/ObjectIdTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/ObjectIdTest.java index 39ffebaf0..d4755dfdc 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/ObjectIdTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/ObjectIdTest.java @@ -1,11 +1,11 @@ package cn.hutool.core.lang; -import java.util.HashSet; - import cn.hutool.core.lang.id.ObjectId; -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.HashSet; /** * ObjectId单元测试 @@ -23,11 +23,11 @@ public class ObjectIdTest { set.add(ObjectId.next()); } - Assert.assertEquals(10000, set.size()); + Assertions.assertEquals(10000, set.size()); } @Test - @Ignore + @Disabled public void nextTest() { Console.log(ObjectId.next()); } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/OptTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/OptTest.java index 66baa5454..df823d0a2 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/OptTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/OptTest.java @@ -5,8 +5,8 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -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.Stream; @@ -20,15 +20,15 @@ public class OptTest { @Test public void ofTest() { - Assert.assertTrue(Opt.of(Optional.empty()).isEmpty()); - Assert.assertTrue(Opt.of(Optional.of(1)).isPresent()); + Assertions.assertTrue(Opt.of(Optional.empty()).isEmpty()); + Assertions.assertTrue(Opt.of(Optional.of(1)).isPresent()); } @Test public void ofBlankAbleTest() { // ofBlankAble相对于ofNullable考虑了字符串为空串的情况 final String hutool = Opt.ofBlankAble("").orElse("hutool"); - Assert.assertEquals("hutool", hutool); + Assertions.assertEquals("hutool", hutool); } @Test @@ -36,7 +36,7 @@ public class OptTest { // 和原版Optional有区别的是,get不会抛出NoSuchElementException // 如果想使用原版Optional中的get这样,获取一个一定不为空的值,则应该使用orElseThrow final Object opt = Opt.ofNullable(null).get(); - Assert.assertNull(opt); + Assertions.assertNull(opt); } @Test @@ -44,7 +44,7 @@ public class OptTest { // 这是jdk11 Optional中的新函数,直接照搬了过来 // 判断包裹内元素是否为空,注意并没有判断空字符串的情况 final boolean isEmpty = Opt.empty().isEmpty(); - Assert.assertTrue(isEmpty); + Assertions.assertTrue(isEmpty); } @Test @@ -52,12 +52,12 @@ public class OptTest { final User user = new User(); // 相当于ifPresent的链式调用 Opt.ofNullable("hutool").peek(user::setUsername).peek(user::setNickname); - Assert.assertEquals("hutool", user.getNickname()); - Assert.assertEquals("hutool", user.getUsername()); + Assertions.assertEquals("hutool", user.getNickname()); + Assertions.assertEquals("hutool", user.getUsername()); // 注意,传入的lambda中,对包裹内的元素执行赋值操作并不会影响到原来的元素 final String name = Opt.ofNullable("hutool").peek(username -> username = "123").peek(username -> username = "456").get(); - Assert.assertEquals("hutool", name); + Assertions.assertEquals("hutool", name); } @Test @@ -68,18 +68,18 @@ public class OptTest { Opt.ofNullable("hutool").peeks(user::setUsername, user::setNickname); // 也可以在适当的地方换行使得代码的可读性提高 Opt.of(user).peeks( - u -> Assert.assertEquals("hutool", u.getNickname()), - u -> Assert.assertEquals("hutool", u.getUsername()) + u -> Assertions.assertEquals("hutool", u.getNickname()), + u -> Assertions.assertEquals("hutool", u.getUsername()) ); - Assert.assertEquals("hutool", user.getNickname()); - Assert.assertEquals("hutool", user.getUsername()); + Assertions.assertEquals("hutool", user.getNickname()); + Assertions.assertEquals("hutool", user.getUsername()); // 注意,传入的lambda中,对包裹内的元素执行赋值操作并不会影响到原来的元素,这是java语言的特性。。。 // 这也是为什么我们需要getter和setter而不直接给bean中的属性赋值中的其中一个原因 final String name = Opt.ofNullable("hutool").peeks( username -> username = "123", username -> username = "456", - n -> Assert.assertEquals("hutool", n)).get(); - Assert.assertEquals("hutool", name); + n -> Assertions.assertEquals("hutool", n)).get(); + Assertions.assertEquals("hutool", name); // 当然,以下情况不会抛出NPE,但也没什么意义 Opt.ofNullable("hutool").peeks().peeks().peeks(); @@ -93,27 +93,31 @@ public class OptTest { // 这是jdk9 Optional中的新函数,直接照搬了过来 // 给一个替代的Opt final String str = Opt.ofNullable(null).or(() -> Opt.ofNullable("Hello hutool!")).map(String::toUpperCase).orElseThrow(); - Assert.assertEquals("HELLO HUTOOL!", str); + Assertions.assertEquals("HELLO HUTOOL!", str); final User user = User.builder().username("hutool").build(); final Opt userOpt = Opt.of(user); // 获取昵称,获取不到则获取用户名 final String name = userOpt.map(User::getNickname).or(() -> userOpt.map(User::getUsername)).get(); - Assert.assertEquals("hutool", name); + Assertions.assertEquals("hutool", name); } - @Test(expected = NoSuchElementException.class) + @Test public void orElseThrowTest() { - // 获取一个不可能为空的值,否则抛出NoSuchElementException异常 - final Object obj = Opt.ofNullable(null).orElseThrow(); - Assert.assertNull(obj); + Assertions.assertThrows(NoSuchElementException.class, ()->{ + // 获取一个不可能为空的值,否则抛出NoSuchElementException异常 + final Object obj = Opt.ofNullable(null).orElseThrow(); + Assertions.assertNull(obj); + }); } - @Test(expected = IllegalStateException.class) + @Test public void orElseThrowTest2() { - // 获取一个不可能为空的值,否则抛出自定义异常 - final Object assignException = Opt.ofNullable(null).orElseThrow(IllegalStateException::new); - Assert.assertNull(assignException); + Assertions.assertThrows(IllegalStateException.class, ()->{ + // 获取一个不可能为空的值,否则抛出自定义异常 + final Object assignException = Opt.ofNullable(null).orElseThrow(IllegalStateException::new); + Assertions.assertNull(assignException); + }); } @Test @@ -125,7 +129,7 @@ public class OptTest { Opt.ofNullable(map.get(key)) .ifPresent(v -> map.put(key, v + 1)) .orElseRun(() -> map.remove(key)); - Assert.assertEquals((Object) 2, map.get(key)); + Assertions.assertEquals((Object) 2, map.get(key)); } @Test @@ -137,8 +141,8 @@ public class OptTest { // 现在,兼容 final User user = Opt.ofNullable(userList).map(List::stream) .flattedMap(Stream::findFirst).orElseGet(User.builder()::build); - Assert.assertNull(user.getUsername()); - Assert.assertNull(user.getNickname()); + Assertions.assertNull(user.getUsername()); + Assertions.assertNull(user.getNickname()); } @Test @@ -148,9 +152,9 @@ public class OptTest { final List past = Opt.ofNullable(Collections.emptyList()).filter(CollUtil::isNotEmpty).orElseGet(() -> Collections.singletonList("hutool")); // 现在,一个ofEmptyAble搞定 final List hutool = Opt.ofEmptyAble(Collections.emptyList()).orElseGet(() -> Collections.singletonList("hutool")); - Assert.assertEquals(past, hutool); - Assert.assertEquals(Collections.singletonList("hutool"), hutool); - Assert.assertTrue(Opt.ofEmptyAble(Arrays.asList(null, null, null)).isEmpty()); + Assertions.assertEquals(past, hutool); + Assertions.assertEquals(Collections.singletonList("hutool"), hutool); + Assertions.assertTrue(Opt.ofEmptyAble(Arrays.asList(null, null, null)).isEmpty()); } @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection", "ConstantConditions"}) @@ -172,24 +176,24 @@ public class OptTest { return list.get(0); }).exceptionOrElse("hutool"); - Assert.assertTrue(Opt.ofTry(() -> { + Assertions.assertTrue(Opt.ofTry(() -> { throw new AssertionError(""); }).getThrowable() instanceof AssertionError); - Assert.assertEquals(npe, npeSituation); - Assert.assertEquals(indexOut, indexOutSituation); - Assert.assertEquals("hutool", npe); - Assert.assertEquals("hutool", indexOut); + Assertions.assertEquals(npe, npeSituation); + Assertions.assertEquals(indexOut, indexOutSituation); + Assertions.assertEquals("hutool", npe); + Assertions.assertEquals("hutool", indexOut); // 多线程下情况测试 Stream.iterate(0, i -> ++i).limit(20000).parallel().forEach(i -> { final Opt opt = Opt.ofTry(() -> { if (i % 2 == 0) { - throw new IllegalStateException(i + ""); + throw new IllegalStateException(String.valueOf(i)); } else { - throw new NullPointerException(i + ""); + throw new NullPointerException(String.valueOf(i)); } }); - Assert.assertTrue( + Assertions.assertTrue( (i % 2 == 0 && opt.getThrowable() instanceof IllegalStateException) || (i % 2 != 0 && opt.getThrowable() instanceof NullPointerException) ); diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/SimpleCacheTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/SimpleCacheTest.java index 198f09c4b..71d5e99ab 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/SimpleCacheTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/SimpleCacheTest.java @@ -3,13 +3,13 @@ package cn.hutool.core.lang; import cn.hutool.core.cache.SimpleCache; import cn.hutool.core.thread.ConcurrencyTester; import cn.hutool.core.thread.ThreadUtil; -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; public class SimpleCacheTest { - @Before + @BeforeEach public void putTest(){ final SimpleCache cache = new SimpleCache<>(); ThreadUtil.execute(()->cache.put("key1", "value1")); @@ -38,12 +38,12 @@ public class SimpleCacheTest { cache.get("key4"); cache.get("key5", ()->"value5"); - Assert.assertEquals("value1", cache.get("key1")); - Assert.assertEquals("value2", cache.get("key2")); - Assert.assertEquals("value3", cache.get("key3")); - Assert.assertEquals("value4", cache.get("key4")); - Assert.assertEquals("value5", cache.get("key5")); - Assert.assertEquals("value6", cache.get("key6", ()-> "value6")); + Assertions.assertEquals("value1", cache.get("key1")); + Assertions.assertEquals("value2", cache.get("key2")); + Assertions.assertEquals("value3", cache.get("key3")); + Assertions.assertEquals("value4", cache.get("key4")); + Assertions.assertEquals("value5", cache.get("key5")); + Assertions.assertEquals("value6", cache.get("key6", ()-> "value6")); } @Test @@ -51,9 +51,10 @@ public class SimpleCacheTest { // 检查predicate空指针 final SimpleCache cache = new SimpleCache<>(); final String value = cache.get("abc", (v)-> v.equals("1"), () -> "123"); - Assert.assertEquals("123", value); + Assertions.assertEquals("123", value); } + @SuppressWarnings("resource") @Test public void getConcurrencyTest(){ final SimpleCache cache = new SimpleCache<>(); @@ -63,7 +64,7 @@ public class SimpleCacheTest { return "aaaValue"; })); - Assert.assertTrue(tester.getInterval() > 0); - Assert.assertEquals("aaaValue", cache.get("aaa")); + Assertions.assertTrue(tester.getInterval() > 0); + Assertions.assertEquals("aaaValue", cache.get("aaa")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/SingletonTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/SingletonTest.java index 0d7a30443..86b4f15be 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/SingletonTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/SingletonTest.java @@ -3,11 +3,14 @@ package cn.hutool.core.lang; import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.thread.ThreadUtil; 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.time.Duration; public class SingletonTest { + @SuppressWarnings("resource") @Test public void getTest(){ // 此测试中使用1000个线程获取单例对象,其间对象只被创建一次 @@ -33,10 +36,12 @@ public class SingletonTest { * 测试单例构建属性锁死问题 * C构建单例时候,同时构建B,此时在SimpleCache中会有写锁竞争(写入C时获取了写锁,此时要写入B,也要获取写锁) */ - @Test(timeout = 1000L) + @Test public void reentrantTest(){ - final C c = Singleton.get(C.class); - Assert.assertEquals("aaa", c.getB().getA()); + Assertions.assertTimeout(Duration.ofMillis(1000L), ()->{ + final C c = Singleton.get(C.class); + Assertions.assertEquals("aaa", c.getB().getA()); + }); } @Data diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/SnowflakeTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/SnowflakeTest.java index ca69f9155..42667b8d7 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/SnowflakeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/SnowflakeTest.java @@ -2,13 +2,13 @@ package cn.hutool.core.lang; import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.exceptions.UtilException; -import cn.hutool.core.lang.id.Snowflake; -import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.lang.id.IdUtil; +import cn.hutool.core.lang.id.Snowflake; import cn.hutool.core.text.StrUtil; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import cn.hutool.core.thread.ThreadUtil; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.HashSet; import java.util.Set; @@ -25,7 +25,7 @@ public class SnowflakeTest { //构建Snowflake,提供终端ID和数据中心ID final Snowflake idWorker = new Snowflake(0, 0); final long nextId = idWorker.nextId(); - Assert.assertTrue(nextId > 0); + Assertions.assertTrue(nextId > 0); } @Test @@ -38,7 +38,7 @@ public class SnowflakeTest { final long id = idWorker.nextId(); hashSet.add(id); } - Assert.assertEquals(1000L, hashSet.size()); + Assertions.assertEquals(1000L, hashSet.size()); } @Test @@ -47,13 +47,13 @@ public class SnowflakeTest { final Snowflake idWorker = new Snowflake(1, 2); final long nextId = idWorker.nextId(); - Assert.assertEquals(1, idWorker.getWorkerId(nextId)); - Assert.assertEquals(2, idWorker.getDataCenterId(nextId)); - Assert.assertTrue(idWorker.getGenerateDateTime(nextId) - System.currentTimeMillis() < 10); + Assertions.assertEquals(1, idWorker.getWorkerId(nextId)); + Assertions.assertEquals(2, idWorker.getDataCenterId(nextId)); + Assertions.assertTrue(idWorker.getGenerateDateTime(nextId) - System.currentTimeMillis() < 10); } @Test - @Ignore + @Disabled public void uniqueTest(){ // 测试并发环境下生成ID是否重复 final Snowflake snowflake = IdUtil.getSnowflake(0, 0); @@ -72,12 +72,12 @@ public class SnowflakeTest { public void getSnowflakeLengthTest(){ for (int i = 0; i < 1000; i++) { final long l = IdUtil.getSnowflake(0, 0).nextId(); - Assert.assertEquals(19, StrUtil.toString(l).length()); + Assertions.assertEquals(19, StrUtil.toString(l).length()); } } @Test - @Ignore + @Disabled public void snowflakeRandomSequenceTest(){ final Snowflake snowflake = new Snowflake(null, 0, 0, false, Snowflake.DEFAULT_TIME_OFFSET, 2); @@ -89,7 +89,7 @@ public class SnowflakeTest { } @Test - @Ignore + @Disabled public void uniqueOfRandomSequenceTest(){ // 测试并发环境下生成ID是否重复 final Snowflake snowflake = new Snowflake(null, 0, 0, diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/StrFormatterTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/StrFormatterTest.java index a53ba501b..978600bb4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/StrFormatterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/StrFormatterTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import cn.hutool.core.text.StrFormatter; @@ -11,44 +11,44 @@ public class StrFormatterTest { public void formatTest() { //通常使用 final String result1 = StrFormatter.format("this is {} for {}", "a", "b"); - Assert.assertEquals("this is a for b", result1); + Assertions.assertEquals("this is a for b", result1); //转义{} final String result2 = StrFormatter.format("this is \\{} for {}", "a", "b"); - Assert.assertEquals("this is {} for a", result2); + Assertions.assertEquals("this is {} for a", result2); //转义\ final String result3 = StrFormatter.format("this is \\\\{} for {}", "a", "b"); - Assert.assertEquals("this is \\a for b", result3); + Assertions.assertEquals("this is \\a for b", result3); } @Test public void formatWithTest() { //通常使用 final String result1 = StrFormatter.formatWith("this is ? for ?", "?", "a", "b"); - Assert.assertEquals("this is a for b", result1); + Assertions.assertEquals("this is a for b", result1); //转义? final String result2 = StrFormatter.formatWith("this is \\? for ?", "?", "a", "b"); - Assert.assertEquals("this is ? for a", result2); + Assertions.assertEquals("this is ? for a", result2); //转义\ final String result3 = StrFormatter.formatWith("this is \\\\? for ?", "?", "a", "b"); - Assert.assertEquals("this is \\a for b", result3); + Assertions.assertEquals("this is \\a for b", result3); } @Test public void formatWithTest2() { //通常使用 final String result1 = StrFormatter.formatWith("this is $$$ for $$$", "$$$", "a", "b"); - Assert.assertEquals("this is a for b", result1); + Assertions.assertEquals("this is a for b", result1); //转义? final String result2 = StrFormatter.formatWith("this is \\$$$ for $$$", "$$$", "a", "b"); - Assert.assertEquals("this is $$$ for a", result2); + Assertions.assertEquals("this is $$$ for a", result2); //转义\ final String result3 = StrFormatter.formatWith("this is \\\\$$$ for $$$", "$$$", "a", "b"); - Assert.assertEquals("this is \\a for b", result3); + Assertions.assertEquals("this is \\a for b", result3); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/TupleTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/TupleTest.java index c8508c298..284f446d4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/TupleTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/TupleTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Locale; import java.util.TimeZone; @@ -12,6 +12,6 @@ public class TupleTest { public void hashCodeTest(){ final Tuple tuple = new Tuple(Locale.getDefault(), TimeZone.getDefault()); final Tuple tuple2 = new Tuple(Locale.getDefault(), TimeZone.getDefault()); - Assert.assertEquals(tuple, tuple2); + Assertions.assertEquals(tuple, tuple2); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/UUIDTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/UUIDTest.java index 294bdf0d1..7a0ba3f89 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/UUIDTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/UUIDTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.lang; import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.lang.id.UUID; 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.Set; @@ -17,7 +17,7 @@ public class UUIDTest { public void fastUUIDTest(){ final Set set = new ConcurrentHashSet<>(100); ThreadUtil.concurrencyTest(100, ()-> set.add(UUID.fastUUID().toString())); - Assert.assertEquals(100, set.size()); + Assertions.assertEquals(100, set.size()); } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/ValidatorTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/ValidatorTest.java index dab979e0a..16a7efd71 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/ValidatorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/ValidatorTest.java @@ -6,8 +6,8 @@ import cn.hutool.core.lang.id.IdUtil; import cn.hutool.core.regex.PatternPool; import cn.hutool.core.text.StrUtil; 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.Date; @@ -20,10 +20,10 @@ public class ValidatorTest { @Test public void isNumberTest() { - Assert.assertTrue(Validator.isNumber("45345365465")); - Assert.assertTrue(Validator.isNumber("0004545435")); - Assert.assertTrue(Validator.isNumber("5.222")); - Assert.assertTrue(Validator.isNumber("0.33323")); + Assertions.assertTrue(Validator.isNumber("45345365465")); + Assertions.assertTrue(Validator.isNumber("0004545435")); + Assertions.assertTrue(Validator.isNumber("5.222")); + Assertions.assertTrue(Validator.isNumber("0.33323")); } @Test @@ -32,207 +32,209 @@ public class ValidatorTest { final String var2 = "str"; final String var3 = "180"; final String var4 = "身高180体重180"; - Assert.assertFalse(Validator.hasNumber(var1)); - Assert.assertFalse(Validator.hasNumber(var2)); - Assert.assertTrue(Validator.hasNumber(var3)); - Assert.assertTrue(Validator.hasNumber(var4)); + Assertions.assertFalse(Validator.hasNumber(var1)); + Assertions.assertFalse(Validator.hasNumber(var2)); + Assertions.assertTrue(Validator.hasNumber(var3)); + Assertions.assertTrue(Validator.hasNumber(var4)); } @Test public void isLetterTest() { - Assert.assertTrue(Validator.isLetter("asfdsdsfds")); - Assert.assertTrue(Validator.isLetter("asfdsdfdsfVCDFDFGdsfds")); - Assert.assertTrue(Validator.isLetter("asfdsdf你好dsfVCDFDFGdsfds")); + Assertions.assertTrue(Validator.isLetter("asfdsdsfds")); + Assertions.assertTrue(Validator.isLetter("asfdsdfdsfVCDFDFGdsfds")); + Assertions.assertTrue(Validator.isLetter("asfdsdf你好dsfVCDFDFGdsfds")); } @Test public void isUperCaseTest() { - Assert.assertTrue(Validator.isUpperCase("VCDFDFG")); - Assert.assertTrue(Validator.isUpperCase("ASSFD")); + Assertions.assertTrue(Validator.isUpperCase("VCDFDFG")); + Assertions.assertTrue(Validator.isUpperCase("ASSFD")); - Assert.assertFalse(Validator.isUpperCase("asfdsdsfds")); - Assert.assertFalse(Validator.isUpperCase("ASSFD你好")); + Assertions.assertFalse(Validator.isUpperCase("asfdsdsfds")); + Assertions.assertFalse(Validator.isUpperCase("ASSFD你好")); } @Test public void isLowerCaseTest() { - Assert.assertTrue(Validator.isLowerCase("asfdsdsfds")); + Assertions.assertTrue(Validator.isLowerCase("asfdsdsfds")); - Assert.assertFalse(Validator.isLowerCase("aaaa你好")); - Assert.assertFalse(Validator.isLowerCase("VCDFDFG")); - Assert.assertFalse(Validator.isLowerCase("ASSFD")); - Assert.assertFalse(Validator.isLowerCase("ASSFD你好")); + Assertions.assertFalse(Validator.isLowerCase("aaaa你好")); + Assertions.assertFalse(Validator.isLowerCase("VCDFDFG")); + Assertions.assertFalse(Validator.isLowerCase("ASSFD")); + Assertions.assertFalse(Validator.isLowerCase("ASSFD你好")); } @Test public void isBirthdayTest() { final boolean b = Validator.isBirthday("20150101"); - Assert.assertTrue(b); + Assertions.assertTrue(b); final boolean b2 = Validator.isBirthday("2015-01-01"); - Assert.assertTrue(b2); + Assertions.assertTrue(b2); final boolean b3 = Validator.isBirthday("2015.01.01"); - Assert.assertTrue(b3); + Assertions.assertTrue(b3); final boolean b4 = Validator.isBirthday("2015年01月01日"); - Assert.assertTrue(b4); + Assertions.assertTrue(b4); final boolean b5 = Validator.isBirthday("2015.01.01"); - Assert.assertTrue(b5); + Assertions.assertTrue(b5); final boolean b6 = Validator.isBirthday("2018-08-15"); - Assert.assertTrue(b6); + Assertions.assertTrue(b6); //验证年非法 - Assert.assertFalse(Validator.isBirthday("2095.05.01")); + Assertions.assertFalse(Validator.isBirthday("2095.05.01")); //验证月非法 - Assert.assertFalse(Validator.isBirthday("2015.13.01")); + Assertions.assertFalse(Validator.isBirthday("2015.13.01")); //验证日非法 - Assert.assertFalse(Validator.isBirthday("2015.02.29")); + Assertions.assertFalse(Validator.isBirthday("2015.02.29")); } @Test public void isCitizenIdTest() { // 18为身份证号码验证 final boolean b = Validator.isCitizenId("110101199003074477"); - Assert.assertTrue(b); + Assertions.assertTrue(b); // 15位身份证号码验证 final boolean b1 = Validator.isCitizenId("410001910101123"); - Assert.assertTrue(b1); + Assertions.assertTrue(b1); // 10位身份证号码验证 final boolean b2 = Validator.isCitizenId("U193683453"); - Assert.assertTrue(b2); + Assertions.assertTrue(b2); } - @Test(expected = ValidateException.class) + @Test public void validateTest() throws ValidateException { - Validator.validateChinese("我是一段zhongwen", "内容中包含非中文"); + Assertions.assertThrows(ValidateException.class, ()->{ + Validator.validateChinese("我是一段zhongwen", "内容中包含非中文"); + }); } @Test public void isEmailTest() { final boolean email = Validator.isEmail("abc_cde@163.com"); - Assert.assertTrue(email); + Assertions.assertTrue(email); final boolean email1 = Validator.isEmail("abc_%cde@163.com"); - Assert.assertTrue(email1); + Assertions.assertTrue(email1); final boolean email2 = Validator.isEmail("abc_%cde@aaa.c"); - Assert.assertTrue(email2); + Assertions.assertTrue(email2); final boolean email3 = Validator.isEmail("xiaolei.lu@aaa.b"); - Assert.assertTrue(email3); + Assertions.assertTrue(email3); final boolean email4 = Validator.isEmail("xiaolei.Lu@aaa.b"); - Assert.assertTrue(email4); + Assertions.assertTrue(email4); } @Test public void isMobileTest() { final boolean m1 = Validator.isMobile("13900221432"); - Assert.assertTrue(m1); + Assertions.assertTrue(m1); final boolean m2 = Validator.isMobile("015100221432"); - Assert.assertTrue(m2); + Assertions.assertTrue(m2); final boolean m3 = Validator.isMobile("+8618600221432"); - Assert.assertTrue(m3); + Assertions.assertTrue(m3); } @Test public void isMatchTest() { String url = "http://aaa-bbb.somthing.com/a.php?a=b&c=2"; - Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url)); + Assertions.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url)); url = "https://aaa-bbb.somthing.com/a.php?a=b&c=2"; - Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url)); + Assertions.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url)); url = "https://aaa-bbb.somthing.com:8080/a.php?a=b&c=2"; - Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url)); + Assertions.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, url)); } @Test public void isGeneralTest() { String str = ""; boolean general = Validator.isGeneral(str, -1, 5); - Assert.assertTrue(general); + Assertions.assertTrue(general); str = "123_abc_ccc"; general = Validator.isGeneral(str, -1, 100); - Assert.assertTrue(general); + Assertions.assertTrue(general); // 不允许中文 str = "123_abc_ccc中文"; general = Validator.isGeneral(str, -1, 100); - Assert.assertFalse(general); + Assertions.assertFalse(general); } @Test public void isPlateNumberTest(){ - Assert.assertTrue(Validator.isPlateNumber("粤BA03205")); - Assert.assertTrue(Validator.isPlateNumber("闽20401领")); + Assertions.assertTrue(Validator.isPlateNumber("粤BA03205")); + Assertions.assertTrue(Validator.isPlateNumber("闽20401领")); } @Test public void isChineseTest(){ - Assert.assertTrue(Validator.isChinese("全都是中文")); - Assert.assertTrue(Validator.isChinese("㐓㐘")); - Assert.assertFalse(Validator.isChinese("not全都是中文")); + Assertions.assertTrue(Validator.isChinese("全都是中文")); + Assertions.assertTrue(Validator.isChinese("㐓㐘")); + Assertions.assertFalse(Validator.isChinese("not全都是中文")); } @Test public void hasChineseTest() { - Assert.assertTrue(Validator.hasChinese("黄单桑米")); - Assert.assertTrue(Validator.hasChinese("Kn 四兄弟")); - Assert.assertTrue(Validator.hasChinese("\uD840\uDDA3")); - Assert.assertFalse(Validator.hasChinese("Abc")); + Assertions.assertTrue(Validator.hasChinese("黄单桑米")); + Assertions.assertTrue(Validator.hasChinese("Kn 四兄弟")); + Assertions.assertTrue(Validator.hasChinese("\uD840\uDDA3")); + Assertions.assertFalse(Validator.hasChinese("Abc")); } @Test public void isUUIDTest(){ - Assert.assertTrue(Validator.isUUID(IdUtil.randomUUID())); - Assert.assertTrue(Validator.isUUID(IdUtil.fastSimpleUUID())); + Assertions.assertTrue(Validator.isUUID(IdUtil.randomUUID())); + Assertions.assertTrue(Validator.isUUID(IdUtil.fastSimpleUUID())); - Assert.assertTrue(Validator.isUUID(IdUtil.randomUUID().toUpperCase())); - Assert.assertTrue(Validator.isUUID(IdUtil.fastSimpleUUID().toUpperCase())); + Assertions.assertTrue(Validator.isUUID(IdUtil.randomUUID().toUpperCase())); + Assertions.assertTrue(Validator.isUUID(IdUtil.fastSimpleUUID().toUpperCase())); } @Test public void isZipCodeTest(){ // 港 boolean zipCode = Validator.isZipCode("999077"); - Assert.assertTrue(zipCode); + Assertions.assertTrue(zipCode); // 澳 zipCode = Validator.isZipCode("999078"); - Assert.assertTrue(zipCode); + Assertions.assertTrue(zipCode); // 台(2020年3月起改用6位邮编,3+3) zipCode = Validator.isZipCode("822001"); - Assert.assertTrue(zipCode); + Assertions.assertTrue(zipCode); // 内蒙 zipCode = Validator.isZipCode("016063"); - Assert.assertTrue(zipCode); + Assertions.assertTrue(zipCode); // 山西 zipCode = Validator.isZipCode("045246"); - Assert.assertTrue(zipCode); + Assertions.assertTrue(zipCode); // 河北 zipCode = Validator.isZipCode("066502"); - Assert.assertTrue(zipCode); + Assertions.assertTrue(zipCode); // 北京 zipCode = Validator.isZipCode("102629"); - Assert.assertTrue(zipCode); + Assertions.assertTrue(zipCode); } @Test public void isBetweenTest() { - Assert.assertTrue(Validator.isBetween(0, 0, 1)); - Assert.assertTrue(Validator.isBetween(1L, 0L, 1L)); - Assert.assertTrue(Validator.isBetween(0.19f, 0.1f, 0.2f)); - Assert.assertTrue(Validator.isBetween(0.19, 0.1, 0.2)); + Assertions.assertTrue(Validator.isBetween(0, 0, 1)); + Assertions.assertTrue(Validator.isBetween(1L, 0L, 1L)); + Assertions.assertTrue(Validator.isBetween(0.19f, 0.1f, 0.2f)); + Assertions.assertTrue(Validator.isBetween(0.19, 0.1, 0.2)); } @Test public void isCarVinTest(){ - Assert.assertTrue(Validator.isCarVin("LSJA24U62JG269225")); - Assert.assertTrue(Validator.isCarVin("LDC613P23A1305189")); - Assert.assertFalse(Validator.isCarVin("LOC613P23A1305189")); + Assertions.assertTrue(Validator.isCarVin("LSJA24U62JG269225")); + Assertions.assertTrue(Validator.isCarVin("LDC613P23A1305189")); + Assertions.assertFalse(Validator.isCarVin("LOC613P23A1305189")); } @Test public void isCarDrivingLicenceTest(){ - Assert.assertTrue(Validator.isCarDrivingLicence("430101758218")); + Assertions.assertTrue(Validator.isCarDrivingLicence("430101758218")); } @Test @@ -249,56 +251,56 @@ public class ValidatorTest { final String content = "https://detail.tmall.com/item.htm?" + "id=639428931841&ali_refid=a3_430582_1006:1152464078:N:Sk5vwkMVsn5O6DcnvicELrFucL21A32m:0af8611e23c1d07697e"; - Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL, content)); - Assert.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, content)); + Assertions.assertTrue(Validator.isMatchRegex(PatternPool.URL, content)); + Assertions.assertTrue(Validator.isMatchRegex(PatternPool.URL_HTTP, content)); } @Test public void validateBetweenTest(){ - Date value = DateUtil.parse("2022-08-09 21:22:00"); + final Date value = DateUtil.parse("2022-08-09 21:22:00"); final Date start = DateUtil.parse("2022-08-01 21:22:00"); final Date end = DateUtil.parse("2022-09-09 21:22:00"); Validator.validateBetween(value, start, end, "您选择的日期超出规定范围!"); - Assert.assertTrue(true); + Assertions.assertTrue(true); final Date value2 = DateUtil.parse("2023-08-09 21:22:00"); - Assert.assertThrows(ValidateException.class, ()-> + Assertions.assertThrows(ValidateException.class, ()-> Validator.validateBetween(value2, start, end, "您选择的日期超出规定范围!") ); } @Test public void validateLengthTest() { - String s1 = "abc"; - Assert.assertThrows(ValidateException.class, ()-> + final String s1 = "abc"; + Assertions.assertThrows(ValidateException.class, ()-> Validator.validateLength(s1, 6, 8, "请输入6到8位的字符!")); } @Test public void validateByteLengthTest() { - String s1 = "abc"; - int len1 = StrUtil.byteLength(s1, CharsetUtil.UTF_8); - Assert.assertEquals(len1, 3); + final String s1 = "abc"; + final int len1 = StrUtil.byteLength(s1, CharsetUtil.UTF_8); + Assertions.assertEquals(len1, 3); - String s2 = "我ab"; - int len2 = StrUtil.byteLength(s2, CharsetUtil.UTF_8); - Assert.assertEquals(len2, 5); + final String s2 = "我ab"; + final int len2 = StrUtil.byteLength(s2, CharsetUtil.UTF_8); + Assertions.assertEquals(len2, 5); //一个汉字在utf-8编码下,占3个字节。 - Assert.assertThrows(ValidateException.class, ()-> + Assertions.assertThrows(ValidateException.class, ()-> Validator.validateByteLength(s2, 1, 3, "您输入的字符串长度超出限制!") ); } @Test public void isChineseNameTest(){ - Assert.assertTrue(Validator.isChineseName("阿卜杜尼亚孜·毛力尼亚孜")); - Assert.assertFalse(Validator.isChineseName("阿卜杜尼亚孜./毛力尼亚孜")); - Assert.assertTrue(Validator.isChineseName("段正淳")); - Assert.assertFalse(Validator.isChineseName("孟 伟")); - Assert.assertFalse(Validator.isChineseName("李")); - Assert.assertFalse(Validator.isChineseName("连逍遥0")); - Assert.assertFalse(Validator.isChineseName("SHE")); + Assertions.assertTrue(Validator.isChineseName("阿卜杜尼亚孜·毛力尼亚孜")); + Assertions.assertFalse(Validator.isChineseName("阿卜杜尼亚孜./毛力尼亚孜")); + Assertions.assertTrue(Validator.isChineseName("段正淳")); + Assertions.assertFalse(Validator.isChineseName("孟 伟")); + Assertions.assertFalse(Validator.isChineseName("李")); + Assertions.assertFalse(Validator.isChineseName("连逍遥0")); + Assertions.assertFalse(Validator.isChineseName("SHE")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/WeightRandomTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/WeightRandomTest.java index 3602ae58c..3b31d89c1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/WeightRandomTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/WeightRandomTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.lang; 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; public class WeightRandomTest { @@ -14,6 +14,6 @@ public class WeightRandomTest { random.add("C", 100); final String result = random.next(); - Assert.assertTrue(ListUtil.of("A", "B", "C").contains(result)); + Assertions.assertTrue(ListUtil.of("A", "B", "C").contains(result)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/ansi/AnsiEncoderTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/ansi/AnsiEncoderTest.java index ccc6e416c..7eef56bb3 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/ansi/AnsiEncoderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/ansi/AnsiEncoderTest.java @@ -1,13 +1,13 @@ package cn.hutool.core.lang.ansi; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class AnsiEncoderTest { @Test public void encodeTest(){ final String encode = AnsiEncoder.encode(Ansi4BitColor.GREEN, "Hutool test"); - Assert.assertEquals("\u001B[32mHutool test\u001B[0;39m", encode); + Assertions.assertEquals("\u001B[32mHutool test\u001B[0;39m", encode); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/builder/GenericBuilderTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/builder/GenericBuilderTest.java index 2b85eb912..303e460b6 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/builder/GenericBuilderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/builder/GenericBuilderTest.java @@ -5,8 +5,8 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; -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; @@ -29,11 +29,11 @@ public class GenericBuilderTest { .with(Box::setHeight, 7) .build(); - Assert.assertEquals(1024L, box.getId().longValue()); - Assert.assertEquals("Hello World!", box.getTitle()); - Assert.assertEquals(9, box.getLength().intValue()); - Assert.assertEquals(8, box.getWidth().intValue()); - Assert.assertEquals(7, box.getHeight().intValue()); + Assertions.assertEquals(1024L, box.getId().longValue()); + Assertions.assertEquals("Hello World!", box.getTitle()); + Assertions.assertEquals(9, box.getLength().intValue()); + Assertions.assertEquals(8, box.getWidth().intValue()); + Assertions.assertEquals(7, box.getHeight().intValue()); // 对象修改 final Box boxModified = GenericBuilder @@ -44,11 +44,11 @@ public class GenericBuilderTest { .with(Box::setHeight, 5) .build(); - Assert.assertEquals(1024L, boxModified.getId().longValue()); - Assert.assertEquals("Hello Friend!", box.getTitle()); - Assert.assertEquals(3, boxModified.getLength().intValue()); - Assert.assertEquals(4, boxModified.getWidth().intValue()); - Assert.assertEquals(5, boxModified.getHeight().intValue()); + Assertions.assertEquals(1024L, boxModified.getId().longValue()); + Assertions.assertEquals("Hello Friend!", box.getTitle()); + Assertions.assertEquals(3, boxModified.getLength().intValue()); + Assertions.assertEquals(4, boxModified.getWidth().intValue()); + Assertions.assertEquals(5, boxModified.getHeight().intValue()); // 多参数构造 final Box box1 = GenericBuilder @@ -56,12 +56,12 @@ public class GenericBuilderTest { .with(Box::alis) .build(); - Assert.assertEquals(2048L, box1.getId().longValue()); - Assert.assertEquals("Hello Partner!", box1.getTitle()); - Assert.assertEquals(222, box1.getLength().intValue()); - Assert.assertEquals(333, box1.getWidth().intValue()); - Assert.assertEquals(444, box1.getHeight().intValue()); - Assert.assertEquals("TomXin:\"Hello Partner!\"", box1.getTitleAlias()); + Assertions.assertEquals(2048L, box1.getId().longValue()); + Assertions.assertEquals("Hello Partner!", box1.getTitle()); + Assertions.assertEquals(222, box1.getLength().intValue()); + Assertions.assertEquals(333, box1.getWidth().intValue()); + Assertions.assertEquals(444, box1.getHeight().intValue()); + Assertions.assertEquals("TomXin:\"Hello Partner!\"", box1.getTitleAlias()); } @Test @@ -73,9 +73,9 @@ public class GenericBuilderTest { .with(Map::put, "yellow", "#FFFF00") .with(Map::put, "blue", "#0000FF") .build(); - Assert.assertEquals("#FF0000", colorMap.get("red")); - Assert.assertEquals("#FFFF00", colorMap.get("yellow")); - Assert.assertEquals("#0000FF", colorMap.get("blue")); + Assertions.assertEquals("#FF0000", colorMap.get("red")); + Assertions.assertEquals("#FFFF00", colorMap.get("yellow")); + Assertions.assertEquals("#0000FF", colorMap.get("blue")); } @Getter diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerTest.java index cedef7ecf..d2fd3ecc7 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang.caller; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * {@link CallerUtil} 单元测试 @@ -13,19 +13,19 @@ public class CallerTest { @Test public void getCallerTest() { final Class caller = CallerUtil.getCaller(); - Assert.assertEquals(this.getClass(), caller); + Assertions.assertEquals(this.getClass(), caller); final Class caller0 = CallerUtil.getCaller(0); - Assert.assertEquals(CallerUtil.class, caller0); + Assertions.assertEquals(CallerUtil.class, caller0); final Class caller1 = CallerUtil.getCaller(1); - Assert.assertEquals(this.getClass(), caller1); + Assertions.assertEquals(this.getClass(), caller1); } @Test public void getCallerCallerTest() { final Class callerCaller = CallerTestClass.getCaller(); - Assert.assertEquals(this.getClass(), callerCaller); + Assertions.assertEquals(this.getClass(), callerCaller); } private static class CallerTestClass{ diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerUtilTest.java index d1508c837..54a6d33ca 100755 --- a/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/caller/CallerUtilTest.java @@ -1,16 +1,16 @@ package cn.hutool.core.lang.caller; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CallerUtilTest { @Test public void getCallerMethodNameTest() { final String callerMethodName = CallerUtil.getCallerMethodName(false); - Assert.assertEquals("getCallerMethodNameTest", callerMethodName); + Assertions.assertEquals("getCallerMethodNameTest", callerMethodName); final String fullCallerMethodName = CallerUtil.getCallerMethodName(true); - Assert.assertEquals("cn.hutool.core.lang.caller.CallerUtilTest.getCallerMethodNameTest", fullCallerMethodName); + Assertions.assertEquals("cn.hutool.core.lang.caller.CallerUtilTest.getCallerMethodNameTest", fullCallerMethodName); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/func/FunctionPoolTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/func/FunctionPoolTest.java index cb8d5f74c..1138dae7b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/func/FunctionPoolTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/func/FunctionPoolTest.java @@ -4,7 +4,7 @@ import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.StopWatch; import cn.hutool.core.util.RandomUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaFactoryTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaFactoryTest.java index 52ed33198..fe13492f4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaFactoryTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaFactoryTest.java @@ -7,11 +7,9 @@ import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.SneakyThrows; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.lang.invoke.*; import java.lang.reflect.Constructor; @@ -35,7 +33,7 @@ public class LambdaFactoryTest { try { LambdaFactory.build(Function.class, Something.class, "setId", Long.class); } catch (final Exception e) { - Assert.assertTrue(e.getCause() instanceof LambdaConversionException); + Assertions.assertTrue(e.getCause() instanceof LambdaConversionException); } } @@ -49,15 +47,15 @@ public class LambdaFactoryTest { final Function get11 = LambdaFactory.build(Function.class, Something.class, "getId"); final Function get12 = LambdaFactory.build(Function.class, Something.class, "getId"); - Assert.assertEquals(get11, get12); + Assertions.assertEquals(get11, get12); // 通过LambdaFactory模拟创建一个getId方法的Lambda句柄函数,通过调用这个函数,实现方法调用。 - Assert.assertEquals(something.getId(), get11.apply(something)); + Assertions.assertEquals(something.getId(), get11.apply(something)); final String name = "sname"; final BiConsumer set = LambdaFactory.build(BiConsumer.class, Something.class, "setName", String.class); set.accept(something, name); - Assert.assertEquals(something.getName(), name); + Assertions.assertEquals(something.getName(), name); } @Data @@ -71,14 +69,11 @@ public class LambdaFactoryTest { * * @author nasodaengineer */ - @RunWith(Parameterized.class) - @Ignore + @Disabled public static class PerformanceTest { - @Parameterized.Parameter public int count; - @Parameterized.Parameters public static Collection parameters() { return ListUtil.of(1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000); } @@ -142,7 +137,7 @@ public class LambdaFactoryTest { @SuppressWarnings({"rawtypes", "unchecked", "Convert2MethodRef"}) @Test @SneakyThrows - @Ignore + @Disabled public void lambdaGetPerformanceTest() { final Something something = new Something(); something.setId(1L); @@ -167,7 +162,7 @@ public class LambdaFactoryTest { final Supplier constructorLambda = LambdaFactory.build(Supplier.class, constructor); // constructorLambda can be cache or transfer final Something something = constructorLambda.get(); - Assert.assertEquals(Something.class, something.getClass()); + Assertions.assertEquals(Something.class, something.getClass()); } /** @@ -229,7 +224,7 @@ public class LambdaFactoryTest { @SuppressWarnings({"rawtypes", "unchecked"}) @Test @SneakyThrows - @Ignore + @Disabled public void lambdaSetPerformanceTest() { final Something something = new Something(); something.setId(1L); @@ -327,6 +322,6 @@ public class LambdaFactoryTest { final Constructor constructor = ConstructorUtil.getConstructor(String.class, char[].class, boolean.class); final BiFunction function = LambdaFactory.build(BiFunction.class, constructor); final String apply = function.apply(a, true); - Assert.assertEquals(apply, new String(a)); + Assertions.assertEquals(apply, new String(a)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaUtilTest.java index 1014d9780..e6445d9e0 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/func/LambdaUtilTest.java @@ -6,8 +6,8 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.FieldNameConstants; -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.Objects; @@ -22,14 +22,14 @@ public class LambdaUtilTest { public void getMethodNameTest() { final SerFunction lambda = MyTeacher::getAge; final String methodName = LambdaUtil.getMethodName(lambda); - Assert.assertEquals("getAge", methodName); + Assertions.assertEquals("getAge", methodName); } @Test public void getFieldNameTest() { final SerFunction lambda = MyTeacher::getAge; final String fieldName = LambdaUtil.getFieldName(lambda); - Assert.assertEquals("age", fieldName); + Assertions.assertEquals("age", fieldName); } @Test @@ -38,32 +38,32 @@ public class LambdaUtilTest { // 引用构造函数 final SerSupplier lambda = MyTeacher::new; final LambdaInfo lambdaInfo = LambdaUtil.resolve(lambda); - Assert.assertEquals(0, lambdaInfo.getParameterTypes().length); - Assert.assertEquals(MyTeacher.class, lambdaInfo.getReturnType()); + Assertions.assertEquals(0, lambdaInfo.getParameterTypes().length); + Assertions.assertEquals(MyTeacher.class, lambdaInfo.getReturnType()); }, () -> { // 数组构造函数引用(此处数组构造参数) final SerFunction lambda = MyTeacher[]::new; final LambdaInfo lambdaInfo = LambdaUtil.resolve(lambda); - Assert.assertEquals(int.class, lambdaInfo.getParameterTypes()[0]); - Assert.assertEquals(MyTeacher[].class, lambdaInfo.getReturnType()); + Assertions.assertEquals(int.class, lambdaInfo.getParameterTypes()[0]); + Assertions.assertEquals(MyTeacher[].class, lambdaInfo.getReturnType()); }, () -> { // 引用静态方法 final SerSupplier lambda = MyTeacher::takeAge; final LambdaInfo lambdaInfo = LambdaUtil.resolve(lambda); - Assert.assertEquals(0, lambdaInfo.getParameterTypes().length); - Assert.assertEquals(String.class, lambdaInfo.getReturnType()); + Assertions.assertEquals(0, lambdaInfo.getParameterTypes().length); + Assertions.assertEquals(String.class, lambdaInfo.getReturnType()); }, () -> { // 引用特定对象的实例方法 final SerSupplier lambda = new MyTeacher()::getAge; final LambdaInfo lambdaInfo = LambdaUtil.resolve(lambda); - Assert.assertEquals(0, lambdaInfo.getParameterTypes().length); - Assert.assertEquals(String.class, lambdaInfo.getReturnType()); + Assertions.assertEquals(0, lambdaInfo.getParameterTypes().length); + Assertions.assertEquals(String.class, lambdaInfo.getReturnType()); }, () -> { // 引用特定类型的任意对象的实例方法 final SerFunction lambda = MyTeacher::getAge; final LambdaInfo lambdaInfo = LambdaUtil.resolve(lambda); - Assert.assertEquals(0, lambdaInfo.getParameterTypes().length); - Assert.assertEquals(String.class, lambdaInfo.getReturnType()); + Assertions.assertEquals(0, lambdaInfo.getParameterTypes().length); + Assertions.assertEquals(String.class, lambdaInfo.getReturnType()); }, () -> { // 最最重要的!!! final Character character = '0'; @@ -76,21 +76,21 @@ public class LambdaUtilTest { }; final LambdaInfo lambdaInfo = LambdaUtil.resolve(lambda); // 获取闭包使用的参数类型 - Assert.assertEquals(Character.class, lambdaInfo.getParameterTypes()[0]); - Assert.assertEquals(Integer.class, lambdaInfo.getParameterTypes()[1]); + Assertions.assertEquals(Character.class, lambdaInfo.getParameterTypes()[0]); + Assertions.assertEquals(Integer.class, lambdaInfo.getParameterTypes()[1]); // 最后几个是原有lambda的参数类型 - Assert.assertEquals(Object.class, lambdaInfo.getParameterTypes()[2]); - Assert.assertEquals(Boolean.class, lambdaInfo.getParameterTypes()[3]); - Assert.assertEquals(String.class, lambdaInfo.getParameterTypes()[4]); + Assertions.assertEquals(Object.class, lambdaInfo.getParameterTypes()[2]); + Assertions.assertEquals(Boolean.class, lambdaInfo.getParameterTypes()[3]); + Assertions.assertEquals(String.class, lambdaInfo.getParameterTypes()[4]); - Assert.assertEquals(void.class, lambdaInfo.getReturnType()); + Assertions.assertEquals(void.class, lambdaInfo.getReturnType()); }, () -> { // 一些特殊的lambda - Assert.assertEquals("T", LambdaUtil.>>resolve(Stream::of).getParameterTypes()[0].getTypeName()); - Assert.assertEquals(MyTeacher[][].class, LambdaUtil.>resolve(MyTeacher[][]::new).getReturnType()); - Assert.assertEquals(Integer[][][].class, LambdaUtil.>resolve(a -> { + Assertions.assertEquals("T", LambdaUtil.>>resolve(Stream::of).getParameterTypes()[0].getTypeName()); + Assertions.assertEquals(MyTeacher[][].class, LambdaUtil.>resolve(MyTeacher[][]::new).getReturnType()); + Assertions.assertEquals(Integer[][][].class, LambdaUtil.>resolve(a -> { }).getParameterTypes()[0]); - Assert.assertEquals(Integer[][][].class, LambdaUtil.resolve((Serializable & SerConsumer3) (a, b, c) -> { + Assertions.assertEquals(Integer[][][].class, LambdaUtil.resolve((Serializable & SerConsumer3) (a, b, c) -> { }).getParameterTypes()[0]); }).forEach(Runnable::run); @@ -105,48 +105,48 @@ public class LambdaUtilTest { Stream.of(() -> { // 引用特定类型的任意对象的实例方法 final SerFunction lambda = MyTeacher::getAge; - Assert.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 枚举测试,不会导致类型擦除 final SerFunction lambda = LambdaKindEnum::ordinal; - Assert.assertEquals(LambdaKindEnum.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(LambdaKindEnum.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 调用父类方法,能获取到正确的子类类型 final SerFunction lambda = MyTeacher::getId; - Assert.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 引用特定对象的实例方法 final SerSupplier lambda = myTeacher::getAge; - Assert.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 枚举测试,只能获取到枚举类型 final SerSupplier lambda = LambdaKindEnum.REF_NONE::ordinal; - Assert.assertEquals(Enum.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(Enum.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 调用父类方法,只能获取到父类类型 final SerSupplier lambda = myTeacher::getId; - Assert.assertEquals(Entity.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(Entity.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 引用静态带参方法,能够获取到正确的参数类型 final SerFunction lambda = MyTeacher::takeAgeBy; - Assert.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 引用父类静态带参方法,只能获取到父类类型 final SerSupplier lambda = MyTeacher::takeId; - Assert.assertEquals(Entity.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(Entity.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 引用静态无参方法,能够获取到正确的类型 final SerSupplier lambda = MyTeacher::takeAge; - Assert.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 引用父类静态无参方法,能够获取到正确的参数类型 final SerFunction lambda = MyTeacher::takeIdBy; - Assert.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(MyTeacher.class, LambdaUtil.getRealClass(lambda)); }, () -> { // 数组测试 final SerConsumer lambda = (final String[] stringList) -> { }; - Assert.assertEquals(String[].class, LambdaUtil.getRealClass(lambda)); + Assertions.assertEquals(String[].class, LambdaUtil.getRealClass(lambda)); }).forEach(Runnable::run); } @@ -158,8 +158,8 @@ public class LambdaUtilTest { final Function getId = LambdaUtil.buildGetter(MethodUtil.getMethod(Bean.class, "getId")); final Function getId2 = LambdaUtil.buildGetter(Bean.class, Bean.Fields.id); - Assert.assertEquals(getId, getId2); - Assert.assertEquals(bean.getId(), getId.apply(bean)); + Assertions.assertEquals(getId, getId2); + Assertions.assertEquals(bean.getId(), getId.apply(bean)); } @Test @@ -171,12 +171,12 @@ public class LambdaUtilTest { final BiConsumer setId = LambdaUtil.buildSetter(MethodUtil.getMethod(Bean.class, "setId", Long.class)); final BiConsumer setId2 = LambdaUtil.buildSetter(Bean.class, Bean.Fields.id); final BiConsumer setFlag = LambdaUtil.buildSetter(Bean.class, Bean.Fields.flag); - Assert.assertEquals(setId, setId2); + Assertions.assertEquals(setId, setId2); setId.accept(bean, 3L); setFlag.accept(bean, true); - Assert.assertEquals(3L, (long) bean.getId()); - Assert.assertTrue(bean.isFlag()); + Assertions.assertEquals(3L, (long) bean.getId()); + Assertions.assertTrue(bean.isFlag()); } @SuppressWarnings("unchecked") @@ -188,8 +188,8 @@ public class LambdaUtilTest { bean.setFlag(true); final BiFunction uniqueKeyFunction = LambdaUtil.build(BiFunction.class, Bean.class, "uniqueKey", String.class); final Function4 paramsFunction = LambdaUtil.build(Function4.class, Bean.class, "params", String.class, Integer.class, Double.class); - Assert.assertEquals(bean.uniqueKey("test"), uniqueKeyFunction.apply(bean, "test")); - Assert.assertEquals(bean.params("test", 1, 0.5), paramsFunction.apply(bean, "test", 1, 0.5)); + Assertions.assertEquals(bean.uniqueKey("test"), uniqueKeyFunction.apply(bean, "test")); + Assertions.assertEquals(bean.params("test", 1, 0.5), paramsFunction.apply(bean, "test", 1, 0.5)); } @FunctionalInterface @@ -287,7 +287,7 @@ public class LambdaUtilTest { public void lambdaClassNameTest() { final String lambdaClassName1 = LambdaUtilTestHelper.getLambdaClassName(MyTeacher::getAge); final String lambdaClassName2 = LambdaUtilTestHelper.getLambdaClassName(MyTeacher::getAge); - Assert.assertNotEquals(lambdaClassName1, lambdaClassName2); + Assertions.assertNotEquals(lambdaClassName1, lambdaClassName2); } static class LambdaUtilTestHelper { diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/func/PredicateUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/func/PredicateUtilTest.java index 9d38c6b72..eb65dea9f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/func/PredicateUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/func/PredicateUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.lang.func; 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.util.List; import java.util.Objects; @@ -21,9 +21,9 @@ public class PredicateUtilTest { .filter(negate(sets::contains)) .collect(Collectors.toList()); - Assert.assertEquals(2, collect.size()); - Assert.assertEquals("4", collect.get(0)); - Assert.assertEquals("5", collect.get(1)); + Assertions.assertEquals(2, collect.size()); + Assertions.assertEquals("4", collect.get(0)); + Assertions.assertEquals("5", collect.get(1)); } @Test @@ -36,7 +36,7 @@ public class PredicateUtilTest { i -> i % 2 == 1 ) ); - Assert.assertTrue(condition); + Assertions.assertTrue(condition); } @Test @@ -49,7 +49,7 @@ public class PredicateUtilTest { i -> i % 2 == 0 ) ); - Assert.assertFalse(condition); + Assertions.assertFalse(condition); } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/intern/InternUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/intern/InternUtilTest.java index 4c6ab5c3c..f5fb9193d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/intern/InternUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/intern/InternUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.lang.intern; 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 InternUtilTest { @@ -16,9 +16,9 @@ public class InternUtilTest { final String a1 = RandomUtil.randomString(RandomUtil.randomInt(100)); final String a2 = new String(a1); - Assert.assertNotSame(a1, a2); + Assertions.assertNotSame(a1, a2); - Assert.assertSame(intern.intern(a1), intern.intern(a2)); + Assertions.assertSame(intern.intern(a1), intern.intern(a2)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/loader/LazyFunLoaderTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/loader/LazyFunLoaderTest.java index 0397f62d3..2722c7a51 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/loader/LazyFunLoaderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/loader/LazyFunLoaderTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang.loader; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class LazyFunLoaderTest { @@ -19,13 +19,13 @@ public class LazyFunLoaderTest { final LazyFunLoader loader = new LazyFunLoader<>(BigObject::new); - Assert.assertNotNull(loader.get()); - Assert.assertTrue(loader.isInitialize()); + Assertions.assertNotNull(loader.get()); + Assertions.assertTrue(loader.isInitialize()); // 对于某些对象,在程序关闭时,需要进行销毁操作 loader.ifInitialized(BigObject::destroy); - Assert.assertTrue(loader.get().isDestroy); + Assertions.assertTrue(loader.get().isDestroy); } @Test @@ -36,11 +36,11 @@ public class LazyFunLoaderTest { // 若从未使用,则可以避免不必要的初始化 loader.ifInitialized(it -> { - Assert.fail(); + Assertions.fail(); it.destroy(); }); - Assert.assertFalse(loader.isInitialize()); + Assertions.assertFalse(loader.isInitialize()); } @Test @@ -48,13 +48,13 @@ public class LazyFunLoaderTest { final LazyFunLoader loader = LazyFunLoader.on(BigObject::new); - Assert.assertNotNull(loader.get()); - Assert.assertTrue(loader.isInitialize()); + Assertions.assertNotNull(loader.get()); + Assertions.assertTrue(loader.isInitialize()); // 对于某些对象,在程序关闭时,需要进行销毁操作 loader.ifInitialized(BigObject::destroy); - Assert.assertTrue(loader.get().isDestroy); + Assertions.assertTrue(loader.get().isDestroy); } @Test @@ -65,7 +65,7 @@ public class LazyFunLoaderTest { // 若从未使用,则可以避免不必要的初始化 loader.ifInitialized(it -> { - Assert.fail(); + Assertions.fail(); it.destroy(); }); diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/page/NavigatePageInfoTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/page/NavigatePageInfoTest.java index 775d6daf0..0fe10b18e 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/page/NavigatePageInfoTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/page/NavigatePageInfoTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang.page; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class NavigatePageInfoTest { @@ -9,29 +9,29 @@ public class NavigatePageInfoTest { public void naviTest1(){ // 首页 final NavigatePageInfo navigatePageInfo = new NavigatePageInfo(10, 2, 6); - Assert.assertEquals("[1] 2 3 4 5 >>", navigatePageInfo.toString()); + Assertions.assertEquals("[1] 2 3 4 5 >>", navigatePageInfo.toString()); // 中间页 navigatePageInfo.nextPage(); - Assert.assertEquals("<< 1 [2] 3 4 5 >>", navigatePageInfo.toString()); + Assertions.assertEquals("<< 1 [2] 3 4 5 >>", navigatePageInfo.toString()); // 尾页 navigatePageInfo.setPageNo(5); - Assert.assertEquals("<< 1 2 3 4 [5]", navigatePageInfo.toString()); + Assertions.assertEquals("<< 1 2 3 4 [5]", navigatePageInfo.toString()); } @Test public void naviTest2(){ // 首页 final NavigatePageInfo navigatePageInfo = new NavigatePageInfo(10, 2, 4); - Assert.assertEquals("[1] 2 3 4 >>", navigatePageInfo.toString()); + Assertions.assertEquals("[1] 2 3 4 >>", navigatePageInfo.toString()); // 中间页 navigatePageInfo.nextPage(); - Assert.assertEquals("<< 1 [2] 3 4 >>", navigatePageInfo.toString()); + Assertions.assertEquals("<< 1 [2] 3 4 >>", navigatePageInfo.toString()); // 尾页 navigatePageInfo.setPageNo(5); - Assert.assertEquals("<< 2 3 4 [5]", navigatePageInfo.toString()); + Assertions.assertEquals("<< 2 3 4 [5]", navigatePageInfo.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/page/PageInfoTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/page/PageInfoTest.java index de4002884..8fddaa2fd 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/page/PageInfoTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/page/PageInfoTest.java @@ -1,32 +1,32 @@ package cn.hutool.core.lang.page; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PageInfoTest { @Test public void pagesTest() { PageInfo pageInfo = new PageInfo(20, 3); - Assert.assertEquals(7, pageInfo.getPageCount()); + Assertions.assertEquals(7, pageInfo.getPageCount()); pageInfo = new PageInfo(20, 4); - Assert.assertEquals(5, pageInfo.getPageCount()); + Assertions.assertEquals(5, pageInfo.getPageCount()); } @Test public void getSegmentTest() { final PageInfo page = PageInfo.of(20, 10); - Assert.assertEquals("[0, 9]", page.getSegment().toString()); - Assert.assertEquals("[10, 19]", page.nextPage().getSegment().toString()); - Assert.assertEquals("[20, 20]", page.nextPage().getSegment().toString()); + Assertions.assertEquals("[0, 9]", page.getSegment().toString()); + Assertions.assertEquals("[10, 19]", page.nextPage().getSegment().toString()); + Assertions.assertEquals("[20, 20]", page.nextPage().getSegment().toString()); } @Test public void getSegmentTest2() { final PageInfo page = PageInfo.of(20, 10); page.setFirstPageNo(0).setPageNo(0); - Assert.assertEquals("[0, 9]", page.getSegment().toString()); - Assert.assertEquals("[10, 19]", page.nextPage().getSegment().toString()); - Assert.assertEquals("[20, 20]", page.nextPage().getSegment().toString()); + Assertions.assertEquals("[0, 9]", page.getSegment().toString()); + Assertions.assertEquals("[10, 19]", page.nextPage().getSegment().toString()); + Assertions.assertEquals("[20, 20]", page.nextPage().getSegment().toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTest.java index d12996c0f..f33ecf44a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang.range; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * test for {@link Bound} @@ -12,61 +12,61 @@ public class BoundTest { @Test public void testEquals() { final Bound bound = new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND); - Assert.assertEquals(bound, bound); - Assert.assertEquals(bound, new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND)); - Assert.assertNotEquals(bound, new FiniteBound<>(2, BoundType.OPEN_UPPER_BOUND)); - Assert.assertNotEquals(bound, new FiniteBound<>(1, BoundType.OPEN_LOWER_BOUND)); - Assert.assertNotEquals(bound, null); + Assertions.assertEquals(bound, bound); + Assertions.assertEquals(bound, new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND)); + Assertions.assertNotEquals(bound, new FiniteBound<>(2, BoundType.OPEN_UPPER_BOUND)); + Assertions.assertNotEquals(bound, new FiniteBound<>(1, BoundType.OPEN_LOWER_BOUND)); + Assertions.assertNotEquals(bound, null); } @Test public void testHashCode() { final int hashCode = new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND).hashCode(); - Assert.assertEquals(hashCode, new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND).hashCode()); - Assert.assertNotEquals(hashCode, new FiniteBound<>(2, BoundType.OPEN_UPPER_BOUND).hashCode()); - Assert.assertNotEquals(hashCode, new FiniteBound<>(1, BoundType.OPEN_LOWER_BOUND).hashCode()); + Assertions.assertEquals(hashCode, new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND).hashCode()); + Assertions.assertNotEquals(hashCode, new FiniteBound<>(2, BoundType.OPEN_UPPER_BOUND).hashCode()); + Assertions.assertNotEquals(hashCode, new FiniteBound<>(1, BoundType.OPEN_LOWER_BOUND).hashCode()); } @Test public void testNoneLowerBound() { final Bound bound = Bound.noneLowerBound(); // negate - Assert.assertEquals(bound, bound.negate()); + Assertions.assertEquals(bound, bound.negate()); // test - Assert.assertTrue(bound.test(Integer.MAX_VALUE)); + Assertions.assertTrue(bound.test(Integer.MAX_VALUE)); // getType - Assert.assertEquals(BoundType.OPEN_LOWER_BOUND, bound.getType()); + Assertions.assertEquals(BoundType.OPEN_LOWER_BOUND, bound.getType()); // getValue - Assert.assertNull(bound.getValue()); + Assertions.assertNull(bound.getValue()); // toString - Assert.assertEquals("(" + "-∞", bound.descBound()); + Assertions.assertEquals("(" + "-∞", bound.descBound()); // compareTo - Assert.assertEquals(0, bound.compareTo(bound)); - Assert.assertEquals(-1, bound.compareTo(Bound.atMost(1))); + Assertions.assertEquals(0, bound.compareTo(bound)); + Assertions.assertEquals(-1, bound.compareTo(Bound.atMost(1))); - Assert.assertEquals(BoundedRange.all(), bound.toRange()); - Assert.assertEquals("{x | x > -∞}", bound.toString()); + Assertions.assertEquals(BoundedRange.all(), bound.toRange()); + Assertions.assertEquals("{x | x > -∞}", bound.toString()); } @Test public void testNoneUpperBound() { final Bound bound = Bound.noneUpperBound(); // negate - Assert.assertEquals(bound, bound.negate()); + Assertions.assertEquals(bound, bound.negate()); // test - Assert.assertTrue(bound.test(Integer.MAX_VALUE)); + Assertions.assertTrue(bound.test(Integer.MAX_VALUE)); // getType - Assert.assertEquals(BoundType.OPEN_UPPER_BOUND, bound.getType()); + Assertions.assertEquals(BoundType.OPEN_UPPER_BOUND, bound.getType()); // getValue - Assert.assertNull(bound.getValue()); + Assertions.assertNull(bound.getValue()); // toString - Assert.assertEquals("+∞" + ")", bound.descBound()); + Assertions.assertEquals("+∞" + ")", bound.descBound()); // compareTo - Assert.assertEquals(0, bound.compareTo(bound)); - Assert.assertEquals(1, bound.compareTo(Bound.atMost(1))); + Assertions.assertEquals(0, bound.compareTo(bound)); + Assertions.assertEquals(1, bound.compareTo(Bound.atMost(1))); - Assert.assertEquals(BoundedRange.all(), bound.toRange()); - Assert.assertEquals("{x | x < +∞}", bound.toString()); + Assertions.assertEquals(BoundedRange.all(), bound.toRange()); + Assertions.assertEquals("{x | x < +∞}", bound.toString()); } @Test @@ -75,33 +75,33 @@ public class BoundTest { Bound bound = Bound.greaterThan(0); // test - Assert.assertTrue(bound.test(1)); - Assert.assertFalse(bound.test(0)); - Assert.assertFalse(bound.test(-1)); + Assertions.assertTrue(bound.test(1)); + Assertions.assertFalse(bound.test(0)); + Assertions.assertFalse(bound.test(-1)); // getType - Assert.assertEquals(BoundType.OPEN_LOWER_BOUND, bound.getType()); + Assertions.assertEquals(BoundType.OPEN_LOWER_BOUND, bound.getType()); // getValue - Assert.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals((Integer)0, bound.getValue()); // toString - Assert.assertEquals("(0", bound.descBound()); - Assert.assertEquals("{x | x > 0}", bound.toString()); + Assertions.assertEquals("(0", bound.descBound()); + Assertions.assertEquals("{x | x > 0}", bound.toString()); // compareTo - Assert.assertEquals(0, bound.compareTo(bound)); - Assert.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); - Assert.assertEquals(1, bound.compareTo(Bound.atLeast(-1))); - Assert.assertEquals(-1, bound.compareTo(Bound.atLeast(2))); - Assert.assertEquals(1, bound.compareTo(Bound.lessThan(0))); - Assert.assertEquals(1, bound.compareTo(Bound.atMost(0))); - Assert.assertEquals(-1, bound.compareTo(Bound.atMost(2))); - Assert.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); + Assertions.assertEquals(0, bound.compareTo(bound)); + Assertions.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); + Assertions.assertEquals(1, bound.compareTo(Bound.atLeast(-1))); + Assertions.assertEquals(-1, bound.compareTo(Bound.atLeast(2))); + Assertions.assertEquals(1, bound.compareTo(Bound.lessThan(0))); + Assertions.assertEquals(1, bound.compareTo(Bound.atMost(0))); + Assertions.assertEquals(-1, bound.compareTo(Bound.atMost(2))); + Assertions.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); // { x | x >= 0} bound = bound.negate(); - Assert.assertEquals((Integer)0, bound.getValue()); - Assert.assertEquals(BoundType.CLOSE_UPPER_BOUND, bound.getType()); + Assertions.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals(BoundType.CLOSE_UPPER_BOUND, bound.getType()); - Assert.assertNotNull(bound.toRange()); + Assertions.assertNotNull(bound.toRange()); } @Test @@ -110,33 +110,33 @@ public class BoundTest { Bound bound = Bound.atLeast(0); // test - Assert.assertTrue(bound.test(1)); - Assert.assertTrue(bound.test(0)); - Assert.assertFalse(bound.test(-1)); + Assertions.assertTrue(bound.test(1)); + Assertions.assertTrue(bound.test(0)); + Assertions.assertFalse(bound.test(-1)); // getType - Assert.assertEquals(BoundType.CLOSE_LOWER_BOUND, bound.getType()); + Assertions.assertEquals(BoundType.CLOSE_LOWER_BOUND, bound.getType()); // getValue - Assert.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals((Integer)0, bound.getValue()); // toString - Assert.assertEquals("[0", bound.descBound()); - Assert.assertEquals("{x | x >= 0}", bound.toString()); + Assertions.assertEquals("[0", bound.descBound()); + Assertions.assertEquals("{x | x >= 0}", bound.toString()); // compareTo - Assert.assertEquals(0, bound.compareTo(bound)); - Assert.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); - Assert.assertEquals(1, bound.compareTo(Bound.greaterThan(-1))); - Assert.assertEquals(-1, bound.compareTo(Bound.greaterThan(0))); - Assert.assertEquals(1, bound.compareTo(Bound.lessThan(0))); - Assert.assertEquals(1, bound.compareTo(Bound.atMost(0))); - Assert.assertEquals(-1, bound.compareTo(Bound.atMost(2))); - Assert.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); + Assertions.assertEquals(0, bound.compareTo(bound)); + Assertions.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); + Assertions.assertEquals(1, bound.compareTo(Bound.greaterThan(-1))); + Assertions.assertEquals(-1, bound.compareTo(Bound.greaterThan(0))); + Assertions.assertEquals(1, bound.compareTo(Bound.lessThan(0))); + Assertions.assertEquals(1, bound.compareTo(Bound.atMost(0))); + Assertions.assertEquals(-1, bound.compareTo(Bound.atMost(2))); + Assertions.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); // { x | x < 0} bound = bound.negate(); - Assert.assertEquals((Integer)0, bound.getValue()); - Assert.assertEquals(BoundType.OPEN_UPPER_BOUND, bound.getType()); + Assertions.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals(BoundType.OPEN_UPPER_BOUND, bound.getType()); - Assert.assertNotNull(bound.toRange()); + Assertions.assertNotNull(bound.toRange()); } @Test @@ -145,33 +145,33 @@ public class BoundTest { Bound bound = Bound.lessThan(0); // test - Assert.assertFalse(bound.test(1)); - Assert.assertFalse(bound.test(0)); - Assert.assertTrue(bound.test(-1)); + Assertions.assertFalse(bound.test(1)); + Assertions.assertFalse(bound.test(0)); + Assertions.assertTrue(bound.test(-1)); // getType - Assert.assertEquals(BoundType.OPEN_UPPER_BOUND, bound.getType()); + Assertions.assertEquals(BoundType.OPEN_UPPER_BOUND, bound.getType()); // getValue - Assert.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals((Integer)0, bound.getValue()); // toString - Assert.assertEquals("0)", bound.descBound()); - Assert.assertEquals("{x | x < 0}", bound.toString()); + Assertions.assertEquals("0)", bound.descBound()); + Assertions.assertEquals("{x | x < 0}", bound.toString()); // compareTo - Assert.assertEquals(0, bound.compareTo(bound)); - Assert.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); - Assert.assertEquals(1, bound.compareTo(Bound.greaterThan(-1))); - Assert.assertEquals(-1, bound.compareTo(Bound.greaterThan(0))); - Assert.assertEquals(1, bound.compareTo(Bound.lessThan(-1))); - Assert.assertEquals(-1, bound.compareTo(Bound.atMost(0))); - Assert.assertEquals(1, bound.compareTo(Bound.atMost(-1))); - Assert.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); + Assertions.assertEquals(0, bound.compareTo(bound)); + Assertions.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); + Assertions.assertEquals(1, bound.compareTo(Bound.greaterThan(-1))); + Assertions.assertEquals(-1, bound.compareTo(Bound.greaterThan(0))); + Assertions.assertEquals(1, bound.compareTo(Bound.lessThan(-1))); + Assertions.assertEquals(-1, bound.compareTo(Bound.atMost(0))); + Assertions.assertEquals(1, bound.compareTo(Bound.atMost(-1))); + Assertions.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); // { x | x >= 0} bound = bound.negate(); - Assert.assertEquals((Integer)0, bound.getValue()); - Assert.assertEquals(BoundType.CLOSE_LOWER_BOUND, bound.getType()); + Assertions.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals(BoundType.CLOSE_LOWER_BOUND, bound.getType()); - Assert.assertNotNull(bound.toRange()); + Assertions.assertNotNull(bound.toRange()); } @Test @@ -180,33 +180,33 @@ public class BoundTest { Bound bound = Bound.atMost(0); // test - Assert.assertFalse(bound.test(1)); - Assert.assertTrue(bound.test(0)); - Assert.assertTrue(bound.test(-1)); + Assertions.assertFalse(bound.test(1)); + Assertions.assertTrue(bound.test(0)); + Assertions.assertTrue(bound.test(-1)); // getType - Assert.assertEquals(BoundType.CLOSE_UPPER_BOUND, bound.getType()); + Assertions.assertEquals(BoundType.CLOSE_UPPER_BOUND, bound.getType()); // getValue - Assert.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals((Integer)0, bound.getValue()); // toString - Assert.assertEquals("0]", bound.descBound()); - Assert.assertEquals("{x | x <= 0}", bound.toString()); + Assertions.assertEquals("0]", bound.descBound()); + Assertions.assertEquals("{x | x <= 0}", bound.toString()); // compareTo - Assert.assertEquals(0, bound.compareTo(bound)); - Assert.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); - Assert.assertEquals(1, bound.compareTo(Bound.greaterThan(-1))); - Assert.assertEquals(-1, bound.compareTo(Bound.greaterThan(0))); - Assert.assertEquals(1, bound.compareTo(Bound.atMost(-1))); - Assert.assertEquals(1, bound.compareTo(Bound.lessThan(0))); - Assert.assertEquals(1, bound.compareTo(Bound.lessThan(-1))); - Assert.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); + Assertions.assertEquals(0, bound.compareTo(bound)); + Assertions.assertEquals(-1, bound.compareTo(Bound.noneUpperBound())); + Assertions.assertEquals(1, bound.compareTo(Bound.greaterThan(-1))); + Assertions.assertEquals(-1, bound.compareTo(Bound.greaterThan(0))); + Assertions.assertEquals(1, bound.compareTo(Bound.atMost(-1))); + Assertions.assertEquals(1, bound.compareTo(Bound.lessThan(0))); + Assertions.assertEquals(1, bound.compareTo(Bound.lessThan(-1))); + Assertions.assertEquals(1, bound.compareTo(Bound.noneLowerBound())); // { x | x > 0} bound = bound.negate(); - Assert.assertEquals((Integer)0, bound.getValue()); - Assert.assertEquals(BoundType.OPEN_LOWER_BOUND, bound.getType()); + Assertions.assertEquals((Integer)0, bound.getValue()); + Assertions.assertEquals(BoundType.OPEN_LOWER_BOUND, bound.getType()); - Assert.assertNotNull(bound.toRange()); + Assertions.assertNotNull(bound.toRange()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTypeTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTypeTest.java index 6fc061ae7..484a5144a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTypeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundTypeTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang.range; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * test for {@link BoundType} @@ -10,74 +10,74 @@ public class BoundTypeTest { @Test public void testIsDislocated() { - Assert.assertTrue(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.CLOSE_UPPER_BOUND)); - Assert.assertTrue(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.OPEN_UPPER_BOUND)); - Assert.assertFalse(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.CLOSE_LOWER_BOUND)); - Assert.assertFalse(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.OPEN_LOWER_BOUND)); + Assertions.assertTrue(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.CLOSE_UPPER_BOUND)); + Assertions.assertTrue(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.OPEN_UPPER_BOUND)); + Assertions.assertFalse(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.CLOSE_LOWER_BOUND)); + Assertions.assertFalse(BoundType.CLOSE_LOWER_BOUND.isDislocated(BoundType.OPEN_LOWER_BOUND)); } @Test public void testIsLowerBound() { - Assert.assertFalse(BoundType.CLOSE_UPPER_BOUND.isLowerBound()); - Assert.assertFalse(BoundType.OPEN_UPPER_BOUND.isLowerBound()); - Assert.assertTrue(BoundType.CLOSE_LOWER_BOUND.isLowerBound()); - Assert.assertTrue(BoundType.OPEN_LOWER_BOUND.isLowerBound()); + Assertions.assertFalse(BoundType.CLOSE_UPPER_BOUND.isLowerBound()); + Assertions.assertFalse(BoundType.OPEN_UPPER_BOUND.isLowerBound()); + Assertions.assertTrue(BoundType.CLOSE_LOWER_BOUND.isLowerBound()); + Assertions.assertTrue(BoundType.OPEN_LOWER_BOUND.isLowerBound()); } @Test public void testIsUpperBound() { - Assert.assertTrue(BoundType.CLOSE_UPPER_BOUND.isUpperBound()); - Assert.assertTrue(BoundType.OPEN_UPPER_BOUND.isUpperBound()); - Assert.assertFalse(BoundType.CLOSE_LOWER_BOUND.isUpperBound()); - Assert.assertFalse(BoundType.OPEN_LOWER_BOUND.isUpperBound()); + Assertions.assertTrue(BoundType.CLOSE_UPPER_BOUND.isUpperBound()); + Assertions.assertTrue(BoundType.OPEN_UPPER_BOUND.isUpperBound()); + Assertions.assertFalse(BoundType.CLOSE_LOWER_BOUND.isUpperBound()); + Assertions.assertFalse(BoundType.OPEN_LOWER_BOUND.isUpperBound()); } @Test public void testIsOpen() { - Assert.assertFalse(BoundType.CLOSE_UPPER_BOUND.isOpen()); - Assert.assertTrue(BoundType.OPEN_UPPER_BOUND.isOpen()); - Assert.assertFalse(BoundType.CLOSE_LOWER_BOUND.isOpen()); - Assert.assertTrue(BoundType.OPEN_LOWER_BOUND.isOpen()); + Assertions.assertFalse(BoundType.CLOSE_UPPER_BOUND.isOpen()); + Assertions.assertTrue(BoundType.OPEN_UPPER_BOUND.isOpen()); + Assertions.assertFalse(BoundType.CLOSE_LOWER_BOUND.isOpen()); + Assertions.assertTrue(BoundType.OPEN_LOWER_BOUND.isOpen()); } @Test public void testIsClose() { - Assert.assertTrue(BoundType.CLOSE_UPPER_BOUND.isClose()); - Assert.assertFalse(BoundType.OPEN_UPPER_BOUND.isClose()); - Assert.assertTrue(BoundType.CLOSE_LOWER_BOUND.isClose()); - Assert.assertFalse(BoundType.OPEN_LOWER_BOUND.isClose()); + Assertions.assertTrue(BoundType.CLOSE_UPPER_BOUND.isClose()); + Assertions.assertFalse(BoundType.OPEN_UPPER_BOUND.isClose()); + Assertions.assertTrue(BoundType.CLOSE_LOWER_BOUND.isClose()); + Assertions.assertFalse(BoundType.OPEN_LOWER_BOUND.isClose()); } @Test public void testNegate() { - Assert.assertEquals(BoundType.CLOSE_UPPER_BOUND, BoundType.OPEN_LOWER_BOUND.negate()); - Assert.assertEquals(BoundType.OPEN_UPPER_BOUND, BoundType.CLOSE_LOWER_BOUND.negate()); - Assert.assertEquals(BoundType.OPEN_LOWER_BOUND, BoundType.CLOSE_UPPER_BOUND.negate()); - Assert.assertEquals(BoundType.CLOSE_LOWER_BOUND, BoundType.OPEN_UPPER_BOUND.negate()); + Assertions.assertEquals(BoundType.CLOSE_UPPER_BOUND, BoundType.OPEN_LOWER_BOUND.negate()); + Assertions.assertEquals(BoundType.OPEN_UPPER_BOUND, BoundType.CLOSE_LOWER_BOUND.negate()); + Assertions.assertEquals(BoundType.OPEN_LOWER_BOUND, BoundType.CLOSE_UPPER_BOUND.negate()); + Assertions.assertEquals(BoundType.CLOSE_LOWER_BOUND, BoundType.OPEN_UPPER_BOUND.negate()); } @Test public void testGetSymbol() { - Assert.assertEquals("]", BoundType.CLOSE_UPPER_BOUND.getSymbol()); - Assert.assertEquals(")", BoundType.OPEN_UPPER_BOUND.getSymbol()); - Assert.assertEquals("[", BoundType.CLOSE_LOWER_BOUND.getSymbol()); - Assert.assertEquals("(", BoundType.OPEN_LOWER_BOUND.getSymbol()); + Assertions.assertEquals("]", BoundType.CLOSE_UPPER_BOUND.getSymbol()); + Assertions.assertEquals(")", BoundType.OPEN_UPPER_BOUND.getSymbol()); + Assertions.assertEquals("[", BoundType.CLOSE_LOWER_BOUND.getSymbol()); + Assertions.assertEquals("(", BoundType.OPEN_LOWER_BOUND.getSymbol()); } @Test public void testGetCode() { - Assert.assertEquals(2, BoundType.CLOSE_UPPER_BOUND.getCode()); - Assert.assertEquals(1, BoundType.OPEN_UPPER_BOUND.getCode()); - Assert.assertEquals(-1, BoundType.OPEN_LOWER_BOUND.getCode()); - Assert.assertEquals(-2, BoundType.CLOSE_LOWER_BOUND.getCode()); + Assertions.assertEquals(2, BoundType.CLOSE_UPPER_BOUND.getCode()); + Assertions.assertEquals(1, BoundType.OPEN_UPPER_BOUND.getCode()); + Assertions.assertEquals(-1, BoundType.OPEN_LOWER_BOUND.getCode()); + Assertions.assertEquals(-2, BoundType.CLOSE_LOWER_BOUND.getCode()); } @Test public void testGetOperator() { - Assert.assertEquals("<=", BoundType.CLOSE_UPPER_BOUND.getOperator()); - Assert.assertEquals("<", BoundType.OPEN_UPPER_BOUND.getOperator()); - Assert.assertEquals(">", BoundType.OPEN_LOWER_BOUND.getOperator()); - Assert.assertEquals(">=", BoundType.CLOSE_LOWER_BOUND.getOperator()); + Assertions.assertEquals("<=", BoundType.CLOSE_UPPER_BOUND.getOperator()); + Assertions.assertEquals("<", BoundType.OPEN_UPPER_BOUND.getOperator()); + Assertions.assertEquals(">", BoundType.OPEN_LOWER_BOUND.getOperator()); + Assertions.assertEquals(">=", BoundType.CLOSE_LOWER_BOUND.getOperator()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundedRangeTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundedRangeTest.java index 7d36e19d1..1e9834386 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundedRangeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/range/BoundedRangeTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.lang.range; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * test for {@link BoundedRange} @@ -13,12 +13,12 @@ public class BoundedRangeTest { final BoundedRange range = new BoundedRange<>( Bound.greaterThan(0), Bound.lessThan(10) ); - Assert.assertEquals(range, range); - Assert.assertNotEquals(range, null); - Assert.assertEquals(range, new BoundedRange<>( + Assertions.assertEquals(range, range); + Assertions.assertNotEquals(range, null); + Assertions.assertEquals(range, new BoundedRange<>( Bound.greaterThan(0), Bound.lessThan(10) )); - Assert.assertNotEquals(range, new BoundedRange<>( + Assertions.assertNotEquals(range, new BoundedRange<>( Bound.greaterThan(1), Bound.lessThan(10) )); } @@ -28,10 +28,10 @@ public class BoundedRangeTest { final int hasCode = new BoundedRange<>( Bound.greaterThan(0), Bound.lessThan(10) ).hashCode(); - Assert.assertEquals(hasCode, new BoundedRange<>( + Assertions.assertEquals(hasCode, new BoundedRange<>( Bound.greaterThan(0), Bound.lessThan(10) ).hashCode()); - Assert.assertNotEquals(hasCode, new BoundedRange<>( + Assertions.assertNotEquals(hasCode, new BoundedRange<>( Bound.greaterThan(1), Bound.lessThan(10) ).hashCode()); } @@ -39,245 +39,245 @@ public class BoundedRangeTest { @Test public void testAll() { final BoundedRange range = BoundedRange.all(); - Assert.assertEquals("(-∞, +∞)", range.toString()); + Assertions.assertEquals("(-∞, +∞)", range.toString()); // getBound - Assert.assertFalse(range.hasLowerBound()); - Assert.assertFalse(range.hasUpperBound()); - Assert.assertNull(range.getLowerBoundValue()); - Assert.assertNull(range.getUpperBoundValue()); + Assertions.assertFalse(range.hasLowerBound()); + Assertions.assertFalse(range.hasUpperBound()); + Assertions.assertNull(range.getLowerBoundValue()); + Assertions.assertNull(range.getUpperBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertTrue(range.test(Integer.MAX_VALUE)); - Assert.assertTrue(range.test(Integer.MIN_VALUE)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertTrue(range.test(Integer.MAX_VALUE)); + Assertions.assertTrue(range.test(Integer.MIN_VALUE)); // isXXX - Assert.assertFalse(range.isDisjoint(BoundedRange.open(0, 5))); - Assert.assertEquals(range, range); - Assert.assertNotEquals(range, BoundedRange.open(0, 5)); - Assert.assertTrue(range.isIntersected(BoundedRange.open(0, 5))); - Assert.assertTrue(range.isIntersected(range)); - Assert.assertFalse(range.isSubset(BoundedRange.open(0, 5))); - Assert.assertTrue(range.isSubset(range)); - Assert.assertFalse(range.isProperSubset(BoundedRange.open(0, 5))); - Assert.assertFalse(range.isProperSubset(range)); - Assert.assertTrue(range.isSuperset(BoundedRange.open(0, 5))); - Assert.assertTrue(range.isSuperset(range)); - Assert.assertTrue(range.isProperSuperset(BoundedRange.open(0, 5))); - Assert.assertFalse(range.isProperSuperset(range)); + Assertions.assertFalse(range.isDisjoint(BoundedRange.open(0, 5))); + Assertions.assertEquals(range, range); + Assertions.assertNotEquals(range, BoundedRange.open(0, 5)); + Assertions.assertTrue(range.isIntersected(BoundedRange.open(0, 5))); + Assertions.assertTrue(range.isIntersected(range)); + Assertions.assertFalse(range.isSubset(BoundedRange.open(0, 5))); + Assertions.assertTrue(range.isSubset(range)); + Assertions.assertFalse(range.isProperSubset(BoundedRange.open(0, 5))); + Assertions.assertFalse(range.isProperSubset(range)); + Assertions.assertTrue(range.isSuperset(BoundedRange.open(0, 5))); + Assertions.assertTrue(range.isSuperset(range)); + Assertions.assertTrue(range.isProperSuperset(BoundedRange.open(0, 5))); + Assertions.assertFalse(range.isProperSuperset(range)); // operate - Assert.assertEquals(range, range.unionIfIntersected(BoundedRange.open(0, 5))); - Assert.assertEquals(range, range.span(BoundedRange.open(0, 5))); - Assert.assertNull(range.gap(BoundedRange.open(0, 5))); - Assert.assertEquals(range, range.intersection(range)); - Assert.assertEquals(BoundedRange.open(0, 5), range.intersection(BoundedRange.open(0, 5))); + Assertions.assertEquals(range, range.unionIfIntersected(BoundedRange.open(0, 5))); + Assertions.assertEquals(range, range.span(BoundedRange.open(0, 5))); + Assertions.assertNull(range.gap(BoundedRange.open(0, 5))); + Assertions.assertEquals(range, range.intersection(range)); + Assertions.assertEquals(BoundedRange.open(0, 5), range.intersection(BoundedRange.open(0, 5))); // sub - Assert.assertEquals("(0, +∞)", range.subGreatThan(0).toString()); - Assert.assertEquals("[0, +∞)", range.subAtLeast(0).toString()); - Assert.assertEquals("(-∞, 0)", range.subLessThan(0).toString()); - Assert.assertEquals("(-∞, 0]", range.subAtMost(0).toString()); + Assertions.assertEquals("(0, +∞)", range.subGreatThan(0).toString()); + Assertions.assertEquals("[0, +∞)", range.subAtLeast(0).toString()); + Assertions.assertEquals("(-∞, 0)", range.subLessThan(0).toString()); + Assertions.assertEquals("(-∞, 0]", range.subAtMost(0).toString()); } @Test public void testOpen() { final BoundedRange range = BoundedRange.open(0, 5); - Assert.assertEquals("(0, 5)", range.toString()); + Assertions.assertEquals("(0, 5)", range.toString()); // getBound - Assert.assertTrue(range.hasLowerBound()); - Assert.assertTrue(range.hasUpperBound()); - Assert.assertEquals((Integer)0, range.getLowerBoundValue()); - Assert.assertEquals((Integer)5, range.getUpperBoundValue()); + Assertions.assertTrue(range.hasLowerBound()); + Assertions.assertTrue(range.hasUpperBound()); + Assertions.assertEquals((Integer)0, range.getLowerBoundValue()); + Assertions.assertEquals((Integer)5, range.getUpperBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertFalse(range.test(6)); - Assert.assertFalse(range.test(5)); - Assert.assertTrue(range.test(3)); - Assert.assertFalse(range.test(0)); - Assert.assertFalse(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertFalse(range.test(6)); + Assertions.assertFalse(range.test(5)); + Assertions.assertTrue(range.test(3)); + Assertions.assertFalse(range.test(0)); + Assertions.assertFalse(range.test(-1)); // isXXX - Assert.assertEquals(range, range); - Assert.assertTrue(range.isDisjoint(BoundedRange.open(-5, 0))); // (-5, 0) - Assert.assertTrue(range.isDisjoint(BoundedRange.close(-5, 0))); // [-5, 0] - Assert.assertTrue(range.isIntersected(BoundedRange.close(-5, 1))); // [-5, 1] - Assert.assertTrue(range.isSubset(BoundedRange.close(0, 5))); // [0, 5] - Assert.assertTrue(range.isProperSubset(BoundedRange.close(0, 5))); // [0, 5] - Assert.assertFalse(range.isSuperset(BoundedRange.close(0, 5))); // [0, 5] - Assert.assertFalse(range.isProperSuperset(BoundedRange.close(0, 5))); // [0, 5] + Assertions.assertEquals(range, range); + Assertions.assertTrue(range.isDisjoint(BoundedRange.open(-5, 0))); // (-5, 0) + Assertions.assertTrue(range.isDisjoint(BoundedRange.close(-5, 0))); // [-5, 0] + Assertions.assertTrue(range.isIntersected(BoundedRange.close(-5, 1))); // [-5, 1] + Assertions.assertTrue(range.isSubset(BoundedRange.close(0, 5))); // [0, 5] + Assertions.assertTrue(range.isProperSubset(BoundedRange.close(0, 5))); // [0, 5] + Assertions.assertFalse(range.isSuperset(BoundedRange.close(0, 5))); // [0, 5] + Assertions.assertFalse(range.isProperSuperset(BoundedRange.close(0, 5))); // [0, 5] // operate - Assert.assertEquals("(0, 10]", range.unionIfIntersected(BoundedRange.close(4, 10)).toString()); - Assert.assertEquals("(0, 10)", range.span(BoundedRange.open(9, 10)).toString()); - Assert.assertEquals("(-2, 0]", range.gap(BoundedRange.close(-10, -2)).toString()); - Assert.assertEquals("(3, 5)", range.intersection(BoundedRange.open(3, 10)).toString()); + Assertions.assertEquals("(0, 10]", range.unionIfIntersected(BoundedRange.close(4, 10)).toString()); + Assertions.assertEquals("(0, 10)", range.span(BoundedRange.open(9, 10)).toString()); + Assertions.assertEquals("(-2, 0]", range.gap(BoundedRange.close(-10, -2)).toString()); + Assertions.assertEquals("(3, 5)", range.intersection(BoundedRange.open(3, 10)).toString()); // sub - Assert.assertEquals("(3, 5)", range.subGreatThan(3).toString()); - Assert.assertEquals("[3, 5)", range.subAtLeast(3).toString()); - Assert.assertEquals("(0, 3)", range.subLessThan(3).toString()); - Assert.assertEquals("(0, 3]", range.subAtMost(3).toString()); + Assertions.assertEquals("(3, 5)", range.subGreatThan(3).toString()); + Assertions.assertEquals("[3, 5)", range.subAtLeast(3).toString()); + Assertions.assertEquals("(0, 3)", range.subLessThan(3).toString()); + Assertions.assertEquals("(0, 3]", range.subAtMost(3).toString()); } @Test public void testClose() { final BoundedRange range = BoundedRange.close(0, 5); - Assert.assertEquals("[0, 5]", range.toString()); + Assertions.assertEquals("[0, 5]", range.toString()); // getBound - Assert.assertTrue(range.hasLowerBound()); - Assert.assertTrue(range.hasUpperBound()); - Assert.assertEquals((Integer)0, range.getLowerBoundValue()); - Assert.assertEquals((Integer)5, range.getUpperBoundValue()); + Assertions.assertTrue(range.hasLowerBound()); + Assertions.assertTrue(range.hasUpperBound()); + Assertions.assertEquals((Integer)0, range.getLowerBoundValue()); + Assertions.assertEquals((Integer)5, range.getUpperBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertFalse(range.test(6)); - Assert.assertTrue(range.test(5)); - Assert.assertTrue(range.test(0)); - Assert.assertFalse(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertFalse(range.test(6)); + Assertions.assertTrue(range.test(5)); + Assertions.assertTrue(range.test(0)); + Assertions.assertFalse(range.test(-1)); // isXXX - Assert.assertEquals(range, range); - Assert.assertTrue(range.isDisjoint(BoundedRange.open(-5, 0))); // (-5, 0) - Assert.assertTrue(range.isDisjoint(BoundedRange.close(-5, 0))); // [-5, 0] - Assert.assertTrue(range.isIntersected(BoundedRange.open(-5, 1))); // [-5, 1] - Assert.assertFalse(range.isSubset(BoundedRange.open(0, 5))); // (0, 5) - Assert.assertFalse(range.isProperSubset(BoundedRange.open(0, 5))); // (0, 5) - Assert.assertTrue(range.isSuperset(BoundedRange.open(0, 5))); // (0, 5) - Assert.assertTrue(range.isProperSuperset(BoundedRange.open(0, 5))); // (0, 5) + Assertions.assertEquals(range, range); + Assertions.assertTrue(range.isDisjoint(BoundedRange.open(-5, 0))); // (-5, 0) + Assertions.assertTrue(range.isDisjoint(BoundedRange.close(-5, 0))); // [-5, 0] + Assertions.assertTrue(range.isIntersected(BoundedRange.open(-5, 1))); // [-5, 1] + Assertions.assertFalse(range.isSubset(BoundedRange.open(0, 5))); // (0, 5) + Assertions.assertFalse(range.isProperSubset(BoundedRange.open(0, 5))); // (0, 5) + Assertions.assertTrue(range.isSuperset(BoundedRange.open(0, 5))); // (0, 5) + Assertions.assertTrue(range.isProperSuperset(BoundedRange.open(0, 5))); // (0, 5) // operate - Assert.assertEquals("[0, 5]", range.unionIfIntersected(BoundedRange.open(5, 10)).toString()); - Assert.assertEquals("[0, 10]", range.unionIfIntersected(BoundedRange.close(4, 10)).toString()); - Assert.assertEquals("[0, 10)", range.span(BoundedRange.open(9, 10)).toString()); - Assert.assertEquals("(-2, 0)", range.gap(BoundedRange.close(-10, -2)).toString()); - Assert.assertEquals("(3, 5]", range.intersection(BoundedRange.open(3, 10)).toString()); - Assert.assertNull(range.intersection(BoundedRange.open(5, 10))); + Assertions.assertEquals("[0, 5]", range.unionIfIntersected(BoundedRange.open(5, 10)).toString()); + Assertions.assertEquals("[0, 10]", range.unionIfIntersected(BoundedRange.close(4, 10)).toString()); + Assertions.assertEquals("[0, 10)", range.span(BoundedRange.open(9, 10)).toString()); + Assertions.assertEquals("(-2, 0)", range.gap(BoundedRange.close(-10, -2)).toString()); + Assertions.assertEquals("(3, 5]", range.intersection(BoundedRange.open(3, 10)).toString()); + Assertions.assertNull(range.intersection(BoundedRange.open(5, 10))); // sub - Assert.assertEquals("(3, 5]", range.subGreatThan(3).toString()); - Assert.assertEquals("[3, 5]", range.subAtLeast(3).toString()); - Assert.assertEquals("[0, 3)", range.subLessThan(3).toString()); - Assert.assertEquals("[0, 3]", range.subAtMost(3).toString()); + Assertions.assertEquals("(3, 5]", range.subGreatThan(3).toString()); + Assertions.assertEquals("[3, 5]", range.subAtLeast(3).toString()); + Assertions.assertEquals("[0, 3)", range.subLessThan(3).toString()); + Assertions.assertEquals("[0, 3]", range.subAtMost(3).toString()); } @Test public void testOpenClose() { final BoundedRange range = BoundedRange.openClose(0, 5); - Assert.assertEquals("(0, 5]", range.toString()); + Assertions.assertEquals("(0, 5]", range.toString()); // getBound - Assert.assertTrue(range.hasLowerBound()); - Assert.assertTrue(range.hasUpperBound()); - Assert.assertEquals((Integer)0, range.getLowerBoundValue()); - Assert.assertEquals((Integer)5, range.getUpperBoundValue()); + Assertions.assertTrue(range.hasLowerBound()); + Assertions.assertTrue(range.hasUpperBound()); + Assertions.assertEquals((Integer)0, range.getLowerBoundValue()); + Assertions.assertEquals((Integer)5, range.getUpperBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertFalse(range.test(6)); - Assert.assertTrue(range.test(5)); - Assert.assertFalse(range.test(0)); - Assert.assertFalse(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertFalse(range.test(6)); + Assertions.assertTrue(range.test(5)); + Assertions.assertFalse(range.test(0)); + Assertions.assertFalse(range.test(-1)); } @Test public void testCloseOpen() { final BoundedRange range = BoundedRange.closeOpen(0, 5); - Assert.assertEquals("[0, 5)", range.toString()); + Assertions.assertEquals("[0, 5)", range.toString()); // getBound - Assert.assertTrue(range.hasLowerBound()); - Assert.assertTrue(range.hasUpperBound()); - Assert.assertEquals((Integer)0, range.getLowerBoundValue()); - Assert.assertEquals((Integer)5, range.getUpperBoundValue()); + Assertions.assertTrue(range.hasLowerBound()); + Assertions.assertTrue(range.hasUpperBound()); + Assertions.assertEquals((Integer)0, range.getLowerBoundValue()); + Assertions.assertEquals((Integer)5, range.getUpperBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertFalse(range.test(6)); - Assert.assertFalse(range.test(5)); - Assert.assertTrue(range.test(0)); - Assert.assertFalse(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertFalse(range.test(6)); + Assertions.assertFalse(range.test(5)); + Assertions.assertTrue(range.test(0)); + Assertions.assertFalse(range.test(-1)); } @Test public void testGreatThan() { final BoundedRange range = BoundedRange.greaterThan(0); - Assert.assertEquals("(0, +∞)", range.toString()); + Assertions.assertEquals("(0, +∞)", range.toString()); // getBound - Assert.assertTrue(range.hasLowerBound()); - Assert.assertFalse(range.hasUpperBound()); - Assert.assertEquals((Integer)0, range.getLowerBoundValue()); - Assert.assertNull(range.getUpperBoundValue()); + Assertions.assertTrue(range.hasLowerBound()); + Assertions.assertFalse(range.hasUpperBound()); + Assertions.assertEquals((Integer)0, range.getLowerBoundValue()); + Assertions.assertNull(range.getUpperBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertTrue(range.test(6)); - Assert.assertTrue(range.test(5)); - Assert.assertFalse(range.test(0)); - Assert.assertFalse(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertTrue(range.test(6)); + Assertions.assertTrue(range.test(5)); + Assertions.assertFalse(range.test(0)); + Assertions.assertFalse(range.test(-1)); } @Test public void testAtLeast() { final BoundedRange range = BoundedRange.atLeast(0); - Assert.assertEquals("[0, +∞)", range.toString()); + Assertions.assertEquals("[0, +∞)", range.toString()); // getBound - Assert.assertTrue(range.hasLowerBound()); - Assert.assertFalse(range.hasUpperBound()); - Assert.assertEquals((Integer)0, range.getLowerBoundValue()); - Assert.assertNull(range.getUpperBoundValue()); + Assertions.assertTrue(range.hasLowerBound()); + Assertions.assertFalse(range.hasUpperBound()); + Assertions.assertEquals((Integer)0, range.getLowerBoundValue()); + Assertions.assertNull(range.getUpperBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertTrue(range.test(6)); - Assert.assertTrue(range.test(5)); - Assert.assertTrue(range.test(0)); - Assert.assertFalse(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertTrue(range.test(6)); + Assertions.assertTrue(range.test(5)); + Assertions.assertTrue(range.test(0)); + Assertions.assertFalse(range.test(-1)); } @Test public void testLessThan() { final BoundedRange range = BoundedRange.lessThan(5); - Assert.assertEquals("(-∞, 5)", range.toString()); + Assertions.assertEquals("(-∞, 5)", range.toString()); // getBound - Assert.assertTrue(range.hasUpperBound()); - Assert.assertFalse(range.hasLowerBound()); - Assert.assertEquals((Integer)5, range.getUpperBoundValue()); - Assert.assertNull(range.getLowerBoundValue()); + Assertions.assertTrue(range.hasUpperBound()); + Assertions.assertFalse(range.hasLowerBound()); + Assertions.assertEquals((Integer)5, range.getUpperBoundValue()); + Assertions.assertNull(range.getLowerBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertFalse(range.test(6)); - Assert.assertFalse(range.test(5)); - Assert.assertTrue(range.test(0)); - Assert.assertTrue(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertFalse(range.test(6)); + Assertions.assertFalse(range.test(5)); + Assertions.assertTrue(range.test(0)); + Assertions.assertTrue(range.test(-1)); } @Test public void testAtMost() { final BoundedRange range = BoundedRange.atMost(5); - Assert.assertEquals("(-∞, 5]", range.toString()); + Assertions.assertEquals("(-∞, 5]", range.toString()); // getBound - Assert.assertTrue(range.hasUpperBound()); - Assert.assertFalse(range.hasLowerBound()); - Assert.assertEquals((Integer)5, range.getUpperBoundValue()); - Assert.assertNull(range.getLowerBoundValue()); + Assertions.assertTrue(range.hasUpperBound()); + Assertions.assertFalse(range.hasLowerBound()); + Assertions.assertEquals((Integer)5, range.getUpperBoundValue()); + Assertions.assertNull(range.getLowerBoundValue()); // test - Assert.assertFalse(range.isEmpty()); - Assert.assertFalse(range.test(6)); - Assert.assertTrue(range.test(5)); - Assert.assertTrue(range.test(0)); - Assert.assertTrue(range.test(-1)); + Assertions.assertFalse(range.isEmpty()); + Assertions.assertFalse(range.test(6)); + Assertions.assertTrue(range.test(5)); + Assertions.assertTrue(range.test(0)); + Assertions.assertTrue(range.test(-1)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/lang/range/RangeTest.java b/hutool-core/src/test/java/cn/hutool/core/lang/range/RangeTest.java index 8bc27ea8c..4b7276215 100644 --- a/hutool-core/src/test/java/cn/hutool/core/lang/range/RangeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/lang/range/RangeTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.date.DateRange; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; 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.List; import java.util.NoSuchElementException; @@ -30,11 +30,11 @@ public class RangeTest { return current.offsetNew(DateField.DAY_OF_YEAR, 1); }); - Assert.assertTrue(range.hasNext()); - Assert.assertEquals(DateUtil.parse("2017-01-01"), range.next()); - Assert.assertTrue(range.hasNext()); - Assert.assertEquals(DateUtil.parse("2017-01-02"), range.next()); - Assert.assertFalse(range.hasNext()); + Assertions.assertTrue(range.hasNext()); + Assertions.assertEquals(DateUtil.parse("2017-01-01"), range.next()); + Assertions.assertTrue(range.hasNext()); + Assertions.assertEquals(DateUtil.parse("2017-01-02"), range.next()); + Assertions.assertFalse(range.hasNext()); } @Test @@ -43,10 +43,10 @@ public class RangeTest { final DateTime end = DateUtil.parse("2021-01-03"); final List dayOfMonthList = DateUtil.rangeFunc(start, end, DateField.DAY_OF_YEAR, a -> DateTime.of(a).dayOfMonth()); - Assert.assertArrayEquals(dayOfMonthList.toArray(new Integer[]{}), new Integer[]{1, 2, 3}); + Assertions.assertArrayEquals(dayOfMonthList.toArray(new Integer[]{}), new Integer[]{1, 2, 3}); final List dayOfMonthList2 = DateUtil.rangeFunc(null, null, DateField.DAY_OF_YEAR, a -> DateTime.of(a).dayOfMonth()); - Assert.assertArrayEquals(dayOfMonthList2.toArray(new Integer[]{}), new Integer[]{}); + Assertions.assertArrayEquals(dayOfMonthList2.toArray(new Integer[]{}), new Integer[]{}); } @Test @@ -56,11 +56,11 @@ public class RangeTest { final StringBuilder sb = new StringBuilder(); DateUtil.rangeConsume(start, end, DateField.DAY_OF_YEAR, a -> sb.append(DateTime.of(a).dayOfMonth()).append("#")); - Assert.assertEquals(sb.toString(), "1#2#3#"); + Assertions.assertEquals(sb.toString(), "1#2#3#"); final StringBuilder sb2 = new StringBuilder(); DateUtil.rangeConsume(null, null, DateField.DAY_OF_YEAR, a -> sb2.append(DateTime.of(a).dayOfMonth()).append("#")); - Assert.assertEquals(sb2.toString(), StrUtil.EMPTY); + Assertions.assertEquals(sb2.toString(), StrUtil.EMPTY); } @Test @@ -70,22 +70,22 @@ public class RangeTest { final DateRange range = DateUtil.range(start, end, DateField.MONTH); - Assert.assertTrue(range.hasNext()); - Assert.assertEquals(DateUtil.parse("2021-01-31"), range.next()); - Assert.assertTrue(range.hasNext()); - Assert.assertEquals(DateUtil.parse("2021-02-28"), range.next()); - Assert.assertTrue(range.hasNext()); - Assert.assertEquals(DateUtil.parse("2021-03-31"), range.next()); - Assert.assertFalse(range.hasNext()); + Assertions.assertTrue(range.hasNext()); + Assertions.assertEquals(DateUtil.parse("2021-01-31"), range.next()); + Assertions.assertTrue(range.hasNext()); + Assertions.assertEquals(DateUtil.parse("2021-02-28"), range.next()); + Assertions.assertTrue(range.hasNext()); + Assertions.assertEquals(DateUtil.parse("2021-03-31"), range.next()); + Assertions.assertFalse(range.hasNext()); } @Test public void intRangeTest() { final Range range = new Range<>(1, 1, (current, end, index) -> current >= end ? null : current + 10); - Assert.assertTrue(range.hasNext()); - Assert.assertEquals(Integer.valueOf(1), range.next()); - Assert.assertFalse(range.hasNext()); + Assertions.assertTrue(range.hasNext()); + Assertions.assertEquals(Integer.valueOf(1), range.next()); + Assertions.assertFalse(range.hasNext()); } @Test @@ -95,19 +95,19 @@ public class RangeTest { // 测试包含开始和结束情况下步进为1的情况 DateRange range = DateUtil.range(start, end, DateField.DAY_OF_YEAR); - Assert.assertEquals(range.next(), DateUtil.parse("2017-01-01")); - Assert.assertEquals(range.next(), DateUtil.parse("2017-01-02")); - Assert.assertEquals(range.next(), DateUtil.parse("2017-01-03")); + Assertions.assertEquals(range.next(), DateUtil.parse("2017-01-01")); + Assertions.assertEquals(range.next(), DateUtil.parse("2017-01-02")); + Assertions.assertEquals(range.next(), DateUtil.parse("2017-01-03")); try { range.next(); - Assert.fail("已超过边界,下一个元素不应该存在!"); + Assertions.fail("已超过边界,下一个元素不应该存在!"); } catch (final NoSuchElementException ignored) { } // 测试多步进的情况 range = new DateRange(start, end, DateField.DAY_OF_YEAR, 2); - Assert.assertEquals(DateUtil.parse("2017-01-01"), range.next()); - Assert.assertEquals(DateUtil.parse("2017-01-03"), range.next()); + Assertions.assertEquals(DateUtil.parse("2017-01-01"), range.next()); + Assertions.assertEquals(DateUtil.parse("2017-01-03"), range.next()); } @Test @@ -117,12 +117,12 @@ public class RangeTest { // 测试不包含开始结束时间的情况 final DateRange range = new DateRange(start, end, DateField.DAY_OF_YEAR, 1, false, false); - Assert.assertEquals(DateUtil.parse("2017-01-02"), range.next()); - Assert.assertEquals(DateUtil.parse("2017-01-03"), range.next()); - Assert.assertEquals(DateUtil.parse("2017-01-04"), range.next()); + Assertions.assertEquals(DateUtil.parse("2017-01-02"), range.next()); + Assertions.assertEquals(DateUtil.parse("2017-01-03"), range.next()); + Assertions.assertEquals(DateUtil.parse("2017-01-04"), range.next()); try { range.next(); - Assert.fail("不包含结束时间情况下,下一个元素不应该存在!"); + Assertions.fail("不包含结束时间情况下,下一个元素不应该存在!"); } catch (final NoSuchElementException ignored) { } } @@ -133,8 +133,8 @@ public class RangeTest { final DateTime end = DateUtil.parse("2017-01-31"); final List rangeToList = DateUtil.rangeToList(start, end, DateField.DAY_OF_YEAR); - Assert.assertEquals(DateUtil.parse("2017-01-01"), rangeToList.get(0)); - Assert.assertEquals(DateUtil.parse("2017-01-02"), rangeToList.get(1)); + Assertions.assertEquals(DateUtil.parse("2017-01-01"), rangeToList.get(0)); + Assertions.assertEquals(DateUtil.parse("2017-01-02"), rangeToList.get(1)); } @@ -150,8 +150,8 @@ public class RangeTest { final DateRange endRange = DateUtil.range(start1, end1, DateField.DAY_OF_YEAR); // 交集 final List dateTimes = DateUtil.rangeContains(startRange, endRange); - Assert.assertEquals(1, dateTimes.size()); - Assert.assertEquals(DateUtil.parse("2017-01-31"), dateTimes.get(0)); + Assertions.assertEquals(1, dateTimes.size()); + Assertions.assertEquals(DateUtil.parse("2017-01-31"), dateTimes.get(0)); } @Test @@ -167,8 +167,8 @@ public class RangeTest { // 差集 final List dateTimes1 = DateUtil.rangeNotContains(startRange, endRange); - Assert.assertEquals(1, dateTimes1.size()); - Assert.assertEquals(DateUtil.parse("2017-01-31"), dateTimes1.get(0)); + Assertions.assertEquals(1, dateTimes1.size()); + Assertions.assertEquals(DateUtil.parse("2017-01-31"), dateTimes1.get(0)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/BiMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/BiMapTest.java index a26816b64..971be19db 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/BiMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/BiMapTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.map; -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,11 +13,11 @@ public class BiMapTest { biMap.put("aaa", 111); biMap.put("bbb", 222); - Assert.assertEquals(new Integer(111), biMap.get("aaa")); - Assert.assertEquals(new Integer(222), biMap.get("bbb")); + Assertions.assertEquals(new Integer(111), biMap.get("aaa")); + Assertions.assertEquals(new Integer(222), biMap.get("bbb")); - Assert.assertEquals("aaa", biMap.getKey(111)); - Assert.assertEquals("bbb", biMap.getKey(222)); + Assertions.assertEquals("aaa", biMap.getKey(111)); + Assertions.assertEquals("bbb", biMap.getKey(222)); } @Test @@ -27,8 +27,8 @@ public class BiMapTest { biMap.put("bbb", 222); biMap.computeIfAbsent("ccc", s -> 333); - Assert.assertEquals(new Integer(333), biMap.get("ccc")); - Assert.assertEquals("ccc", biMap.getKey(333)); + Assertions.assertEquals(new Integer(333), biMap.get("ccc")); + Assertions.assertEquals("ccc", biMap.getKey(333)); } @Test @@ -38,7 +38,7 @@ public class BiMapTest { biMap.put("bbb", 222); biMap.putIfAbsent("ccc", 333); - Assert.assertEquals(new Integer(333), biMap.get("ccc")); - Assert.assertEquals("ccc", biMap.getKey(333)); + Assertions.assertEquals(new Integer(333), biMap.get("ccc")); + Assertions.assertEquals("ccc", biMap.getKey(333)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/CamelCaseMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/CamelCaseMapTest.java index b436a7b7f..78ad32070 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/CamelCaseMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/CamelCaseMapTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.map; import cn.hutool.core.io.SerializeUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CamelCaseMapTest { @@ -10,16 +10,16 @@ public class CamelCaseMapTest { public void caseInsensitiveMapTest() { final CamelCaseMap map = new CamelCaseMap<>(); map.put("customKey", "OK"); - Assert.assertEquals("OK", map.get("customKey")); - Assert.assertEquals("OK", map.get("custom_key")); + Assertions.assertEquals("OK", map.get("customKey")); + Assertions.assertEquals("OK", map.get("custom_key")); } @Test public void caseInsensitiveLinkedMapTest() { final CamelCaseLinkedMap map = new CamelCaseLinkedMap<>(); map.put("customKey", "OK"); - Assert.assertEquals("OK", map.get("customKey")); - Assert.assertEquals("OK", map.get("custom_key")); + Assertions.assertEquals("OK", map.get("customKey")); + Assertions.assertEquals("OK", map.get("custom_key")); } @Test @@ -27,10 +27,10 @@ public class CamelCaseMapTest { final CamelCaseMap map = new CamelCaseMap<>(); map.put("serializable_key", "OK"); final CamelCaseMap deSerializableMap = SerializeUtil.deserialize(SerializeUtil.serialize(map)); - Assert.assertEquals("OK", deSerializableMap.get("serializable_key")); - Assert.assertEquals("OK", deSerializableMap.get("serializableKey")); + Assertions.assertEquals("OK", deSerializableMap.get("serializable_key")); + Assertions.assertEquals("OK", deSerializableMap.get("serializableKey")); deSerializableMap.put("serializable_func", "OK"); - Assert.assertEquals("OK", deSerializableMap.get("serializable_func")); - Assert.assertEquals("OK", deSerializableMap.get("serializableFunc")); + Assertions.assertEquals("OK", deSerializableMap.get("serializable_func")); + Assertions.assertEquals("OK", deSerializableMap.get("serializableFunc")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/CaseInsensitiveMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/CaseInsensitiveMapTest.java index 8e572f0ca..2256c84f4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/CaseInsensitiveMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/CaseInsensitiveMapTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -11,16 +11,16 @@ public class CaseInsensitiveMapTest { public void caseInsensitiveMapTest() { final CaseInsensitiveMap map = new CaseInsensitiveMap<>(); map.put("aAA", "OK"); - Assert.assertEquals("OK", map.get("aaa")); - Assert.assertEquals("OK", map.get("AAA")); + Assertions.assertEquals("OK", map.get("aaa")); + Assertions.assertEquals("OK", map.get("AAA")); } @Test public void caseInsensitiveLinkedMapTest() { final CaseInsensitiveLinkedMap map = new CaseInsensitiveLinkedMap<>(); map.put("aAA", "OK"); - Assert.assertEquals("OK", map.get("aaa")); - Assert.assertEquals("OK", map.get("AAA")); + Assertions.assertEquals("OK", map.get("aaa")); + Assertions.assertEquals("OK", map.get("AAA")); } @Test @@ -32,6 +32,6 @@ public class CaseInsensitiveMapTest { map.merge(b.getKey(), b.getValue(), (A, B) -> A); map.merge(a.getKey(), a.getValue(), (A, B) -> A); - Assert.assertEquals(1, map.size()); + Assertions.assertEquals(1, map.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/CollectionValueMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/CollectionValueMapTest.java index e624bcc6b..906f83c7c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/CollectionValueMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/CollectionValueMapTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.map; import cn.hutool.core.map.multi.CollectionValueMap; import cn.hutool.core.map.multi.MultiValueMap; 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.*; @@ -13,9 +13,9 @@ public class CollectionValueMapTest { @Test public void putTest() { MultiValueMap map = new CollectionValueMap<>(); - Assert.assertNull(map.put(1, Arrays.asList("a", "b"))); + Assertions.assertNull(map.put(1, Arrays.asList("a", "b"))); Collection collection = map.put(1, Arrays.asList("c", "d")); - Assert.assertEquals(Arrays.asList("a", "b"), collection); + Assertions.assertEquals(Arrays.asList("a", "b"), collection); } @Test @@ -24,112 +24,112 @@ public class CollectionValueMapTest { Map> source = new HashMap<>(); source.put(1, Arrays.asList("a", "b", "c")); map.putAll(source); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); } @Test public void putValueTest() { MultiValueMap map = new CollectionValueMap<>(); - Assert.assertTrue(map.putValue(1, "a")); - Assert.assertTrue(map.putValue(1, "b")); - Assert.assertTrue(map.putValue(1, "c")); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertTrue(map.putValue(1, "a")); + Assertions.assertTrue(map.putValue(1, "b")); + Assertions.assertTrue(map.putValue(1, "c")); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); } @Test public void putAllValueTest() { MultiValueMap map = new CollectionValueMap<>(); - Assert.assertTrue(map.putAllValues(1, Arrays.asList("a", "b", "c"))); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertTrue(map.putAllValues(1, Arrays.asList("a", "b", "c"))); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); Map> source = new HashMap<>(); - Assert.assertTrue(map.putValue(1, "e")); - Assert.assertTrue(map.putValue(1, "f")); + Assertions.assertTrue(map.putValue(1, "e")); + Assertions.assertTrue(map.putValue(1, "f")); map.putAllValues(source); - Assert.assertEquals(Arrays.asList("a", "b", "c", "e", "f"), map.get(1)); + Assertions.assertEquals(Arrays.asList("a", "b", "c", "e", "f"), map.get(1)); } @Test public void putValuesTest() { MultiValueMap map = new CollectionValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); } @Test public void testFilterAllValues() { MultiValueMap map = new CollectionValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertTrue(map.putValues(2, "a", "b", "c")); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertTrue(map.putValues(2, "a", "b", "c")); - Assert.assertEquals(map, map.filterAllValues((k, v) -> StrUtil.equals(v, "a"))); - Assert.assertEquals(Collections.singletonList("a"), map.getValues(1)); - Assert.assertEquals(Collections.singletonList("a"), map.getValues(2)); + Assertions.assertEquals(map, map.filterAllValues((k, v) -> StrUtil.equals(v, "a"))); + Assertions.assertEquals(Collections.singletonList("a"), map.getValues(1)); + Assertions.assertEquals(Collections.singletonList("a"), map.getValues(2)); - Assert.assertEquals(map, map.filterAllValues(v -> !StrUtil.equals(v, "a"))); - Assert.assertEquals(Collections.emptyList(), map.getValues(1)); - Assert.assertEquals(Collections.emptyList(), map.getValues(2)); + Assertions.assertEquals(map, map.filterAllValues(v -> !StrUtil.equals(v, "a"))); + Assertions.assertEquals(Collections.emptyList(), map.getValues(1)); + Assertions.assertEquals(Collections.emptyList(), map.getValues(2)); } @Test public void testReplaceAllValues() { MultiValueMap map = new CollectionValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertTrue(map.putValues(2, "a", "b", "c")); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertTrue(map.putValues(2, "a", "b", "c")); - Assert.assertEquals(map, map.replaceAllValues((k, v) -> v + "2")); - Assert.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(1)); - Assert.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(2)); + Assertions.assertEquals(map, map.replaceAllValues((k, v) -> v + "2")); + Assertions.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(1)); + Assertions.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(2)); - Assert.assertEquals(map, map.replaceAllValues(v -> v + "3")); - Assert.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(1)); - Assert.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(2)); + Assertions.assertEquals(map, map.replaceAllValues(v -> v + "3")); + Assertions.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(1)); + Assertions.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(2)); } @Test public void removeValueTest() { MultiValueMap map = new CollectionValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeValue(1, "d")); - Assert.assertTrue(map.removeValue(1, "c")); - Assert.assertEquals(Arrays.asList("a", "b"), map.get(1)); + Assertions.assertFalse(map.removeValue(1, "d")); + Assertions.assertTrue(map.removeValue(1, "c")); + Assertions.assertEquals(Arrays.asList("a", "b"), map.get(1)); } @Test public void removeAllValuesTest() { MultiValueMap map = new CollectionValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeAllValues(1, Arrays.asList("e", "f"))); - Assert.assertTrue(map.removeAllValues(1, Arrays.asList("b", "c"))); - Assert.assertEquals(Collections.singletonList("a"), map.get(1)); + Assertions.assertFalse(map.removeAllValues(1, Arrays.asList("e", "f"))); + Assertions.assertTrue(map.removeAllValues(1, Arrays.asList("b", "c"))); + Assertions.assertEquals(Collections.singletonList("a"), map.get(1)); } @Test public void removeValuesTest() { MultiValueMap map = new CollectionValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeValues(1, "e", "f")); - Assert.assertTrue(map.removeValues(1, "b", "c")); - Assert.assertEquals(Collections.singletonList("a"), map.get(1)); + Assertions.assertFalse(map.removeValues(1, "e", "f")); + Assertions.assertTrue(map.removeValues(1, "b", "c")); + Assertions.assertEquals(Collections.singletonList("a"), map.get(1)); } @Test public void getValuesTest() { MultiValueMap map = new CollectionValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertEquals(Collections.emptyList(), map.getValues(2)); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.getValues(1)); + Assertions.assertEquals(Collections.emptyList(), map.getValues(2)); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.getValues(1)); } @Test public void sizeTest() { MultiValueMap map = new CollectionValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertEquals(0, map.size(2)); - Assert.assertEquals(3, map.size(1)); + Assertions.assertEquals(0, map.size(2)); + Assertions.assertEquals(3, map.size(1)); } @Test @@ -142,8 +142,8 @@ public class CollectionValueMapTest { keys.add(k); values.add(v); }); - Assert.assertEquals(Arrays.asList(1, 1, 1), keys); - Assert.assertEquals(Arrays.asList("a", "b", "c"), values); + Assertions.assertEquals(Arrays.asList(1, 1, 1), keys); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), values); } @Test @@ -151,7 +151,7 @@ public class CollectionValueMapTest { MultiValueMap map = new CollectionValueMap<>(new LinkedHashMap<>()); map.putAllValues(1, Arrays.asList("a", "b", "c")); map.putAllValues(2, Arrays.asList("d", "e")); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("a", "b", "c", "d", "e"), map.allValues() ); diff --git a/hutool-core/src/test/java/cn/hutool/core/map/GraphTest.java b/hutool-core/src/test/java/cn/hutool/core/map/GraphTest.java index 758d3e5eb..12a43c077 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/GraphTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/GraphTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.map; import cn.hutool.core.map.multi.Graph; -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.LinkedHashSet; @@ -20,9 +20,9 @@ public class GraphTest { graph.putEdge(1, 2); graph.putEdge(2, 0); - Assert.assertEquals(asSet(1, 2), graph.getValues(0)); - Assert.assertEquals(asSet(0, 2), graph.getValues(1)); - Assert.assertEquals(asSet(0, 1), graph.getValues(2)); + Assertions.assertEquals(asSet(1, 2), graph.getValues(0)); + Assertions.assertEquals(asSet(0, 2), graph.getValues(1)); + Assertions.assertEquals(asSet(0, 1), graph.getValues(2)); } @Test @@ -36,29 +36,29 @@ public class GraphTest { graph.putEdge(2, 3); graph.putEdge(3, 0); - Assert.assertTrue(graph.containsEdge(0, 1)); - Assert.assertTrue(graph.containsEdge(1, 0)); + Assertions.assertTrue(graph.containsEdge(0, 1)); + Assertions.assertTrue(graph.containsEdge(1, 0)); - Assert.assertTrue(graph.containsEdge(1, 2)); - Assert.assertTrue(graph.containsEdge(2, 1)); + Assertions.assertTrue(graph.containsEdge(1, 2)); + Assertions.assertTrue(graph.containsEdge(2, 1)); - Assert.assertTrue(graph.containsEdge(2, 3)); - Assert.assertTrue(graph.containsEdge(3, 2)); + Assertions.assertTrue(graph.containsEdge(2, 3)); + Assertions.assertTrue(graph.containsEdge(3, 2)); - Assert.assertTrue(graph.containsEdge(3, 0)); - Assert.assertTrue(graph.containsEdge(0, 3)); + Assertions.assertTrue(graph.containsEdge(3, 0)); + Assertions.assertTrue(graph.containsEdge(0, 3)); - Assert.assertFalse(graph.containsEdge(1, 3)); + Assertions.assertFalse(graph.containsEdge(1, 3)); } @Test public void removeEdge() { final Graph graph = new Graph<>(); graph.putEdge(0, 1); - Assert.assertTrue(graph.containsEdge(0, 1)); + Assertions.assertTrue(graph.containsEdge(0, 1)); graph.removeEdge(0, 1); - Assert.assertFalse(graph.containsEdge(0, 1)); + Assertions.assertFalse(graph.containsEdge(0, 1)); } @Test @@ -72,14 +72,14 @@ public class GraphTest { graph.putEdge(2, 3); graph.putEdge(3, 0); - Assert.assertTrue(graph.containsAssociation(0, 2)); - Assert.assertTrue(graph.containsAssociation(2, 0)); + Assertions.assertTrue(graph.containsAssociation(0, 2)); + Assertions.assertTrue(graph.containsAssociation(2, 0)); - Assert.assertTrue(graph.containsAssociation(1, 3)); - Assert.assertTrue(graph.containsAssociation(3, 1)); + Assertions.assertTrue(graph.containsAssociation(1, 3)); + Assertions.assertTrue(graph.containsAssociation(3, 1)); - Assert.assertFalse(graph.containsAssociation(-1, 1)); - Assert.assertFalse(graph.containsAssociation(1, -1)); + Assertions.assertFalse(graph.containsAssociation(-1, 1)); + Assertions.assertFalse(graph.containsAssociation(1, -1)); } @Test @@ -93,19 +93,19 @@ public class GraphTest { graph.putEdge(2, 3); graph.putEdge(3, 0); - Assert.assertEquals(asSet(0, 1, 2, 3), graph.getAssociatedPoints(0, true)); - Assert.assertEquals(asSet(1, 2, 3), graph.getAssociatedPoints(0, false)); + Assertions.assertEquals(asSet(0, 1, 2, 3), graph.getAssociatedPoints(0, true)); + Assertions.assertEquals(asSet(1, 2, 3), graph.getAssociatedPoints(0, false)); - Assert.assertEquals(asSet(1, 2, 3, 0), graph.getAssociatedPoints(1, true)); - Assert.assertEquals(asSet(2, 3, 0), graph.getAssociatedPoints(1, false)); + Assertions.assertEquals(asSet(1, 2, 3, 0), graph.getAssociatedPoints(1, true)); + Assertions.assertEquals(asSet(2, 3, 0), graph.getAssociatedPoints(1, false)); - Assert.assertEquals(asSet(2, 3, 0, 1), graph.getAssociatedPoints(2, true)); - Assert.assertEquals(asSet(3, 0, 1), graph.getAssociatedPoints(2, false)); + Assertions.assertEquals(asSet(2, 3, 0, 1), graph.getAssociatedPoints(2, true)); + Assertions.assertEquals(asSet(3, 0, 1), graph.getAssociatedPoints(2, false)); - Assert.assertEquals(asSet(3, 0, 1, 2), graph.getAssociatedPoints(3, true)); - Assert.assertEquals(asSet(0, 1, 2), graph.getAssociatedPoints(3, false)); + Assertions.assertEquals(asSet(3, 0, 1, 2), graph.getAssociatedPoints(3, true)); + Assertions.assertEquals(asSet(0, 1, 2), graph.getAssociatedPoints(3, false)); - Assert.assertTrue(graph.getAssociatedPoints(-1, false).isEmpty()); + Assertions.assertTrue(graph.getAssociatedPoints(-1, false).isEmpty()); } @Test @@ -119,10 +119,10 @@ public class GraphTest { graph.putEdge(2, 3); graph.putEdge(3, 0); - Assert.assertEquals(asSet(1, 3), graph.getAdjacentPoints(0)); - Assert.assertEquals(asSet(2, 0), graph.getAdjacentPoints(1)); - Assert.assertEquals(asSet(1, 3), graph.getAdjacentPoints(2)); - Assert.assertEquals(asSet(2, 0), graph.getAdjacentPoints(3)); + Assertions.assertEquals(asSet(1, 3), graph.getAdjacentPoints(0)); + Assertions.assertEquals(asSet(2, 0), graph.getAdjacentPoints(1)); + Assertions.assertEquals(asSet(1, 3), graph.getAdjacentPoints(2)); + Assertions.assertEquals(asSet(2, 0), graph.getAdjacentPoints(3)); } @Test @@ -141,10 +141,10 @@ public class GraphTest { // 3 -- 2 graph.removePoint(1); - Assert.assertEquals(asSet(3), graph.getAdjacentPoints(0)); - Assert.assertTrue(graph.getAdjacentPoints(1).isEmpty()); - Assert.assertEquals(asSet(3), graph.getAdjacentPoints(2)); - Assert.assertEquals(asSet(2, 0), graph.getAdjacentPoints(3)); + Assertions.assertEquals(asSet(3), graph.getAdjacentPoints(0)); + Assertions.assertTrue(graph.getAdjacentPoints(1).isEmpty()); + Assertions.assertEquals(asSet(3), graph.getAdjacentPoints(2)); + Assertions.assertEquals(asSet(2, 0), graph.getAdjacentPoints(3)); } @SafeVarargs diff --git a/hutool-core/src/test/java/cn/hutool/core/map/Issue2349Test.java b/hutool-core/src/test/java/cn/hutool/core/map/Issue2349Test.java index 70b9618bc..dcdc2ade0 100755 --- a/hutool-core/src/test/java/cn/hutool/core/map/Issue2349Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/Issue2349Test.java @@ -1,7 +1,7 @@ package cn.hutool.core.map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.concurrent.ConcurrentHashMap; @@ -15,8 +15,8 @@ public class Issue2349Test { final ConcurrentHashMap map=new SafeConcurrentHashMap<>(16); map.computeIfAbsent("AaAa", key->map.computeIfAbsent("BBBB",key2->42)); - Assert.assertEquals(2, map.size()); - Assert.assertEquals(Integer.valueOf(42), map.get("AaAa")); - Assert.assertEquals(Integer.valueOf(42), map.get("BBBB")); + Assertions.assertEquals(2, map.size()); + Assertions.assertEquals(Integer.valueOf(42), map.get("AaAa")); + Assertions.assertEquals(Integer.valueOf(42), map.get("BBBB")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/ListValueMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/ListValueMapTest.java index b607127c5..656fe354f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/ListValueMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/ListValueMapTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.map; import cn.hutool.core.map.multi.ListValueMap; import cn.hutool.core.map.multi.MultiValueMap; 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.*; @@ -13,9 +13,9 @@ public class ListValueMapTest { @Test public void putTest() { MultiValueMap map = new ListValueMap<>(); - Assert.assertNull(map.put(1, Arrays.asList("a", "b"))); + Assertions.assertNull(map.put(1, Arrays.asList("a", "b"))); Collection collection = map.put(1, Arrays.asList("c", "d")); - Assert.assertEquals(Arrays.asList("a", "b"), collection); + Assertions.assertEquals(Arrays.asList("a", "b"), collection); } @Test @@ -24,112 +24,112 @@ public class ListValueMapTest { Map> source = new HashMap<>(); source.put(1, Arrays.asList("a", "b", "c")); map.putAll(source); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); } @Test public void putValueTest() { MultiValueMap map = new ListValueMap<>(); - Assert.assertTrue(map.putValue(1, "a")); - Assert.assertTrue(map.putValue(1, "b")); - Assert.assertTrue(map.putValue(1, "c")); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertTrue(map.putValue(1, "a")); + Assertions.assertTrue(map.putValue(1, "b")); + Assertions.assertTrue(map.putValue(1, "c")); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); } @Test public void putAllValueTest() { MultiValueMap map = new ListValueMap<>(); - Assert.assertTrue(map.putAllValues(1, Arrays.asList("a", "b", "c"))); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertTrue(map.putAllValues(1, Arrays.asList("a", "b", "c"))); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); Map> source = new HashMap<>(); - Assert.assertTrue(map.putValue(1, "e")); - Assert.assertTrue(map.putValue(1, "f")); + Assertions.assertTrue(map.putValue(1, "e")); + Assertions.assertTrue(map.putValue(1, "f")); map.putAllValues(source); - Assert.assertEquals(Arrays.asList("a", "b", "c", "e", "f"), map.get(1)); + Assertions.assertEquals(Arrays.asList("a", "b", "c", "e", "f"), map.get(1)); } @Test public void putValuesTest() { MultiValueMap map = new ListValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); } @Test public void removeValueTest() { MultiValueMap map = new ListValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeValue(1, "d")); - Assert.assertTrue(map.removeValue(1, "c")); - Assert.assertEquals(Arrays.asList("a", "b"), map.get(1)); + Assertions.assertFalse(map.removeValue(1, "d")); + Assertions.assertTrue(map.removeValue(1, "c")); + Assertions.assertEquals(Arrays.asList("a", "b"), map.get(1)); } @Test public void removeAllValuesTest() { MultiValueMap map = new ListValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeAllValues(1, Arrays.asList("e", "f"))); - Assert.assertTrue(map.removeAllValues(1, Arrays.asList("b", "c"))); - Assert.assertEquals(Collections.singletonList("a"), map.get(1)); + Assertions.assertFalse(map.removeAllValues(1, Arrays.asList("e", "f"))); + Assertions.assertTrue(map.removeAllValues(1, Arrays.asList("b", "c"))); + Assertions.assertEquals(Collections.singletonList("a"), map.get(1)); } @Test public void removeValuesTest() { MultiValueMap map = new ListValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeValues(1, "e", "f")); - Assert.assertTrue(map.removeValues(1, "b", "c")); - Assert.assertEquals(Collections.singletonList("a"), map.get(1)); + Assertions.assertFalse(map.removeValues(1, "e", "f")); + Assertions.assertTrue(map.removeValues(1, "b", "c")); + Assertions.assertEquals(Collections.singletonList("a"), map.get(1)); } @Test public void testFilterAllValues() { MultiValueMap map = new ListValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertTrue(map.putValues(2, "a", "b", "c")); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertTrue(map.putValues(2, "a", "b", "c")); - Assert.assertEquals(map, map.filterAllValues((k, v) -> StrUtil.equals(v, "a"))); - Assert.assertEquals(Collections.singletonList("a"), map.getValues(1)); - Assert.assertEquals(Collections.singletonList("a"), map.getValues(2)); + Assertions.assertEquals(map, map.filterAllValues((k, v) -> StrUtil.equals(v, "a"))); + Assertions.assertEquals(Collections.singletonList("a"), map.getValues(1)); + Assertions.assertEquals(Collections.singletonList("a"), map.getValues(2)); - Assert.assertEquals(map, map.filterAllValues(v -> !StrUtil.equals(v, "a"))); - Assert.assertEquals(Collections.emptyList(), map.getValues(1)); - Assert.assertEquals(Collections.emptyList(), map.getValues(2)); + Assertions.assertEquals(map, map.filterAllValues(v -> !StrUtil.equals(v, "a"))); + Assertions.assertEquals(Collections.emptyList(), map.getValues(1)); + Assertions.assertEquals(Collections.emptyList(), map.getValues(2)); } @Test public void testReplaceAllValues() { MultiValueMap map = new ListValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertTrue(map.putValues(2, "a", "b", "c")); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertTrue(map.putValues(2, "a", "b", "c")); - Assert.assertEquals(map, map.replaceAllValues((k, v) -> v + "2")); - Assert.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(1)); - Assert.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(2)); + Assertions.assertEquals(map, map.replaceAllValues((k, v) -> v + "2")); + Assertions.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(1)); + Assertions.assertEquals(Arrays.asList("a2", "b2", "c2"), map.getValues(2)); - Assert.assertEquals(map, map.replaceAllValues(v -> v + "3")); - Assert.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(1)); - Assert.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(2)); + Assertions.assertEquals(map, map.replaceAllValues(v -> v + "3")); + Assertions.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(1)); + Assertions.assertEquals(Arrays.asList("a23", "b23", "c23"), map.getValues(2)); } @Test public void getValuesTest() { MultiValueMap map = new ListValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertEquals(Collections.emptyList(), map.getValues(2)); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.getValues(1)); + Assertions.assertEquals(Collections.emptyList(), map.getValues(2)); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.getValues(1)); } @Test public void sizeTest() { MultiValueMap map = new ListValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertEquals(0, map.size(2)); - Assert.assertEquals(3, map.size(1)); + Assertions.assertEquals(0, map.size(2)); + Assertions.assertEquals(3, map.size(1)); } @Test @@ -142,8 +142,8 @@ public class ListValueMapTest { keys.add(k); values.add(v); }); - Assert.assertEquals(Arrays.asList(1, 1, 1), keys); - Assert.assertEquals(Arrays.asList("a", "b", "c"), values); + Assertions.assertEquals(Arrays.asList(1, 1, 1), keys); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), values); } @Test @@ -151,7 +151,7 @@ public class ListValueMapTest { MultiValueMap map = new ListValueMap<>(); map.putAllValues(1, Arrays.asList("a", "b", "c")); map.putAllValues(2, Arrays.asList("d", "e")); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("a", "b", "c", "d", "e"), map.allValues() ); diff --git a/hutool-core/src/test/java/cn/hutool/core/map/MapBuilderTest.java b/hutool-core/src/test/java/cn/hutool/core/map/MapBuilderTest.java index f3c029619..8b725c2be 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/MapBuilderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/MapBuilderTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -16,10 +16,10 @@ public class MapBuilderTest { .put(false, "d", () -> getValue(4)) .build(); - Assert.assertEquals(map.get("a"), "1"); - Assert.assertFalse(map.containsKey("b")); - Assert.assertEquals(map.get("c"), "3"); - Assert.assertFalse(map.containsKey("d")); + Assertions.assertEquals(map.get("a"), "1"); + Assertions.assertFalse(map.containsKey("b")); + Assertions.assertEquals(map.get("c"), "3"); + Assertions.assertFalse(map.containsKey("d")); } public String getValue(final int value) { diff --git a/hutool-core/src/test/java/cn/hutool/core/map/MapJoinerTest.java b/hutool-core/src/test/java/cn/hutool/core/map/MapJoinerTest.java index 96c6ee2d1..66213a553 100755 --- a/hutool-core/src/test/java/cn/hutool/core/map/MapJoinerTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/MapJoinerTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class MapJoinerTest { @@ -11,7 +11,7 @@ public class MapJoinerTest { final MapJoiner joiner = MapJoiner.of("+", "-"); joiner.append(v1, null); - Assert.assertEquals("id-12+name-张三+age-23", joiner.toString()); + Assertions.assertEquals("id-12+name-张三+age-23", joiner.toString()); } @Test @@ -20,6 +20,6 @@ public class MapJoinerTest { final MapJoiner joiner = MapJoiner.of("+", "-"); joiner.append(v1, (entry)->"age".equals(entry.getKey())); - Assert.assertEquals("age-23", joiner.toString()); + Assertions.assertEquals("age-23", joiner.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/MapUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/map/MapUtilTest.java index 83cd78dcb..20bf08c8c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/MapUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/MapUtilTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.lang.Opt; import cn.hutool.core.text.StrUtil; 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; import java.util.ArrayDeque; import java.util.ArrayList; @@ -55,10 +55,10 @@ public class MapUtilTest { final Map map2 = MapUtil.filter(map, t -> Convert.toInt(t.getValue()) % 2 == 0); - Assert.assertEquals(2, map2.size()); + Assertions.assertEquals(2, map2.size()); - Assert.assertEquals("2", map2.get("b")); - Assert.assertEquals("4", map2.get("d")); + Assertions.assertEquals("2", map2.get("b")); + Assertions.assertEquals("4", map2.get("d")); } @Test @@ -72,9 +72,9 @@ public class MapUtilTest { final Map resultMap = MapUtil.map(adjectivesMap, (k, v) -> v + " " + PeopleEnum.values()[k].name().toLowerCase()); - Assert.assertEquals("lovely girl", resultMap.get(0)); - Assert.assertEquals("friendly boy", resultMap.get(1)); - Assert.assertEquals("happily child", resultMap.get(2)); + Assertions.assertEquals("lovely girl", resultMap.get(0)); + Assertions.assertEquals("friendly boy", resultMap.get(1)); + Assertions.assertEquals("happily child", resultMap.get(2)); // 下单用户,Queue表示正在 .排队. 抢我抢不到的二次元周边! final Queue customers = new ArrayDeque<>(Arrays.asList("刑部尚书手工耿", "木瓜大盗大漠叔", "竹鼠发烧找华农", "朴实无华朱一旦")); @@ -94,10 +94,10 @@ public class MapUtilTest { // 下面是测试报告 groups.forEach(group -> { final List users = group.getUsers(); - Assert.assertEquals("刑部尚书手工耿", users.get(0).getName()); - Assert.assertEquals("木瓜大盗大漠叔", users.get(1).getName()); - Assert.assertEquals("竹鼠发烧找华农", users.get(2).getName()); - Assert.assertEquals("朴实无华朱一旦", users.get(3).getName()); + Assertions.assertEquals("刑部尚书手工耿", users.get(0).getName()); + Assertions.assertEquals("木瓜大盗大漠叔", users.get(1).getName()); + Assertions.assertEquals("竹鼠发烧找华农", users.get(2).getName()); + Assertions.assertEquals("朴实无华朱一旦", users.get(3).getName()); }); // 能写代码真开心 } @@ -114,10 +114,10 @@ public class MapUtilTest { final Map map2 = MapUtil.filter(camelCaseMap, t -> Convert.toInt(t.getValue()) % 2 == 0); - Assert.assertEquals(2, map2.size()); + Assertions.assertEquals(2, map2.size()); - Assert.assertEquals("2", map2.get("b")); - Assert.assertEquals("4", map2.get("d")); + Assertions.assertEquals("2", map2.get("b")); + Assertions.assertEquals("4", map2.get("d")); } @Test @@ -129,9 +129,9 @@ public class MapUtilTest { map.put("fgh", "4"); final Map map2 = MapUtil.filter(map, t -> StrUtil.contains(t.getKey(), "bc")); - Assert.assertEquals(2, map2.size()); - Assert.assertEquals("1", map2.get("abc")); - Assert.assertEquals("2", map2.get("bcd")); + Assertions.assertEquals(2, map2.size()); + Assertions.assertEquals("1", map2.get("abc")); + Assertions.assertEquals("2", map2.get("bcd")); } @Test @@ -148,12 +148,12 @@ public class MapUtilTest { return t; }); - Assert.assertEquals(4, map2.size()); + Assertions.assertEquals(4, map2.size()); - Assert.assertEquals("10", map2.get("a")); - Assert.assertEquals("20", map2.get("b")); - Assert.assertEquals("30", map2.get("c")); - Assert.assertEquals("40", map2.get("d")); + Assertions.assertEquals("10", map2.get("a")); + Assertions.assertEquals("20", map2.get("b")); + Assertions.assertEquals("30", map2.get("c")); + Assertions.assertEquals("40", map2.get("d")); } @Test @@ -166,10 +166,10 @@ public class MapUtilTest { final Map map2 = MapUtil.reverse(map); - Assert.assertEquals("a", map2.get("1")); - Assert.assertEquals("b", map2.get("2")); - Assert.assertEquals("c", map2.get("3")); - Assert.assertEquals("d", map2.get("4")); + Assertions.assertEquals("a", map2.get("1")); + Assertions.assertEquals("b", map2.get("2")); + Assertions.assertEquals("c", map2.get("3")); + Assertions.assertEquals("d", map2.get("4")); } @Test @@ -181,14 +181,14 @@ public class MapUtilTest { map.put("d", "4"); final Object[][] objectArray = MapUtil.toObjectArray(map); - Assert.assertEquals("a", objectArray[0][0]); - Assert.assertEquals("1", objectArray[0][1]); - Assert.assertEquals("b", objectArray[1][0]); - Assert.assertEquals("2", objectArray[1][1]); - Assert.assertEquals("c", objectArray[2][0]); - Assert.assertEquals("3", objectArray[2][1]); - Assert.assertEquals("d", objectArray[3][0]); - Assert.assertEquals("4", objectArray[3][1]); + Assertions.assertEquals("a", objectArray[0][0]); + Assertions.assertEquals("1", objectArray[0][1]); + Assertions.assertEquals("b", objectArray[1][0]); + Assertions.assertEquals("2", objectArray[1][1]); + Assertions.assertEquals("c", objectArray[2][0]); + Assertions.assertEquals("3", objectArray[2][1]); + Assertions.assertEquals("d", objectArray[3][0]); + Assertions.assertEquals("4", objectArray[3][1]); } @Test @@ -199,39 +199,41 @@ public class MapUtilTest { .put("key2", "value2").build(); final String join1 = MapUtil.sortJoin(build, StrUtil.EMPTY, StrUtil.EMPTY, false); - Assert.assertEquals("key1value1key2value2key3value3", join1); + Assertions.assertEquals("key1value1key2value2key3value3", join1); final String join2 = MapUtil.sortJoin(build, StrUtil.EMPTY, StrUtil.EMPTY, false, "123"); - Assert.assertEquals("key1value1key2value2key3value3123", join2); + Assertions.assertEquals("key1value1key2value2key3value3123", join2); final String join3 = MapUtil.sortJoin(build, StrUtil.EMPTY, StrUtil.EMPTY, false, "123", "abc"); - Assert.assertEquals("key1value1key2value2key3value3123abc", join3); + Assertions.assertEquals("key1value1key2value2key3value3123abc", join3); } @Test public void ofEntriesTest(){ final Map map = MapUtil.ofEntries(MapUtil.entry("a", 1), MapUtil.entry("b", 2)); - Assert.assertEquals(2, map.size()); + Assertions.assertEquals(2, map.size()); - Assert.assertEquals(Integer.valueOf(1), map.get("a")); - Assert.assertEquals(Integer.valueOf(2), map.get("b")); + Assertions.assertEquals(Integer.valueOf(1), map.get("a")); + Assertions.assertEquals(Integer.valueOf(2), map.get("b")); } - @Test(expected = NumberFormatException.class) + @Test public void getIntTest(){ - final Map map = MapUtil.ofEntries(MapUtil.entry("a", "d")); - final Integer a = MapUtil.getInt(map, "a"); - Assert.assertNotNull(a); + Assertions.assertThrows(NumberFormatException.class, ()->{ + final Map map = MapUtil.ofEntries(MapUtil.entry("a", "d")); + final Integer a = MapUtil.getInt(map, "a"); + Assertions.assertNotNull(a); + }); } @Test public void getIntValueTest(){ final Map map = MapUtil.ofEntries(MapUtil.entry("a", "1"), MapUtil.entry("b", null)); final int a = MapUtil.get(map, "a", int.class); - Assert.assertEquals(1, a); + Assertions.assertEquals(1, a); final int b = MapUtil.getInt(map, "b", 0); - Assert.assertEquals(0, b); + Assertions.assertEquals(0, b); } @Test @@ -241,20 +243,20 @@ public class MapUtilTest { final String[] keys = v1.keySet().toArray(new String[0]); final ArrayList v1s = MapUtil.valuesOfKeys(v1, keys); - Assert.assertTrue(v1s.contains(12)); - Assert.assertTrue(v1s.contains(23)); - Assert.assertTrue(v1s.contains("张三")); + Assertions.assertTrue(v1s.contains(12)); + Assertions.assertTrue(v1s.contains(23)); + Assertions.assertTrue(v1s.contains("张三")); final ArrayList v2s = MapUtil.valuesOfKeys(v2, keys); - Assert.assertTrue(v2s.contains(15)); - Assert.assertTrue(v2s.contains(13)); - Assert.assertTrue(v2s.contains("李四")); + Assertions.assertTrue(v2s.contains(15)); + Assertions.assertTrue(v2s.contains(13)); + Assertions.assertTrue(v2s.contains("李四")); } @Test public void joinIgnoreNullTest() { final Dict v1 = Dict.of().set("id", 12).set("name", "张三").set("age", null); final String s = MapUtil.joinIgnoreNull(v1, ",", "="); - Assert.assertEquals("id=12,name=张三", s); + Assertions.assertEquals("id=12,name=张三", s); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/RowKeyTableTest.java b/hutool-core/src/test/java/cn/hutool/core/map/RowKeyTableTest.java index d59509909..1a6044b74 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/RowKeyTableTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/RowKeyTableTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.map; import cn.hutool.core.map.multi.RowKeyTable; import cn.hutool.core.map.multi.Table; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -15,25 +15,25 @@ public class RowKeyTableTest { table.put(1, 2, 3); table.put(1, 6, 4); - Assert.assertEquals(new Integer(3), table.get(1, 2)); - Assert.assertNull(table.get(1, 3)); + Assertions.assertEquals(new Integer(3), table.get(1, 2)); + Assertions.assertNull(table.get(1, 3)); //判断row和column确定的二维点是否存在 - Assert.assertTrue(table.contains(1, 2)); - Assert.assertFalse(table.contains(1, 3)); + Assertions.assertTrue(table.contains(1, 2)); + Assertions.assertFalse(table.contains(1, 3)); //判断列 - Assert.assertTrue(table.containsColumn(2)); - Assert.assertFalse(table.containsColumn(3)); + Assertions.assertTrue(table.containsColumn(2)); + Assertions.assertFalse(table.containsColumn(3)); // 判断行 - Assert.assertTrue(table.containsRow(1)); - Assert.assertFalse(table.containsRow(2)); + Assertions.assertTrue(table.containsRow(1)); + Assertions.assertFalse(table.containsRow(2)); // 获取列 final Map column = table.getColumn(6); - Assert.assertEquals(1, column.size()); - Assert.assertEquals(new Integer(4), column.get(1)); + Assertions.assertEquals(1, column.size()); + Assertions.assertEquals(new Integer(4), column.get(1)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/SerFunctionMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/SerFunctionMapTest.java index 01654139e..621587083 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/SerFunctionMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/SerFunctionMapTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.HashMap; @@ -16,7 +16,7 @@ public class SerFunctionMapTest { map.put("aaa", "b"); map.put("BBB", "c"); - Assert.assertEquals("B", map.get("aaa")); - Assert.assertEquals("C", map.get("bbb")); + Assertions.assertEquals("B", map.get("aaa")); + Assertions.assertEquals("C", map.get("bbb")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/SetValueMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/SetValueMapTest.java index e41e5f872..be63d6d27 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/SetValueMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/SetValueMapTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.map; import cn.hutool.core.map.multi.MultiValueMap; import cn.hutool.core.map.multi.SetValueMap; 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.*; @@ -13,9 +13,9 @@ public class SetValueMapTest { @Test public void putTest() { MultiValueMap map = new SetValueMap<>(); - Assert.assertNull(map.put(1, Arrays.asList("a", "b"))); + Assertions.assertNull(map.put(1, Arrays.asList("a", "b"))); Collection collection = map.put(1, Arrays.asList("c", "d")); - Assert.assertEquals(Arrays.asList("a", "b"), collection); + Assertions.assertEquals(Arrays.asList("a", "b"), collection); } @Test @@ -24,114 +24,114 @@ public class SetValueMapTest { Map> source = new HashMap<>(); source.put(1, Arrays.asList("a", "b", "c")); map.putAll(source); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), map.get(1)); } @Test public void putValueTest() { MultiValueMap map = new SetValueMap<>(); - Assert.assertTrue(map.putValue(1, "a")); - Assert.assertTrue(map.putValue(1, "b")); - Assert.assertTrue(map.putValue(1, "c")); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.get(1)); + Assertions.assertTrue(map.putValue(1, "a")); + Assertions.assertTrue(map.putValue(1, "b")); + Assertions.assertTrue(map.putValue(1, "c")); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.get(1)); } @Test public void putAllValueTest() { MultiValueMap map = new SetValueMap<>(); - Assert.assertTrue(map.putAllValues(1, Arrays.asList("a", "b", "c"))); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.get(1)); + Assertions.assertTrue(map.putAllValues(1, Arrays.asList("a", "b", "c"))); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.get(1)); Map> source = new HashMap<>(); - Assert.assertTrue(map.putValue(1, "e")); - Assert.assertFalse(map.putValue(1, "e")); - Assert.assertTrue(map.putValue(1, "f")); - Assert.assertFalse(map.putValue(1, "f")); + Assertions.assertTrue(map.putValue(1, "e")); + Assertions.assertFalse(map.putValue(1, "e")); + Assertions.assertTrue(map.putValue(1, "f")); + Assertions.assertFalse(map.putValue(1, "f")); map.putAllValues(source); - Assert.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c", "e", "f")), map.get(1)); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c", "e", "f")), map.get(1)); } @Test public void putValuesTest() { MultiValueMap map = new SetValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.get(1)); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.get(1)); } @Test public void removeValueTest() { MultiValueMap map = new SetValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeValue(1, "d")); - Assert.assertTrue(map.removeValue(1, "c")); - Assert.assertEquals(new HashSet<>(Arrays.asList("a", "b")), map.get(1)); + Assertions.assertFalse(map.removeValue(1, "d")); + Assertions.assertTrue(map.removeValue(1, "c")); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a", "b")), map.get(1)); } @Test public void removeAllValuesTest() { MultiValueMap map = new SetValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeAllValues(1, Arrays.asList("e", "f"))); - Assert.assertTrue(map.removeAllValues(1, Arrays.asList("b", "c"))); - Assert.assertEquals(Collections.singleton("a"), map.get(1)); + Assertions.assertFalse(map.removeAllValues(1, Arrays.asList("e", "f"))); + Assertions.assertTrue(map.removeAllValues(1, Arrays.asList("b", "c"))); + Assertions.assertEquals(Collections.singleton("a"), map.get(1)); } @Test public void removeValuesTest() { MultiValueMap map = new SetValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertFalse(map.removeValues(1, "e", "f")); - Assert.assertTrue(map.removeValues(1, "b", "c")); - Assert.assertEquals(Collections.singleton("a"), map.get(1)); + Assertions.assertFalse(map.removeValues(1, "e", "f")); + Assertions.assertTrue(map.removeValues(1, "b", "c")); + Assertions.assertEquals(Collections.singleton("a"), map.get(1)); } @Test public void testFilterAllValues() { MultiValueMap map = new SetValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertTrue(map.putValues(2, "a", "b", "c")); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertTrue(map.putValues(2, "a", "b", "c")); - Assert.assertEquals(map, map.filterAllValues((k, v) -> StrUtil.equals(v, "a"))); - Assert.assertEquals(Collections.singleton("a"), map.getValues(1)); - Assert.assertEquals(Collections.singleton("a"), map.getValues(2)); + Assertions.assertEquals(map, map.filterAllValues((k, v) -> StrUtil.equals(v, "a"))); + Assertions.assertEquals(Collections.singleton("a"), map.getValues(1)); + Assertions.assertEquals(Collections.singleton("a"), map.getValues(2)); - Assert.assertEquals(map, map.filterAllValues(v -> !StrUtil.equals(v, "a"))); - Assert.assertEquals(Collections.emptySet(), map.getValues(1)); - Assert.assertEquals(Collections.emptySet(), map.getValues(2)); + Assertions.assertEquals(map, map.filterAllValues(v -> !StrUtil.equals(v, "a"))); + Assertions.assertEquals(Collections.emptySet(), map.getValues(1)); + Assertions.assertEquals(Collections.emptySet(), map.getValues(2)); } @Test public void testReplaceAllValues() { MultiValueMap map = new SetValueMap<>(); - Assert.assertTrue(map.putValues(1, "a", "b", "c")); - Assert.assertTrue(map.putValues(2, "a", "b", "c")); + Assertions.assertTrue(map.putValues(1, "a", "b", "c")); + Assertions.assertTrue(map.putValues(2, "a", "b", "c")); - Assert.assertEquals(map, map.replaceAllValues((k, v) -> v + "2")); - Assert.assertEquals(new HashSet<>(Arrays.asList("a2", "b2", "c2")), map.getValues(1)); - Assert.assertEquals(new HashSet<>(Arrays.asList("a2", "b2", "c2")), map.getValues(2)); + Assertions.assertEquals(map, map.replaceAllValues((k, v) -> v + "2")); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a2", "b2", "c2")), map.getValues(1)); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a2", "b2", "c2")), map.getValues(2)); - Assert.assertEquals(map, map.replaceAllValues(v -> v + "3")); - Assert.assertEquals(new HashSet<>(Arrays.asList("a23", "b23", "c23")), map.getValues(1)); - Assert.assertEquals(new HashSet<>(Arrays.asList("a23", "b23", "c23")), map.getValues(2)); + Assertions.assertEquals(map, map.replaceAllValues(v -> v + "3")); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a23", "b23", "c23")), map.getValues(1)); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a23", "b23", "c23")), map.getValues(2)); } @Test public void getValuesTest() { MultiValueMap map = new SetValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertEquals(Collections.emptyList(), map.getValues(2)); - Assert.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.getValues(1)); + Assertions.assertEquals(Collections.emptyList(), map.getValues(2)); + Assertions.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c")), map.getValues(1)); } @Test public void sizeTest() { MultiValueMap map = new SetValueMap<>(); map.putValues(1, "a", "b", "c"); - Assert.assertEquals(0, map.size(2)); - Assert.assertEquals(3, map.size(1)); + Assertions.assertEquals(0, map.size(2)); + Assertions.assertEquals(3, map.size(1)); } @Test @@ -144,8 +144,8 @@ public class SetValueMapTest { keys.add(k); values.add(v); }); - Assert.assertEquals(Arrays.asList(1, 1, 1), keys); - Assert.assertEquals(Arrays.asList("a", "b", "c"), values); + Assertions.assertEquals(Arrays.asList(1, 1, 1), keys); + Assertions.assertEquals(Arrays.asList("a", "b", "c"), values); } @Test @@ -153,7 +153,7 @@ public class SetValueMapTest { MultiValueMap map = new SetValueMap<>(); map.putAllValues(1, Arrays.asList("a", "b", "c")); map.putAllValues(2, Arrays.asList("d", "e")); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("a", "b", "c", "d", "e"), map.allValues() ); diff --git a/hutool-core/src/test/java/cn/hutool/core/map/TableMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/TableMapTest.java index f13a720ea..254c9621d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/TableMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/TableMapTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TableMapTest { @@ -11,11 +11,11 @@ public class TableMapTest { tableMap.put("aaa", 111); tableMap.put("bbb", 222); - Assert.assertEquals(new Integer(111), tableMap.get("aaa")); - Assert.assertEquals(new Integer(222), tableMap.get("bbb")); + Assertions.assertEquals(new Integer(111), tableMap.get("aaa")); + Assertions.assertEquals(new Integer(222), tableMap.get("bbb")); - Assert.assertEquals("aaa", tableMap.getKey(111)); - Assert.assertEquals("bbb", tableMap.getKey(222)); + Assertions.assertEquals("aaa", tableMap.getKey(111)); + Assertions.assertEquals("bbb", tableMap.getKey(222)); } @SuppressWarnings("OverwrittenKey") @@ -28,7 +28,7 @@ public class TableMapTest { tableMap.remove("a"); - Assert.assertEquals(0, tableMap.size()); + Assertions.assertEquals(0, tableMap.size()); } @SuppressWarnings("OverwrittenKey") @@ -41,6 +41,6 @@ public class TableMapTest { tableMap.remove("a", 222); - Assert.assertEquals(1, tableMap.size()); + Assertions.assertEquals(1, tableMap.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/map/TolerantMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/TolerantMapTest.java index c1c030e40..cd8db0666 100644 --- a/hutool-core/src/test/java/cn/hutool/core/map/TolerantMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/TolerantMapTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.map; import cn.hutool.core.io.SerializeUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.RandomUtil; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; @@ -12,7 +12,7 @@ public class TolerantMapTest { private final TolerantMap map = TolerantMap.of(new HashMap<>(), "default"); - @Before + @BeforeEach public void before() { map.put("monday", "星期一"); map.put("tuesday", "星期二"); diff --git a/hutool-core/src/test/java/cn/hutool/core/map/WeakConcurrentMapTest.java b/hutool-core/src/test/java/cn/hutool/core/map/WeakConcurrentMapTest.java index d0670794a..7b79a90a0 100755 --- a/hutool-core/src/test/java/cn/hutool/core/map/WeakConcurrentMapTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/map/WeakConcurrentMapTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.thread.ConcurrencyTester; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.ObjUtil; 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 WeakConcurrentMapTest { @@ -26,10 +26,10 @@ public class WeakConcurrentMapTest { map.put(key3, value3); map.put(key4, value4); - Assert.assertEquals(value1, map.get(key1)); - Assert.assertEquals(value2, map.get(key2)); - Assert.assertEquals(value3, map.get(key3)); - Assert.assertEquals(value4, map.get(key4)); + Assertions.assertEquals(value1, map.get(key1)); + Assertions.assertEquals(value2, map.get(key2)); + Assertions.assertEquals(value3, map.get(key3)); + Assertions.assertEquals(value4, map.get(key4)); // 清空引用 //noinspection UnusedAssignment @@ -40,7 +40,7 @@ public class WeakConcurrentMapTest { System.gc(); ThreadUtil.sleep(200L); - Assert.assertEquals(2, map.size()); + Assertions.assertEquals(2, map.size()); } @Test @@ -49,8 +49,8 @@ public class WeakConcurrentMapTest { final ConcurrencyTester tester = new ConcurrencyTester(2000); tester.test(()-> cache.computeIfAbsent("aaa" + RandomUtil.randomInt(2), (key)-> "aaaValue")); - Assert.assertTrue(tester.getInterval() > 0); + Assertions.assertTrue(tester.getInterval() > 0); final String value = ObjUtil.defaultIfNull(cache.get("aaa0"), cache.get("aaa1")); - Assert.assertEquals("aaaValue", value); + Assertions.assertEquals("aaaValue", value); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/math/ArrangementTest.java b/hutool-core/src/test/java/cn/hutool/core/math/ArrangementTest.java index 3376a716f..07c158ed4 100755 --- a/hutool-core/src/test/java/cn/hutool/core/math/ArrangementTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/math/ArrangementTest.java @@ -1,12 +1,11 @@ package cn.hutool.core.math; -import java.util.List; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - import cn.hutool.core.lang.Console; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.util.List; /** * 排列单元测试 @@ -18,45 +17,45 @@ public class ArrangementTest { @Test public void arrangementTest() { long result = Arrangement.count(4, 2); - Assert.assertEquals(12, result); + Assertions.assertEquals(12, result); result = Arrangement.count(4, 1); - Assert.assertEquals(4, result); + Assertions.assertEquals(4, result); result = Arrangement.count(4, 0); - Assert.assertEquals(1, result); + Assertions.assertEquals(1, result); final long resultAll = Arrangement.countAll(4); - Assert.assertEquals(64, resultAll); + Assertions.assertEquals(64, resultAll); } @Test public void selectTest() { final Arrangement arrangement = new Arrangement(new String[] { "1", "2", "3", "4" }); final List list = arrangement.select(2); - Assert.assertEquals(Arrangement.count(4, 2), list.size()); - Assert.assertArrayEquals(new String[] {"1", "2"}, list.get(0)); - Assert.assertArrayEquals(new String[] {"1", "3"}, list.get(1)); - Assert.assertArrayEquals(new String[] {"1", "4"}, list.get(2)); - Assert.assertArrayEquals(new String[] {"2", "1"}, list.get(3)); - Assert.assertArrayEquals(new String[] {"2", "3"}, list.get(4)); - Assert.assertArrayEquals(new String[] {"2", "4"}, list.get(5)); - Assert.assertArrayEquals(new String[] {"3", "1"}, list.get(6)); - Assert.assertArrayEquals(new String[] {"3", "2"}, list.get(7)); - Assert.assertArrayEquals(new String[] {"3", "4"}, list.get(8)); - Assert.assertArrayEquals(new String[] {"4", "1"}, list.get(9)); - Assert.assertArrayEquals(new String[] {"4", "2"}, list.get(10)); - Assert.assertArrayEquals(new String[] {"4", "3"}, list.get(11)); + Assertions.assertEquals(Arrangement.count(4, 2), list.size()); + Assertions.assertArrayEquals(new String[] {"1", "2"}, list.get(0)); + Assertions.assertArrayEquals(new String[] {"1", "3"}, list.get(1)); + Assertions.assertArrayEquals(new String[] {"1", "4"}, list.get(2)); + Assertions.assertArrayEquals(new String[] {"2", "1"}, list.get(3)); + Assertions.assertArrayEquals(new String[] {"2", "3"}, list.get(4)); + Assertions.assertArrayEquals(new String[] {"2", "4"}, list.get(5)); + Assertions.assertArrayEquals(new String[] {"3", "1"}, list.get(6)); + Assertions.assertArrayEquals(new String[] {"3", "2"}, list.get(7)); + Assertions.assertArrayEquals(new String[] {"3", "4"}, list.get(8)); + Assertions.assertArrayEquals(new String[] {"4", "1"}, list.get(9)); + Assertions.assertArrayEquals(new String[] {"4", "2"}, list.get(10)); + Assertions.assertArrayEquals(new String[] {"4", "3"}, list.get(11)); final List selectAll = arrangement.selectAll(); - Assert.assertEquals(Arrangement.countAll(4), selectAll.size()); + Assertions.assertEquals(Arrangement.countAll(4), selectAll.size()); final List list2 = arrangement.select(0); - Assert.assertEquals(1, list2.size()); + Assertions.assertEquals(1, list2.size()); } @Test - @Ignore + @Disabled public void selectTest2() { final List list = MathUtil.arrangementSelect(new String[] { "1", "1", "3", "4" }); for (final String[] strings : list) { diff --git a/hutool-core/src/test/java/cn/hutool/core/math/CalculatorTest.java b/hutool-core/src/test/java/cn/hutool/core/math/CalculatorTest.java index 9ad352fc9..ab451171c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/math/CalculatorTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/math/CalculatorTest.java @@ -1,52 +1,52 @@ package cn.hutool.core.math; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CalculatorTest { @Test public void conversationTest(){ final double conversion = Calculator.conversion("(0*1--3)-5/-4-(3*(-2.13))"); - Assert.assertEquals(10.64, conversion, 0); + Assertions.assertEquals(10.64, conversion, 0); } @Test public void conversationTest2(){ final double conversion = Calculator.conversion("77 * 12"); - Assert.assertEquals(924.0, conversion, 0); + Assertions.assertEquals(924.0, conversion, 0); } @Test public void conversationTest3(){ final double conversion = Calculator.conversion("1"); - Assert.assertEquals(1, conversion, 0); + Assertions.assertEquals(1, conversion, 0); } @Test public void conversationTest4(){ final double conversion = Calculator.conversion("(88*66/23)%26+45%9"); - Assert.assertEquals((88D * 66 / 23) % 26, conversion, 0.000000001); + Assertions.assertEquals((88D * 66 / 23) % 26, conversion, 0.000000001); } @Test public void conversationTest5(){ // https://github.com/dromara/hutool/issues/1984 final double conversion = Calculator.conversion("((1/1) / (1/1) -1) * 100"); - Assert.assertEquals(0, conversion, 0); + Assertions.assertEquals(0, conversion, 0); } @Test public void conversationTest6() { final double conversion = Calculator.conversion("-((2.12-2) * 100)"); - Assert.assertEquals(-1D * (2.12D - 2D) * 100D, conversion, 0.00001); + Assertions.assertEquals(-1D * (2.12D - 2D) * 100D, conversion, 0.00001); } @Test public void conversationTest7() { //https://gitee.com/dromara/hutool/issues/I4KONB final double conversion = Calculator.conversion("((-2395+0) * 0.3+140.24+35+90)/30"); - Assert.assertEquals(-15.11D, conversion, 0.01); + Assertions.assertEquals(-15.11D, conversion, 0.01); } @Test @@ -54,6 +54,6 @@ public class CalculatorTest { // 忽略数字之间的运算符,按照乘法对待。 // https://github.com/dromara/hutool/issues/2964 final double calcValue = Calculator.conversion("(11+2)12"); - Assert.assertEquals(156D, calcValue, 0.001); + Assertions.assertEquals(156D, calcValue, 0.001); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/math/CombinationTest.java b/hutool-core/src/test/java/cn/hutool/core/math/CombinationTest.java index 980f5f849..0eb34da72 100644 --- a/hutool-core/src/test/java/cn/hutool/core/math/CombinationTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/math/CombinationTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.math; -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,39 +16,39 @@ public class CombinationTest { @Test public void countTest() { long result = Combination.count(5, 2); - Assert.assertEquals(10, result); + Assertions.assertEquals(10, result); result = Combination.count(5, 5); - Assert.assertEquals(1, result); + Assertions.assertEquals(1, result); result = Combination.count(5, 0); - Assert.assertEquals(1, result); + Assertions.assertEquals(1, result); final long resultAll = Combination.countAll(5); - Assert.assertEquals(31, resultAll); + Assertions.assertEquals(31, resultAll); } @Test public void selectTest() { final Combination combination = new Combination(new String[] { "1", "2", "3", "4", "5" }); final List list = combination.select(2); - Assert.assertEquals(Combination.count(5, 2), list.size()); + Assertions.assertEquals(Combination.count(5, 2), list.size()); - Assert.assertArrayEquals(new String[] {"1", "2"}, list.get(0)); - Assert.assertArrayEquals(new String[] {"1", "3"}, list.get(1)); - Assert.assertArrayEquals(new String[] {"1", "4"}, list.get(2)); - Assert.assertArrayEquals(new String[] {"1", "5"}, list.get(3)); - Assert.assertArrayEquals(new String[] {"2", "3"}, list.get(4)); - Assert.assertArrayEquals(new String[] {"2", "4"}, list.get(5)); - Assert.assertArrayEquals(new String[] {"2", "5"}, list.get(6)); - Assert.assertArrayEquals(new String[] {"3", "4"}, list.get(7)); - Assert.assertArrayEquals(new String[] {"3", "5"}, list.get(8)); - Assert.assertArrayEquals(new String[] {"4", "5"}, list.get(9)); + Assertions.assertArrayEquals(new String[] {"1", "2"}, list.get(0)); + Assertions.assertArrayEquals(new String[] {"1", "3"}, list.get(1)); + Assertions.assertArrayEquals(new String[] {"1", "4"}, list.get(2)); + Assertions.assertArrayEquals(new String[] {"1", "5"}, list.get(3)); + Assertions.assertArrayEquals(new String[] {"2", "3"}, list.get(4)); + Assertions.assertArrayEquals(new String[] {"2", "4"}, list.get(5)); + Assertions.assertArrayEquals(new String[] {"2", "5"}, list.get(6)); + Assertions.assertArrayEquals(new String[] {"3", "4"}, list.get(7)); + Assertions.assertArrayEquals(new String[] {"3", "5"}, list.get(8)); + Assertions.assertArrayEquals(new String[] {"4", "5"}, list.get(9)); final List selectAll = combination.selectAll(); - Assert.assertEquals(Combination.countAll(5), selectAll.size()); + Assertions.assertEquals(Combination.countAll(5), selectAll.size()); final List list2 = combination.select(0); - Assert.assertEquals(1, list2.size()); + Assertions.assertEquals(1, list2.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/math/MathUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/math/MathUtilTest.java index b196b3dbf..b28cabb64 100644 --- a/hutool-core/src/test/java/cn/hutool/core/math/MathUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/math/MathUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.math; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.math.BigInteger; @@ -9,36 +9,36 @@ public class MathUtilTest { @Test public void factorialTest(){ long factorial = MathUtil.factorial(0); - Assert.assertEquals(1, factorial); + Assertions.assertEquals(1, factorial); - Assert.assertEquals(1L, MathUtil.factorial(1)); - Assert.assertEquals(1307674368000L, MathUtil.factorial(15)); - Assert.assertEquals(2432902008176640000L, MathUtil.factorial(20)); + Assertions.assertEquals(1L, MathUtil.factorial(1)); + Assertions.assertEquals(1307674368000L, MathUtil.factorial(15)); + Assertions.assertEquals(2432902008176640000L, MathUtil.factorial(20)); factorial = MathUtil.factorial(5, 0); - Assert.assertEquals(120, factorial); + Assertions.assertEquals(120, factorial); factorial = MathUtil.factorial(5, 1); - Assert.assertEquals(120, factorial); + Assertions.assertEquals(120, factorial); - Assert.assertEquals(5, MathUtil.factorial(5, 4)); - Assert.assertEquals(2432902008176640000L, MathUtil.factorial(20, 0)); + Assertions.assertEquals(5, MathUtil.factorial(5, 4)); + Assertions.assertEquals(2432902008176640000L, MathUtil.factorial(20, 0)); } @Test public void factorialTest2(){ long factorial = MathUtil.factorial(new BigInteger("0")).longValue(); - Assert.assertEquals(1, factorial); + Assertions.assertEquals(1, factorial); - Assert.assertEquals(1L, MathUtil.factorial(new BigInteger("1")).longValue()); - Assert.assertEquals(1307674368000L, MathUtil.factorial(new BigInteger("15")).longValue()); - Assert.assertEquals(2432902008176640000L, MathUtil.factorial(20)); + Assertions.assertEquals(1L, MathUtil.factorial(new BigInteger("1")).longValue()); + Assertions.assertEquals(1307674368000L, MathUtil.factorial(new BigInteger("15")).longValue()); + Assertions.assertEquals(2432902008176640000L, MathUtil.factorial(20)); factorial = MathUtil.factorial(new BigInteger("5"), new BigInteger("0")).longValue(); - Assert.assertEquals(120, factorial); + Assertions.assertEquals(120, factorial); factorial = MathUtil.factorial(new BigInteger("5"), BigInteger.ONE).longValue(); - Assert.assertEquals(120, factorial); + Assertions.assertEquals(120, factorial); - Assert.assertEquals(5, MathUtil.factorial(new BigInteger("5"), new BigInteger("4")).longValue()); - Assert.assertEquals(2432902008176640000L, MathUtil.factorial(new BigInteger("20"), BigInteger.ZERO).longValue()); + Assertions.assertEquals(5, MathUtil.factorial(new BigInteger("5"), new BigInteger("4")).longValue()); + Assertions.assertEquals(2432902008176640000L, MathUtil.factorial(new BigInteger("20"), BigInteger.ZERO).longValue()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/math/MoneyTest.java b/hutool-core/src/test/java/cn/hutool/core/math/MoneyTest.java index c83389dfa..f9c01ad58 100644 --- a/hutool-core/src/test/java/cn/hutool/core/math/MoneyTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/math/MoneyTest.java @@ -1,23 +1,23 @@ package cn.hutool.core.math; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class MoneyTest { @Test public void yuanToCentTest() { final Money money = new Money("1234.56"); - Assert.assertEquals(123456, money.getCent()); + Assertions.assertEquals(123456, money.getCent()); - Assert.assertEquals(123456, MathUtil.yuanToCent(1234.56)); + Assertions.assertEquals(123456, MathUtil.yuanToCent(1234.56)); } @Test public void centToYuanTest() { final Money money = new Money(1234, 56); - Assert.assertEquals(1234.56D, money.getAmount().doubleValue(), 0); + Assertions.assertEquals(1234.56D, money.getAmount().doubleValue(), 0); - Assert.assertEquals(1234.56D, MathUtil.centToYuan(123456), 0); + Assertions.assertEquals(1234.56D, MathUtil.centToYuan(123456), 0); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/FormUrlencodedTest.java b/hutool-core/src/test/java/cn/hutool/core/net/FormUrlencodedTest.java index 51ee92c64..6d26269a0 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/FormUrlencodedTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/FormUrlencodedTest.java @@ -2,17 +2,17 @@ package cn.hutool.core.net; import cn.hutool.core.net.url.FormUrlencoded; 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; public class FormUrlencodedTest { @Test public void encodeParamTest(){ String encode = FormUrlencoded.ALL.encode("a+b", CharsetUtil.UTF_8); - Assert.assertEquals("a%2Bb", encode); + Assertions.assertEquals("a%2Bb", encode); encode = FormUrlencoded.ALL.encode("a b", CharsetUtil.UTF_8); - Assert.assertEquals("a+b", encode); + Assertions.assertEquals("a+b", encode); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/Ipv4UtilTest.java b/hutool-core/src/test/java/cn/hutool/core/net/Ipv4UtilTest.java index 234213362..f7c02606b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/Ipv4UtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/Ipv4UtilTest.java @@ -1,34 +1,32 @@ package cn.hutool.core.net; -import org.junit.Assert; -import org.junit.Test; -import org.junit.function.ThrowingRunnable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Ipv4UtilTest { @Test public void formatIpBlockTest() { for (int i = Ipv4Util.IPV4_MASK_BIT_VALID_MIN; i < Ipv4Util.IPV4_MASK_BIT_MAX; i++) { - Assert.assertEquals("192.168.1.101/" + i, Ipv4Util.formatIpBlock("192.168.1.101", Ipv4Util.getMaskByMaskBit(i))); + Assertions.assertEquals("192.168.1.101/" + i, Ipv4Util.formatIpBlock("192.168.1.101", Ipv4Util.getMaskByMaskBit(i))); } } @Test public void getMaskBitByMaskTest() { final int maskBitByMask = Ipv4Util.getMaskBitByMask("255.255.255.0"); - Assert.assertEquals(24, maskBitByMask); + Assertions.assertEquals(24, maskBitByMask); } @Test public void getMaskBitByIllegalMaskTest() { - final ThrowingRunnable getMaskBitByMaskRunnable = () -> Ipv4Util.getMaskBitByMask("255.255.0.255"); - Assert.assertThrows("非法掩码测试", IllegalArgumentException.class, getMaskBitByMaskRunnable); + Assertions.assertThrows(IllegalArgumentException.class, () -> Ipv4Util.getMaskBitByMask("255.255.0.255"), "非法掩码测试"); } @Test public void getMaskByMaskBitTest() { final String mask = Ipv4Util.getMaskByMaskBit(24); - Assert.assertEquals("255.255.255.0", mask); + Assertions.assertEquals("255.255.255.0", mask); } @Test @@ -50,7 +48,7 @@ public class Ipv4UtilTest { final String ip = "192.168.1.1"; final int maskBitByMask = Ipv4Util.getMaskBitByMask("255.255.255.0"); final String endIpStr = Ipv4Util.getEndIpStr(ip, maskBitByMask); - Assert.assertEquals("192.168.1.255", endIpStr); + Assertions.assertEquals("192.168.1.255", endIpStr); } @Test @@ -106,52 +104,52 @@ public class Ipv4UtilTest { @Test public void isMaskValidTest() { final boolean maskValid = Ipv4Util.isMaskValid("255.255.255.0"); - Assert.assertTrue("掩码合法检验", maskValid); + Assertions.assertTrue(maskValid, "掩码合法检验"); } @Test public void isMaskInvalidTest() { - Assert.assertFalse("掩码非法检验 - 255.255.0.255", Ipv4Util.isMaskValid("255.255.0.255")); - Assert.assertFalse("掩码非法检验 - null值", Ipv4Util.isMaskValid(null)); - Assert.assertFalse("掩码非法检验 - 空字符串", Ipv4Util.isMaskValid("")); - Assert.assertFalse("掩码非法检验 - 空白字符串", Ipv4Util.isMaskValid(" ")); + Assertions.assertFalse(Ipv4Util.isMaskValid("255.255.0.255"), "掩码非法检验 - 255.255.0.255"); + Assertions.assertFalse(Ipv4Util.isMaskValid(null), "掩码非法检验 - null值"); + Assertions.assertFalse(Ipv4Util.isMaskValid(""), "掩码非法检验 - 空字符串"); + Assertions.assertFalse(Ipv4Util.isMaskValid(" "), "掩码非法检验 - 空白字符串"); } @Test public void isMaskBitValidTest() { for (int i = 1; i < 32; i++) { - Assert.assertTrue("掩码位非法:" + i, Ipv4Util.isMaskBitValid(i)); + Assertions.assertTrue(Ipv4Util.isMaskBitValid(i), "掩码位非法:" + i); } } @Test public void isMaskBitInvalidTest() { final boolean maskBitValid = Ipv4Util.isMaskBitValid(33); - Assert.assertFalse("掩码位非法检验", maskBitValid); + Assertions.assertFalse(maskBitValid, "掩码位非法检验"); } @Test public void ipv4ToLongTest() { long l = Ipv4Util.ipv4ToLong("127.0.0.1"); - Assert.assertEquals(2130706433L, l); + Assertions.assertEquals(2130706433L, l); l = Ipv4Util.ipv4ToLong("114.114.114.114"); - Assert.assertEquals(1920103026L, l); + Assertions.assertEquals(1920103026L, l); l = Ipv4Util.ipv4ToLong("0.0.0.0"); - Assert.assertEquals(0L, l); + Assertions.assertEquals(0L, l); l = Ipv4Util.ipv4ToLong("255.255.255.255"); - Assert.assertEquals(4294967295L, l); + Assertions.assertEquals(4294967295L, l); } @Test public void getMaskIpLongTest() { for (int i = 1; i <= 32; i++) { - Assert.assertEquals(Ipv4Util.ipv4ToLong(MaskBit.get(i)), MaskBit.getMaskIpLong(i)); + Assertions.assertEquals(Ipv4Util.ipv4ToLong(MaskBit.get(i)), MaskBit.getMaskIpLong(i)); } } @SuppressWarnings("SameParameterValue") private void testGenerateIpList(final String fromIp, final String toIp) { - Assert.assertEquals( + Assertions.assertEquals( Ipv4Util.countByIpRange(fromIp, toIp), Ipv4Util.list(fromIp, toIp).size() ); @@ -159,7 +157,7 @@ public class Ipv4UtilTest { @SuppressWarnings("SameParameterValue") private void testGenerateIpList(final String ip, final int maskBit, final boolean isAll) { - Assert.assertEquals( + Assertions.assertEquals( Ipv4Util.countByMaskBit(maskBit, isAll), Ipv4Util.list(ip, maskBit, isAll).size() ); @@ -168,28 +166,28 @@ public class Ipv4UtilTest { private static void testLongToIp(final String ip) { final long ipLong = Ipv4Util.ipv4ToLong(ip); final String ipv4 = Ipv4Util.longToIpv4(ipLong); - Assert.assertEquals(ip, ipv4); + Assertions.assertEquals(ip, ipv4); } @Test public void isInnerTest() { - Assert.assertTrue(Ipv4Util.isInnerIP(Ipv4Util.LOCAL_IP)); - Assert.assertTrue(Ipv4Util.isInnerIP("192.168.5.12")); - Assert.assertTrue(Ipv4Util.isInnerIP("172.20.10.1")); + Assertions.assertTrue(Ipv4Util.isInnerIP(Ipv4Util.LOCAL_IP)); + Assertions.assertTrue(Ipv4Util.isInnerIP("192.168.5.12")); + Assertions.assertTrue(Ipv4Util.isInnerIP("172.20.10.1")); - Assert.assertFalse(Ipv4Util.isInnerIP("180.10.2.5")); - Assert.assertFalse(Ipv4Util.isInnerIP("192.160.10.3")); + Assertions.assertFalse(Ipv4Util.isInnerIP("180.10.2.5")); + Assertions.assertFalse(Ipv4Util.isInnerIP("192.160.10.3")); } @Test public void isPublicTest() { - Assert.assertTrue(Ipv4Util.isPublicIP("180.10.2.5")); - Assert.assertTrue(Ipv4Util.isPublicIP("192.160.10.3")); + Assertions.assertTrue(Ipv4Util.isPublicIP("180.10.2.5")); + Assertions.assertTrue(Ipv4Util.isPublicIP("192.160.10.3")); - Assert.assertFalse(Ipv4Util.isPublicIP(Ipv4Util.LOCAL_IP)); - Assert.assertFalse(Ipv4Util.isPublicIP("192.168.5.12")); - Assert.assertFalse(Ipv4Util.isPublicIP("127.0.0.1")); - Assert.assertFalse(Ipv4Util.isPublicIP("172.20.10.1")); + Assertions.assertFalse(Ipv4Util.isPublicIP(Ipv4Util.LOCAL_IP)); + Assertions.assertFalse(Ipv4Util.isPublicIP("192.168.5.12")); + Assertions.assertFalse(Ipv4Util.isPublicIP("127.0.0.1")); + Assertions.assertFalse(Ipv4Util.isPublicIP("172.20.10.1")); } @Test @@ -198,7 +196,7 @@ public class Ipv4UtilTest { for (int i = 1; i <= 32; i++) { final String beginIpStr = Ipv4Util.getBeginIpStr(ip, i); final String endIpStr = Ipv4Util.getEndIpStr(ip, i); - Assert.assertEquals(Ipv4Util.getMaskByMaskBit(i), Ipv4Util.getMaskByIpRange(beginIpStr, endIpStr)); + Assertions.assertEquals(Ipv4Util.getMaskByMaskBit(i), Ipv4Util.getMaskByIpRange(beginIpStr, endIpStr)); } } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/NetUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/net/NetUtilTest.java index f7b2bf917..52c41abca 100755 --- a/hutool-core/src/test/java/cn/hutool/core/net/NetUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/NetUtilTest.java @@ -3,9 +3,9 @@ package cn.hutool.core.net; import cn.hutool.core.lang.Console; import cn.hutool.core.regex.PatternPool; import cn.hutool.core.regex.ReUtil; -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.net.HttpCookie; import java.net.InetAddress; @@ -21,88 +21,88 @@ import java.util.List; public class NetUtilTest { @Test - @Ignore + @Disabled public void getLocalhostStrTest() { final String localhost = NetUtil.getLocalhostStr(); - Assert.assertNotNull(localhost); + Assertions.assertNotNull(localhost); } @Test - @Ignore + @Disabled public void getLocalhostTest() { final InetAddress localhost = NetUtil.getLocalhost(); - Assert.assertNotNull(localhost); + Assertions.assertNotNull(localhost); } @Test - @Ignore + @Disabled public void getLocalMacAddressTest() { final String macAddress = NetUtil.getLocalMacAddress(); - Assert.assertNotNull(macAddress); + Assertions.assertNotNull(macAddress); // 验证MAC地址正确 final boolean match = ReUtil.isMatch(PatternPool.MAC_ADDRESS, macAddress); - Assert.assertTrue(match); + Assertions.assertTrue(match); } @Test public void longToIpTest() { final String ipv4 = NetUtil.longToIpv4(2130706433L); - Assert.assertEquals("127.0.0.1", ipv4); + Assertions.assertEquals("127.0.0.1", ipv4); } @Test public void ipToLongTest() { final long ipLong = NetUtil.ipv4ToLong("127.0.0.1"); - Assert.assertEquals(2130706433L, ipLong); + Assertions.assertEquals(2130706433L, ipLong); } @Test - @Ignore + @Disabled public void isUsableLocalPortTest(){ - Assert.assertTrue(NetUtil.isUsableLocalPort(80)); + Assertions.assertTrue(NetUtil.isUsableLocalPort(80)); } @Test public void parseCookiesTest(){ final String cookieStr = "cookieName=\"cookieValue\";Path=\"/\";Domain=\"cookiedomain.com\""; final List httpCookies = NetUtil.parseCookies(cookieStr); - Assert.assertEquals(1, httpCookies.size()); + Assertions.assertEquals(1, httpCookies.size()); final HttpCookie httpCookie = httpCookies.get(0); - Assert.assertEquals(0, httpCookie.getVersion()); - Assert.assertEquals("cookieName", httpCookie.getName()); - Assert.assertEquals("cookieValue", httpCookie.getValue()); - Assert.assertEquals("/", httpCookie.getPath()); - Assert.assertEquals("cookiedomain.com", httpCookie.getDomain()); + Assertions.assertEquals(0, httpCookie.getVersion()); + Assertions.assertEquals("cookieName", httpCookie.getName()); + Assertions.assertEquals("cookieValue", httpCookie.getValue()); + Assertions.assertEquals("/", httpCookie.getPath()); + Assertions.assertEquals("cookiedomain.com", httpCookie.getDomain()); } @Test - @Ignore + @Disabled public void getLocalHostNameTest() { // 注意此方法会触发反向DNS解析,导致阻塞,阻塞时间取决于网络! - Assert.assertNotNull(NetUtil.getLocalHostName()); + Assertions.assertNotNull(NetUtil.getLocalHostName()); } @Test public void getLocalHostTest() { - Assert.assertNotNull(NetUtil.getLocalhost()); + Assertions.assertNotNull(NetUtil.getLocalhost()); } @Test public void pingTest(){ - Assert.assertTrue(NetUtil.ping("127.0.0.1")); + Assertions.assertTrue(NetUtil.ping("127.0.0.1")); } @Test - @Ignore + @Disabled public void isOpenTest(){ final InetSocketAddress address = new InetSocketAddress("www.hutool.cn", 443); - Assert.assertTrue(NetUtil.isOpen(address, 200)); + Assertions.assertTrue(NetUtil.isOpen(address, 200)); } @Test - @Ignore + @Disabled public void getDnsInfoTest(){ final List txt = NetUtil.getDnsInfo("hutool.cn", "TXT"); Console.log(txt); @@ -110,13 +110,13 @@ public class NetUtilTest { @Test public void isInRangeTest(){ - Assert.assertTrue(NetUtil.isInRange("114.114.114.114","0.0.0.0/0")); - Assert.assertTrue(NetUtil.isInRange("192.168.3.4","192.0.0.0/8")); - Assert.assertTrue(NetUtil.isInRange("192.168.3.4","192.168.0.0/16")); - Assert.assertTrue(NetUtil.isInRange("192.168.3.4","192.168.3.0/24")); - Assert.assertTrue(NetUtil.isInRange("192.168.3.4","192.168.3.4/32")); - Assert.assertFalse(NetUtil.isInRange("8.8.8.8","192.0.0.0/8")); - Assert.assertFalse(NetUtil.isInRange("114.114.114.114","192.168.3.4/32")); + Assertions.assertTrue(NetUtil.isInRange("114.114.114.114","0.0.0.0/0")); + Assertions.assertTrue(NetUtil.isInRange("192.168.3.4","192.0.0.0/8")); + Assertions.assertTrue(NetUtil.isInRange("192.168.3.4","192.168.0.0/16")); + Assertions.assertTrue(NetUtil.isInRange("192.168.3.4","192.168.3.0/24")); + Assertions.assertTrue(NetUtil.isInRange("192.168.3.4","192.168.3.4/32")); + Assertions.assertFalse(NetUtil.isInRange("8.8.8.8","192.0.0.0/8")); + Assertions.assertFalse(NetUtil.isInRange("114.114.114.114","192.168.3.4/32")); } @Test @@ -124,6 +124,6 @@ public class NetUtilTest { // 获取结果应该去掉空格 final String ips = "unknown, 12.34.56.78, 23.45.67.89"; final String ip = NetUtil.getMultistageReverseProxyIp(ips); - Assert.assertEquals("12.34.56.78", ip); + Assertions.assertEquals("12.34.56.78", ip); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/RFC3986Test.java b/hutool-core/src/test/java/cn/hutool/core/net/RFC3986Test.java index 740e8cd8f..89f510ec6 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/RFC3986Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/RFC3986Test.java @@ -2,35 +2,35 @@ package cn.hutool.core.net; import cn.hutool.core.net.url.RFC3986; 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; public class RFC3986Test { @Test public void pacharTest(){ final String encode = RFC3986.PCHAR.encode("=", CharsetUtil.UTF_8); - Assert.assertEquals("=", encode); + Assertions.assertEquals("=", encode); } @Test public void encodeQueryTest(){ String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=b", CharsetUtil.UTF_8); - Assert.assertEquals("a=b", encode); + Assertions.assertEquals("a=b", encode); encode = RFC3986.QUERY_PARAM_VALUE.encode("a+1=b", CharsetUtil.UTF_8); - Assert.assertEquals("a+1=b", encode); + Assertions.assertEquals("a+1=b", encode); } @Test public void encodeQueryPercentTest(){ final String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=%b", CharsetUtil.UTF_8); - Assert.assertEquals("a=%25b", encode); + Assertions.assertEquals("a=%25b", encode); } @Test public void encodeQueryWithSafeTest(){ final String encode = RFC3986.QUERY_PARAM_VALUE.encode("a=%25", CharsetUtil.UTF_8, '%'); - Assert.assertEquals("a=%25", encode); + Assertions.assertEquals("a=%25", encode); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/URLEncoderTest.java b/hutool-core/src/test/java/cn/hutool/core/net/URLEncoderTest.java index d03988639..29ce7c5ce 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/URLEncoderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/URLEncoderTest.java @@ -2,33 +2,33 @@ package cn.hutool.core.net; import cn.hutool.core.net.url.URLDecoder; import cn.hutool.core.net.url.URLEncoder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class URLEncoderTest { @Test public void encodeTest() { final String body = "366466 - 副本.jpg"; final String encode = URLEncoder.encodeAll(body); - Assert.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode); - Assert.assertEquals(body, URLDecoder.decode(encode)); + Assertions.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode); + Assertions.assertEquals(body, URLDecoder.decode(encode)); final String encode2 = URLEncoder.encodeQuery(body); - Assert.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode2); + Assertions.assertEquals("366466%20-%20%E5%89%AF%E6%9C%AC.jpg", encode2); } @Test public void encodeQueryPlusTest() { final String body = "+"; final String encode2 = URLEncoder.encodeQuery(body); - Assert.assertEquals("+", encode2); + Assertions.assertEquals("+", encode2); } @Test public void encodeEmojiTest(){ final String emoji = "🐶😊😂🤣"; final String encode = URLEncoder.encodeAll(emoji); - Assert.assertEquals("%F0%9F%90%B6%F0%9F%98%8A%F0%9F%98%82%F0%9F%A4%A3", encode); - Assert.assertEquals(emoji, URLDecoder.decode(encode)); + Assertions.assertEquals("%F0%9F%90%B6%F0%9F%98%8A%F0%9F%98%82%F0%9F%A4%A3", encode); + Assertions.assertEquals(emoji, URLDecoder.decode(encode)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/URLUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/net/URLUtilTest.java index eeb690cba..14bb0b726 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/URLUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/URLUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.net; import cn.hutool.core.net.url.URLUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.net.MalformedURLException; import java.net.URI; @@ -21,51 +21,51 @@ public class URLUtilTest { // issue#I25MZL,多个/被允许 String url = "http://www.hutool.cn//aaa/bbb"; String normalize = URLUtil.normalize(url); - Assert.assertEquals("http://www.hutool.cn//aaa/bbb", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa/bbb", normalize); url = "www.hutool.cn//aaa/bbb"; normalize = URLUtil.normalize(url); - Assert.assertEquals("http://www.hutool.cn//aaa/bbb", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa/bbb", normalize); } @Test public void normalizeTest2() { String url = "http://www.hutool.cn//aaa/\\bbb?a=1&b=2"; String normalize = URLUtil.normalize(url); - Assert.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize); url = "www.hutool.cn//aaa/bbb?a=1&b=2"; normalize = URLUtil.normalize(url); - Assert.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize); } @Test public void normalizeTest3() { String url = "http://www.hutool.cn//aaa/\\bbb?a=1&b=2"; String normalize = URLUtil.normalize(url, true); - Assert.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize); url = "www.hutool.cn//aaa/bbb?a=1&b=2"; normalize = URLUtil.normalize(url, true); - Assert.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize); url = "\\/www.hutool.cn//aaa/bbb?a=1&b=2"; normalize = URLUtil.normalize(url, true); - Assert.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa/bbb?a=1&b=2", normalize); } @Test public void normalizeIpv6Test() { final String url = "http://[fe80::8f8:2022:a603:d180]:9439"; final String normalize = URLUtil.normalize("http://[fe80::8f8:2022:a603:d180]:9439", true); - Assert.assertEquals(url, normalize); + Assertions.assertEquals(url, normalize); } @Test public void formatTest() { final String url = "//www.hutool.cn//aaa/\\bbb?a=1&b=2"; final String normalize = URLUtil.normalize(url); - Assert.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize); + Assertions.assertEquals("http://www.hutool.cn//aaa//bbb?a=1&b=2", normalize); } @Test @@ -73,13 +73,13 @@ public class URLUtilTest { final String url = "https://www.hutool.cn//aaa/\\bbb?a=1&b=2"; final String normalize = URLUtil.normalize(url); final URI host = URLUtil.getHost(new URL(normalize)); - Assert.assertEquals("https://www.hutool.cn", host.toString()); + Assertions.assertEquals("https://www.hutool.cn", host.toString()); } @Test public void getPathTest(){ final String url = " http://www.aaa.bbb/search?scope=ccc&q=ddd"; final String path = URLUtil.getPath(url); - Assert.assertEquals("/search", path); + Assertions.assertEquals("/search", path); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/UrlBuilderTest.java b/hutool-core/src/test/java/cn/hutool/core/net/UrlBuilderTest.java index 43fcc70e6..29baab4d2 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/UrlBuilderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/UrlBuilderTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.net; import cn.hutool.core.date.DateUtil; import cn.hutool.core.net.url.UrlBuilder; 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.net.URI; import java.net.URISyntaxException; @@ -19,28 +19,28 @@ public class UrlBuilderTest { final UrlBuilder builder = UrlBuilder.of(); final String buildUrl = builder.setHost("www.hutool.cn").build(); - Assert.assertEquals("http://www.hutool.cn/", buildUrl); - Assert.assertEquals(buildUrl, 80, builder.getPortWithDefault()); + Assertions.assertEquals("http://www.hutool.cn/", buildUrl); + Assertions.assertEquals(80, builder.getPortWithDefault()); } @Test public void buildWithoutSlashTest() { // https://github.com/dromara/hutool/issues/2459 String buildUrl = UrlBuilder.of().setScheme("http").setHost("192.168.1.1").setPort(8080).setWithEndTag(false).build(); - Assert.assertEquals("http://192.168.1.1:8080", buildUrl); + Assertions.assertEquals("http://192.168.1.1:8080", buildUrl); final UrlBuilder urlBuilder = UrlBuilder.of(); buildUrl = urlBuilder.setScheme("http").setHost("192.168.1.1").setPort(8080).addQuery("url", "http://192.168.1.1/test/1") .setWithEndTag(false).build(); - Assert.assertEquals("http://192.168.1.1:8080?url=http://192.168.1.1/test/1", buildUrl); - Assert.assertEquals(buildUrl, 8080, urlBuilder.getPortWithDefault()); + Assertions.assertEquals("http://192.168.1.1:8080?url=http://192.168.1.1/test/1", buildUrl); + Assertions.assertEquals(8080, urlBuilder.getPortWithDefault()); } @Test public void buildTest2() { // path中的+不做处理 final String buildUrl = UrlBuilder.ofHttp("http://www.hutool.cn/+8618888888888", CharsetUtil.UTF_8).build(); - Assert.assertEquals("http://www.hutool.cn/+8618888888888", buildUrl); + Assertions.assertEquals("http://www.hutool.cn/+8618888888888", buildUrl); } @Test @@ -48,7 +48,7 @@ public class UrlBuilderTest { final String buildUrl = UrlBuilder.of() .setScheme("https") .setHost("www.hutool.cn").build(); - Assert.assertEquals("https://www.hutool.cn/", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/", buildUrl); } @Test @@ -58,7 +58,7 @@ public class UrlBuilderTest { .setHost("www.hutool.cn") .setPort(8080) .build(); - Assert.assertEquals("https://www.hutool.cn:8080/", buildUrl); + Assertions.assertEquals("https://www.hutool.cn:8080/", buildUrl); } @Test @@ -71,7 +71,7 @@ public class UrlBuilderTest { .addQuery("wd", "test") .build(); - Assert.assertEquals("https://www.hutool.cn/aaa/bbb?ie=UTF-8&wd=test", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/aaa/bbb?ie=UTF-8&wd=test", buildUrl); } @Test @@ -84,7 +84,7 @@ public class UrlBuilderTest { .addQuery("wd", "测试") .build(); - Assert.assertEquals("https://www.hutool.cn/aaa/bbb?ie=UTF-8&wd=%E6%B5%8B%E8%AF%95", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/aaa/bbb?ie=UTF-8&wd=%E6%B5%8B%E8%AF%95", buildUrl); } @Test @@ -98,7 +98,7 @@ public class UrlBuilderTest { .addQuery("wd", "测试") .build(); - Assert.assertEquals("https://www.hutool.cn/s?ie=UTF-8&ie=GBK&wd=%E6%B5%8B%E8%AF%95", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/s?ie=UTF-8&ie=GBK&wd=%E6%B5%8B%E8%AF%95", buildUrl); } @Test @@ -107,7 +107,7 @@ public class UrlBuilderTest { .setScheme("https") .setHost("www.hutool.cn") .setFragment("abc").build(); - Assert.assertEquals("https://www.hutool.cn/#abc", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/#abc", buildUrl); } @Test @@ -116,7 +116,7 @@ public class UrlBuilderTest { .setScheme("https") .setHost("www.hutool.cn") .setFragment("测试").build(); - Assert.assertEquals("https://www.hutool.cn/#%E6%B5%8B%E8%AF%95", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/#%E6%B5%8B%E8%AF%95", buildUrl); } @Test @@ -126,7 +126,7 @@ public class UrlBuilderTest { .setHost("www.hutool.cn") .addPath("/s") .setFragment("测试").build(); - Assert.assertEquals("https://www.hutool.cn/s#%E6%B5%8B%E8%AF%95", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/s#%E6%B5%8B%E8%AF%95", buildUrl); } @Test @@ -137,75 +137,75 @@ public class UrlBuilderTest { .addPath("/s") .addQuery("wd", "test") .setFragment("测试").build(); - Assert.assertEquals("https://www.hutool.cn/s?wd=test#%E6%B5%8B%E8%AF%95", buildUrl); + Assertions.assertEquals("https://www.hutool.cn/s?wd=test#%E6%B5%8B%E8%AF%95", buildUrl); } @Test public void ofTest() { final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb/?a=1&b=2#frag1", CharsetUtil.UTF_8); - Assert.assertEquals("http", builder.getScheme()); - Assert.assertEquals("www.hutool.cn", builder.getHost()); + Assertions.assertEquals("http", builder.getScheme()); + Assertions.assertEquals("www.hutool.cn", builder.getHost()); - Assert.assertEquals("aaa", builder.getPath().getSegment(0)); - Assert.assertEquals("bbb", builder.getPath().getSegment(1)); + Assertions.assertEquals("aaa", builder.getPath().getSegment(0)); + Assertions.assertEquals("bbb", builder.getPath().getSegment(1)); - Assert.assertEquals("1", builder.getQuery().get("a")); - Assert.assertEquals("2", builder.getQuery().get("b")); + Assertions.assertEquals("1", builder.getQuery().get("a")); + Assertions.assertEquals("2", builder.getQuery().get("b")); - Assert.assertEquals("frag1", builder.getFragment()); + Assertions.assertEquals("frag1", builder.getFragment()); } @Test public void ofNullQueryTest() { final UrlBuilder builder = UrlBuilder.of("http://www.hutool.cn/aaa/bbb", CharsetUtil.UTF_8); - Assert.assertNotNull(builder.getQuery()); - Assert.assertNull(builder.getQuery().get("a")); + Assertions.assertNotNull(builder.getQuery()); + Assertions.assertNull(builder.getQuery().get("a")); } @Test public void ofWithChineseTest() { final UrlBuilder builder = UrlBuilder.ofHttp("www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.UTF_8); - Assert.assertEquals("http", builder.getScheme()); - Assert.assertEquals("www.hutool.cn", builder.getHost()); + Assertions.assertEquals("http", builder.getScheme()); + Assertions.assertEquals("www.hutool.cn", builder.getHost()); - Assert.assertEquals("aaa", builder.getPath().getSegment(0)); - Assert.assertEquals("bbb", builder.getPath().getSegment(1)); + Assertions.assertEquals("aaa", builder.getPath().getSegment(0)); + Assertions.assertEquals("bbb", builder.getPath().getSegment(1)); - Assert.assertEquals("张三", builder.getQuery().get("a")); - Assert.assertEquals("李四", builder.getQuery().get("b")); + Assertions.assertEquals("张三", builder.getQuery().get("a")); + Assertions.assertEquals("李四", builder.getQuery().get("b")); - Assert.assertEquals("frag1", builder.getFragment()); + Assertions.assertEquals("frag1", builder.getFragment()); } @Test public void ofWithBlankTest() { final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.UTF_8); - Assert.assertEquals("http", builder.getScheme()); - Assert.assertEquals("www.hutool.cn", builder.getHost()); + Assertions.assertEquals("http", builder.getScheme()); + Assertions.assertEquals("www.hutool.cn", builder.getHost()); - Assert.assertEquals("aaa", builder.getPath().getSegment(0)); - Assert.assertEquals("bbb", builder.getPath().getSegment(1)); + Assertions.assertEquals("aaa", builder.getPath().getSegment(0)); + Assertions.assertEquals("bbb", builder.getPath().getSegment(1)); - Assert.assertEquals("张三", builder.getQuery().get("a")); - Assert.assertEquals("李四", builder.getQuery().get("b")); + Assertions.assertEquals("张三", builder.getQuery().get("a")); + Assertions.assertEquals("李四", builder.getQuery().get("b")); - Assert.assertEquals("frag1", builder.getFragment()); + Assertions.assertEquals("frag1", builder.getFragment()); } @Test public void ofSpecialTest() { //测试不规范的或者无需解码的字符串是否成功解码 final UrlBuilder builder = UrlBuilder.ofHttp(" www.hutool.cn/aaa/bbb/?a=张三&b=%%e5%9b%9b#frag1", CharsetUtil.UTF_8); - Assert.assertEquals("http", builder.getScheme()); - Assert.assertEquals("www.hutool.cn", builder.getHost()); + Assertions.assertEquals("http", builder.getScheme()); + Assertions.assertEquals("www.hutool.cn", builder.getHost()); - Assert.assertEquals("aaa", builder.getPath().getSegment(0)); - Assert.assertEquals("bbb", builder.getPath().getSegment(1)); + Assertions.assertEquals("aaa", builder.getPath().getSegment(0)); + Assertions.assertEquals("bbb", builder.getPath().getSegment(1)); - Assert.assertEquals("张三", builder.getQuery().get("a")); - Assert.assertEquals("%四", builder.getQuery().get("b")); + Assertions.assertEquals("张三", builder.getQuery().get("a")); + Assertions.assertEquals("%四", builder.getQuery().get("b")); - Assert.assertEquals("frag1", builder.getFragment()); + Assertions.assertEquals("frag1", builder.getFragment()); } @Test @@ -218,7 +218,7 @@ public class UrlBuilderTest { "&chksm=6cbda3a25bca2ab4516410db6ce6e125badaac2f8c5548ea6e18eab6dc3c5422cb8cbe1095f7"; final UrlBuilder builder = UrlBuilder.ofHttp(urlStr, CharsetUtil.UTF_8); // 原URL中的&替换为& - Assert.assertEquals("https://mp.weixin.qq.com/s?" + + Assertions.assertEquals("https://mp.weixin.qq.com/s?" + "__biz=MzI5NjkyNTIxMg==" + "&mid=100000465&idx=1" + "&sn=1044c0d19723f74f04f4c1da34eefa35" + @@ -232,40 +232,40 @@ public class UrlBuilderTest { final String today = DateUtil.now().toString("yyyyMMdd"); final String getWorkDayUrl = "https://tool.bitefu.net/jiari/?info=1&d=" + today; final UrlBuilder builder = UrlBuilder.ofHttp(getWorkDayUrl, CharsetUtil.UTF_8); - Assert.assertEquals(getWorkDayUrl, builder.toString()); + Assertions.assertEquals(getWorkDayUrl, builder.toString()); } @Test public void blankEncodeTest() { final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://a.com/aaa bbb.html", CharsetUtil.UTF_8); - Assert.assertEquals("http://a.com/aaa%20bbb.html", urlBuilder.toString()); + Assertions.assertEquals("http://a.com/aaa%20bbb.html", urlBuilder.toString()); } @Test public void dotEncodeTest() { final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://xtbgyy.digitalgd.com.cn/ebus/../../..", CharsetUtil.UTF_8); - Assert.assertEquals("http://xtbgyy.digitalgd.com.cn/ebus/../../..", urlBuilder.toString()); + Assertions.assertEquals("http://xtbgyy.digitalgd.com.cn/ebus/../../..", urlBuilder.toString()); } @Test public void multiSlashTest() { //issue#I25MZL,某些URL中有多个斜杠,此为合法路径 final UrlBuilder urlBuilder = UrlBuilder.ofHttp("https://hutool.cn//file/test.jpg", CharsetUtil.UTF_8); - Assert.assertEquals("https://hutool.cn//file/test.jpg", urlBuilder.toString()); + Assertions.assertEquals("https://hutool.cn//file/test.jpg", urlBuilder.toString()); } @Test public void toURITest() throws URISyntaxException { final String webUrl = "http://exmple.com/patha/pathb?a=123"; // 报错数据 final UrlBuilder urlBuilder = UrlBuilder.of(webUrl, StandardCharsets.UTF_8); - Assert.assertEquals(new URI(webUrl), urlBuilder.toURI()); + Assertions.assertEquals(new URI(webUrl), urlBuilder.toURI()); } @Test public void testEncodeInQuery() { final String webUrl = "http://exmple.com/patha/pathb?a=123&b=4?6&c=789"; // b=4?6 参数中有未编码的? final UrlBuilder urlBuilder = UrlBuilder.of(webUrl, StandardCharsets.UTF_8); - Assert.assertEquals("a=123&b=4?6&c=789", urlBuilder.getQueryStr()); + Assertions.assertEquals("a=123&b=4?6&c=789", urlBuilder.getQueryStr()); } @Test @@ -273,7 +273,7 @@ public class UrlBuilderTest { // Path中的某些符号无需转义,比如= final String urlStr = "http://hq.sinajs.cn/list=sh600519"; final UrlBuilder urlBuilder = UrlBuilder.ofHttp(urlStr, CharsetUtil.UTF_8); - Assert.assertEquals(urlStr, urlBuilder.toString()); + Assertions.assertEquals(urlStr, urlBuilder.toString()); } @Test @@ -282,7 +282,7 @@ public class UrlBuilderTest { // Path中`:`在第一个segment需要转义,之后的不需要 final String urlStr = "https://hutool.cn/aa/bb/Pre-K,Kindergarten,First,Second,Third,Fourth,Fifth/Page:3"; final UrlBuilder urlBuilder = UrlBuilder.ofHttp(urlStr, CharsetUtil.UTF_8); - Assert.assertEquals(urlStr, urlBuilder.toString()); + Assertions.assertEquals(urlStr, urlBuilder.toString()); } @Test @@ -292,7 +292,7 @@ public class UrlBuilderTest { // PATH除了第一个path外,:是允许的 final String url2 = "https://gimg2.baidu.com/image_search/src=http:%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F1114%2F0H320120Z3%2F200H3120Z3-6-1200.jpg&refer=http:%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621996490&t=8c384c2823ea453da15a1b9cd5183eea"; - Assert.assertEquals(url2, urlBuilder.toString()); + Assertions.assertEquals(url2, urlBuilder.toString()); } @Test @@ -301,10 +301,10 @@ public class UrlBuilderTest { // 见:https://stackoverflow.com/questions/26088849/url-fragment-allowed-characters final String url = "https://hutool.cn/docs/#/?id=简介"; UrlBuilder urlBuilder = UrlBuilder.ofHttp(url); - Assert.assertEquals("https://hutool.cn/docs/#/?id=%E7%AE%80%E4%BB%8B", urlBuilder.toString()); + Assertions.assertEquals("https://hutool.cn/docs/#/?id=%E7%AE%80%E4%BB%8B", urlBuilder.toString()); urlBuilder = UrlBuilder.ofHttp(urlBuilder.toString()); - Assert.assertEquals(urlBuilder.toString(), urlBuilder.toString()); + Assertions.assertEquals(urlBuilder.toString(), urlBuilder.toString()); } @Test @@ -314,7 +314,7 @@ public class UrlBuilderTest { // 见:https://www.rfc-editor.org/rfc/rfc3986.html#section-3.4 final String url = "https://invoice.maycur.com/2b27a802-8423-4d41-86f5-63a6b259f61e.xlsx?download/2b27a802-8423-4d41-86f5-63a6b259f61e.xlsx&e=1630491088"; final UrlBuilder urlBuilder = UrlBuilder.ofHttp(url); - Assert.assertEquals(url, urlBuilder.toString()); + Assertions.assertEquals(url, urlBuilder.toString()); } @Test @@ -327,7 +327,7 @@ public class UrlBuilderTest { .addPath("bbb") .build(); - Assert.assertEquals("https://domain.cn/api/xxx/bbb", url); + Assertions.assertEquals("https://domain.cn/api/xxx/bbb", url); } @Test @@ -339,21 +339,21 @@ public class UrlBuilderTest { .addPath("/api/xxx/bbb") .build(); - Assert.assertEquals("https://domain.cn/api/xxx/bbb", url); + Assertions.assertEquals("https://domain.cn/api/xxx/bbb", url); } @Test public void percent2BTest() { final String url = "http://xxx.cn/a?Signature=3R013Bj9Uq4YeISzAs2iC%2BTVCL8%3D"; final UrlBuilder of = UrlBuilder.ofHttpWithoutEncode(url); - Assert.assertEquals(url, of.toString()); + Assertions.assertEquals(url, of.toString()); } @Test public void paramTest() { final String url = "http://ci.xiaohongshu.com/spectrum/c136c98aa2047babe25b994a26ffa7b492bd8058?imageMogr2/thumbnail/x800/format/jpg"; final UrlBuilder builder = UrlBuilder.ofHttp(url); - Assert.assertEquals(url, builder.toString()); + Assertions.assertEquals(url, builder.toString()); } @Test @@ -362,7 +362,7 @@ public class UrlBuilderTest { final String url = "https://www.hutool.cn/#/a/b?timestamp=1640391380204"; final UrlBuilder builder = UrlBuilder.ofHttp(url); - Assert.assertEquals(url, builder.toString()); + Assertions.assertEquals(url, builder.toString()); } @Test @@ -371,7 +371,7 @@ public class UrlBuilderTest { final String url = "https://www.hutool.cn/#/a/b"; final UrlBuilder builder = UrlBuilder.ofHttp(url); builder.setFragment(builder.getFragment() + "?timestamp=1640391380204"); - Assert.assertEquals("https://www.hutool.cn/#/a/b?timestamp=1640391380204", builder.toString()); + Assertions.assertEquals("https://www.hutool.cn/#/a/b?timestamp=1640391380204", builder.toString()); } @Test @@ -386,7 +386,7 @@ public class UrlBuilderTest { "/RqAAYRYVCBiyuzAexSiDiJX1VqWljg4jYp1sdyv3HpV3sXVcf6VH6AN9ot5YNTw4JNO0aNpLpLm93rRMrOKIOsve+OmNyZ4HS7qHQKt1qp7HY1A" + "/wGhJstkAoGQt+CHSMwVdIx3bVT1+ZYnJdM/oIQ/90afw4EEEQaRE51Z0rQC7z8d"; final String build = UrlBuilder.of(url).build(); - Assert.assertEquals(url, build); + Assertions.assertEquals(url, build); } @Test @@ -398,21 +398,21 @@ public class UrlBuilderTest { "&Signature=oYUu26JufAyPY4PdzaOp1x4sr4Q%3D"; final UrlBuilder urlBuilder = UrlBuilder.ofHttp(url, null); - Assert.assertEquals(url, urlBuilder.toString()); + Assertions.assertEquals(url, urlBuilder.toString()); } @Test public void issue2215Test() { final String url = "https://hutool.cn/v1/104303371/messages:send"; final String build = UrlBuilder.of(url).build(); - Assert.assertEquals(url, build); + Assertions.assertEquals(url, build); } @Test public void issuesI4Z2ETTest() { final String url = "http://hutool.cn/2022/03/09/123.zip?Expires=1648704684&OSSAccessKeyId=LTAI4FncgaVtwZGBnYHHi8ox&Signature=%2BK%2B%3D"; final String build = UrlBuilder.of(url, null).build(); - Assert.assertEquals(url, build); + Assertions.assertEquals(url, build); } @Test @@ -426,7 +426,7 @@ public class UrlBuilderTest { final UrlBuilder builder = UrlBuilder.of(url); params.forEach(builder::addQuery); - Assert.assertEquals("http://127.0.0.1/devicerecord/list?start=2022-03-31%2000:00:00&end=2022-03-31%2023:59:59&page=1&limit=10", builder.toString()); + Assertions.assertEquals("http://127.0.0.1/devicerecord/list?start=2022-03-31%2000:00:00&end=2022-03-31%2023:59:59&page=1&limit=10", builder.toString()); } @Test @@ -435,7 +435,7 @@ public class UrlBuilderTest { // 如果用户已经做了%编码,不应该重复编码 final String url = "https://hutool.cn/v1.0?privateNum=%2B8616512884988"; final String s = UrlBuilder.of(url, null).setCharset(CharsetUtil.UTF_8).toString(); - Assert.assertEquals(url, s); + Assertions.assertEquals(url, s); } @Test @@ -443,7 +443,7 @@ public class UrlBuilderTest { // &自动转换为& final String url = "https://hutool.cn/a.mp3?Expires=1652423884&key=JMv2rKNc7Pz&sign=12zva00BpVqgZcX1wcb%2BrmN7H3E%3D"; final UrlBuilder of = UrlBuilder.of(url, null); - Assert.assertEquals(url.replace("&", "&"), of.toString()); + Assertions.assertEquals(url.replace("&", "&"), of.toString()); } @SuppressWarnings("ConstantConditions") @@ -453,14 +453,14 @@ public class UrlBuilderTest { .addQuery("param[0].field", "编码") .toURI() .toString(); - Assert.assertEquals("http://127.0.0.1:8080?param%5B0%5D.field=%E7%BC%96%E7%A0%81", duplicate); + Assertions.assertEquals("http://127.0.0.1:8080?param%5B0%5D.field=%E7%BC%96%E7%A0%81", duplicate); final String normal = UrlBuilder.ofHttp("127.0.0.1:8080") .addQuery("param[0].field", "编码") .toURL() .toURI() .toString(); - Assert.assertEquals(duplicate, normal); + Assertions.assertEquals(duplicate, normal); } @Test @@ -468,7 +468,7 @@ public class UrlBuilderTest { final UrlBuilder builder = UrlBuilder.ofHttp("127.0.0.1:8080") .addQuery("param[0].field", "编码"); - Assert.assertEquals("127.0.0.1:8080", builder.getAuthority()); + Assertions.assertEquals("127.0.0.1:8080", builder.getAuthority()); } @Test @@ -483,15 +483,15 @@ public class UrlBuilderTest { @Test public void ofHttpTest() { UrlBuilder ofHttp = UrlBuilder.ofHttp("http://hutool.cn"); - Assert.assertEquals("http://hutool.cn", ofHttp.toString()); + Assertions.assertEquals("http://hutool.cn", ofHttp.toString()); ofHttp = UrlBuilder.ofHttp("https://hutool.cn"); - Assert.assertEquals("https://hutool.cn", ofHttp.toString()); + Assertions.assertEquals("https://hutool.cn", ofHttp.toString()); ofHttp = UrlBuilder.ofHttp("hutool.cn"); - Assert.assertEquals("http://hutool.cn", ofHttp.toString()); + Assertions.assertEquals("http://hutool.cn", ofHttp.toString()); ofHttp = UrlBuilder.ofHttp("hutool.cn?old=http://aaa"); - Assert.assertEquals("http://hutool.cn?old=http://aaa", ofHttp.toString()); + Assertions.assertEquals("http://hutool.cn?old=http://aaa", ofHttp.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/UrlDecoderTest.java b/hutool-core/src/test/java/cn/hutool/core/net/UrlDecoderTest.java index 48fa6eece..f2122d1fe 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/UrlDecoderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/UrlDecoderTest.java @@ -2,12 +2,12 @@ package cn.hutool.core.net; import cn.hutool.core.net.url.URLDecoder; 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; public class UrlDecoderTest { @Test public void decodeForPathTest(){ - Assert.assertEquals("+", URLDecoder.decodeForPath("+", CharsetUtil.UTF_8)); + Assertions.assertEquals("+", URLDecoder.decodeForPath("+", CharsetUtil.UTF_8)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/UrlQueryTest.java b/hutool-core/src/test/java/cn/hutool/core/net/UrlQueryTest.java index ad2b3fbab..175f4dfbf 100644 --- a/hutool-core/src/test/java/cn/hutool/core/net/UrlQueryTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/UrlQueryTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.net.url.URLUtil; import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.net.url.UrlQuery; 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.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -21,8 +21,8 @@ public class UrlQueryTest { final String queryStr = "a=1&b=111=="; final UrlQuery q = new UrlQuery(); final UrlQuery parse = q.parse(queryStr, Charset.defaultCharset()); - Assert.assertEquals("111==", parse.get("b")); - Assert.assertEquals("a=1&b=111==", parse.toString()); + Assertions.assertEquals("111==", parse.get("b")); + Assertions.assertEquals("a=1&b=111==", parse.toString()); } @Test @@ -31,7 +31,7 @@ public class UrlQueryTest { final String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848"; final UrlBuilder urlBuilder = UrlBuilder.ofHttpWithoutEncode(url); final String queryStr = urlBuilder.getQueryStr(); - Assert.assertEquals("imageMogr2/auto-orient/thumbnail/500&pid=259848", queryStr); + Assertions.assertEquals("imageMogr2/auto-orient/thumbnail/500&pid=259848", queryStr); } @Test @@ -39,7 +39,7 @@ public class UrlQueryTest { final String requestUrl = "http://192.168.1.1:8080/pc?=d52i5837i4ed=o39-ap9e19s5--=72e54*ll0lodl-f338868d2"; final UrlQuery q = new UrlQuery(); final UrlQuery parse = q.parse(requestUrl, Charset.defaultCharset()); - Assert.assertEquals("=d52i5837i4ed=o39-ap9e19s5--=72e54*ll0lodl-f338868d2", parse.toString()); + Assertions.assertEquals("=d52i5837i4ed=o39-ap9e19s5--=72e54*ll0lodl-f338868d2", parse.toString()); } @Test @@ -47,7 +47,7 @@ public class UrlQueryTest { // issue#1688@Github final String u = "https://www.baidu.com/proxy"; final UrlQuery query = UrlQuery.of(URLUtil.url(u).getQuery(), Charset.defaultCharset()); - Assert.assertTrue(MapUtil.isEmpty(query.getQueryMap())); + Assertions.assertTrue(MapUtil.isEmpty(query.getQueryMap())); } @Test @@ -55,7 +55,7 @@ public class UrlQueryTest { // https://github.com/dromara/hutool/issues/1989 final String queryStr = "imageMogr2/thumbnail/x800/format/jpg"; final UrlQuery query = UrlQuery.of(queryStr, CharsetUtil.UTF_8); - Assert.assertEquals(queryStr, query.toString()); + Assertions.assertEquals(queryStr, query.toString()); } @Test @@ -64,13 +64,13 @@ public class UrlQueryTest { map.put("username", "SSM"); map.put("password", "123456"); String query = URLUtil.buildQuery(map, StandardCharsets.UTF_8); - Assert.assertEquals("username=SSM&password=123456", query); + Assertions.assertEquals("username=SSM&password=123456", query); map = new TreeMap<>(); map.put("username", "SSM"); map.put("password", "123456"); query = URLUtil.buildQuery(map, StandardCharsets.UTF_8); - Assert.assertEquals("password=123456&username=SSM", query); + Assertions.assertEquals("password=123456&username=SSM", query); } @Test @@ -79,19 +79,19 @@ public class UrlQueryTest { map.put(null, "SSM"); map.put("password", "123456"); String query = URLUtil.buildQuery(map, StandardCharsets.UTF_8); - Assert.assertEquals("password=123456", query); + Assertions.assertEquals("password=123456", query); map = new TreeMap<>(); map.put("username", "SSM"); map.put("password", ""); query = URLUtil.buildQuery(map, StandardCharsets.UTF_8); - Assert.assertEquals("password=&username=SSM", query); + Assertions.assertEquals("password=&username=SSM", query); map = new TreeMap<>(); map.put("username", "SSM"); map.put("password", null); query = URLUtil.buildQuery(map, StandardCharsets.UTF_8); - Assert.assertEquals("password&username=SSM", query); + Assertions.assertEquals("password&username=SSM", query); } @Test @@ -100,20 +100,20 @@ public class UrlQueryTest { map.put("key1&", "SSM"); map.put("key2", "123456&"); String query = URLUtil.buildQuery(map, StandardCharsets.UTF_8); - Assert.assertEquals("key1%26=SSM&key2=123456%26", query); + Assertions.assertEquals("key1%26=SSM&key2=123456%26", query); map = new TreeMap<>(); map.put("username=", "SSM"); map.put("password", "="); query = URLUtil.buildQuery(map, StandardCharsets.UTF_8); - Assert.assertEquals("password==&username%3D=SSM", query); + Assertions.assertEquals("password==&username%3D=SSM", query); } @Test public void plusTest(){ // 根据RFC3986,在URL中,+是安全字符,即此符号不转义 final String a = UrlQuery.of(MapUtil.of("a+b", "1+2")).build(CharsetUtil.UTF_8); - Assert.assertEquals("a+b=1+2", a); + Assertions.assertEquals("a+b=1+2", a); } @Test @@ -121,27 +121,27 @@ public class UrlQueryTest { // 根据RFC3986,在URL中,+是安全字符,即此符号不转义 final String a = UrlQuery.of("a+b=1+2", CharsetUtil.UTF_8) .build(CharsetUtil.UTF_8); - Assert.assertEquals("a+b=1+2", a); + Assertions.assertEquals("a+b=1+2", a); } @Test public void spaceTest(){ // 根据RFC3986,在URL中,空格编码为"%20" final String a = UrlQuery.of(MapUtil.of("a ", " ")).build(CharsetUtil.UTF_8); - Assert.assertEquals("a%20=%20", a); + Assertions.assertEquals("a%20=%20", a); } @Test public void parsePercentTest(){ final String queryStr = "a%2B=ccc"; final UrlQuery query = UrlQuery.of(queryStr, null); - Assert.assertEquals(queryStr, query.toString()); + Assertions.assertEquals(queryStr, query.toString()); } @Test public void parsePercentTest2(){ final String queryStr = "signature=%2Br1ekUCGjXiu50Y%2Bk0MO4ovulK8%3D"; final UrlQuery query = UrlQuery.of(queryStr, null); - Assert.assertEquals(queryStr, query.toString()); + Assertions.assertEquals(queryStr, query.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/net/url/UrlQueryUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/net/url/UrlQueryUtilTest.java index 17994e794..30417bf86 100755 --- a/hutool-core/src/test/java/cn/hutool/core/net/url/UrlQueryUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/net/url/UrlQueryUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.net.url; 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.List; import java.util.Map; @@ -12,17 +12,17 @@ public class UrlQueryUtilTest { public void decodeQueryTest() { final String paramsStr = "uuuu=0&a=b&c=%3F%23%40!%24%25%5E%26%3Ddsssss555555"; final Map> map = UrlQueryUtil.decodeQuery(paramsStr, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("0", map.get("uuuu").get(0)); - Assert.assertEquals("b", map.get("a").get(0)); - Assert.assertEquals("?#@!$%^&=dsssss555555", map.get("c").get(0)); + Assertions.assertEquals("0", map.get("uuuu").get(0)); + Assertions.assertEquals("b", map.get("a").get(0)); + Assertions.assertEquals("?#@!$%^&=dsssss555555", map.get("c").get(0)); } @Test public void decodeQueryTest2() { // 参数值存在分界标记等号时 final Map paramMap = UrlQueryUtil.decodeQuery("https://www.xxx.com/api.action?aa=123&f_token=NzBkMjQxNDM1MDVlMDliZTk1OTU3ZDI1OTI0NTBiOWQ=", CharsetUtil.UTF_8); - Assert.assertEquals("123",paramMap.get("aa")); - Assert.assertEquals("NzBkMjQxNDM1MDVlMDliZTk1OTU3ZDI1OTI0NTBiOWQ=",paramMap.get("f_token")); + Assertions.assertEquals("123",paramMap.get("aa")); + Assertions.assertEquals("NzBkMjQxNDM1MDVlMDliZTk1OTU3ZDI1OTI0NTBiOWQ=",paramMap.get("f_token")); } @Test @@ -31,7 +31,7 @@ public class UrlQueryUtilTest { final Map> map = UrlQueryUtil.decodeQuery(paramsStr, CharsetUtil.NAME_UTF_8); final String encodedParams = UrlQueryUtil.toQuery(map); - Assert.assertEquals(paramsStr, encodedParams); + Assertions.assertEquals(paramsStr, encodedParams); } @Test @@ -39,52 +39,52 @@ public class UrlQueryUtilTest { // ?单独存在去除之,&单位位于末尾去除之 String paramsStr = "?a=b&c=d&"; String encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("a=b&c=d", encode); + Assertions.assertEquals("a=b&c=d", encode); // url不参与转码 paramsStr = "http://www.abc.dd?a=b&c=d&"; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("http://www.abc.dd?a=b&c=d", encode); + Assertions.assertEquals("http://www.abc.dd?a=b&c=d", encode); // b=b中的=被当作值的一部分,不做encode paramsStr = "a=b=b&c=d&"; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("a=b=b&c=d", encode); + Assertions.assertEquals("a=b=b&c=d", encode); // =d的情况被处理为key为空 paramsStr = "a=bbb&c=d&=d"; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("a=bbb&c=d&=d", encode); + Assertions.assertEquals("a=bbb&c=d&=d", encode); // d=的情况被处理为value为空 paramsStr = "a=bbb&c=d&d="; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("a=bbb&c=d&d=", encode); + Assertions.assertEquals("a=bbb&c=d&d=", encode); // 多个&&被处理为单个,相当于空条件 paramsStr = "a=bbb&c=d&&&d="; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("a=bbb&c=d&d=", encode); + Assertions.assertEquals("a=bbb&c=d&d=", encode); // &d&相当于只有键,无值得情况 paramsStr = "a=bbb&c=d&d&"; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("a=bbb&c=d&d=", encode); + Assertions.assertEquals("a=bbb&c=d&d=", encode); // 中文的键和值被编码 paramsStr = "a=bbb&c=你好&哈喽&"; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("a=bbb&c=%E4%BD%A0%E5%A5%BD&%E5%93%88%E5%96%BD=", encode); + Assertions.assertEquals("a=bbb&c=%E4%BD%A0%E5%A5%BD&%E5%93%88%E5%96%BD=", encode); // URL原样输出 paramsStr = "https://www.hutool.cn/"; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals(paramsStr, encode); + Assertions.assertEquals(paramsStr, encode); // URL原样输出 paramsStr = "https://www.hutool.cn/?"; encode = UrlQueryUtil.encodeQuery(paramsStr, CharsetUtil.UTF_8); - Assert.assertEquals("https://www.hutool.cn/", encode); + Assertions.assertEquals("https://www.hutool.cn/", encode); } @Test @@ -92,62 +92,62 @@ public class UrlQueryUtilTest { // 开头的?被去除 String a = "?a=b&c=d&"; Map> map = UrlQueryUtil.decodeQuery(a, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("b", map.get("a").get(0)); - Assert.assertEquals("d", map.get("c").get(0)); + Assertions.assertEquals("b", map.get("a").get(0)); + Assertions.assertEquals("d", map.get("c").get(0)); // =e被当作空为key,e为value a = "?a=b&c=d&=e"; map = UrlQueryUtil.decodeQuery(a, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("b", map.get("a").get(0)); - Assert.assertEquals("d", map.get("c").get(0)); - Assert.assertEquals("e", map.get("").get(0)); + Assertions.assertEquals("b", map.get("a").get(0)); + Assertions.assertEquals("d", map.get("c").get(0)); + Assertions.assertEquals("e", map.get("").get(0)); // 多余的&去除 a = "?a=b&c=d&=e&&&&"; map = UrlQueryUtil.decodeQuery(a, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("b", map.get("a").get(0)); - Assert.assertEquals("d", map.get("c").get(0)); - Assert.assertEquals("e", map.get("").get(0)); + Assertions.assertEquals("b", map.get("a").get(0)); + Assertions.assertEquals("d", map.get("c").get(0)); + Assertions.assertEquals("e", map.get("").get(0)); // 值为空 a = "?a=b&c=d&e="; map = UrlQueryUtil.decodeQuery(a, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("b", map.get("a").get(0)); - Assert.assertEquals("d", map.get("c").get(0)); - Assert.assertEquals("", map.get("e").get(0)); + Assertions.assertEquals("b", map.get("a").get(0)); + Assertions.assertEquals("d", map.get("c").get(0)); + Assertions.assertEquals("", map.get("e").get(0)); // &=被作为键和值都为空 a = "a=b&c=d&="; map = UrlQueryUtil.decodeQuery(a, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("b", map.get("a").get(0)); - Assert.assertEquals("d", map.get("c").get(0)); - Assert.assertEquals("", map.get("").get(0)); + Assertions.assertEquals("b", map.get("a").get(0)); + Assertions.assertEquals("d", map.get("c").get(0)); + Assertions.assertEquals("", map.get("").get(0)); // &e&这类单独的字符串被当作key a = "a=b&c=d&e&"; map = UrlQueryUtil.decodeQuery(a, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("b", map.get("a").get(0)); - Assert.assertEquals("d", map.get("c").get(0)); - Assert.assertNull(map.get("e").get(0)); - Assert.assertNull(map.get("").get(0)); + Assertions.assertEquals("b", map.get("a").get(0)); + Assertions.assertEquals("d", map.get("c").get(0)); + Assertions.assertNull(map.get("e").get(0)); + Assertions.assertNull(map.get("").get(0)); // 被编码的键和值被还原 a = "a=bbb&c=%E4%BD%A0%E5%A5%BD&%E5%93%88%E5%96%BD="; map = UrlQueryUtil.decodeQuery(a, CharsetUtil.NAME_UTF_8); - Assert.assertEquals("bbb", map.get("a").get(0)); - Assert.assertEquals("你好", map.get("c").get(0)); - Assert.assertEquals("", map.get("哈喽").get(0)); + Assertions.assertEquals("bbb", map.get("a").get(0)); + Assertions.assertEquals("你好", map.get("c").get(0)); + Assertions.assertEquals("", map.get("哈喽").get(0)); } @Test public void normalizeQueryTest() { final String encodeResult = UrlQueryUtil.normalizeQuery("参数", CharsetUtil.UTF_8); - Assert.assertEquals("%E5%8F%82%E6%95%B0", encodeResult); + Assertions.assertEquals("%E5%8F%82%E6%95%B0", encodeResult); } @Test public void normalizeBlankQueryTest() { final String encodeResult = UrlQueryUtil.normalizeQuery("", CharsetUtil.UTF_8); - Assert.assertEquals("", encodeResult); + Assertions.assertEquals("", encodeResult); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/reflect/ActualTypeMapperPoolTest.java b/hutool-core/src/test/java/cn/hutool/core/reflect/ActualTypeMapperPoolTest.java index 2ec2ae206..c34cd9bc0 100644 --- a/hutool-core/src/test/java/cn/hutool/core/reflect/ActualTypeMapperPoolTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/reflect/ActualTypeMapperPoolTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.reflect; -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; import java.util.Map; @@ -18,15 +18,15 @@ public class ActualTypeMapperPoolTest { final Map typeTypeMap = ActualTypeMapperPool.get(FinalClass.class); typeTypeMap.forEach((key, value)->{ if("A".equals(key.getTypeName())){ - Assert.assertEquals(Character.class, value); + Assertions.assertEquals(Character.class, value); } else if("B".equals(key.getTypeName())){ - Assert.assertEquals(Boolean.class, value); + Assertions.assertEquals(Boolean.class, value); } else if("C".equals(key.getTypeName())){ - Assert.assertEquals(String.class, value); + Assertions.assertEquals(String.class, value); } else if("D".equals(key.getTypeName())){ - Assert.assertEquals(Double.class, value); + Assertions.assertEquals(Double.class, value); } else if("E".equals(key.getTypeName())){ - Assert.assertEquals(Integer.class, value); + Assertions.assertEquals(Integer.class, value); } }); } @@ -36,15 +36,15 @@ public class ActualTypeMapperPoolTest { final Map typeTypeMap = ActualTypeMapperPool.getStrKeyMap(FinalClass.class); typeTypeMap.forEach((key, value)->{ if("A".equals(key)){ - Assert.assertEquals(Character.class, value); + Assertions.assertEquals(Character.class, value); } else if("B".equals(key)){ - Assert.assertEquals(Boolean.class, value); + Assertions.assertEquals(Boolean.class, value); } else if("C".equals(key)){ - Assert.assertEquals(String.class, value); + Assertions.assertEquals(String.class, value); } else if("D".equals(key)){ - Assert.assertEquals(Double.class, value); + Assertions.assertEquals(Double.class, value); } else if("E".equals(key)){ - Assert.assertEquals(Integer.class, value); + Assertions.assertEquals(Integer.class, value); } }); } diff --git a/hutool-core/src/test/java/cn/hutool/core/reflect/ClassScannerTest.java b/hutool-core/src/test/java/cn/hutool/core/reflect/ClassScannerTest.java index ed1d8c601..87a27ae27 100644 --- a/hutool-core/src/test/java/cn/hutool/core/reflect/ClassScannerTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/reflect/ClassScannerTest.java @@ -1,15 +1,15 @@ package cn.hutool.core.reflect; 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.util.Set; public class ClassScannerTest { @Test - @Ignore + @Disabled public void scanTest() { final ClassScanner scaner = new ClassScanner("cn.hutool.core.util", null); final Set> set = scaner.scan(); @@ -19,7 +19,7 @@ public class ClassScannerTest { } @Test - @Ignore + @Disabled public void scanPackageBySuperTest() { // 扫描包,如果在classpath下找到,就不扫描JDK的jar了 final Set> classes = ClassScanner.scanPackageBySuper(null, Iterable.class); @@ -27,7 +27,7 @@ public class ClassScannerTest { } @Test - @Ignore + @Disabled public void scanAllPackageBySuperTest() { // 扫描包,如果在classpath下找到,就不扫描JDK的jar了 final Set> classes = ClassScanner.scanAllPackageBySuper(null, Iterable.class); @@ -35,7 +35,7 @@ public class ClassScannerTest { } @Test - @Ignore + @Disabled public void scanAllPackageIgnoreLoadErrorTest() { final ClassScanner classScanner = new ClassScanner(null, null); classScanner.setIgnoreLoadError(true); diff --git a/hutool-core/src/test/java/cn/hutool/core/reflect/ConstructorUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/reflect/ConstructorUtilTest.java index 4f0cf7778..499a4689d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/reflect/ConstructorUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/reflect/ConstructorUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.reflect; import cn.hutool.core.date.Week; -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.Map; @@ -11,29 +11,29 @@ public class ConstructorUtilTest { @Test public void noneStaticInnerClassTest() { final ReflectUtilTest.NoneStaticClass testAClass = ConstructorUtil.newInstanceIfPossible(ReflectUtilTest.NoneStaticClass.class); - Assert.assertNotNull(testAClass); - Assert.assertEquals(2, testAClass.getA()); + Assertions.assertNotNull(testAClass); + Assertions.assertEquals(2, testAClass.getA()); } @Test public void newInstanceIfPossibleTest(){ //noinspection ConstantConditions final int intValue = ConstructorUtil.newInstanceIfPossible(int.class); - Assert.assertEquals(0, intValue); + Assertions.assertEquals(0, intValue); final Integer integer = ConstructorUtil.newInstanceIfPossible(Integer.class); - Assert.assertEquals(new Integer(0), integer); + Assertions.assertEquals(new Integer(0), integer); final Map map = ConstructorUtil.newInstanceIfPossible(Map.class); - Assert.assertNotNull(map); + Assertions.assertNotNull(map); final Collection collection = ConstructorUtil.newInstanceIfPossible(Collection.class); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); final Week week = ConstructorUtil.newInstanceIfPossible(Week.class); - Assert.assertEquals(Week.SUNDAY, week); + Assertions.assertEquals(Week.SUNDAY, week); final int[] intArray = ConstructorUtil.newInstanceIfPossible(int[].class); - Assert.assertArrayEquals(new int[0], intArray); + Assertions.assertArrayEquals(new int[0], intArray); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/reflect/FieldUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/reflect/FieldUtilTest.java index 411127c3f..bb7cb3da1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/reflect/FieldUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/reflect/FieldUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.reflect; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; @@ -10,33 +10,33 @@ public class FieldUtilTest { public void getFieldTest() { // 能够获取到父类字段 final Field privateField = FieldUtil.getField(ReflectUtilTest.TestSubClass.class, "privateField"); - Assert.assertNotNull(privateField); + Assertions.assertNotNull(privateField); } @Test public void getFieldsTest() { // 能够获取到父类字段 final Field[] fields = FieldUtil.getFields(ReflectUtilTest.TestSubClass.class); - Assert.assertEquals(4, fields.length); + Assertions.assertEquals(4, fields.length); } @Test public void setFieldTest() { final ReflectUtilTest.AClass testClass = new ReflectUtilTest.AClass(); FieldUtil.setFieldValue(testClass, "a", "111"); - Assert.assertEquals(111, testClass.getA()); + Assertions.assertEquals(111, testClass.getA()); } @Test public void getDeclaredField() { final Field noField = FieldUtil.getField(ReflectUtilTest.TestSubClass.class, "noField"); - Assert.assertNull(noField); + Assertions.assertNull(noField); // 获取不到父类字段 final Field field = FieldUtil.getDeClearField(ReflectUtilTest.TestSubClass.class, "field"); - Assert.assertNull(field); + Assertions.assertNull(field); final Field subField = FieldUtil.getField(ReflectUtilTest.TestSubClass.class, "subField"); - Assert.assertNotNull(subField); + Assertions.assertNotNull(subField); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/reflect/MethodHandleUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/reflect/MethodHandleUtilTest.java index ea2426a09..4b95accf9 100644 --- a/hutool-core/src/test/java/cn/hutool/core/reflect/MethodHandleUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/reflect/MethodHandleUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.reflect; import cn.hutool.core.classloader.ClassLoaderUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; @@ -18,16 +18,16 @@ public class MethodHandleUtilTest { new Class[] { Duck.class }, MethodHandleUtil::invokeSpecial); - Assert.assertEquals("Quack", duck.quack()); + Assertions.assertEquals("Quack", duck.quack()); // 测试子类执行default方法 final Method quackMethod = MethodUtil.getMethod(Duck.class, "quack"); String quack = MethodHandleUtil.invokeSpecial(new BigDuck(), quackMethod); - Assert.assertEquals("Quack", quack); + Assertions.assertEquals("Quack", quack); // 测试反射执行默认方法 quack = MethodUtil.invoke(new Duck() {}, quackMethod); - Assert.assertEquals("Quack", quack); + Assertions.assertEquals("Quack", quack); } @Test @@ -37,7 +37,7 @@ public class MethodHandleUtilTest { new Class[] { Duck.class }, MethodUtil::invoke); - Assert.assertEquals("Quack", duck.quack()); + Assertions.assertEquals("Quack", duck.quack()); } @Test @@ -47,7 +47,7 @@ public class MethodHandleUtilTest { new Class[] { Duck.class }, MethodUtil::invoke); - Assert.assertEquals("Quack", duck.quack()); + Assertions.assertEquals("Quack", duck.quack()); } @Test @@ -55,7 +55,7 @@ public class MethodHandleUtilTest { // 测试执行普通方法 final int size = MethodHandleUtil.invokeSpecial(new BigDuck(), MethodUtil.getMethod(BigDuck.class, "getSize")); - Assert.assertEquals(36, size); + Assertions.assertEquals(36, size); } @Test @@ -63,45 +63,45 @@ public class MethodHandleUtilTest { // 测试执行普通方法 final String result = MethodHandleUtil.invoke(null, MethodUtil.getMethod(Duck.class, "getDuck", int.class), 78); - Assert.assertEquals("Duck 78", result); + Assertions.assertEquals("Duck 78", result); } @Test public void findMethodTest() throws Throwable { MethodHandle handle = MethodHandleUtil.findMethod(Duck.class, "quack", MethodType.methodType(String.class)); - Assert.assertNotNull(handle); + Assertions.assertNotNull(handle); // 对象方法自行需要绑定对象或者传入对象参数 final String invoke = (String) handle.invoke(new BigDuck()); - Assert.assertEquals("Quack", invoke); + Assertions.assertEquals("Quack", invoke); // 对象的方法获取 handle = MethodHandleUtil.findMethod(BigDuck.class, "getSize", MethodType.methodType(int.class)); - Assert.assertNotNull(handle); + Assertions.assertNotNull(handle); final int invokeInt = (int) handle.invoke(new BigDuck()); - Assert.assertEquals(36, invokeInt); + Assertions.assertEquals(36, invokeInt); } @Test public void findStaticMethodTest() throws Throwable { final MethodHandle handle = MethodHandleUtil.findMethod(Duck.class, "getDuck", MethodType.methodType(String.class, int.class)); - Assert.assertNotNull(handle); + Assertions.assertNotNull(handle); // static 方法执行不需要绑定或者传入对象,直接传入参数即可 final String invoke = (String) handle.invoke(12); - Assert.assertEquals("Duck 12", invoke); + Assertions.assertEquals("Duck 12", invoke); } @Test public void findPrivateMethodTest() throws Throwable { final MethodHandle handle = MethodHandleUtil.findMethod(BigDuck.class, "getPrivateValue", MethodType.methodType(String.class)); - Assert.assertNotNull(handle); + Assertions.assertNotNull(handle); final String invoke = (String) handle.invoke(new BigDuck()); - Assert.assertEquals("private value", invoke); + Assertions.assertEquals("private value", invoke); } @Test @@ -109,20 +109,20 @@ public class MethodHandleUtilTest { // 查找父类的方法 final MethodHandle handle = MethodHandleUtil.findMethod(BigDuck.class, "quack", MethodType.methodType(String.class)); - Assert.assertNotNull(handle); + Assertions.assertNotNull(handle); final String invoke = (String) handle.invoke(new BigDuck()); - Assert.assertEquals("Quack", invoke); + Assertions.assertEquals("Quack", invoke); } @Test public void findPrivateStaticMethodTest() throws Throwable { final MethodHandle handle = MethodHandleUtil.findMethod(BigDuck.class, "getPrivateStaticValue", MethodType.methodType(String.class)); - Assert.assertNotNull(handle); + Assertions.assertNotNull(handle); final String invoke = (String) handle.invoke(); - Assert.assertEquals("private static value", invoke); + Assertions.assertEquals("private static value", invoke); } interface Duck { diff --git a/hutool-core/src/test/java/cn/hutool/core/reflect/MethodUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/reflect/MethodUtilTest.java index 6c8a8a228..cc94beb1c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/reflect/MethodUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/reflect/MethodUtilTest.java @@ -1,15 +1,15 @@ package cn.hutool.core.reflect; +import cn.hutool.core.array.ArrayUtil; import cn.hutool.core.date.StopWatch; import cn.hutool.core.lang.Console; import cn.hutool.core.lang.test.bean.ExamInfoDict; import cn.hutool.core.text.StrUtil; -import cn.hutool.core.array.ArrayUtil; import cn.hutool.core.util.SystemUtil; 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.lang.reflect.Method; @@ -32,70 +32,70 @@ public class MethodUtilTest { @Test public void getMethodsTest() { Method[] methods = MethodUtil.getMethods(ExamInfoDict.class); - Assert.assertEquals(isGteJdk15 ? 19 : 20, methods.length); + Assertions.assertEquals(isGteJdk15 ? 19 : 20, methods.length); //过滤器测试 methods = MethodUtil.getMethods(ExamInfoDict.class, t -> Integer.class.equals(t.getReturnType())); - Assert.assertEquals(4, methods.length); + Assertions.assertEquals(4, methods.length); final Method method = methods[0]; - Assert.assertNotNull(method); + Assertions.assertNotNull(method); //null过滤器测试 methods = MethodUtil.getMethods(ExamInfoDict.class, null); - Assert.assertEquals(isGteJdk15 ? 19 : 20, methods.length); + Assertions.assertEquals(isGteJdk15 ? 19 : 20, methods.length); final Method method2 = methods[0]; - Assert.assertNotNull(method2); + Assertions.assertNotNull(method2); } @Test public void getMethodTest() { Method method = MethodUtil.getMethod(ExamInfoDict.class, "getId"); - Assert.assertEquals("getId", method.getName()); - Assert.assertEquals(0, method.getParameterTypes().length); + Assertions.assertEquals("getId", method.getName()); + Assertions.assertEquals(0, method.getParameterTypes().length); method = MethodUtil.getMethod(ExamInfoDict.class, "getId", Integer.class); - Assert.assertEquals("getId", method.getName()); - Assert.assertEquals(1, method.getParameterTypes().length); + Assertions.assertEquals("getId", method.getName()); + Assertions.assertEquals(1, method.getParameterTypes().length); } @Test public void getMethodIgnoreCaseTest() { Method method = MethodUtil.getMethodIgnoreCase(ExamInfoDict.class, "getId"); - Assert.assertEquals("getId", method.getName()); - Assert.assertEquals(0, method.getParameterTypes().length); + Assertions.assertEquals("getId", method.getName()); + Assertions.assertEquals(0, method.getParameterTypes().length); method = MethodUtil.getMethodIgnoreCase(ExamInfoDict.class, "GetId"); - Assert.assertEquals("getId", method.getName()); - Assert.assertEquals(0, method.getParameterTypes().length); + Assertions.assertEquals("getId", method.getName()); + Assertions.assertEquals(0, method.getParameterTypes().length); method = MethodUtil.getMethodIgnoreCase(ExamInfoDict.class, "setanswerIs", Integer.class); - Assert.assertEquals("setAnswerIs", method.getName()); - Assert.assertEquals(1, method.getParameterTypes().length); + Assertions.assertEquals("setAnswerIs", method.getName()); + Assertions.assertEquals(1, method.getParameterTypes().length); } @Test public void invokeTest() { final ReflectUtilTest.AClass testClass = new ReflectUtilTest.AClass(); MethodUtil.invoke(testClass, "setA", 10); - Assert.assertEquals(10, testClass.getA()); + Assertions.assertEquals(10, testClass.getA()); } @Test public void getDeclaredMethodsTest() { Class type = ReflectUtilTest.TestBenchClass.class; Method[] methods = type.getDeclaredMethods(); - Assert.assertArrayEquals(methods, MethodUtil.getDeclaredMethods(type)); - Assert.assertSame(MethodUtil.getDeclaredMethods(type), MethodUtil.getDeclaredMethods(type)); + Assertions.assertArrayEquals(methods, MethodUtil.getDeclaredMethods(type)); + Assertions.assertSame(MethodUtil.getDeclaredMethods(type), MethodUtil.getDeclaredMethods(type)); type = Object.class; methods = type.getDeclaredMethods(); - Assert.assertArrayEquals(methods, MethodUtil.getDeclaredMethods(type)); + Assertions.assertArrayEquals(methods, MethodUtil.getDeclaredMethods(type)); } @Test - @Ignore + @Disabled public void getMethodBenchTest() { // 预热 getMethodWithReturnTypeCheck(ReflectUtilTest.TestBenchClass.class, false, "getH"); @@ -141,19 +141,19 @@ public class MethodUtilTest { public void getMethodsFromClassExtends() { // 继承情况下,需解决方法去重问题 Method[] methods = MethodUtil.getMethods(ReflectUtilTest.C2.class); - Assert.assertEquals(isGteJdk15 ? 14 : 15, methods.length); + Assertions.assertEquals(isGteJdk15 ? 14 : 15, methods.length); // 排除Object中的方法 // 3个方法包括类 methods = MethodUtil.getMethodsDirectly(ReflectUtilTest.C2.class, true, false); - Assert.assertEquals(3, methods.length); + Assertions.assertEquals(3, methods.length); // getA属于本类 - Assert.assertEquals("public void cn.hutool.core.reflect.ReflectUtilTest$C2.getA()", methods[0].toString()); + Assertions.assertEquals("public void cn.hutool.core.reflect.ReflectUtilTest$C2.getA()", methods[0].toString()); // getB属于父类 - Assert.assertEquals("public void cn.hutool.core.reflect.ReflectUtilTest$C1.getB()", methods[1].toString()); + Assertions.assertEquals("public void cn.hutool.core.reflect.ReflectUtilTest$C1.getB()", methods[1].toString()); // getC属于接口中的默认方法 - Assert.assertEquals("public default void cn.hutool.core.reflect.ReflectUtilTest$TestInterface1.getC()", methods[2].toString()); + Assertions.assertEquals("public default void cn.hutool.core.reflect.ReflectUtilTest$TestInterface1.getC()", methods[2].toString()); } @Test @@ -161,47 +161,47 @@ public class MethodUtilTest { // 对于接口,直接调用Class.getMethods方法获取所有方法,因为接口都是public方法 // 因此此处得到包括TestInterface1、TestInterface2、TestInterface3中一共4个方法 final Method[] methods = MethodUtil.getMethods(ReflectUtilTest.TestInterface3.class); - Assert.assertEquals(4, methods.length); + Assertions.assertEquals(4, methods.length); // 接口里,调用getMethods和getPublicMethods效果相同 final Method[] publicMethods = MethodUtil.getPublicMethods(ReflectUtilTest.TestInterface3.class); - Assert.assertArrayEquals(methods, publicMethods); + Assertions.assertArrayEquals(methods, publicMethods); } @Test public void getPublicMethod() { final Method superPublicMethod = MethodUtil.getPublicMethod(ReflectUtilTest.TestSubClass.class, "publicMethod"); - Assert.assertNotNull(superPublicMethod); + Assertions.assertNotNull(superPublicMethod); final Method superPrivateMethod = MethodUtil.getPublicMethod(ReflectUtilTest.TestSubClass.class, "privateMethod"); - Assert.assertNull(superPrivateMethod); + Assertions.assertNull(superPrivateMethod); final Method publicMethod = MethodUtil.getPublicMethod(ReflectUtilTest.TestSubClass.class, "publicSubMethod"); - Assert.assertNotNull(publicMethod); + Assertions.assertNotNull(publicMethod); final Method privateMethod = MethodUtil.getPublicMethod(ReflectUtilTest.TestSubClass.class, "privateSubMethod"); - Assert.assertNull(privateMethod); + Assertions.assertNull(privateMethod); } @Test public void getDeclaredMethod() { final Method noMethod = MethodUtil.getMethod(ReflectUtilTest.TestSubClass.class, "noMethod"); - Assert.assertNull(noMethod); + Assertions.assertNull(noMethod); final Method privateMethod = MethodUtil.getMethod(ReflectUtilTest.TestSubClass.class, "privateMethod"); - Assert.assertNotNull(privateMethod); + Assertions.assertNotNull(privateMethod); final Method publicMethod = MethodUtil.getMethod(ReflectUtilTest.TestSubClass.class, "publicMethod"); - Assert.assertNotNull(publicMethod); + Assertions.assertNotNull(publicMethod); final Method publicSubMethod = MethodUtil.getMethod(ReflectUtilTest.TestSubClass.class, "publicSubMethod"); - Assert.assertNotNull(publicSubMethod); + Assertions.assertNotNull(publicSubMethod); final Method privateSubMethod = MethodUtil.getMethod(ReflectUtilTest.TestSubClass.class, "privateSubMethod"); - Assert.assertNotNull(privateSubMethod); + Assertions.assertNotNull(privateSubMethod); } @Test public void issue2625Test(){ // 内部类继承的情况下父类方法会被定义为桥接方法,因此按照pr#1965@Github判断返回值的继承关系来代替判断桥接。 final Method getThis = MethodUtil.getMethod(A.C.class, "getThis"); - Assert.assertTrue(getThis.isBridge()); + Assertions.assertTrue(getThis.isBridge()); } @SuppressWarnings("InnerClassMayBeStatic") @@ -228,7 +228,7 @@ public class MethodUtilTest { final TestClass testClass = new TestClass(); final Method method = MethodUtil.getMethod(TestClass.class, "setA", int.class); MethodUtil.invoke(testClass, method, 10); - Assert.assertEquals(10, testClass.getA()); + Assertions.assertEquals(10, testClass.getA()); } @Test @@ -236,14 +236,14 @@ public class MethodUtilTest { final TestClass testClass = new TestClass(); final Method method = MethodUtil.getMethod(TestClass.class, "setA", int.class); MethodUtil.invoke(testClass, method, "10"); - Assert.assertEquals(10, testClass.getA()); + Assertions.assertEquals(10, testClass.getA()); } @Test public void invokeMethodWithParamConvertFailedTest() { final TestClass testClass = new TestClass(); final Method method = MethodUtil.getMethod(TestClass.class, "setA", int.class); - Assert.assertThrows(IllegalArgumentException.class, + Assertions.assertThrows(IllegalArgumentException.class, () -> MethodUtil.invoke(testClass, method, "NaN")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/reflect/ReflectUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/reflect/ReflectUtilTest.java index d60e5379d..51fb89dad 100644 --- a/hutool-core/src/test/java/cn/hutool/core/reflect/ReflectUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/reflect/ReflectUtilTest.java @@ -1,9 +1,9 @@ package cn.hutool.core.reflect; -import cn.hutool.core.lang.Assert; import lombok.Data; import lombok.SneakyThrows; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -80,6 +80,7 @@ public class ReflectUtilTest { } } + @SuppressWarnings("RedundantMethodOverride") class C2 extends C1 { @Override public void getA() { @@ -115,20 +116,20 @@ public class ReflectUtilTest { @SneakyThrows public void testGetDescriptor() { // methods - Assert.equals("()I", ReflectUtil.getDescriptor(Object.class.getMethod("hashCode"))); - Assert.equals("()Ljava/lang/String;", ReflectUtil.getDescriptor(Object.class.getMethod("toString"))); - Assert.equals("(Ljava/lang/Object;)Z", ReflectUtil.getDescriptor(Object.class.getMethod("equals", Object.class))); - Assert.equals("(II)I", ReflectUtil.getDescriptor(Integer.class.getDeclaredMethod("compare", int.class, int.class))); - Assert.equals("([Ljava/lang/Object;)Ljava/util/List;", ReflectUtil.getDescriptor(Arrays.class.getMethod("asList", Object[].class))); - Assert.equals("()V", ReflectUtil.getDescriptor(Object.class.getConstructor())); + Assertions.assertEquals("()I", ReflectUtil.getDescriptor(Object.class.getMethod("hashCode"))); + Assertions.assertEquals("()Ljava/lang/String;", ReflectUtil.getDescriptor(Object.class.getMethod("toString"))); + Assertions.assertEquals("(Ljava/lang/Object;)Z", ReflectUtil.getDescriptor(Object.class.getMethod("equals", Object.class))); + Assertions.assertEquals("(II)I", ReflectUtil.getDescriptor(Integer.class.getDeclaredMethod("compare", int.class, int.class))); + Assertions.assertEquals("([Ljava/lang/Object;)Ljava/util/List;", ReflectUtil.getDescriptor(Arrays.class.getMethod("asList", Object[].class))); + Assertions.assertEquals("()V", ReflectUtil.getDescriptor(Object.class.getConstructor())); // clazz - Assert.equals("Z", ReflectUtil.getDescriptor(boolean.class)); - Assert.equals("Ljava/lang/Boolean;", ReflectUtil.getDescriptor(Boolean.class)); - Assert.equals("[[[D", ReflectUtil.getDescriptor(double[][][].class)); - Assert.equals("I", ReflectUtil.getDescriptor(int.class)); - Assert.equals("Ljava/lang/Integer;", ReflectUtil.getDescriptor(Integer.class)); - Assert.equals("V", ReflectUtil.getDescriptor(void.class)); - Assert.equals("Ljava/lang/Void;", ReflectUtil.getDescriptor(Void.class)); - Assert.equals("Ljava/lang/Object;", ReflectUtil.getDescriptor(Object.class)); + Assertions.assertEquals("Z", ReflectUtil.getDescriptor(boolean.class)); + Assertions.assertEquals("Ljava/lang/Boolean;", ReflectUtil.getDescriptor(Boolean.class)); + Assertions.assertEquals("[[[D", ReflectUtil.getDescriptor(double[][][].class)); + Assertions.assertEquals("I", ReflectUtil.getDescriptor(int.class)); + Assertions.assertEquals("Ljava/lang/Integer;", ReflectUtil.getDescriptor(Integer.class)); + Assertions.assertEquals("V", ReflectUtil.getDescriptor(void.class)); + Assertions.assertEquals("Ljava/lang/Void;", ReflectUtil.getDescriptor(Void.class)); + Assertions.assertEquals("Ljava/lang/Object;", ReflectUtil.getDescriptor(Object.class)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/stream/AbstractEnhancedWrappedStreamTest.java b/hutool-core/src/test/java/cn/hutool/core/stream/AbstractEnhancedWrappedStreamTest.java index 033d35c13..efb24d019 100644 --- a/hutool-core/src/test/java/cn/hutool/core/stream/AbstractEnhancedWrappedStreamTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/stream/AbstractEnhancedWrappedStreamTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.collection.ListUtil; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -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.concurrent.atomic.AtomicBoolean; @@ -27,42 +27,42 @@ public class AbstractEnhancedWrappedStreamTest { public void testToList() { final List list = asList(1, 2, 3); final List toList = wrap(list).toList(); - Assert.assertEquals(list, toList); + Assertions.assertEquals(list, toList); } @Test public void testToUnmodifiableList() { final List list = wrap(1, 2, 3) .toUnmodifiableList(); - Assert.assertThrows(UnsupportedOperationException.class, () -> list.remove(0)); + Assertions.assertThrows(UnsupportedOperationException.class, () -> list.remove(0)); } @Test public void testToSet() { final List list = asList(1, 2, 3); final Set toSet = wrap(list).map(String::valueOf).toSet(); - Assert.assertEquals(new HashSet<>(asList("1", "2", "3")), toSet); + Assertions.assertEquals(new HashSet<>(asList("1", "2", "3")), toSet); } @Test public void testToUnmodifiableSet() { final Set set = wrap(1, 2, 3) .toUnmodifiableSet(); - Assert.assertThrows(UnsupportedOperationException.class, () -> set.remove(0)); + Assertions.assertThrows(UnsupportedOperationException.class, () -> set.remove(0)); } @Test public void testToCollection() { final List list = asList(1, 2, 3); final List toCollection = wrap(list).map(String::valueOf).toColl(LinkedList::new); - Assert.assertEquals(asList("1", "2", "3"), toCollection); + Assertions.assertEquals(asList("1", "2", "3"), toCollection); } @Test public void testToMap() { final List list = asList(1, 2, 3); final Map identityMap = wrap(list).toMap(String::valueOf); - Assert.assertEquals(new HashMap() { + Assertions.assertEquals(new HashMap() { private static final long serialVersionUID = 1L; { @@ -76,9 +76,9 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testToUnmodifiableMap() { final Map map1 = wrap(1, 2, 3).toUnmodifiableMap(Function.identity(), Function.identity()); - Assert.assertThrows(UnsupportedOperationException.class, () -> map1.remove(1)); + Assertions.assertThrows(UnsupportedOperationException.class, () -> map1.remove(1)); final Map map2 = wrap(1, 2, 3).toUnmodifiableMap(Function.identity(), Function.identity(), (t1, t2) -> t1); - Assert.assertThrows(UnsupportedOperationException.class, () -> map2.remove(1)); + Assertions.assertThrows(UnsupportedOperationException.class, () -> map2.remove(1)); } @Test @@ -86,7 +86,7 @@ public class AbstractEnhancedWrappedStreamTest { final List orders = asList(1, 2, 3); final List list = asList("dromara", "hutool", "sweet"); final Map toZip = wrap(orders).toZip(list); - Assert.assertEquals(new HashMap() { + Assertions.assertEquals(new HashMap() { private static final long serialVersionUID = 1L; { @@ -100,53 +100,53 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testFindFirst() { final List list = asList(1, 2, 3); - Assert.assertEquals((Integer) 1, wrap(list).findFirst(t -> (t & 1) == 1).orElse(null)); - Assert.assertEquals((Integer) 1, wrap(list).filter(t -> (t & 1) == 1).findFirst().orElse(null)); + Assertions.assertEquals((Integer) 1, wrap(list).findFirst(t -> (t & 1) == 1).orElse(null)); + Assertions.assertEquals((Integer) 1, wrap(list).filter(t -> (t & 1) == 1).findFirst().orElse(null)); } @Test public void testFindFirstIdx() { final List list = asList(1, 2, 3); - Assert.assertEquals(1, wrap(list).findFirstIdx(t -> (t & 1) == 0)); + Assertions.assertEquals(1, wrap(list).findFirstIdx(t -> (t & 1) == 0)); } @Test public void testFindLast() { final List list = asList(1, 2, 3); - Assert.assertEquals((Integer) 3, wrap(list).findLast(t -> (t & 1) == 1).orElse(null)); + Assertions.assertEquals((Integer) 3, wrap(list).findLast(t -> (t & 1) == 1).orElse(null)); } @Test public void testFindLastIdx() { final List list = asList(1, 2, 3); - Assert.assertEquals(1, wrap(list).findLastIdx(t -> (t & 1) == 0)); + Assertions.assertEquals(1, wrap(list).findLastIdx(t -> (t & 1) == 0)); } @Test public void testAt() { final List list = asList(1, 2, 3); - Assert.assertEquals((Integer) 3, wrap(list).at(2).orElse(null)); + Assertions.assertEquals((Integer) 3, wrap(list).at(2).orElse(null)); } @Test public void testIsEmpty() { - Assert.assertTrue(wrap(Collections.emptyList()).isEmpty()); - Assert.assertFalse(wrap(asList(1, 2, 3)).isEmpty()); + Assertions.assertTrue(wrap(Collections.emptyList()).isEmpty()); + Assertions.assertFalse(wrap(asList(1, 2, 3)).isEmpty()); } @Test public void testIsNotEmpty() { - Assert.assertFalse(wrap(Collections.emptyList()).isNotEmpty()); - Assert.assertTrue(wrap(asList(1, 2, 3)).isNotEmpty()); + Assertions.assertFalse(wrap(Collections.emptyList()).isNotEmpty()); + Assertions.assertTrue(wrap(asList(1, 2, 3)).isNotEmpty()); } @Test public void testJoining() { final List list = asList(1, 2, 3); final String joining = wrap(list).join(); - Assert.assertEquals("123", joining); - Assert.assertEquals("1,2,3", wrap(list).join(",")); - Assert.assertEquals("(1,2,3)", wrap(list).join(",", "(", ")")); + Assertions.assertEquals("123", joining); + Assertions.assertEquals("1,2,3", wrap(list).join(",")); + Assertions.assertEquals("(1,2,3)", wrap(list).join(",", "(", ")")); } @Test @@ -163,11 +163,11 @@ public class AbstractEnhancedWrappedStreamTest { }; Map> group = wrap(list).group(String::valueOf, HashMap::new, Collectors.toList()); - Assert.assertEquals(map, group); + Assertions.assertEquals(map, group); group = wrap(list).group(String::valueOf, Collectors.toList()); - Assert.assertEquals(map, group); + Assertions.assertEquals(map, group); group = wrap(list).group(String::valueOf); - Assert.assertEquals(map, group); + Assertions.assertEquals(map, group); } @Test @@ -183,9 +183,9 @@ public class AbstractEnhancedWrappedStreamTest { }; Map> partition = wrap(list).partition(t -> (t & 1) == 0, Collectors.toList()); - Assert.assertEquals(map, partition); + Assertions.assertEquals(map, partition); partition = wrap(list).partition(t -> (t & 1) == 0); - Assert.assertEquals(map, partition); + Assertions.assertEquals(map, partition); } @Test @@ -196,8 +196,8 @@ public class AbstractEnhancedWrappedStreamTest { elements.add(t); indexes.add(i); }); - Assert.assertEquals(asList(1, 2, 3), elements); - Assert.assertEquals(asList(0, 1, 2), indexes); + Assertions.assertEquals(asList(1, 2, 3), elements); + Assertions.assertEquals(asList(0, 1, 2), indexes); } @Test @@ -208,75 +208,75 @@ public class AbstractEnhancedWrappedStreamTest { elements.add(t); indexes.add(i); }); - Assert.assertEquals(asList(1, 2, 3), elements); - Assert.assertEquals(asList(0, 1, 2), indexes); + Assertions.assertEquals(asList(1, 2, 3), elements); + Assertions.assertEquals(asList(0, 1, 2), indexes); } @Test public void testForEachOrdered() { final List elements = new ArrayList<>(); wrap(1, 2, 3).forEachOrdered(elements::add); - Assert.assertEquals(asList(1, 2, 3), elements); + Assertions.assertEquals(asList(1, 2, 3), elements); } @Test public void testForEach() { final List elements = new ArrayList<>(); wrap(1, 2, 3).forEach(elements::add); - Assert.assertEquals(asList(1, 2, 3), elements); + Assertions.assertEquals(asList(1, 2, 3), elements); } @Test public void testMapToInt() { final int[] array = wrap(1, 2, 3).mapToInt(Integer::intValue).toArray(); - Assert.assertArrayEquals(new int[]{1, 2, 3}, array); + Assertions.assertArrayEquals(new int[]{1, 2, 3}, array); } @Test public void testMapToLong() { final long[] array = wrap(1L, 2L, 3L).mapToLong(Long::intValue).toArray(); - Assert.assertArrayEquals(new long[]{1L, 2L, 3L}, array); + Assertions.assertArrayEquals(new long[]{1L, 2L, 3L}, array); } @Test public void testMapToDouble() { final double[] array = wrap(1d, 2d, 3d).mapToDouble(Double::intValue).toArray(); - Assert.assertEquals(1d, array[0], 0); - Assert.assertEquals(2d, array[1], 0); - Assert.assertEquals(3d, array[2], 0); + Assertions.assertEquals(1d, array[0], 0); + Assertions.assertEquals(2d, array[1], 0); + Assertions.assertEquals(3d, array[2], 0); } @Test public void testFlatMapToInt() { final int[] array = wrap(1, 2, 3).flatMapToInt(IntStream::of).toArray(); - Assert.assertArrayEquals(new int[]{1, 2, 3}, array); + Assertions.assertArrayEquals(new int[]{1, 2, 3}, array); } @Test public void testFlatMapToLong() { final long[] array = wrap(1L, 2L, 3L).flatMapToLong(LongStream::of).toArray(); - Assert.assertArrayEquals(new long[]{1L, 2L, 3L}, array); + Assertions.assertArrayEquals(new long[]{1L, 2L, 3L}, array); } @Test public void testFlatMapToDouble() { final double[] array = wrap(1d, 2d, 3d).flatMapToDouble(DoubleStream::of).toArray(); - Assert.assertEquals(1d, array[0], 0); - Assert.assertEquals(2d, array[1], 0); - Assert.assertEquals(3d, array[2], 0); + Assertions.assertEquals(1d, array[0], 0); + Assertions.assertEquals(2d, array[1], 0); + Assertions.assertEquals(3d, array[2], 0); } @Test public void testSorted() { final List list = wrap(3, 1, 2).sorted().toList(); - Assert.assertEquals(asList(1, 2, 3), list); + Assertions.assertEquals(asList(1, 2, 3), list); } @Test public void testPeek() { final List elements = new ArrayList<>(); wrap(1, 2, 3).peek(elements::add).exec(); - Assert.assertEquals(asList(1, 2, 3), elements); + Assertions.assertEquals(asList(1, 2, 3), elements); } @Test @@ -287,44 +287,44 @@ public class AbstractEnhancedWrappedStreamTest { elements.add(t); indexes.add(i); }).exec(); - Assert.assertEquals(asList(1, 2, 3), elements); - Assert.assertEquals(asList(0, 1, 2), indexes); + Assertions.assertEquals(asList(1, 2, 3), elements); + Assertions.assertEquals(asList(0, 1, 2), indexes); wrap("one", "two", "three", "four").parallel().filter(e -> e.length() == 4) - .peekIdx((e, i) -> Assert.assertEquals("four:0", e + ":" + i)).exec(); + .peekIdx((e, i) -> Assertions.assertEquals("four:0", e + ":" + i)).exec(); } @Test public void testLimit() { final List list = wrap(1, 2, 3).limit(2L).toList(); - Assert.assertEquals(asList(1, 2), list); + Assertions.assertEquals(asList(1, 2), list); } @Test public void testSkip() { final List list = wrap(1, 2, 3).skip(1L).toList(); - Assert.assertEquals(asList(2, 3), list); + Assertions.assertEquals(asList(2, 3), list); } @Test public void testToArray() { Object[] array1 = wrap(1, 2, 3).toArray(); - Assert.assertArrayEquals(new Object[]{1, 2, 3}, array1); + Assertions.assertArrayEquals(new Object[]{1, 2, 3}, array1); array1 = wrap(1, 2, 3).toArray(Object[]::new); - Assert.assertArrayEquals(new Object[]{1, 2, 3}, array1); + Assertions.assertArrayEquals(new Object[]{1, 2, 3}, array1); } @Test public void testReduce() { - Assert.assertEquals((Integer) 6, wrap(1, 2, 3).reduce(Integer::sum).orElse(null)); - Assert.assertEquals((Integer) 6, wrap(1, 2, 3).reduce(0, Integer::sum)); - Assert.assertEquals((Integer) 6, wrap(1, 2, 3).reduce(0, Integer::sum, Integer::sum)); + Assertions.assertEquals((Integer) 6, wrap(1, 2, 3).reduce(Integer::sum).orElse(null)); + Assertions.assertEquals((Integer) 6, wrap(1, 2, 3).reduce(0, Integer::sum)); + Assertions.assertEquals((Integer) 6, wrap(1, 2, 3).reduce(0, Integer::sum, Integer::sum)); } @Test public void testCollect() { - Assert.assertEquals(asList(1, 2, 3), wrap(1, 2, 3).collect(Collectors.toList())); - Assert.assertEquals( + Assertions.assertEquals(asList(1, 2, 3), wrap(1, 2, 3).collect(Collectors.toList())); + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 2, 3).collect(ArrayList::new, List::add, List::addAll) ); @@ -332,40 +332,40 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testMin() { - Assert.assertEquals((Integer) 1, wrap(1, 2, 3).min(Comparator.comparingInt(Integer::intValue)).orElse(null)); + Assertions.assertEquals((Integer) 1, wrap(1, 2, 3).min(Comparator.comparingInt(Integer::intValue)).orElse(null)); } @Test public void testMax() { - Assert.assertEquals((Integer) 3, wrap(1, 2, 3).max(Comparator.comparingInt(Integer::intValue)).orElse(null)); + Assertions.assertEquals((Integer) 3, wrap(1, 2, 3).max(Comparator.comparingInt(Integer::intValue)).orElse(null)); } @Test public void testCount() { - Assert.assertEquals(3, wrap(1, 2, 3).count()); + Assertions.assertEquals(3, wrap(1, 2, 3).count()); } @Test public void testAnyMatch() { - Assert.assertTrue(wrap(1, 2, 3).anyMatch(t -> (t & 1) == 0)); - Assert.assertFalse(wrap(1, 3).anyMatch(t -> (t & 1) == 0)); + Assertions.assertTrue(wrap(1, 2, 3).anyMatch(t -> (t & 1) == 0)); + Assertions.assertFalse(wrap(1, 3).anyMatch(t -> (t & 1) == 0)); } @Test public void testAllMatch() { - Assert.assertFalse(wrap(1, 2, 3).allMatch(t -> (t & 1) == 0)); - Assert.assertTrue(wrap(2, 4).anyMatch(t -> (t & 1) == 0)); + Assertions.assertFalse(wrap(1, 2, 3).allMatch(t -> (t & 1) == 0)); + Assertions.assertTrue(wrap(2, 4).anyMatch(t -> (t & 1) == 0)); } @Test public void testNoneMatch() { - Assert.assertFalse(wrap(1, 2, 3).noneMatch(t -> (t & 1) == 0)); - Assert.assertTrue(wrap(1, 3).noneMatch(t -> (t & 1) == 0)); + Assertions.assertFalse(wrap(1, 2, 3).noneMatch(t -> (t & 1) == 0)); + Assertions.assertTrue(wrap(1, 3).noneMatch(t -> (t & 1) == 0)); } @Test public void testFindAny() { - Assert.assertNotNull(wrap(1, 2, 3).findAny()); + Assertions.assertNotNull(wrap(1, 2, 3).findAny()); } @Test @@ -373,7 +373,7 @@ public class AbstractEnhancedWrappedStreamTest { final Iterator iter1 = Stream.of(1, 2, 3).iterator(); final Iterator iter2 = wrap(1, 2, 3).iterator(); while (iter1.hasNext() && iter2.hasNext()) { - Assert.assertEquals(iter1.next(), iter2.next()); + Assertions.assertEquals(iter1.next(), iter2.next()); } } @@ -381,60 +381,60 @@ public class AbstractEnhancedWrappedStreamTest { public void testSpliterator() { final Spliterator iter1 = Stream.of(1, 2, 3).spliterator(); final Spliterator iter2 = wrap(1, 2, 3).spliterator(); - Assert.assertEquals(iter1.trySplit().estimateSize(), iter2.trySplit().estimateSize()); + Assertions.assertEquals(iter1.trySplit().estimateSize(), iter2.trySplit().estimateSize()); } @Test public void testIsParallel() { - Assert.assertTrue(wrap(Stream.of(1, 2, 3).parallel()).isParallel()); + Assertions.assertTrue(wrap(Stream.of(1, 2, 3).parallel()).isParallel()); } @Test public void testSequential() { - Assert.assertFalse(wrap(Stream.of(1, 2, 3).parallel()).sequential().isParallel()); + Assertions.assertFalse(wrap(Stream.of(1, 2, 3).parallel()).sequential().isParallel()); } @Test public void testUnordered() { - Assert.assertNotNull(wrap(Stream.of(1, 2, 3)).unordered()); + Assertions.assertNotNull(wrap(Stream.of(1, 2, 3)).unordered()); } @Test public void testOnClose() { final AtomicBoolean atomicBoolean = new AtomicBoolean(false); wrap(Stream.of(1, 2, 3).onClose(() -> atomicBoolean.set(true))).close(); - Assert.assertTrue(atomicBoolean.get()); + Assertions.assertTrue(atomicBoolean.get()); } @Test public void testClose() { final Wrapper stream = wrap(Stream.of(1, 2, 3)); stream.close(); - Assert.assertThrows(IllegalStateException.class, stream::exec); + Assertions.assertThrows(IllegalStateException.class, stream::exec); } @Test public void testReverse() { - Assert.assertEquals( + Assertions.assertEquals( asList(3, 2, 1), wrap(1, 2, 3).reverse().toList() ); } @Test public void testParallel() { - Assert.assertTrue(wrap(1, 2, 3).parallel().isParallel()); + Assertions.assertTrue(wrap(1, 2, 3).parallel().isParallel()); } @Test public void testSplice() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 4, 5), wrap(1, 2, 3).splice(1, 2, 4, 5).toList() ); } @Test public void testTakeWhile() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2), wrap(1, 2, 3, 4).takeWhile(i -> !Objects.equals(i, 3)).toList() ); @@ -443,7 +443,7 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testDropWhile() { - Assert.assertEquals( + Assertions.assertEquals( asList(3, 4), wrap(1, 2, 3, 4).dropWhile(i -> !Objects.equals(i, 3)).toList() ); @@ -451,53 +451,53 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testDistinct() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 1, 2, 3).distinct().toList() ); } @Test public void testLog() { - Assert.assertNotNull(wrap(1, 2, 3).log().toList()); + Assertions.assertNotNull(wrap(1, 2, 3).log().toList()); } @Test public void testPush() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1).push(2, 3).toList() ); } @Test public void testUnshift() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(3).unshift(1, 2).toList() ); } @Test public void testAppend() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1).append(asList(2, 3)).toList() ); - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 2, 3).append(null).toList() ); } @Test public void testPrepend() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(3).prepend(asList(1, 2)).toList() ); - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 2, 3).prepend(null).toList() ); } @Test public void testNonNull() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 3), wrap(1, null, 3).nonNull().toList() ); } @@ -505,26 +505,26 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testFilterIdx() { final List indexes = new ArrayList<>(); - Assert.assertEquals( + Assertions.assertEquals( asList(1, 3), wrap(1, 2, 3).filterIdx((t, i) -> { indexes.add(i); return (t & 1) == 1; }).toList() ); - Assert.assertEquals(asList(0, 1, 2), indexes); + Assertions.assertEquals(asList(0, 1, 2), indexes); } @Test public void testFilter() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 3), wrap(1, 2, 3).filter(i -> (i & 1) == 1).toList() ); } @Test public void testFlatMap() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 2, 3).flatMap(Stream::of).toList() ); } @@ -532,25 +532,25 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testFlatMapIdx() { final List indexes = new ArrayList<>(); - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 2, 3).flatMapIdx((t, i) -> { indexes.add(i); return Stream.of(t); }).toList() ); - Assert.assertEquals(asList(0, 1, 2), indexes); + Assertions.assertEquals(asList(0, 1, 2), indexes); } @Test public void testFlat() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 2, 3).flat(Collections::singletonList).toList() ); } @Test public void testFlatNonNull() { - Assert.assertEquals( + Assertions.assertEquals( asList(2, 3), wrap(null, 2, 3).flatNonNull(Collections::singletonList).toList() ); } @@ -558,19 +558,19 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testFlatTree() { final Tree root = new Tree(1, ListUtil.of(new Tree(2, ListUtil.of(new Tree(3, Collections.emptyList()))))); - Assert.assertEquals(3L, wrap(root).flatTree(Tree::getChildren, Tree::setChildren).count()); + Assertions.assertEquals(3L, wrap(root).flatTree(Tree::getChildren, Tree::setChildren).count()); } @Test public void testMap() { - Assert.assertEquals( + Assertions.assertEquals( asList("1", "2", "3"), wrap(1, 2, 3).map(String::valueOf).toList() ); } @Test public void testMapNonNull() { - Assert.assertEquals( + Assertions.assertEquals( ListUtil.of("3"), wrap(null, 2, 3, 4).mapNonNull(t -> ((t & 1) == 0) ? null : String.valueOf(t)).toList() ); } @@ -578,18 +578,18 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testMapIdx() { final List indexes = new ArrayList<>(); - Assert.assertEquals( + Assertions.assertEquals( asList("1", "2", "3"), wrap(1, 2, 3).mapIdx((t, i) -> { indexes.add(i); return String.valueOf(t); }).toList() ); - Assert.assertEquals(asList(0, 1, 2), indexes); + Assertions.assertEquals(asList(0, 1, 2), indexes); } @Test public void testMapMulti() { - Assert.assertEquals( + Assertions.assertEquals( asList(1, 2, 3), wrap(1, 2, 3).mapMulti((t, builder) -> builder.accept(t)).toList() ); @@ -598,19 +598,19 @@ public class AbstractEnhancedWrappedStreamTest { @Test public void testHashCode() { final Stream stream = Stream.of(1, 2, 3); - Assert.assertEquals(stream.hashCode(), wrap(stream).hashCode()); + Assertions.assertEquals(stream.hashCode(), wrap(stream).hashCode()); } @Test public void testEquals() { final Stream stream = Stream.of(1, 2, 3); - Assert.assertEquals(wrap(stream), stream); + Assertions.assertEquals(wrap(stream), stream); } @Test public void testToString() { final Stream stream = Stream.of(1, 2, 3); - Assert.assertEquals(stream.toString(), wrap(stream).toString()); + Assertions.assertEquals(stream.toString(), wrap(stream).toString()); } @Test @@ -627,12 +627,12 @@ public class AbstractEnhancedWrappedStreamTest { Map map = EasyStream.of(1, 2, 3) .toEntries(Function.identity(), Function.identity()) .toMap(); - Assert.assertEquals(expect, map); + Assertions.assertEquals(expect, map); map = EasyStream.of(1, 2, 3) .toEntries(Function.identity()) .toMap(); - Assert.assertEquals(expect, map); + Assertions.assertEquals(expect, map); } @Test @@ -640,32 +640,32 @@ public class AbstractEnhancedWrappedStreamTest { final List orders = Arrays.asList(1, 2, 3); final List list = Arrays.asList("dromara", "hutool", "sweet"); List zip = wrap(orders).zip(list, (e1, e2) -> e1 + "." + e2).toList(); - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip); + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip); zip = this.wrap((Stream) EasyStream.iterate(1, i -> i + 1)).limit(10).zip(list, (e1, e2) -> e1 + "." + e2).toList(); - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip); + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip); } @Test public void testListSplit() { final List list = Arrays.asList(1, 2, 3, 4, 5); List> lists = wrap(list).split(2).map(TerminableWrappedStream::toList).toList(); - Assert.assertEquals(ListUtil.partition(list, 2), lists); + Assertions.assertEquals(ListUtil.partition(list, 2), lists); // 指定长度 大于等于 列表长度 lists = wrap(list).split(list.size()).map(TerminableWrappedStream::toList).toList(); - Assert.assertEquals(singletonList(list), lists); + Assertions.assertEquals(singletonList(list), lists); } @Test public void testSplitList() { final List list = Arrays.asList(1, 2, 3, 4, 5); List> lists = wrap(list).splitList(2).toList(); - Assert.assertEquals(ListUtil.partition(list, 2), lists); + Assertions.assertEquals(ListUtil.partition(list, 2), lists); // 指定长度 大于等于 列表长度 lists = wrap(list).splitList(list.size()).toList(); - Assert.assertEquals(singletonList(list), lists); + Assertions.assertEquals(singletonList(list), lists); } @SafeVarargs diff --git a/hutool-core/src/test/java/cn/hutool/core/stream/CollectorUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/stream/CollectorUtilTest.java index 7605a653e..d6baee33f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/stream/CollectorUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/stream/CollectorUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.stream; import cn.hutool.core.map.MapUtil; -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.function.Function; @@ -29,7 +29,7 @@ public class CollectorUtilTest { // 执行聚合 final Map> nameScoresMap = nameScoreMapList.stream().collect(CollectorUtil.reduceListMap()); - Assert.assertEquals(MapUtil.builder("苏格拉底", Arrays.asList(1, 2)) + Assertions.assertEquals(MapUtil.builder("苏格拉底", Arrays.asList(1, 2)) .put("特拉叙马霍斯", Arrays.asList(3, 1, 2)).build(), nameScoresMap); } @@ -38,18 +38,18 @@ public class CollectorUtilTest { public void testTransform() { Stream stream = Stream.of(1, 2, 3, 4) .collect(CollectorUtil.transform(EasyStream::of)); - Assert.assertEquals(EasyStream.class, stream.getClass()); + Assertions.assertEquals(EasyStream.class, stream.getClass()); stream = Stream.of(1, 2, 3, 4) .collect(CollectorUtil.transform(HashSet::new, EasyStream::of)); - Assert.assertEquals(EasyStream.class, stream.getClass()); + Assertions.assertEquals(EasyStream.class, stream.getClass()); } @Test public void testToEasyStream() { final Stream stream = Stream.of(1, 2, 3, 4) .collect(CollectorUtil.toEasyStream()); - Assert.assertEquals(EasyStream.class, stream.getClass()); + Assertions.assertEquals(EasyStream.class, stream.getClass()); } @Test @@ -61,9 +61,9 @@ public class CollectorUtilTest { .filterByKey(k -> (k & 1) == 1) .inverse() .toMap(); - Assert.assertEquals((Integer) 1, map.get("1")); - Assert.assertEquals((Integer) 3, map.get("3")); - Assert.assertEquals((Integer) 5, map.get("5")); + Assertions.assertEquals((Integer) 1, map.get("1")); + Assertions.assertEquals((Integer) 3, map.get("3")); + Assertions.assertEquals((Integer) 5, map.get("5")); } @Test @@ -72,7 +72,7 @@ public class CollectorUtilTest { .collect(Collectors.groupingBy(Function.identity(), CollectorUtil.filtering(i -> i > 1, Collectors.counting()) )); - Assert.assertEquals(MapUtil.builder() + Assertions.assertEquals(MapUtil.builder() .put(1, 0L) .put(2, 1L) .put(3, 1L) @@ -85,20 +85,20 @@ public class CollectorUtilTest { Map> map = list.stream() .collect(CollectorUtil.groupingBy(t -> (t & 1) == 0, String::valueOf, LinkedHashSet::new, LinkedHashMap::new)); - Assert.assertEquals(LinkedHashMap.class, map.getClass()); - Assert.assertEquals(new LinkedHashSet<>(Arrays.asList("2", "4")), map.get(Boolean.TRUE)); - Assert.assertEquals(new LinkedHashSet<>(Arrays.asList("1", "3")), map.get(Boolean.FALSE)); + Assertions.assertEquals(LinkedHashMap.class, map.getClass()); + Assertions.assertEquals(new LinkedHashSet<>(Arrays.asList("2", "4")), map.get(Boolean.TRUE)); + Assertions.assertEquals(new LinkedHashSet<>(Arrays.asList("1", "3")), map.get(Boolean.FALSE)); map = list.stream() .collect(CollectorUtil.groupingBy(t -> (t & 1) == 0, String::valueOf, LinkedHashSet::new)); - Assert.assertEquals(HashMap.class, map.getClass()); - Assert.assertEquals(new LinkedHashSet<>(Arrays.asList("2", "4")), map.get(Boolean.TRUE)); - Assert.assertEquals(new LinkedHashSet<>(Arrays.asList("1", "3")), map.get(Boolean.FALSE)); + Assertions.assertEquals(HashMap.class, map.getClass()); + Assertions.assertEquals(new LinkedHashSet<>(Arrays.asList("2", "4")), map.get(Boolean.TRUE)); + Assertions.assertEquals(new LinkedHashSet<>(Arrays.asList("1", "3")), map.get(Boolean.FALSE)); Map> map2 = list.stream() .collect(CollectorUtil.groupingBy(t -> (t & 1) == 0, String::valueOf)); - Assert.assertEquals(Arrays.asList("2", "2", "4"), map2.get(Boolean.TRUE)); - Assert.assertEquals(Arrays.asList("1", "1", "3"), map2.get(Boolean.FALSE)); + Assertions.assertEquals(Arrays.asList("2", "2", "4"), map2.get(Boolean.TRUE)); + Assertions.assertEquals(Arrays.asList("1", "1", "3"), map2.get(Boolean.FALSE)); } diff --git a/hutool-core/src/test/java/cn/hutool/core/stream/EasyStreamTest.java b/hutool-core/src/test/java/cn/hutool/core/stream/EasyStreamTest.java index ee92c4d17..21cf35467 100644 --- a/hutool-core/src/test/java/cn/hutool/core/stream/EasyStreamTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/stream/EasyStreamTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.collection.ListUtil; import cn.hutool.core.lang.Opt; import cn.hutool.core.map.MapUtil; import cn.hutool.core.math.NumberUtil; -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.math.RoundingMode; @@ -37,59 +37,59 @@ public class EasyStreamTest { public void testConcat() { final Stream stream1 = Stream.of(1, 2); final Stream stream2 = Stream.of(3, 4); - Assert.assertEquals(4, EasyStream.concat(stream1, stream2).count()); + Assertions.assertEquals(4, EasyStream.concat(stream1, stream2).count()); } @Test public void testBuilder() { final List list = EasyStream.builder().add(1).add(2).add(3).build().toList(); - Assert.assertEquals(Arrays.asList(1, 2, 3), list); + Assertions.assertEquals(Arrays.asList(1, 2, 3), list); } @Test public void testGenerate() { final List list = EasyStream.generate(() -> 0).limit(3).toList(); - Assert.assertEquals(Arrays.asList(0, 0, 0), list); + Assertions.assertEquals(Arrays.asList(0, 0, 0), list); } @Test public void testOf() { - Assert.assertEquals(3, EasyStream.of(Arrays.asList(1, 2, 3), true).count()); - Assert.assertEquals(3, EasyStream.of(1, 2, 3).count()); - Assert.assertEquals(3, EasyStream.of(Stream.builder().add(1).add(2).add(3).build()).count()); + Assertions.assertEquals(3, EasyStream.of(Arrays.asList(1, 2, 3), true).count()); + Assertions.assertEquals(3, EasyStream.of(1, 2, 3).count()); + Assertions.assertEquals(3, EasyStream.of(Stream.builder().add(1).add(2).add(3).build()).count()); } @Test public void testSplit() { final List list = EasyStream.split("1,2,3", ",").map(Integer::valueOf).toList(); - Assert.assertEquals(Arrays.asList(1, 2, 3), list); + Assertions.assertEquals(Arrays.asList(1, 2, 3), list); } @Test public void testIterator() { final List list = EasyStream.iterate(0, i -> i < 3, i -> ++i).toList(); - Assert.assertEquals(Arrays.asList(0, 1, 2), list); + Assertions.assertEquals(Arrays.asList(0, 1, 2), list); } @Test public void testToColl() { final List list = Arrays.asList(1, 2, 3); final List toCollection = EasyStream.of(list).map(String::valueOf).toColl(LinkedList::new); - Assert.assertEquals(Arrays.asList("1", "2", "3"), toCollection); + Assertions.assertEquals(Arrays.asList("1", "2", "3"), toCollection); } @Test public void testToList() { final List list = Arrays.asList(1, 2, 3); final List toList = EasyStream.of(list).map(String::valueOf).toList(); - Assert.assertEquals(Arrays.asList("1", "2", "3"), toList); + Assertions.assertEquals(Arrays.asList("1", "2", "3"), toList); } @Test public void testToSet() { final List list = Arrays.asList(1, 2, 3); final Set toSet = EasyStream.of(list).map(String::valueOf).toSet(); - Assert.assertEquals(new HashSet<>(Arrays.asList("1", "2", "3")), toSet); + Assertions.assertEquals(new HashSet<>(Arrays.asList("1", "2", "3")), toSet); } @Test @@ -103,26 +103,26 @@ public class EasyStreamTest { .build(); final Map toZip = EasyStream.of(orders).toZip(list); - Assert.assertEquals(map, toZip); + Assertions.assertEquals(map, toZip); final Map toZipParallel = EasyStream.of(orders).parallel().nonNull().toZip(list); - Assert.assertEquals(map, toZipParallel); + Assertions.assertEquals(map, toZipParallel); } @Test public void testJoin() { final List list = Arrays.asList(1, 2, 3); final String joining = EasyStream.of(list).join(); - Assert.assertEquals("123", joining); - Assert.assertEquals("1,2,3", EasyStream.of(list).join(",")); - Assert.assertEquals("(1,2,3)", EasyStream.of(list).join(",", "(", ")")); + Assertions.assertEquals("123", joining); + Assertions.assertEquals("1,2,3", EasyStream.of(list).join(",")); + Assertions.assertEquals("(1,2,3)", EasyStream.of(list).join(",", "(", ")")); } @Test public void testToMap() { final List list = Arrays.asList(1, 2, 3); final Map identityMap = EasyStream.of(list).toMap(String::valueOf); - Assert.assertEquals(new HashMap() { + Assertions.assertEquals(new HashMap() { private static final long serialVersionUID = 1L; { @@ -137,7 +137,7 @@ public class EasyStreamTest { public void testGroup() { final List list = Arrays.asList(1, 2, 3); final Map> group = EasyStream.of(list).group(String::valueOf); - Assert.assertEquals( + Assertions.assertEquals( new HashMap>() { private static final long serialVersionUID = 1L; @@ -153,9 +153,9 @@ public class EasyStreamTest { public void testMapIdx() { final List list = Arrays.asList("dromara", "hutool", "sweet"); final List mapIndex = EasyStream.of(list).mapIdx((e, i) -> i + 1 + "." + e).toList(); - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), mapIndex); + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), mapIndex); // 并行流时正常 - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), EasyStream.of("dromara", "hutool", "sweet").parallel().mapIdx((e, i) -> i + 1 + "." + e).toList()); } @@ -167,14 +167,14 @@ public class EasyStreamTest { buffer.accept(e); } }).toList(); - Assert.assertEquals(Arrays.asList(1, 2, 2, 3, 3, 3), mapMulti); + Assertions.assertEquals(Arrays.asList(1, 2, 2, 3, 3, 3), mapMulti); } @Test public void testMapNonNull() { final List list = Arrays.asList(1, 2, 3, null); final List mapNonNull = EasyStream.of(list).mapNonNull(String::valueOf).toList(); - Assert.assertEquals(Arrays.asList("1", "2", "3"), mapNonNull); + Assertions.assertEquals(Arrays.asList("1", "2", "3"), mapNonNull); } @Test @@ -191,12 +191,12 @@ public class EasyStreamTest { final List distinctBy1 = EasyStream.of(list).distinct().toList(); final List distinctBy2 = EasyStream.of(list).parallel().distinct(String::valueOf).toList(); - Assert.assertEquals(collect1, distinctBy1); + Assertions.assertEquals(collect1, distinctBy1); // 并行流测试 - Assert.assertEquals(ListUtil.sort(collect2), ListUtil.sort(distinctBy2)); + Assertions.assertEquals(ListUtil.sort(collect2), ListUtil.sort(distinctBy2)); - Assert.assertEquals( + Assertions.assertEquals( 4, EasyStream.of(1, 2, 2, null, 3, null).parallel(true) .distinct(t -> Objects.isNull(t) ? null : t.toString()).sequential().count() ); @@ -207,11 +207,11 @@ public class EasyStreamTest { final List list = Arrays.asList("dromara", "hutool", "sweet"); final EasyStream.Builder builder = EasyStream.builder(); EasyStream.of(list).forEachIdx((e, i) -> builder.accept(i + 1 + "." + e)); - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), builder.build().toList()); + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), builder.build().toList()); // 并行流时正常 final AtomicInteger total = new AtomicInteger(0); EasyStream.of("dromara", "hutool", "sweet").parallel().forEachIdx((e, i) -> total.addAndGet(i)); - Assert.assertEquals(3, total.get()); + Assertions.assertEquals(3, total.get()); } @Test @@ -219,11 +219,11 @@ public class EasyStreamTest { final List list = Arrays.asList("dromara", "hutool", "sweet"); final EasyStream.Builder builder = EasyStream.builder(); EasyStream.of(list).forEachOrderedIdx((e, i) -> builder.accept(i + 1 + "." + e)); - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), builder.build().toList()); + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), builder.build().toList()); final EasyStream.Builder streamBuilder = EasyStream.builder(); EasyStream.of(list).parallel().forEachOrderedIdx((e, i) -> streamBuilder.accept(i + 1 + "." + e)); - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), streamBuilder.build().toList()); + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), streamBuilder.build().toList()); } @@ -231,9 +231,9 @@ public class EasyStreamTest { public void testFlatMapIdx() { final List list = Arrays.asList("dromara", "hutool", "sweet"); final List mapIndex = EasyStream.of(list).flatMapIdx((e, i) -> EasyStream.of(i + 1 + "." + e)).toList(); - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), mapIndex); + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), mapIndex); // 并行流时正常 - Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), + Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), EasyStream.of("dromara", "hutool", "sweet").parallel() .flatMapIdx((e, i) -> EasyStream.of(i + 1 + "." + e)).toList()); } @@ -242,9 +242,9 @@ public class EasyStreamTest { public void testPeek() { EasyStream.of("one", "two", "three", "four") .filter(e -> e.length() == 4) - .peek(e -> Assert.assertEquals("four", e)) + .peek(e -> Assertions.assertEquals("four", e)) .map(String::toUpperCase) - .peek(e -> Assert.assertEquals("FOUR", e)) + .peek(e -> Assertions.assertEquals("FOUR", e)) .collect(Collectors.toList()); } @@ -252,9 +252,9 @@ public class EasyStreamTest { public void testPeekIdx() { EasyStream.of("one", "two", "three", "four") .filter(e -> e.length() == 4) - .peekIdx((e, i) -> Assert.assertEquals("four:0", e + ":" + i)) + .peekIdx((e, i) -> Assertions.assertEquals("four:0", e + ":" + i)) .map(String::toUpperCase) - .peekIdx((e, i) -> Assert.assertEquals("FOUR:0", e + ":" + i)) + .peekIdx((e, i) -> Assertions.assertEquals("FOUR:0", e + ":" + i)) .collect(Collectors.toList()); } @@ -264,33 +264,33 @@ public class EasyStreamTest { // 一个元素 扩散为 多个元素(迭代器) List flat = EasyStream.of(list).flat(e -> Arrays.asList(e, e * 10)).toList(); - Assert.assertEquals(ListUtil.of(1, 10, 2, 20, 3, 30), flat); + Assertions.assertEquals(ListUtil.of(1, 10, 2, 20, 3, 30), flat); // 过滤迭代器为null的元素 flat = EasyStream.of(list).flat(e -> null).toList(); - Assert.assertEquals(Collections.emptyList(), flat); + Assertions.assertEquals(Collections.emptyList(), flat); // 自动过滤null元素 flat = EasyStream.of(list).flat(e -> Arrays.asList(e, e > 2 ? e : null)).toList(); - Assert.assertEquals(ListUtil.of(1, null, 2, null, 3, 3), flat); + Assertions.assertEquals(ListUtil.of(1, null, 2, null, 3, 3), flat); // 不报npe测试 - Assert.assertTrue(EasyStream.of(list).flat(e -> null).isEmpty()); + Assertions.assertTrue(EasyStream.of(list).flat(e -> null).isEmpty()); } @Test public void testFilter() { final List list = Arrays.asList(1, 2, 3); final List filterIndex = EasyStream.of(list).filter(String::valueOf, "1").toList(); - Assert.assertEquals(Collections.singletonList(1), filterIndex); + Assertions.assertEquals(Collections.singletonList(1), filterIndex); } @Test public void testFilterIdx() { final List list = Arrays.asList("dromara", "hutool", "sweet"); final List filterIndex = EasyStream.of(list).filterIdx((e, i) -> i < 2).toList(); - Assert.assertEquals(Arrays.asList("dromara", "hutool"), filterIndex); + Assertions.assertEquals(Arrays.asList("dromara", "hutool"), filterIndex); // 并行流时正常 - Assert.assertEquals(Arrays.asList("dromara", "hutool"), + Assertions.assertEquals(Arrays.asList("dromara", "hutool"), EasyStream.of("dromara", "hutool", "sweet").parallel().filterIdx((e, i) -> i < 2).toList()); } @@ -298,97 +298,97 @@ public class EasyStreamTest { public void testNonNull() { final List list = Arrays.asList(1, null, 2, 3); final List nonNull = EasyStream.of(list).nonNull().toList(); - Assert.assertEquals(Arrays.asList(1, 2, 3), nonNull); + Assertions.assertEquals(Arrays.asList(1, 2, 3), nonNull); } @Test public void testParallel() { - Assert.assertTrue(EasyStream.of(1, 2, 3).parallel(true).isParallel()); - Assert.assertFalse(EasyStream.of(1, 2, 3).parallel(false).isParallel()); + Assertions.assertTrue(EasyStream.of(1, 2, 3).parallel(true).isParallel()); + Assertions.assertFalse(EasyStream.of(1, 2, 3).parallel(false).isParallel()); } @Test public void testPush() { final List list = Arrays.asList(1, 2); final List push = EasyStream.of(list).push(3).toList(); - Assert.assertEquals(Arrays.asList(1, 2, 3), push); + Assertions.assertEquals(Arrays.asList(1, 2, 3), push); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4), EasyStream.of(list).push(3, 4).toList()); + Assertions.assertEquals(Arrays.asList(1, 2, 3, 4), EasyStream.of(list).push(3, 4).toList()); } @Test public void testUnshift() { final List list = Arrays.asList(2, 3); final List unshift = EasyStream.of(list).unshift(1).toList(); - Assert.assertEquals(Arrays.asList(1, 2, 3), unshift); + Assertions.assertEquals(Arrays.asList(1, 2, 3), unshift); - Assert.assertEquals(Arrays.asList(1, 2, 2, 3), EasyStream.of(list).unshift(1, 2).toList()); + Assertions.assertEquals(Arrays.asList(1, 2, 2, 3), EasyStream.of(list).unshift(1, 2).toList()); } @Test public void testAt() { final List list = Arrays.asList(1, 2, 3); - Assert.assertEquals(1, (Object) EasyStream.of(list).at(0).orElse(null)); - Assert.assertEquals(2, (Object) EasyStream.of(list).at(1).orElse(null)); - Assert.assertEquals(3, (Object) EasyStream.of(list).at(2).orElse(null)); - Assert.assertEquals(1, (Object) EasyStream.of(list).at(-3).orElse(null)); - Assert.assertEquals(3, (Object) EasyStream.of(list).at(-1).orElse(null)); - Assert.assertNull(EasyStream.of(list).at(-4).orElse(null)); + Assertions.assertEquals(1, (Object) EasyStream.of(list).at(0).orElse(null)); + Assertions.assertEquals(2, (Object) EasyStream.of(list).at(1).orElse(null)); + Assertions.assertEquals(3, (Object) EasyStream.of(list).at(2).orElse(null)); + Assertions.assertEquals(1, (Object) EasyStream.of(list).at(-3).orElse(null)); + Assertions.assertEquals(3, (Object) EasyStream.of(list).at(-1).orElse(null)); + Assertions.assertNull(EasyStream.of(list).at(-4).orElse(null)); } @Test public void testSplice() { final List list = Arrays.asList(1, 2, 3); - Assert.assertEquals(Arrays.asList(1, 2, 2, 3), EasyStream.of(list).splice(1, 0, 2).toList()); - Assert.assertEquals(Arrays.asList(1, 2, 3, 3), EasyStream.of(list).splice(3, 1, 3).toList()); - Assert.assertEquals(Arrays.asList(1, 2, 4), EasyStream.of(list).splice(2, 1, 4).toList()); - Assert.assertEquals(Arrays.asList(1, 2), EasyStream.of(list).splice(2, 1).toList()); - Assert.assertEquals(Arrays.asList(1, 2, 3), EasyStream.of(list).splice(2, 0).toList()); - Assert.assertEquals(Arrays.asList(1, 2), EasyStream.of(list).splice(-1, 1).toList()); - Assert.assertEquals(Arrays.asList(1, 2, 3), EasyStream.of(list).splice(-2, 2, 2, 3).toList()); + Assertions.assertEquals(Arrays.asList(1, 2, 2, 3), EasyStream.of(list).splice(1, 0, 2).toList()); + Assertions.assertEquals(Arrays.asList(1, 2, 3, 3), EasyStream.of(list).splice(3, 1, 3).toList()); + Assertions.assertEquals(Arrays.asList(1, 2, 4), EasyStream.of(list).splice(2, 1, 4).toList()); + Assertions.assertEquals(Arrays.asList(1, 2), EasyStream.of(list).splice(2, 1).toList()); + Assertions.assertEquals(Arrays.asList(1, 2, 3), EasyStream.of(list).splice(2, 0).toList()); + Assertions.assertEquals(Arrays.asList(1, 2), EasyStream.of(list).splice(-1, 1).toList()); + Assertions.assertEquals(Arrays.asList(1, 2, 3), EasyStream.of(list).splice(-2, 2, 2, 3).toList()); } @Test public void testFindFirst() { final List list = Arrays.asList(1, 2, 3); final Integer find = EasyStream.of(list).findFirst(Objects::nonNull).orElse(null); - Assert.assertEquals(1, (Object) find); + Assertions.assertEquals(1, (Object) find); } @Test public void testFindFirstIdx() { final List list = Arrays.asList(null, 2, 3); - Assert.assertEquals(1, EasyStream.of(list).findFirstIdx(Objects::nonNull)); - Assert.assertEquals(-1, (Object) EasyStream.of(list).parallel().findFirstIdx(Objects::nonNull)); + Assertions.assertEquals(1, EasyStream.of(list).findFirstIdx(Objects::nonNull)); + Assertions.assertEquals(-1, (Object) EasyStream.of(list).parallel().findFirstIdx(Objects::nonNull)); } @Test public void testFindLast() { final List list = ListUtil.of(1, 2, 4, 5, 6, 7, 8, 9, 10, 3); - Assert.assertEquals(3, (Object) EasyStream.of(list).findLast().orElse(null)); - Assert.assertEquals(3, (Object) EasyStream.of(list).parallel().findLast().orElse(null)); + Assertions.assertEquals(3, (Object) EasyStream.of(list).findLast().orElse(null)); + Assertions.assertEquals(3, (Object) EasyStream.of(list).parallel().findLast().orElse(null)); final List list2 = ListUtil.of(1, 2, 4, 5, 6, 7, 8, 9, 10, 3, null); - Assert.assertEquals(3, (Object) EasyStream.of(list2).parallel().findLast(Objects::nonNull).orElse(null)); + Assertions.assertEquals(3, (Object) EasyStream.of(list2).parallel().findLast(Objects::nonNull).orElse(null)); - Assert.assertNull(EasyStream.of().parallel().findLast(Objects::nonNull).orElse(null)); - Assert.assertNull(EasyStream.of((Object) null).parallel().findLast(Objects::nonNull).orElse(null)); + Assertions.assertNull(EasyStream.of().parallel().findLast(Objects::nonNull).orElse(null)); + Assertions.assertNull(EasyStream.of((Object) null).parallel().findLast(Objects::nonNull).orElse(null)); } @Test public void testFindLastIdx() { final List list = Arrays.asList(1, null, 3); - Assert.assertEquals(2, (Object) EasyStream.of(list).findLastIdx(Objects::nonNull)); - Assert.assertEquals(-1, (Object) EasyStream.of(list).parallel().findLastIdx(Objects::nonNull)); + Assertions.assertEquals(2, (Object) EasyStream.of(list).findLastIdx(Objects::nonNull)); + Assertions.assertEquals(-1, (Object) EasyStream.of(list).parallel().findLastIdx(Objects::nonNull)); } @Test public void testReverse() { final List list = ListUtil.of(Stream.iterate(1, i -> i + 1).limit(1000).collect(Collectors.toList())); - Assert.assertEquals(ListUtil.reverseNew(list), EasyStream.of(list).reverse().toList()); - Assert.assertEquals(ListUtil.empty(), EasyStream.of().reverse().toList()); - Assert.assertEquals(ListUtil.of((Object) null), EasyStream.of((Object) null).reverse().toList()); + Assertions.assertEquals(ListUtil.reverseNew(list), EasyStream.of(list).reverse().toList()); + Assertions.assertEquals(ListUtil.empty(), EasyStream.of().reverse().toList()); + Assertions.assertEquals(ListUtil.of((Object) null), EasyStream.of((Object) null).reverse().toList()); } @Test @@ -405,7 +405,7 @@ public class EasyStreamTest { .sorted(Comparator.reverseOrder()) .map(String::valueOf) .toList(); - Assert.assertEquals(Arrays.asList("4", "2"), res1); + Assertions.assertEquals(Arrays.asList("4", "2"), res1); final List res2 = EasyStream.iterate(1, i -> i + 1) .parallel() @@ -414,7 +414,7 @@ public class EasyStreamTest { .map(Integer::valueOf) .sorted(Comparator.naturalOrder()) .toList(); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4), res2); + Assertions.assertEquals(Arrays.asList(1, 2, 3, 4), res2); } @Test @@ -431,7 +431,7 @@ public class EasyStreamTest { .sorted(Comparator.reverseOrder()) .map(String::valueOf) .toList(); - Assert.assertEquals(Arrays.asList("9", "7", "5"), res1); + Assertions.assertEquals(Arrays.asList("9", "7", "5"), res1); final List res2 = EasyStream.of(list) .parallel() @@ -442,12 +442,12 @@ public class EasyStreamTest { .map(Integer::valueOf) .sorted(Comparator.naturalOrder()) .toList(); - Assert.assertEquals(Arrays.asList(5, 7, 9), res2); + Assertions.assertEquals(Arrays.asList(5, 7, 9), res2); } @Test public void testIsNotEmpty() { - Assert.assertTrue(EasyStream.of(1).isNotEmpty()); + Assertions.assertTrue(EasyStream.of(1).isNotEmpty()); } @@ -455,21 +455,21 @@ public class EasyStreamTest { public void testIntSumAndAvg() { //测试int类型的总和 final int sum = EasyStream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).sum(Integer::intValue); - Assert.assertEquals(55, sum); + Assertions.assertEquals(55, sum); //测试为空 final List integerList = new ArrayList<>(); final int emptySum = EasyStream.of(integerList).sum(Integer::intValue); - Assert.assertEquals(0, emptySum); + Assertions.assertEquals(0, emptySum); //测试平均值 final OptionalDouble avg = EasyStream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).avg(Integer::intValue); - Assert.assertTrue(avg.isPresent()); - Assert.assertEquals(5.5, avg.getAsDouble(), 2); + Assertions.assertTrue(avg.isPresent()); + Assertions.assertEquals(5.5, avg.getAsDouble(), 2); //测试元素为空 final OptionalDouble emptyAvg = EasyStream.of(integerList).avg(Integer::intValue); - Assert.assertFalse(emptyAvg.isPresent()); + Assertions.assertFalse(emptyAvg.isPresent()); } @@ -477,22 +477,22 @@ public class EasyStreamTest { public void testDoubleSumAndAvg() { //测试double类型的sum final double doubleSum = EasyStream.of(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10).sum(Double::doubleValue); - Assert.assertEquals(59.6, doubleSum, 2); + Assertions.assertEquals(59.6, doubleSum, 2); //测试double类型的sum 无元素double final List doubleList = new ArrayList<>(); final double emptySum = EasyStream.of(doubleList).sum(Double::doubleValue); - Assert.assertEquals(0.0, emptySum, 2); + Assertions.assertEquals(0.0, emptySum, 2); //测试double类型的avg final OptionalDouble doubleAvg = EasyStream.of(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10) .avg(Double::doubleValue); - Assert.assertTrue(doubleAvg.isPresent()); - Assert.assertEquals(5.96, doubleAvg.getAsDouble(), 2); + Assertions.assertTrue(doubleAvg.isPresent()); + Assertions.assertEquals(5.96, doubleAvg.getAsDouble(), 2); //测试double类型的 空元素的avg final OptionalDouble emptyDoubleAvg = EasyStream.of(doubleList).avg(Double::doubleValue); - Assert.assertFalse(emptyDoubleAvg.isPresent()); + Assertions.assertFalse(emptyDoubleAvg.isPresent()); } @@ -500,21 +500,21 @@ public class EasyStreamTest { public void testLongSumAndAvg() { //测试long类型的sum final long sum = EasyStream.of(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L).sum(Long::longValue); - Assert.assertEquals(55L, sum); + Assertions.assertEquals(55L, sum); //测试long类型的空元素 sum final List longList = new ArrayList<>(); final long emptySum = EasyStream.of(longList).sum(Long::longValue); - Assert.assertEquals(0L, emptySum); + Assertions.assertEquals(0L, emptySum); //测试long类型的avg final OptionalDouble doubleAvg = EasyStream.of(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L).avg(Long::longValue); - Assert.assertTrue(doubleAvg.isPresent()); - Assert.assertEquals(5.5, doubleAvg.getAsDouble(), 2); + Assertions.assertTrue(doubleAvg.isPresent()); + Assertions.assertEquals(5.5, doubleAvg.getAsDouble(), 2); //测试long类型的avg 空元素 final OptionalDouble emptyDoubleAvg = EasyStream.of(longList).avg(Long::longValue); - Assert.assertFalse(emptyDoubleAvg.isPresent()); + Assertions.assertFalse(emptyDoubleAvg.isPresent()); } @@ -524,35 +524,35 @@ public class EasyStreamTest { //测试bigDecimal的sum final BigDecimal sum = EasyStream.of(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10).map(NumberUtil::toBigDecimal) .sum(Function.identity()); - Assert.assertEquals(NumberUtil.toBigDecimal(59.6), sum); + Assertions.assertEquals(NumberUtil.toBigDecimal(59.6), sum); //测试bigDecimal的sum 空元素 final List bigDecimalEmptyList = new ArrayList<>(); final BigDecimal emptySum = EasyStream.of(bigDecimalEmptyList).sum(Function.identity()); - Assert.assertEquals(BigDecimal.ZERO, emptySum); + Assertions.assertEquals(BigDecimal.ZERO, emptySum); //测试bigDecimal的avg全参 final Opt bigDecimalAvgFullParam = EasyStream.of(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10) .map(NumberUtil::toBigDecimal) .avg(Function.identity(), 2, RoundingMode.HALF_UP); - Assert.assertEquals(NumberUtil.toBigDecimal(5.96), bigDecimalAvgFullParam.get()); + Assertions.assertEquals(NumberUtil.toBigDecimal(5.96), bigDecimalAvgFullParam.get()); //测试bigDecimal的avg单参 final Opt bigDecimalAvgOneParam = EasyStream.of(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10) .map(NumberUtil::toBigDecimal) .avg(Function.identity()); - Assert.assertEquals(NumberUtil.toBigDecimal(5.96), bigDecimalAvgOneParam.get()); + Assertions.assertEquals(NumberUtil.toBigDecimal(5.96), bigDecimalAvgOneParam.get()); //测试bigDecimal的avg双参 final Opt bigDecimalAvgTwoParam = EasyStream.of(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10) .map(NumberUtil::toBigDecimal) .avg(Function.identity(), 2); - Assert.assertEquals(NumberUtil.toBigDecimal(5.96), bigDecimalAvgTwoParam.get()); + Assertions.assertEquals(NumberUtil.toBigDecimal(5.96), bigDecimalAvgTwoParam.get()); //测试bigDecimal的avg 空元素 final Opt emptyBigDecimalAvg = EasyStream.of(bigDecimalEmptyList) .avg(Function.identity(), 2, RoundingMode.HALF_UP); - Assert.assertFalse(emptyBigDecimalAvg.isPresent()); + Assertions.assertFalse(emptyBigDecimalAvg.isPresent()); } diff --git a/hutool-core/src/test/java/cn/hutool/core/stream/EntryStreamTest.java b/hutool-core/src/test/java/cn/hutool/core/stream/EntryStreamTest.java index ff2c5d6bd..227a9c455 100644 --- a/hutool-core/src/test/java/cn/hutool/core/stream/EntryStreamTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/stream/EntryStreamTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.stream; import cn.hutool.core.map.multi.Table; -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.Arrays; @@ -23,30 +23,30 @@ public class EntryStreamTest { @Test public void testMerge() { - Assert.assertEquals(0, EntryStream.merge(null, null).count()); - Assert.assertEquals( + Assertions.assertEquals(0, EntryStream.merge(null, null).count()); + Assertions.assertEquals( Arrays.asList(2, 4, 6), EntryStream.merge(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3)) .map(Integer::sum) .toList() ); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList(1, 2, null), EntryStream.merge(Arrays.asList(1, 2, 3), Arrays.asList(1, 2)) .collectValues(Collectors.toList()) ); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList(1, 2, null), EntryStream.merge(Arrays.asList(1, 2), Arrays.asList(1, 2, 3)) .collectKeys(Collectors.toList()) ); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList(1, 2), EntryStream.merge(null, Arrays.asList(1, 2)) .collectValues(Collectors.toList()) ); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList(1, 2), EntryStream.merge(Arrays.asList(1, 2), null) .collectKeys(Collectors.toList()) @@ -57,27 +57,27 @@ public class EntryStreamTest { public void testOf() { final Map map = new HashMap<>(); map.put("1", "1"); - Assert.assertEquals(1, EntryStream.of(map).count()); - Assert.assertEquals(0, EntryStream.of((Map)null).count()); + Assertions.assertEquals(1, EntryStream.of(map).count()); + Assertions.assertEquals(0, EntryStream.of((Map)null).count()); final Set> entries = new HashSet<>(); entries.add(new Entry<>(1, 1)); entries.add(null); - Assert.assertEquals(2, EntryStream.of(entries).count()); - Assert.assertEquals(0, EntryStream.of((Set>)null).count()); - Assert.assertEquals(2, EntryStream.of(entries.stream()).count()); - Assert.assertEquals(0, EntryStream.of((Stream>)null).count()); - Assert.assertEquals(2, new EntryStream<>(entries.stream()).count()); - Assert.assertThrows(NullPointerException.class, () -> new EntryStream<>(null)); + Assertions.assertEquals(2, EntryStream.of(entries).count()); + Assertions.assertEquals(0, EntryStream.of((Set>)null).count()); + Assertions.assertEquals(2, EntryStream.of(entries.stream()).count()); + Assertions.assertEquals(0, EntryStream.of((Stream>)null).count()); + Assertions.assertEquals(2, new EntryStream<>(entries.stream()).count()); + Assertions.assertThrows(NullPointerException.class, () -> new EntryStream<>(null)); final Iterable iterable = Arrays.asList(1, 2, null); - Assert.assertEquals(3, EntryStream.of(iterable, Function.identity(), Function.identity()).count()); - Assert.assertEquals(0, EntryStream.of(null, Function.identity(), Function.identity()).count()); + Assertions.assertEquals(3, EntryStream.of(iterable, Function.identity(), Function.identity()).count()); + Assertions.assertEquals(0, EntryStream.of(null, Function.identity(), Function.identity()).count()); } @Test public void testEmpty() { - Assert.assertEquals(0, EntryStream.empty().count()); + Assertions.assertEquals(0, EntryStream.empty().count()); } @Test @@ -85,7 +85,7 @@ public class EntryStreamTest { final long count = EntryStream.of(Arrays.asList(new Entry<>(1, 1), new Entry<>(1, 2), new Entry<>(2, 1), new Entry<>(2, 2))) .distinctByKey() .count(); - Assert.assertEquals(2, count); + Assertions.assertEquals(2, count); } @Test @@ -93,7 +93,7 @@ public class EntryStreamTest { final long count = EntryStream.of(Arrays.asList(new Entry<>(1, 1), new Entry<>(1, 2), new Entry<>(2, 1), new Entry<>(2, 2))) .distinctByValue() .count(); - Assert.assertEquals(2, count); + Assertions.assertEquals(2, count); } @Test @@ -101,7 +101,7 @@ public class EntryStreamTest { final long count = EntryStream.of(Arrays.asList(new Entry<>(1, 1), new Entry<>(1, 2), new Entry<>(2, 1), new Entry<>(2, 2))) .filter((k, v) -> k == 1 && v == 1) .count(); - Assert.assertEquals(1, count); + Assertions.assertEquals(1, count); } @Test @@ -109,7 +109,7 @@ public class EntryStreamTest { final long count = EntryStream.of(Arrays.asList(new Entry<>(1, 1), new Entry<>(1, 2), new Entry<>(2, 1), new Entry<>(2, 2))) .filterByKey(k -> k == 1) .count(); - Assert.assertEquals(2, count); + Assertions.assertEquals(2, count); } @Test @@ -117,7 +117,7 @@ public class EntryStreamTest { final long count = EntryStream.of(Arrays.asList(new Entry<>(1, 1), new Entry<>(1, 2), new Entry<>(2, 1), new Entry<>(2, 2))) .filterByValue(v -> v == 1) .count(); - Assert.assertEquals(2, count); + Assertions.assertEquals(2, count); } @Test @@ -126,7 +126,7 @@ public class EntryStreamTest { EntryStream.of(Arrays.asList(new Entry<>(1, 1), new Entry<>(1, 2), new Entry<>(2, 1), new Entry<>(2, 2))) .peekKey(keys::add) .toList(); - Assert.assertEquals(Arrays.asList(1, 1, 2, 2), keys); + Assertions.assertEquals(Arrays.asList(1, 1, 2, 2), keys); } @Test @@ -135,12 +135,12 @@ public class EntryStreamTest { EntryStream.of(Arrays.asList(new Entry<>(1, 1), new Entry<>(1, 2), new Entry<>(2, 1), new Entry<>(2, 2))) .peekValue(values::add) .toList(); - Assert.assertEquals(Arrays.asList(1, 2, 1, 2), values); + Assertions.assertEquals(Arrays.asList(1, 2, 1, 2), values); } @Test public void testPush() { - Assert.assertEquals( + Assertions.assertEquals( 5, EntryStream.of(Arrays.asList(1, 2, 3), Function.identity(), Function.identity()) .push(4, 4) @@ -151,7 +151,7 @@ public class EntryStreamTest { @Test public void testUnshift() { - Assert.assertEquals( + Assertions.assertEquals( 5, EntryStream.of(Arrays.asList(1, 2, 3), Function.identity(), Function.identity()) .unshift(4, 4) @@ -176,7 +176,7 @@ public class EntryStreamTest { put(3, 3); put(4, 4); }}; - Assert.assertEquals( + Assertions.assertEquals( new ArrayList>(){ private static final long serialVersionUID = -4045530648496761947L; @@ -186,7 +186,7 @@ public class EntryStreamTest { }}, EntryStream.of(map1).append(map2.entrySet()).toList() ); - Assert.assertEquals( + Assertions.assertEquals( new ArrayList<>(map1.entrySet()), EntryStream.of(map1).append(null).toList() ); } @@ -207,7 +207,7 @@ public class EntryStreamTest { put(3, 3); put(4, 4); }}; - Assert.assertEquals( + Assertions.assertEquals( new ArrayList>(){ private static final long serialVersionUID = 7564826138581563332L; @@ -217,7 +217,7 @@ public class EntryStreamTest { }}, EntryStream.of(map1).prepend(map2.entrySet()).toList() ); - Assert.assertEquals( + Assertions.assertEquals( new ArrayList<>(map1.entrySet()), EntryStream.of(map1).prepend(null).toList() ); } @@ -227,7 +227,7 @@ public class EntryStreamTest { final List> entries = EntryStream.of(Arrays.asList(new Entry<>(3, 1), new Entry<>(2, 1), new Entry<>(4, 1), new Entry<>(1, 1))) .sortByKey(Comparator.comparingInt(Integer::intValue)) .collect(Collectors.toList()); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList(1, 2, 3, 4), entries.stream().map(Map.Entry::getKey).collect(Collectors.toList()) ); @@ -238,7 +238,7 @@ public class EntryStreamTest { final List> entries = EntryStream.of(Arrays.asList(new Entry<>(4, 4), new Entry<>(2, 2), new Entry<>(1, 1), new Entry<>(3, 3))) .sortByValue(Comparator.comparingInt(Integer::intValue)) .collect(Collectors.toList()); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList(1, 2, 3, 4), entries.stream().map(Map.Entry::getValue).collect(Collectors.toList()) ); @@ -250,7 +250,7 @@ public class EntryStreamTest { map.put(1, 1); map.put(2, 2); map.put(3, 3); - Assert.assertEquals( + Assertions.assertEquals( new ArrayList<>(map.values()), EntryStream.of(map).toValueStream().collect(Collectors.toList()) ); } @@ -261,7 +261,7 @@ public class EntryStreamTest { map.put(1, 1); map.put(2, 2); map.put(3, 3); - Assert.assertEquals( + Assertions.assertEquals( new ArrayList<>(map.keySet()), EntryStream.of(map).toKeyStream().collect(Collectors.toList()) ); } @@ -273,7 +273,7 @@ public class EntryStreamTest { map.put(2, 2); map.put(3, 3); final List keys = EntryStream.of(map).collectKeys(Collectors.toList()); - Assert.assertEquals(new ArrayList<>(map.keySet()), keys); + Assertions.assertEquals(new ArrayList<>(map.keySet()), keys); } @Test @@ -283,7 +283,7 @@ public class EntryStreamTest { map.put(2, 2); map.put(3, 3); final List keys = EntryStream.of(map).collectValues(Collectors.toList()); - Assert.assertEquals(new ArrayList<>(map.keySet()), keys); + Assertions.assertEquals(new ArrayList<>(map.keySet()), keys); } @Test @@ -292,7 +292,7 @@ public class EntryStreamTest { map.put(1, 1); map.put(2, 2); map.put(3, 3); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("1", "2", "3"), EntryStream.of(map) .mapKeys(String::valueOf) @@ -307,7 +307,7 @@ public class EntryStreamTest { map.put(1, 1); map.put(2, 2); map.put(3, 3); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("1", "2", "3"), EntryStream.of(map) .mapValues(String::valueOf) @@ -322,13 +322,13 @@ public class EntryStreamTest { map.put(1, 1); map.put(2, 2); map.put(3, 3); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("11", "22", "33"), EntryStream.of(map) .map((k, v) -> k.toString() + v.toString()) .collect(Collectors.toList()) ); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("11", "22", "33"), EntryStream.of(map) .map(e -> e.getKey().toString() + e.getValue().toString()) @@ -345,7 +345,7 @@ public class EntryStreamTest { final List list = EntryStream.of(map) .flatMap(e -> Stream.of(e.getKey(), e.getKey() + 1)) .collect(Collectors.toList()); - Assert.assertEquals(Arrays.asList(1, 2, 2, 3, 3, 4), list); + Assertions.assertEquals(Arrays.asList(1, 2, 2, 3, 3, 4), list); } @Test @@ -359,7 +359,7 @@ public class EntryStreamTest { .map((k, v) -> v + "=" + k) .sorted() .collect(Collectors.toList()); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList( "1=class1's student1", "1=class1's student2", "2=class2's student1", "2=class2's student2", @@ -379,7 +379,7 @@ public class EntryStreamTest { .inverse() .map((k, v) -> k + "=" + v) .collect(Collectors.toList()); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("value1=key1", "value2=key2", "value3=key3"), results ); @@ -395,7 +395,7 @@ public class EntryStreamTest { .flatMapValue(v -> Stream.of(v + "'s student1", v + "'s student2")) .map((k, v) -> k + "=" + v) .collect(Collectors.toList()); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList( "1=class1's student1", "1=class1's student2", "2=class2's student1", "2=class2's student2", @@ -418,8 +418,8 @@ public class EntryStreamTest { keys.add(k); values.add(v); }); - Assert.assertEquals(Arrays.asList(1, 2, 3), keys); - Assert.assertEquals(Arrays.asList(1, 2, 3), values); + Assertions.assertEquals(Arrays.asList(1, 2, 3), keys); + Assertions.assertEquals(Arrays.asList(1, 2, 3), values); } @Test @@ -430,13 +430,13 @@ public class EntryStreamTest { map.put(3, 3); Map result = EntryStream.of(map).toMap(); - Assert.assertEquals(map, result); + Assertions.assertEquals(map, result); result = EntryStream.of(map).toMap((Supplier>)LinkedHashMap::new); - Assert.assertEquals(new LinkedHashMap<>(map), result); + Assertions.assertEquals(new LinkedHashMap<>(map), result); result = EntryStream.of(map).toMap(LinkedHashMap::new, (t1, t2) -> t1); - Assert.assertEquals(new LinkedHashMap<>(map), result); + Assertions.assertEquals(new LinkedHashMap<>(map), result); } @Test @@ -451,16 +451,16 @@ public class EntryStreamTest { Table table = EntryStream.of(map).toTable( (k ,v) -> (k & 1) == 0, HashMap::new, (t1, t2) -> t1 ); - Assert.assertEquals((Integer)1, table.get(false, 1)); - Assert.assertEquals((Integer)3, table.get(false, 3)); - Assert.assertEquals((Integer)2, table.get(true, 2)); - Assert.assertEquals((Integer)4, table.get(true, 4)); + Assertions.assertEquals((Integer)1, table.get(false, 1)); + Assertions.assertEquals((Integer)3, table.get(false, 3)); + Assertions.assertEquals((Integer)2, table.get(true, 2)); + Assertions.assertEquals((Integer)4, table.get(true, 4)); table = EntryStream.of(map).toTable((k ,v) -> (k & 1) == 0); - Assert.assertEquals((Integer)1, table.get(false, 1)); - Assert.assertEquals((Integer)3, table.get(false, 3)); - Assert.assertEquals((Integer)2, table.get(true, 2)); - Assert.assertEquals((Integer)4, table.get(true, 4)); + Assertions.assertEquals((Integer)1, table.get(false, 1)); + Assertions.assertEquals((Integer)3, table.get(false, 3)); + Assertions.assertEquals((Integer)2, table.get(true, 2)); + Assertions.assertEquals((Integer)4, table.get(true, 4)); } @Test @@ -475,16 +475,16 @@ public class EntryStreamTest { Table table = EntryStream.of(map).toTableByKey( k -> (k & 1) == 0, HashMap::new, (t1, t2) -> t1 ); - Assert.assertEquals((Integer)1, table.get(false, 1)); - Assert.assertEquals((Integer)3, table.get(false, 3)); - Assert.assertEquals((Integer)2, table.get(true, 2)); - Assert.assertEquals((Integer)4, table.get(true, 4)); + Assertions.assertEquals((Integer)1, table.get(false, 1)); + Assertions.assertEquals((Integer)3, table.get(false, 3)); + Assertions.assertEquals((Integer)2, table.get(true, 2)); + Assertions.assertEquals((Integer)4, table.get(true, 4)); table = EntryStream.of(map).toTableByKey(k -> (k & 1) == 0); - Assert.assertEquals((Integer)1, table.get(false, 1)); - Assert.assertEquals((Integer)3, table.get(false, 3)); - Assert.assertEquals((Integer)2, table.get(true, 2)); - Assert.assertEquals((Integer)4, table.get(true, 4)); + Assertions.assertEquals((Integer)1, table.get(false, 1)); + Assertions.assertEquals((Integer)3, table.get(false, 3)); + Assertions.assertEquals((Integer)2, table.get(true, 2)); + Assertions.assertEquals((Integer)4, table.get(true, 4)); } @Test @@ -499,60 +499,60 @@ public class EntryStreamTest { Table table = EntryStream.of(map).toTableByValue( v -> (v & 1) == 0, HashMap::new, (t1, t2) -> t1 ); - Assert.assertEquals((Integer)1, table.get(false, 1)); - Assert.assertEquals((Integer)3, table.get(false, 3)); - Assert.assertEquals((Integer)2, table.get(true, 2)); - Assert.assertEquals((Integer)4, table.get(true, 4)); + Assertions.assertEquals((Integer)1, table.get(false, 1)); + Assertions.assertEquals((Integer)3, table.get(false, 3)); + Assertions.assertEquals((Integer)2, table.get(true, 2)); + Assertions.assertEquals((Integer)4, table.get(true, 4)); table = EntryStream.of(map).toTableByValue(v -> (v & 1) == 0); - Assert.assertEquals((Integer)1, table.get(false, 1)); - Assert.assertEquals((Integer)3, table.get(false, 3)); - Assert.assertEquals((Integer)2, table.get(true, 2)); - Assert.assertEquals((Integer)4, table.get(true, 4)); + Assertions.assertEquals((Integer)1, table.get(false, 1)); + Assertions.assertEquals((Integer)3, table.get(false, 3)); + Assertions.assertEquals((Integer)2, table.get(true, 2)); + Assertions.assertEquals((Integer)4, table.get(true, 4)); } @Test public void testGroupByKey() { final Map> map1 = EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) .groupByKey(); - Assert.assertEquals(2, map1.size()); - Assert.assertEquals(Arrays.asList(1, 1), map1.get(1)); - Assert.assertEquals(Arrays.asList(2, 2), map1.get(2)); + Assertions.assertEquals(2, map1.size()); + Assertions.assertEquals(Arrays.asList(1, 1), map1.get(1)); + Assertions.assertEquals(Arrays.asList(2, 2), map1.get(2)); final Map> map2 = EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) .groupByKey(Collectors.toSet()); - Assert.assertEquals(2, map2.size()); - Assert.assertEquals(Collections.singleton(1), map2.get(1)); - Assert.assertEquals(Collections.singleton(2), map2.get(2)); + Assertions.assertEquals(2, map2.size()); + Assertions.assertEquals(Collections.singleton(1), map2.get(1)); + Assertions.assertEquals(Collections.singleton(2), map2.get(2)); final Map> map3 = EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) .groupByKey(LinkedHashMap::new, Collectors.toSet()); - Assert.assertEquals(2, map3.size()); - Assert.assertEquals(Collections.singleton(1), map3.get(1)); - Assert.assertEquals(Collections.singleton(2), map3.get(2)); + Assertions.assertEquals(2, map3.size()); + Assertions.assertEquals(Collections.singleton(1), map3.get(1)); + Assertions.assertEquals(Collections.singleton(2), map3.get(2)); } @Test public void testAnyMatch() { - Assert.assertTrue(EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) + Assertions.assertTrue(EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) .anyMatch((k, v) -> (k & 1) == 1)); - Assert.assertFalse(EntryStream.of(Arrays.asList(2, 2, 2, 2), Function.identity(), Function.identity()) + Assertions.assertFalse(EntryStream.of(Arrays.asList(2, 2, 2, 2), Function.identity(), Function.identity()) .anyMatch((k, v) -> (k & 1) == 1)); } @Test public void testAllMatch() { - Assert.assertFalse(EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) + Assertions.assertFalse(EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) .allMatch((k, v) -> (k & 1) == 1)); - Assert.assertTrue(EntryStream.of(Arrays.asList(2, 2, 2, 2), Function.identity(), Function.identity()) + Assertions.assertTrue(EntryStream.of(Arrays.asList(2, 2, 2, 2), Function.identity(), Function.identity()) .allMatch((k, v) -> (k & 1) == 0)); } @Test public void testNoneMatch() { - Assert.assertFalse(EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) + Assertions.assertFalse(EntryStream.of(Arrays.asList(1, 1, 2, 2), Function.identity(), Function.identity()) .noneMatch((k, v) -> (k & 1) == 1)); - Assert.assertTrue(EntryStream.of(Arrays.asList(2, 2, 2, 2), Function.identity(), Function.identity()) + Assertions.assertTrue(EntryStream.of(Arrays.asList(2, 2, 2, 2), Function.identity(), Function.identity()) .noneMatch((k, v) -> (k & 1) == 1)); } @@ -561,7 +561,7 @@ public class EntryStreamTest { final Map map = new HashMap<>(); map.put(1, null); map.put(null, 1); - Assert.assertEquals(0, EntryStream.of(map).nonNullKeyValue().count()); + Assertions.assertEquals(0, EntryStream.of(map).nonNullKeyValue().count()); } @Test @@ -569,7 +569,7 @@ public class EntryStreamTest { final Map map = new HashMap<>(); map.put(1, null); map.put(null, 1); - Assert.assertEquals(1, EntryStream.of(map).nonNullKey().count()); + Assertions.assertEquals(1, EntryStream.of(map).nonNullKey().count()); } @Test @@ -577,7 +577,7 @@ public class EntryStreamTest { final Map map = new HashMap<>(); map.put(1, null); map.put(null, 1); - Assert.assertEquals(1, EntryStream.of(map).nonNullValue().count()); + Assertions.assertEquals(1, EntryStream.of(map).nonNullValue().count()); } private static class Entry implements Map.Entry { diff --git a/hutool-core/src/test/java/cn/hutool/core/stream/StreamUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/stream/StreamUtilTest.java index 41c352989..ffac6cf8d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/stream/StreamUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/stream/StreamUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.stream; 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.util.*; import java.util.stream.Collectors; @@ -15,13 +15,13 @@ public class StreamUtilTest { public void ofTest(){ final Stream stream = StreamUtil.of(2, x -> x * 2, 4); final String result = stream.collect(CollectorUtil.joining(",")); - Assert.assertEquals("2,4,8,16", result); + Assertions.assertEquals("2,4,8,16", result); } // === iterator === @Test public void streamTestNullIterator() { - Assert.assertThrows(IllegalArgumentException.class, () -> StreamUtil.ofIter((Iterator) null)); + Assertions.assertThrows(IllegalArgumentException.class, () -> StreamUtil.ofIter((Iterator) null)); } @SuppressWarnings({"RedundantOperationOnEmptyContainer", "RedundantCollectionOperation"}) @@ -38,15 +38,15 @@ public class StreamUtilTest { @Test public void streamTestOrdinaryIterator() { final List arrayList = ListUtil.of(1, 2, 3); - Assert.assertArrayEquals(new Integer[]{1, 2, 3}, StreamUtil.ofIter(arrayList.iterator()).toArray()); + Assertions.assertArrayEquals(new Integer[]{1, 2, 3}, StreamUtil.ofIter(arrayList.iterator()).toArray()); final HashSet hashSet = SetUtil.of(1, 2, 3); - Assert.assertEquals(hashSet, StreamUtil.ofIter(hashSet.iterator()).collect(Collectors.toSet())); + Assertions.assertEquals(hashSet, StreamUtil.ofIter(hashSet.iterator()).collect(Collectors.toSet())); } void assertStreamIsEmpty(final Stream stream) { - Assert.assertNotNull(stream); - Assert.assertEquals(0, stream.toArray().length); + Assertions.assertNotNull(stream); + Assertions.assertEquals(0, stream.toArray().length); } // ================ stream test end ================ } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/AntPathMatcherTest.java b/hutool-core/src/test/java/cn/hutool/core/text/AntPathMatcherTest.java index 3f589b798..14623848b 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/AntPathMatcherTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/AntPathMatcherTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.HashMap; @@ -11,7 +11,7 @@ public class AntPathMatcherTest { public void matchesTest() { final AntPathMatcher antPathMatcher = new AntPathMatcher(); final boolean matched = antPathMatcher.match("/api/org/organization/{orgId}", "/api/org/organization/999"); - Assert.assertTrue(matched); + Assertions.assertTrue(matched); } @Test @@ -21,17 +21,17 @@ public class AntPathMatcherTest { String pattern = "/**/*.xml*"; String path = "/WEB-INF/web.xml"; boolean isMatched = antPathMatcher.match(pattern, path); - Assert.assertTrue(isMatched); + Assertions.assertTrue(isMatched); pattern = "org/codelabor/*/**/*Service"; path = "org/codelabor/example/HelloWorldService"; isMatched = antPathMatcher.match(pattern, path); - Assert.assertTrue(isMatched); + Assertions.assertTrue(isMatched); pattern = "org/codelabor/*/**/*Service?"; path = "org/codelabor/example/HelloWorldServices"; isMatched = antPathMatcher.match(pattern, path); - Assert.assertTrue(isMatched); + Assertions.assertTrue(isMatched); } @Test @@ -42,13 +42,13 @@ public class AntPathMatcherTest { pathMatcher.setPathSeparator("/"); pathMatcher.setTrimTokens(true); - Assert.assertTrue(pathMatcher.match("a", "a")); - Assert.assertTrue(pathMatcher.match("a*", "ab")); - Assert.assertTrue(pathMatcher.match("a*/**/a", "ab/asdsa/a")); - Assert.assertTrue(pathMatcher.match("a*/**/a", "ab/asdsa/asdasd/a")); + Assertions.assertTrue(pathMatcher.match("a", "a")); + Assertions.assertTrue(pathMatcher.match("a*", "ab")); + Assertions.assertTrue(pathMatcher.match("a*/**/a", "ab/asdsa/a")); + Assertions.assertTrue(pathMatcher.match("a*/**/a", "ab/asdsa/asdasd/a")); - Assert.assertTrue(pathMatcher.match("*", "a")); - Assert.assertTrue(pathMatcher.match("*/*", "a/a")); + Assertions.assertTrue(pathMatcher.match("*", "a")); + Assertions.assertTrue(pathMatcher.match("*/*", "a/a")); } /** @@ -61,43 +61,43 @@ public class AntPathMatcherTest { final AntPathMatcher pathMatcher = new AntPathMatcher(); // 精确匹配 - Assert.assertTrue(pathMatcher.match("/test", "/test")); - Assert.assertFalse(pathMatcher.match("test", "/test")); + Assertions.assertTrue(pathMatcher.match("/test", "/test")); + Assertions.assertFalse(pathMatcher.match("test", "/test")); //测试通配符? - Assert.assertTrue(pathMatcher.match("t?st", "test")); - Assert.assertTrue(pathMatcher.match("te??", "test")); - Assert.assertFalse(pathMatcher.match("tes?", "tes")); - Assert.assertFalse(pathMatcher.match("tes?", "testt")); + Assertions.assertTrue(pathMatcher.match("t?st", "test")); + Assertions.assertTrue(pathMatcher.match("te??", "test")); + Assertions.assertFalse(pathMatcher.match("tes?", "tes")); + Assertions.assertFalse(pathMatcher.match("tes?", "testt")); //测试通配符* - Assert.assertTrue(pathMatcher.match("*", "test")); - Assert.assertTrue(pathMatcher.match("test*", "test")); - Assert.assertTrue(pathMatcher.match("test/*", "test/Test")); - Assert.assertTrue(pathMatcher.match("*.*", "test.")); - Assert.assertTrue(pathMatcher.match("*.*", "test.test.test")); - Assert.assertFalse(pathMatcher.match("test*", "test/")); //注意这里是false 因为路径不能用*匹配 - Assert.assertFalse(pathMatcher.match("test*", "test/t")); //这同理 - Assert.assertFalse(pathMatcher.match("test*aaa", "testblaaab")); //这个是false 因为最后一个b无法匹配了 前面都是能匹配成功的 + Assertions.assertTrue(pathMatcher.match("*", "test")); + Assertions.assertTrue(pathMatcher.match("test*", "test")); + Assertions.assertTrue(pathMatcher.match("test/*", "test/Test")); + Assertions.assertTrue(pathMatcher.match("*.*", "test.")); + Assertions.assertTrue(pathMatcher.match("*.*", "test.test.test")); + Assertions.assertFalse(pathMatcher.match("test*", "test/")); //注意这里是false 因为路径不能用*匹配 + Assertions.assertFalse(pathMatcher.match("test*", "test/t")); //这同理 + Assertions.assertFalse(pathMatcher.match("test*aaa", "testblaaab")); //这个是false 因为最后一个b无法匹配了 前面都是能匹配成功的 //测试通配符** 匹配多级URL - Assert.assertTrue(pathMatcher.match("/*/**", "/testing/testing")); - Assert.assertTrue(pathMatcher.match("/**/*", "/testing/testing")); - Assert.assertTrue(pathMatcher.match("/bla/**/bla", "/bla/testing/testing/bla/bla")); //这里也是true哦 - Assert.assertFalse(pathMatcher.match("/bla*bla/test", "/blaXXXbl/test")); + Assertions.assertTrue(pathMatcher.match("/*/**", "/testing/testing")); + Assertions.assertTrue(pathMatcher.match("/**/*", "/testing/testing")); + Assertions.assertTrue(pathMatcher.match("/bla/**/bla", "/bla/testing/testing/bla/bla")); //这里也是true哦 + Assertions.assertFalse(pathMatcher.match("/bla*bla/test", "/blaXXXbl/test")); - Assert.assertFalse(pathMatcher.match("/????", "/bala/bla")); - Assert.assertFalse(pathMatcher.match("/**/*bla", "/bla/bla/bla/bbb")); + Assertions.assertFalse(pathMatcher.match("/????", "/bala/bla")); + Assertions.assertFalse(pathMatcher.match("/**/*bla", "/bla/bla/bla/bbb")); - Assert.assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing/")); - Assert.assertTrue(pathMatcher.match("/*bla*/**/bla/*", "/XXXblaXXXX/testing/testing/bla/testing")); - Assert.assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing")); - Assert.assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing.jpg")); - Assert.assertTrue(pathMatcher.match("/foo/bar/**", "/foo/bar")); + Assertions.assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing/")); + Assertions.assertTrue(pathMatcher.match("/*bla*/**/bla/*", "/XXXblaXXXX/testing/testing/bla/testing")); + Assertions.assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing")); + Assertions.assertTrue(pathMatcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing.jpg")); + Assertions.assertTrue(pathMatcher.match("/foo/bar/**", "/foo/bar")); //这个需要特别注意:{}里面的相当于Spring MVC里接受一个参数一样,所以任何东西都会匹配的 - Assert.assertTrue(pathMatcher.match("/{bla}.*", "/testing.html")); - Assert.assertFalse(pathMatcher.match("/{bla}.htm", "/testing.html")); //这样就是false了 + Assertions.assertTrue(pathMatcher.match("/{bla}.*", "/testing.html")); + Assertions.assertFalse(pathMatcher.match("/{bla}.htm", "/testing.html")); //这样就是false了 } /** @@ -110,6 +110,6 @@ public class AntPathMatcherTest { "/api/org" + "/organization" + "/999"); - Assert.assertEquals(1, map.size()); + Assertions.assertEquals(1, map.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/CharSequenceUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/text/CharSequenceUtilTest.java index 81a7bfcc5..ffbe6dc96 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/CharSequenceUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/CharSequenceUtilTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.text; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; 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.time.Instant; import java.util.regex.Pattern; @@ -14,7 +14,7 @@ public class CharSequenceUtilTest { @Test public void replaceTest() { final String actual = CharSequenceUtil.replace("SSM15930297701BeryAllen", Pattern.compile("[0-9]"), matcher -> ""); - Assert.assertEquals("SSMBeryAllen", actual); + Assertions.assertEquals("SSMBeryAllen", actual); } @Test @@ -22,41 +22,41 @@ public class CharSequenceUtilTest { // https://gitee.com/dromara/hutool/issues/I4M16G final String replace = "#{A}"; final String result = CharSequenceUtil.replace(replace, "#{AAAAAAA}", "1"); - Assert.assertEquals(replace, result); + Assertions.assertEquals(replace, result); } @Test public void replaceByStrTest() { final String replace = "SSM15930297701BeryAllen"; final String result = CharSequenceUtil.replace(replace, 5, 12, "***"); - Assert.assertEquals("SSM15***01BeryAllen", result); + Assertions.assertEquals("SSM15***01BeryAllen", result); final String emoji = StrUtil.replace("\uD83D\uDE00aabb\uD83D\uDE00ccdd", 2, 6, "***"); - Assert.assertEquals("\uD83D\uDE00a***ccdd", emoji); + Assertions.assertEquals("\uD83D\uDE00a***ccdd", emoji); } @Test public void addPrefixIfNotTest() { final String str = "hutool"; String result = CharSequenceUtil.addPrefixIfNot(str, "hu"); - Assert.assertEquals(str, result); + Assertions.assertEquals(str, result); result = CharSequenceUtil.addPrefixIfNot(str, "Good"); - Assert.assertEquals("Good" + str, result); + Assertions.assertEquals("Good" + str, result); } @Test public void addSuffixIfNotTest() { final String str = "hutool"; String result = CharSequenceUtil.addSuffixIfNot(str, "tool"); - Assert.assertEquals(str, result); + Assertions.assertEquals(str, result); result = CharSequenceUtil.addSuffixIfNot(str, " is Good"); - Assert.assertEquals(str + " is Good", result); + Assertions.assertEquals(str + " is Good", result); // https://gitee.com/dromara/hutool/issues/I4NS0F result = CharSequenceUtil.addSuffixIfNot("", "/"); - Assert.assertEquals("/", result); + Assertions.assertEquals("/", result); } @SuppressWarnings("UnnecessaryUnicodeEscape") @@ -67,30 +67,30 @@ public class CharSequenceUtilTest { String str1 = "\u00C1"; String str2 = "\u0041\u0301"; - Assert.assertNotEquals(str1, str2); + Assertions.assertNotEquals(str1, str2); str1 = CharSequenceUtil.normalize(str1); str2 = CharSequenceUtil.normalize(str2); - Assert.assertEquals(str1, str2); + Assertions.assertEquals(str1, str2); } @Test public void indexOfTest() { int index = CharSequenceUtil.indexOf("abc123", '1'); - Assert.assertEquals(3, index); + Assertions.assertEquals(3, index); index = CharSequenceUtil.indexOf("abc123", '3'); - Assert.assertEquals(5, index); + Assertions.assertEquals(5, index); index = CharSequenceUtil.indexOf("abc123", 'a'); - Assert.assertEquals(0, index); + Assertions.assertEquals(0, index); } @Test public void indexOfTest2() { int index = CharSequenceUtil.indexOf("abc123", '1', 0, 3); - Assert.assertEquals(-1, index); + Assertions.assertEquals(-1, index); index = CharSequenceUtil.indexOf("abc123", 'b', 0, 3); - Assert.assertEquals(1, index); + Assertions.assertEquals(1, index); } @Test @@ -99,80 +99,80 @@ public class CharSequenceUtilTest { final String s = "华硕K42Intel酷睿i31代2G以下独立显卡不含机械硬盘固态硬盘120GB-192GB4GB-6GB"; String v = CharSequenceUtil.subPreGbk(s, 40, false); - Assert.assertEquals(39, v.getBytes(CharsetUtil.GBK).length); + Assertions.assertEquals(39, v.getBytes(CharsetUtil.GBK).length); v = CharSequenceUtil.subPreGbk(s, 40, true); - Assert.assertEquals(41, v.getBytes(CharsetUtil.GBK).length); + Assertions.assertEquals(41, v.getBytes(CharsetUtil.GBK).length); } @Test public void startWithTest() { // https://gitee.com/dromara/hutool/issues/I4MV7Q - Assert.assertFalse(CharSequenceUtil.startWith("123", "123", false, true)); - Assert.assertFalse(CharSequenceUtil.startWith(null, null, false, true)); - Assert.assertFalse(CharSequenceUtil.startWith("abc", "abc", true, true)); + Assertions.assertFalse(CharSequenceUtil.startWith("123", "123", false, true)); + Assertions.assertFalse(CharSequenceUtil.startWith(null, null, false, true)); + Assertions.assertFalse(CharSequenceUtil.startWith("abc", "abc", true, true)); - Assert.assertTrue(CharSequenceUtil.startWithIgnoreCase(null, null)); - Assert.assertFalse(CharSequenceUtil.startWithIgnoreCase(null, "abc")); - Assert.assertFalse(CharSequenceUtil.startWithIgnoreCase("abcdef", null)); - Assert.assertTrue(CharSequenceUtil.startWithIgnoreCase("abcdef", "abc")); - Assert.assertTrue(CharSequenceUtil.startWithIgnoreCase("ABCDEF", "abc")); + Assertions.assertTrue(CharSequenceUtil.startWithIgnoreCase(null, null)); + Assertions.assertFalse(CharSequenceUtil.startWithIgnoreCase(null, "abc")); + Assertions.assertFalse(CharSequenceUtil.startWithIgnoreCase("abcdef", null)); + Assertions.assertTrue(CharSequenceUtil.startWithIgnoreCase("abcdef", "abc")); + Assertions.assertTrue(CharSequenceUtil.startWithIgnoreCase("ABCDEF", "abc")); } @Test public void endWithTest() { - Assert.assertFalse(CharSequenceUtil.endWith("123", "123", false, true)); - Assert.assertFalse(CharSequenceUtil.endWith(null, null, false, true)); - Assert.assertFalse(CharSequenceUtil.endWith("abc", "abc", true, true)); + Assertions.assertFalse(CharSequenceUtil.endWith("123", "123", false, true)); + Assertions.assertFalse(CharSequenceUtil.endWith(null, null, false, true)); + Assertions.assertFalse(CharSequenceUtil.endWith("abc", "abc", true, true)); - Assert.assertTrue(CharSequenceUtil.endWithIgnoreCase(null, null)); - Assert.assertFalse(CharSequenceUtil.endWithIgnoreCase(null, "abc")); - Assert.assertFalse(CharSequenceUtil.endWithIgnoreCase("abcdef", null)); - Assert.assertTrue(CharSequenceUtil.endWithIgnoreCase("abcdef", "def")); - Assert.assertTrue(CharSequenceUtil.endWithIgnoreCase("ABCDEF", "def")); + Assertions.assertTrue(CharSequenceUtil.endWithIgnoreCase(null, null)); + Assertions.assertFalse(CharSequenceUtil.endWithIgnoreCase(null, "abc")); + Assertions.assertFalse(CharSequenceUtil.endWithIgnoreCase("abcdef", null)); + Assertions.assertTrue(CharSequenceUtil.endWithIgnoreCase("abcdef", "def")); + Assertions.assertTrue(CharSequenceUtil.endWithIgnoreCase("ABCDEF", "def")); } @Test public void removePrefixIgnoreCaseTest(){ - Assert.assertEquals("de", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "abc")); - Assert.assertEquals("de", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "ABC")); - Assert.assertEquals("de", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "Abc")); - Assert.assertEquals("ABCde", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "")); - Assert.assertEquals("ABCde", CharSequenceUtil.removePrefixIgnoreCase("ABCde", null)); - Assert.assertEquals("", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "ABCde")); - Assert.assertEquals("ABCde", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "ABCdef")); - Assert.assertNull(CharSequenceUtil.removePrefixIgnoreCase(null, "ABCdef")); + Assertions.assertEquals("de", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "abc")); + Assertions.assertEquals("de", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "ABC")); + Assertions.assertEquals("de", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "Abc")); + Assertions.assertEquals("ABCde", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "")); + Assertions.assertEquals("ABCde", CharSequenceUtil.removePrefixIgnoreCase("ABCde", null)); + Assertions.assertEquals("", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "ABCde")); + Assertions.assertEquals("ABCde", CharSequenceUtil.removePrefixIgnoreCase("ABCde", "ABCdef")); + Assertions.assertNull(CharSequenceUtil.removePrefixIgnoreCase(null, "ABCdef")); } @Test public void removeSuffixIgnoreCaseTest(){ - Assert.assertEquals("AB", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "cde")); - Assert.assertEquals("AB", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "CDE")); - Assert.assertEquals("AB", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "Cde")); - Assert.assertEquals("ABCde", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "")); - Assert.assertEquals("ABCde", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", null)); - Assert.assertEquals("", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "ABCde")); - Assert.assertEquals("ABCde", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "ABCdef")); - Assert.assertNull(CharSequenceUtil.removeSuffixIgnoreCase(null, "ABCdef")); + Assertions.assertEquals("AB", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "cde")); + Assertions.assertEquals("AB", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "CDE")); + Assertions.assertEquals("AB", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "Cde")); + Assertions.assertEquals("ABCde", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "")); + Assertions.assertEquals("ABCde", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", null)); + Assertions.assertEquals("", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "ABCde")); + Assertions.assertEquals("ABCde", CharSequenceUtil.removeSuffixIgnoreCase("ABCde", "ABCdef")); + Assertions.assertNull(CharSequenceUtil.removeSuffixIgnoreCase(null, "ABCdef")); } @SuppressWarnings("ConstantValue") @Test public void trimToNullTest(){ String a = " "; - Assert.assertNull(CharSequenceUtil.trimToNull(a)); + Assertions.assertNull(CharSequenceUtil.trimToNull(a)); a = ""; - Assert.assertNull(CharSequenceUtil.trimToNull(a)); + Assertions.assertNull(CharSequenceUtil.trimToNull(a)); a = null; - Assert.assertNull(CharSequenceUtil.trimToNull(a)); + Assertions.assertNull(CharSequenceUtil.trimToNull(a)); } @Test public void containsAllTest() { final String a = "2142342422423423"; - Assert.assertTrue(StrUtil.containsAll(a, "214", "234")); + Assertions.assertTrue(StrUtil.containsAll(a, "214", "234")); } @Test @@ -180,12 +180,12 @@ public class CharSequenceUtilTest { final String emptyValue = ""; final Instant result1 = CharSequenceUtil.defaultIfEmpty(emptyValue, (v) -> DateUtil.parse(v, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant::now); - Assert.assertNotNull(result1); + Assertions.assertNotNull(result1); final String dateStr = "2020-10-23 15:12:30"; final Instant result2 = CharSequenceUtil.defaultIfEmpty(dateStr, (v) -> DateUtil.parse(v, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant::now); - Assert.assertNotNull(result2); + Assertions.assertNotNull(result2); } @Test @@ -193,32 +193,32 @@ public class CharSequenceUtilTest { final String emptyValue = " "; final Instant result1 = CharSequenceUtil.defaultIfBlank(emptyValue, (v) -> DateUtil.parse(v, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant::now); - Assert.assertNotNull(result1); + Assertions.assertNotNull(result1); final String dateStr = "2020-10-23 15:12:30"; final Instant result2 = CharSequenceUtil.defaultIfBlank(dateStr, (v) -> DateUtil.parse(v, DatePattern.NORM_DATETIME_PATTERN).toInstant(), Instant::now); - Assert.assertNotNull(result2); + Assertions.assertNotNull(result2); } @Test public void replaceLastTest() { final String str = "i am jack and jack"; final String result = StrUtil.replaceLast(str, "JACK", null, true); - Assert.assertEquals(result, "i am jack and "); + Assertions.assertEquals(result, "i am jack and "); } @Test public void replaceFirstTest() { final String str = "yes and yes i do"; final String result = StrUtil.replaceFirst(str, "YES", "", true); - Assert.assertEquals(result, " and yes i do"); + Assertions.assertEquals(result, " and yes i do"); } @Test public void issueI5YN49Test() { final String str = "A5E6005700000000000000000000000000000000000000090D0100000000000001003830"; - Assert.assertEquals("38", StrUtil.subByLength(str,-2,2)); + Assertions.assertEquals("38", StrUtil.subByLength(str,-2,2)); } @Test @@ -226,22 +226,22 @@ public class CharSequenceUtilTest { // -------------------------- None match ----------------------- - Assert.assertEquals("", CharSequenceUtil.commonPrefix("", "abc")); - Assert.assertEquals("", CharSequenceUtil.commonPrefix(null, "abc")); - Assert.assertEquals("", CharSequenceUtil.commonPrefix("abc", null)); - Assert.assertEquals("", CharSequenceUtil.commonPrefix("abc", "")); + Assertions.assertEquals("", CharSequenceUtil.commonPrefix("", "abc")); + Assertions.assertEquals("", CharSequenceUtil.commonPrefix(null, "abc")); + Assertions.assertEquals("", CharSequenceUtil.commonPrefix("abc", null)); + Assertions.assertEquals("", CharSequenceUtil.commonPrefix("abc", "")); - Assert.assertEquals("", CharSequenceUtil.commonPrefix("azzzj", "bzzzj")); + Assertions.assertEquals("", CharSequenceUtil.commonPrefix("azzzj", "bzzzj")); - Assert.assertEquals("", CharSequenceUtil.commonPrefix("english中文", "french中文")); + Assertions.assertEquals("", CharSequenceUtil.commonPrefix("english中文", "french中文")); // -------------------------- Matched ----------------------- - Assert.assertEquals("name_", CharSequenceUtil.commonPrefix("name_abc", "name_efg")); + Assertions.assertEquals("name_", CharSequenceUtil.commonPrefix("name_abc", "name_efg")); - Assert.assertEquals("zzzj", CharSequenceUtil.commonPrefix("zzzja", "zzzjb")); + Assertions.assertEquals("zzzj", CharSequenceUtil.commonPrefix("zzzja", "zzzjb")); - Assert.assertEquals("中文", CharSequenceUtil.commonPrefix("中文english", "中文french")); + Assertions.assertEquals("中文", CharSequenceUtil.commonPrefix("中文english", "中文french")); // { space * 10 } + "abc" final String str1 = CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 10) + "abc"; @@ -250,7 +250,7 @@ public class CharSequenceUtilTest { final String str2 = CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 5) + "efg"; // Expect common prefix: { space * 5 } - Assert.assertEquals(CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 5), CharSequenceUtil.commonPrefix(str1, str2)); + Assertions.assertEquals(CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 5), CharSequenceUtil.commonPrefix(str1, str2)); } @Test @@ -258,22 +258,22 @@ public class CharSequenceUtilTest { // -------------------------- None match ----------------------- - Assert.assertEquals("", CharSequenceUtil.commonSuffix("", "abc")); - Assert.assertEquals("", CharSequenceUtil.commonSuffix(null, "abc")); - Assert.assertEquals("", CharSequenceUtil.commonSuffix("abc", null)); - Assert.assertEquals("", CharSequenceUtil.commonSuffix("abc", "")); + Assertions.assertEquals("", CharSequenceUtil.commonSuffix("", "abc")); + Assertions.assertEquals("", CharSequenceUtil.commonSuffix(null, "abc")); + Assertions.assertEquals("", CharSequenceUtil.commonSuffix("abc", null)); + Assertions.assertEquals("", CharSequenceUtil.commonSuffix("abc", "")); - Assert.assertEquals("", CharSequenceUtil.commonSuffix("zzzja", "zzzjb")); + Assertions.assertEquals("", CharSequenceUtil.commonSuffix("zzzja", "zzzjb")); - Assert.assertEquals("", CharSequenceUtil.commonSuffix("中文english", "中文Korean")); + Assertions.assertEquals("", CharSequenceUtil.commonSuffix("中文english", "中文Korean")); // -------------------------- Matched ----------------------- - Assert.assertEquals("_name", CharSequenceUtil.commonSuffix("abc_name", "efg_name")); + Assertions.assertEquals("_name", CharSequenceUtil.commonSuffix("abc_name", "efg_name")); - Assert.assertEquals("zzzj", CharSequenceUtil.commonSuffix("abczzzj", "efgzzzj")); + Assertions.assertEquals("zzzj", CharSequenceUtil.commonSuffix("abczzzj", "efgzzzj")); - Assert.assertEquals("中文", CharSequenceUtil.commonSuffix("english中文", "Korean中文")); + Assertions.assertEquals("中文", CharSequenceUtil.commonSuffix("english中文", "Korean中文")); // "abc" + { space * 10 } final String str1 = "abc" + CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 10); @@ -282,6 +282,6 @@ public class CharSequenceUtilTest { final String str2 = "efg" + CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 15); // Expect common suffix: { space * 10 } - Assert.assertEquals(CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 10), CharSequenceUtil.commonSuffix(str1, str2)); + Assertions.assertEquals(CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 10), CharSequenceUtil.commonSuffix(str1, str2)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/NamingCaseTest.java b/hutool-core/src/test/java/cn/hutool/core/text/NamingCaseTest.java index addddfef2..011f947ad 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/NamingCaseTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/NamingCaseTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.text; import cn.hutool.core.map.Dict; import cn.hutool.core.util.CharUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class NamingCaseTest { @@ -13,14 +13,14 @@ public class NamingCaseTest { .set("Table_Test_Of_day","tableTestOfDay") .set("TableTestOfDay","TableTestOfDay") .set("abc_1d","abc1d") - .forEach((key, value) -> Assert.assertEquals(value, NamingCase.toCamelCase(key))); + .forEach((key, value) -> Assertions.assertEquals(value, NamingCase.toCamelCase(key))); } @Test public void toCamelCaseFromDashedTest() { Dict.of() .set("Table-Test-Of-day","tableTestOfDay") - .forEach((key, value) -> Assert.assertEquals(value, NamingCase.toCamelCase(key, CharUtil.DASHED))); + .forEach((key, value) -> Assertions.assertEquals(value, NamingCase.toCamelCase(key, CharUtil.DASHED))); } @Test @@ -39,12 +39,12 @@ public class NamingCaseTest { .set("customerNickV2", "customer_nick_v2") // https://gitee.com/dromara/hutool/issues/I4X9TT .set("DEPT_NAME","DEPT_NAME") - .forEach((key, value) -> Assert.assertEquals(value, NamingCase.toUnderlineCase(key))); + .forEach((key, value) -> Assertions.assertEquals(value, NamingCase.toUnderlineCase(key))); } @Test public void issueI5TVMUTest(){ // https://gitee.com/dromara/hutool/issues/I5TVMU - Assert.assertEquals("t1C1", NamingCase.toUnderlineCase("t1C1")); + Assertions.assertEquals("t1C1", NamingCase.toUnderlineCase("t1C1")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/PasswdStrengthTest.java b/hutool-core/src/test/java/cn/hutool/core/text/PasswdStrengthTest.java index 6d8006d2a..618672a53 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/PasswdStrengthTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/PasswdStrengthTest.java @@ -1,18 +1,18 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PasswdStrengthTest { @Test public void strengthTest(){ final String passwd = "2hAj5#mne-ix.86H"; - Assert.assertEquals(13, PasswdStrength.check(passwd)); + Assertions.assertEquals(13, PasswdStrength.check(passwd)); } @Test public void strengthNumberTest(){ final String passwd = "9999999999999"; - Assert.assertEquals(0, PasswdStrength.check(passwd)); + Assertions.assertEquals(0, PasswdStrength.check(passwd)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/PlaceholderParserTest.java b/hutool-core/src/test/java/cn/hutool/core/text/PlaceholderParserTest.java index bb7b7a3de..cd054cc92 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/PlaceholderParserTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/PlaceholderParserTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * test for {@link PlaceholderParser} @@ -14,28 +14,28 @@ public class PlaceholderParserTest { public void testParse() { String text = "i {a}{m} a {jvav} programmer"; PlaceholderParser parser = new PlaceholderParser(str -> str, "{", "}"); - Assert.assertEquals( + Assertions.assertEquals( "i am a jvav programmer", parser.apply(text) ); text = "i [a][m] a [jvav] programmer"; parser = new PlaceholderParser(str -> str, "[", "]"); - Assert.assertEquals( + Assertions.assertEquals( "i am a jvav programmer", parser.apply(text) ); text = "i \\[a][[m\\]] a [jvav] programmer"; parser = new PlaceholderParser(str -> str, "[", "]"); - Assert.assertEquals( + Assertions.assertEquals( "i [a][m] a jvav programmer", parser.apply(text) ); text = "i /[a][[m/]] a [jvav] programmer"; parser = new PlaceholderParser(str -> str, "[", "]", '/'); - Assert.assertEquals( + Assertions.assertEquals( "i [a][m] a jvav programmer", parser.apply(text) ); diff --git a/hutool-core/src/test/java/cn/hutool/core/text/SplitUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/text/SplitUtilTest.java index 5c004f1bd..5293a1bf1 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/SplitUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/SplitUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.text; 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; import java.util.List; @@ -11,27 +11,27 @@ public class SplitUtilTest { @Test public void issueI6FKSITest(){ // issue:I6FKSI - Assert.assertThrows(IllegalArgumentException.class, () -> SplitUtil.splitByLength("test length 0", 0)); + Assertions.assertThrows(IllegalArgumentException.class, () -> SplitUtil.splitByLength("test length 0", 0)); } @Test public void splitToLongTest() { final String str = "1,2,3,4, 5"; long[] longArray = SplitUtil.splitTo(str, ",", long[].class); - Assert.assertArrayEquals(new long[]{1, 2, 3, 4, 5}, longArray); + Assertions.assertArrayEquals(new long[]{1, 2, 3, 4, 5}, longArray); longArray = SplitUtil.splitTo(str, ",", long[].class); - Assert.assertArrayEquals(new long[]{1, 2, 3, 4, 5}, longArray); + Assertions.assertArrayEquals(new long[]{1, 2, 3, 4, 5}, longArray); } @Test public void splitToIntTest() { final String str = "1,2,3,4, 5"; int[] intArray = SplitUtil.splitTo(str, ",", int[].class); - Assert.assertArrayEquals(new int[]{1, 2, 3, 4, 5}, intArray); + Assertions.assertArrayEquals(new int[]{1, 2, 3, 4, 5}, intArray); intArray = SplitUtil.splitTo(str, ",", int[].class); - Assert.assertArrayEquals(new int[]{1, 2, 3, 4, 5}, intArray); + Assertions.assertArrayEquals(new int[]{1, 2, 3, 4, 5}, intArray); } @Test @@ -39,12 +39,12 @@ public class SplitUtilTest { final String str = "a,b ,c,d,,e"; final List split = SplitUtil.split(str, ",", -1, true, true); // 测试空是否被去掉 - Assert.assertEquals(5, split.size()); + Assertions.assertEquals(5, split.size()); // 测试去掉两边空白符是否生效 - Assert.assertEquals("b", split.get(1)); + Assertions.assertEquals("b", split.get(1)); final String[] strings = SplitUtil.splitToArray("abc/", StrUtil.SLASH); - Assert.assertEquals(2, strings.length); + Assertions.assertEquals(2, strings.length); } @Test @@ -52,14 +52,14 @@ public class SplitUtilTest { final String str = ""; final List split = SplitUtil.split(str, ",", -1, true, true); // 测试空是否被去掉 - Assert.assertEquals(0, split.size()); + Assertions.assertEquals(0, split.size()); } @Test public void splitToArrayNullTest() { final String[] strings = SplitUtil.splitToArray(null, "."); - Assert.assertNotNull(strings); - Assert.assertEquals(0, strings.length); + Assertions.assertNotNull(strings); + Assertions.assertEquals(0, strings.length); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrCheckerTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrCheckerTest.java index 1d9ee4240..d43ef603c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrCheckerTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrCheckerTest.java @@ -1,43 +1,43 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class StrCheckerTest { @Test public void isEmptyTest() { - Assert.assertTrue(StrUtil.isEmpty(null)); - Assert.assertTrue(StrUtil.isEmpty("")); + Assertions.assertTrue(StrUtil.isEmpty(null)); + Assertions.assertTrue(StrUtil.isEmpty("")); - Assert.assertFalse(StrUtil.isEmpty(" \t\n")); - Assert.assertFalse(StrUtil.isEmpty("abc")); + Assertions.assertFalse(StrUtil.isEmpty(" \t\n")); + Assertions.assertFalse(StrUtil.isEmpty("abc")); } @Test public void isNotEmptyTest() { - Assert.assertFalse(StrUtil.isNotEmpty(null)); - Assert.assertFalse(StrUtil.isNotEmpty("")); + Assertions.assertFalse(StrUtil.isNotEmpty(null)); + Assertions.assertFalse(StrUtil.isNotEmpty("")); - Assert.assertTrue(StrUtil.isNotEmpty(" \t\n")); - Assert.assertTrue(StrUtil.isNotEmpty("abc")); + Assertions.assertTrue(StrUtil.isNotEmpty(" \t\n")); + Assertions.assertTrue(StrUtil.isNotEmpty("abc")); } @Test public void isBlankTest() { - Assert.assertTrue(StrUtil.isBlank(null)); - Assert.assertTrue(StrUtil.isBlank("")); - Assert.assertTrue(StrUtil.isBlank(" \t\n")); + Assertions.assertTrue(StrUtil.isBlank(null)); + Assertions.assertTrue(StrUtil.isBlank("")); + Assertions.assertTrue(StrUtil.isBlank(" \t\n")); - Assert.assertFalse(StrUtil.isBlank("abc")); + Assertions.assertFalse(StrUtil.isBlank("abc")); } @Test public void isNotBlankTest() { - Assert.assertFalse(StrUtil.isNotBlank(null)); - Assert.assertFalse(StrUtil.isNotBlank("")); - Assert.assertFalse(StrUtil.isNotBlank(" \t\n")); + Assertions.assertFalse(StrUtil.isNotBlank(null)); + Assertions.assertFalse(StrUtil.isNotBlank("")); + Assertions.assertFalse(StrUtil.isNotBlank(" \t\n")); - Assert.assertTrue(StrUtil.isNotBlank("abc")); + Assertions.assertTrue(StrUtil.isNotBlank("abc")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrJoinerTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrJoinerTest.java index b666768a5..619dd3484 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrJoinerTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrJoinerTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.text; 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.util.ArrayList; import java.util.List; @@ -14,20 +14,20 @@ public class StrJoinerTest { public void joinIntArrayTest(){ final int[] a = {1,2,3,4,5}; final StrJoiner append = StrJoiner.of(",").append(a); - Assert.assertEquals("1,2,3,4,5", append.toString()); + Assertions.assertEquals("1,2,3,4,5", append.toString()); } @Test public void joinEmptyTest(){ final List list = new ArrayList<>(); final StrJoiner append = StrJoiner.of(",").append(list); - Assert.assertEquals("", append.toString()); + Assertions.assertEquals("", append.toString()); } @Test public void noJoinTest(){ final StrJoiner append = StrJoiner.of(","); - Assert.assertEquals("", append.toString()); + Assertions.assertEquals("", append.toString()); } @Test @@ -36,7 +36,7 @@ public class StrJoinerTest { append.append(new Object[]{ListUtil.view("1", "2"), SetUtil.ofLinked("3", "4") }); - Assert.assertEquals("1,2,3,4", append.toString()); + Assertions.assertEquals("1,2,3,4", append.toString()); } @Test @@ -46,21 +46,21 @@ public class StrJoinerTest { .append("1") .append((Object)null) .append("3"); - Assert.assertEquals("1,3", append.toString()); + Assertions.assertEquals("1,3", append.toString()); append = StrJoiner.of(",") .setNullMode(StrJoiner.NullMode.TO_EMPTY) .append("1") .append((Object)null) .append("3"); - Assert.assertEquals("1,,3", append.toString()); + Assertions.assertEquals("1,,3", append.toString()); append = StrJoiner.of(",") .setNullMode(StrJoiner.NullMode.NULL_STRING) .append("1") .append((Object)null) .append("3"); - Assert.assertEquals("1,null,3", append.toString()); + Assertions.assertEquals("1,null,3", append.toString()); } @Test @@ -69,23 +69,23 @@ public class StrJoinerTest { .append("1") .append("2") .append("3"); - Assert.assertEquals("[1,2,3]", append.toString()); + Assertions.assertEquals("[1,2,3]", append.toString()); append = StrJoiner.of(",", "[", "]") .setWrapElement(true) .append("1") .append("2") .append("3"); - Assert.assertEquals("[1],[2],[3]", append.toString()); + Assertions.assertEquals("[1],[2],[3]", append.toString()); } @Test public void lengthTest(){ final StrJoiner joiner = StrJoiner.of(",", "[", "]"); - Assert.assertEquals(joiner.toString().length(), joiner.length()); + Assertions.assertEquals(joiner.toString().length(), joiner.length()); joiner.append("123"); - Assert.assertEquals(joiner.toString().length(), joiner.length()); + Assertions.assertEquals(joiner.toString().length(), joiner.length()); } @Test @@ -97,6 +97,6 @@ public class StrJoinerTest { joiner1.append("789"); final StrJoiner merge = joiner1.merge(joiner2); - Assert.assertEquals("[123,456,789]", merge.toString()); + Assertions.assertEquals("[123,456,789]", merge.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java index d5f88f953..277cad814 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -11,13 +11,13 @@ public class StrMatcherTest { public void matcherTest(){ final StrMatcher strMatcher = new StrMatcher("${name}-${age}-${gender}-${country}-${province}-${city}-${status}"); final Map match = strMatcher.match("小明-19-男-中国-河南-郑州-已婚"); - Assert.assertEquals("小明", match.get("name")); - Assert.assertEquals("19", match.get("age")); - Assert.assertEquals("男", match.get("gender")); - Assert.assertEquals("中国", match.get("country")); - Assert.assertEquals("河南", match.get("province")); - Assert.assertEquals("郑州", match.get("city")); - Assert.assertEquals("已婚", match.get("status")); + Assertions.assertEquals("小明", match.get("name")); + Assertions.assertEquals("19", match.get("age")); + Assertions.assertEquals("男", match.get("gender")); + Assertions.assertEquals("中国", match.get("country")); + Assertions.assertEquals("河南", match.get("province")); + Assertions.assertEquals("郑州", match.get("city")); + Assertions.assertEquals("已婚", match.get("status")); } @Test @@ -25,7 +25,7 @@ public class StrMatcherTest { // 当有无匹配项的时候,按照全不匹配对待 final StrMatcher strMatcher = new StrMatcher("${name}-${age}-${gender}-${country}-${province}-${city}-${status}"); final Map match = strMatcher.match("小明-19-男-中国-河南-郑州"); - Assert.assertEquals(0, match.size()); + Assertions.assertEquals(0, match.size()); } @Test @@ -34,7 +34,7 @@ public class StrMatcherTest { final StrMatcher strMatcher = new StrMatcher("${name}经过${year}年"); final Map match = strMatcher.match("小明经过20年,成长为一个大人。"); //Console.log(match); - Assert.assertEquals("小明", match.get("name")); - Assert.assertEquals("20", match.get("year")); + Assertions.assertEquals("小明", match.get("name")); + Assertions.assertEquals("20", match.get("year")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrRegionMatcherTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrRegionMatcherTest.java index bab77315d..250e03eaf 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrRegionMatcherTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrRegionMatcherTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class StrRegionMatcherTest { @Test @@ -9,7 +9,7 @@ public class StrRegionMatcherTest { final StrRegionMatcher matcher = new StrRegionMatcher( false, false, true); final boolean test = matcher.test("abcdef", "ab"); - Assert.assertTrue(test); + Assertions.assertTrue(test); } @Test @@ -17,7 +17,7 @@ public class StrRegionMatcherTest { final StrRegionMatcher matcher = new StrRegionMatcher( false, false, false); final boolean test = matcher.test("abcdef", "ef"); - Assert.assertTrue(test); + Assertions.assertTrue(test); } @Test @@ -25,7 +25,7 @@ public class StrRegionMatcherTest { final StrRegionMatcher matcher = new StrRegionMatcher( false, false, 1); final boolean test = matcher.test("abcdef", "bc"); - Assert.assertTrue(test); + Assertions.assertTrue(test); } @Test @@ -33,7 +33,7 @@ public class StrRegionMatcherTest { final StrRegionMatcher matcher = new StrRegionMatcher( false, false, -2); final boolean test = matcher.test("abcdef", "de"); - Assert.assertTrue(test); + Assertions.assertTrue(test); } @Test @@ -42,7 +42,7 @@ public class StrRegionMatcherTest { final StrRegionMatcher matcher = new StrRegionMatcher( false, false, 5); final boolean test = matcher.test("abcdef", "de"); - Assert.assertFalse(test); + Assertions.assertFalse(test); } @Test @@ -51,6 +51,6 @@ public class StrRegionMatcherTest { final StrRegionMatcher matcher = new StrRegionMatcher( false, false, 6); final boolean test = matcher.test("abcdef", "de"); - Assert.assertFalse(test); + Assertions.assertFalse(test); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrRepeaterTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrRepeaterTest.java index 8187727fd..9fd7d471a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrRepeaterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrRepeaterTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class StrRepeaterTest { @@ -9,13 +9,13 @@ public class StrRepeaterTest { public void repeatByLengthTest() { // 如果指定长度非指定字符串的整数倍,截断到固定长度 final String ab = StrRepeater.of(5).repeatByLength("ab"); - Assert.assertEquals("ababa", ab); + Assertions.assertEquals("ababa", ab); } @Test public void repeatByLengthTest2() { // 如果指定长度小于字符串本身的长度,截断之 final String ab = StrRepeater.of(2).repeatByLength("abcde"); - Assert.assertEquals("ab", ab); + Assertions.assertEquals("ab", ab); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java index 66015f20d..f795f283d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrUtilTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.map.Dict; import cn.hutool.core.text.split.SplitUtil; import cn.hutool.core.util.CharUtil; 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; import java.util.LinkedList; import java.util.List; @@ -19,32 +19,32 @@ public class StrUtilTest { @Test public void isBlankTest() { final String blank = "   "; - Assert.assertTrue(StrUtil.isBlank(blank)); + Assertions.assertTrue(StrUtil.isBlank(blank)); } @Test public void trimTest() { final String blank = " 哈哈  "; final String trim = StrUtil.trim(blank); - Assert.assertEquals("哈哈", trim); + Assertions.assertEquals("哈哈", trim); } @Test public void trimNewLineTest() { String str = "\r\naaa"; - Assert.assertEquals("aaa", StrUtil.trim(str)); + Assertions.assertEquals("aaa", StrUtil.trim(str)); str = "\raaa"; - Assert.assertEquals("aaa", StrUtil.trim(str)); + Assertions.assertEquals("aaa", StrUtil.trim(str)); str = "\naaa"; - Assert.assertEquals("aaa", StrUtil.trim(str)); + Assertions.assertEquals("aaa", StrUtil.trim(str)); str = "\r\n\r\naaa"; - Assert.assertEquals("aaa", StrUtil.trim(str)); + Assertions.assertEquals("aaa", StrUtil.trim(str)); } @Test public void trimTabTest() { final String str = "\taaa"; - Assert.assertEquals("aaa", StrUtil.trim(str)); + Assertions.assertEquals("aaa", StrUtil.trim(str)); } @Test @@ -52,192 +52,192 @@ public class StrUtilTest { // 包含:制表符、英文空格、不间断空白符、全角空格 final String str = " 你 好 "; final String cleanBlank = StrUtil.cleanBlank(str); - Assert.assertEquals("你好", cleanBlank); + Assertions.assertEquals("你好", cleanBlank); } @Test public void cutTest() { final String str = "aaabbbcccdddaadfdfsdfsdf0"; final String[] cut = StrUtil.cut(str, 4); - Assert.assertArrayEquals(new String[]{"aaab", "bbcc", "cddd", "aadf", "dfsd", "fsdf", "0"}, cut); + Assertions.assertArrayEquals(new String[]{"aaab", "bbcc", "cddd", "aadf", "dfsd", "fsdf", "0"}, cut); } @Test public void splitTest2() { final String str = "a.b."; final List split = SplitUtil.split(str, "."); - Assert.assertEquals(3, split.size()); - Assert.assertEquals("b", split.get(1)); - Assert.assertEquals("", split.get(2)); + Assertions.assertEquals(3, split.size()); + Assertions.assertEquals("b", split.get(1)); + Assertions.assertEquals("", split.get(2)); } @Test public void splitNullTest() { - Assert.assertEquals(0, SplitUtil.split(null, ".").size()); + Assertions.assertEquals(0, SplitUtil.split(null, ".").size()); } @Test public void formatTest() { final String template = "你好,我是{name},我的电话是:{phone}"; final String result = StrUtil.format(template, Dict.of().set("name", "张三").set("phone", "13888881111")); - Assert.assertEquals("你好,我是张三,我的电话是:13888881111", result); + Assertions.assertEquals("你好,我是张三,我的电话是:13888881111", result); final String result2 = StrUtil.format(template, Dict.of().set("name", "张三").set("phone", null)); - Assert.assertEquals("你好,我是张三,我的电话是:{phone}", result2); + Assertions.assertEquals("你好,我是张三,我的电话是:{phone}", result2); } @Test public void stripTest() { String str = "abcd123"; String strip = StrUtil.strip(str, "ab", "23"); - Assert.assertEquals("cd1", strip); + Assertions.assertEquals("cd1", strip); str = "abcd123"; strip = StrUtil.strip(str, "ab", ""); - Assert.assertEquals("cd123", strip); + Assertions.assertEquals("cd123", strip); str = "abcd123"; strip = StrUtil.strip(str, null, ""); - Assert.assertEquals("abcd123", strip); + Assertions.assertEquals("abcd123", strip); str = "abcd123"; strip = StrUtil.strip(str, null, "567"); - Assert.assertEquals("abcd123", strip); + Assertions.assertEquals("abcd123", strip); - Assert.assertEquals("", StrUtil.strip("a", "a")); - Assert.assertEquals("", StrUtil.strip("a", "a", "b")); + Assertions.assertEquals("", StrUtil.strip("a", "a")); + Assertions.assertEquals("", StrUtil.strip("a", "a", "b")); } @Test public void stripIgnoreCaseTest() { String str = "abcd123"; String strip = StrUtil.stripIgnoreCase(str, "Ab", "23"); - Assert.assertEquals("cd1", strip); + Assertions.assertEquals("cd1", strip); str = "abcd123"; strip = StrUtil.stripIgnoreCase(str, "AB", ""); - Assert.assertEquals("cd123", strip); + Assertions.assertEquals("cd123", strip); str = "abcd123"; strip = StrUtil.stripIgnoreCase(str, "ab", ""); - Assert.assertEquals("cd123", strip); + Assertions.assertEquals("cd123", strip); str = "abcd123"; strip = StrUtil.stripIgnoreCase(str, null, ""); - Assert.assertEquals("abcd123", strip); + Assertions.assertEquals("abcd123", strip); str = "abcd123"; strip = StrUtil.stripIgnoreCase(str, null, "567"); - Assert.assertEquals("abcd123", strip); + Assertions.assertEquals("abcd123", strip); } @Test public void indexOfIgnoreCaseTest() { - Assert.assertEquals(-1, StrUtil.indexOfIgnoreCase(null, "balabala", 0)); - Assert.assertEquals(-1, StrUtil.indexOfIgnoreCase("balabala", null, 0)); - Assert.assertEquals(0, StrUtil.indexOfIgnoreCase("", "", 0)); - Assert.assertEquals(0, StrUtil.indexOfIgnoreCase("aabaabaa", "A", 0)); - Assert.assertEquals(2, StrUtil.indexOfIgnoreCase("aabaabaa", "B", 0)); - Assert.assertEquals(1, StrUtil.indexOfIgnoreCase("aabaabaa", "AB", 0)); - Assert.assertEquals(5, StrUtil.indexOfIgnoreCase("aabaabaa", "B", 3)); - Assert.assertEquals(-1, StrUtil.indexOfIgnoreCase("aabaabaa", "B", 9)); - Assert.assertEquals(2, StrUtil.indexOfIgnoreCase("aabaabaa", "B", -1)); - Assert.assertEquals(-1, StrUtil.indexOfIgnoreCase("aabaabaa", "", 2)); - Assert.assertEquals(-1, StrUtil.indexOfIgnoreCase("abc", "", 9)); + Assertions.assertEquals(-1, StrUtil.indexOfIgnoreCase(null, "balabala", 0)); + Assertions.assertEquals(-1, StrUtil.indexOfIgnoreCase("balabala", null, 0)); + Assertions.assertEquals(0, StrUtil.indexOfIgnoreCase("", "", 0)); + Assertions.assertEquals(0, StrUtil.indexOfIgnoreCase("aabaabaa", "A", 0)); + Assertions.assertEquals(2, StrUtil.indexOfIgnoreCase("aabaabaa", "B", 0)); + Assertions.assertEquals(1, StrUtil.indexOfIgnoreCase("aabaabaa", "AB", 0)); + Assertions.assertEquals(5, StrUtil.indexOfIgnoreCase("aabaabaa", "B", 3)); + Assertions.assertEquals(-1, StrUtil.indexOfIgnoreCase("aabaabaa", "B", 9)); + Assertions.assertEquals(2, StrUtil.indexOfIgnoreCase("aabaabaa", "B", -1)); + Assertions.assertEquals(-1, StrUtil.indexOfIgnoreCase("aabaabaa", "", 2)); + Assertions.assertEquals(-1, StrUtil.indexOfIgnoreCase("abc", "", 9)); } @Test public void lastIndexOfTest() { final String a = "aabbccddcc"; final int lastIndexOf = StrUtil.lastIndexOf(a, "c", 0, false); - Assert.assertEquals(-1, lastIndexOf); + Assertions.assertEquals(-1, lastIndexOf); } @Test public void lastIndexOfIgnoreCaseTest() { - Assert.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase(null, "balabala", 0)); - Assert.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("balabala", null)); - Assert.assertEquals(0, StrUtil.lastIndexOfIgnoreCase("", "")); - Assert.assertEquals(7, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "A")); - Assert.assertEquals(5, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B")); - Assert.assertEquals(4, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "AB")); - Assert.assertEquals(2, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B", 3)); - Assert.assertEquals(5, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B", 9)); - Assert.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B", -1)); - Assert.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "", 2)); - Assert.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("abc", "", 9)); - Assert.assertEquals(0, StrUtil.lastIndexOfIgnoreCase("AAAcsd", "aaa")); + Assertions.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase(null, "balabala", 0)); + Assertions.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("balabala", null)); + Assertions.assertEquals(0, StrUtil.lastIndexOfIgnoreCase("", "")); + Assertions.assertEquals(7, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "A")); + Assertions.assertEquals(5, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B")); + Assertions.assertEquals(4, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "AB")); + Assertions.assertEquals(2, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B", 3)); + Assertions.assertEquals(5, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B", 9)); + Assertions.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "B", -1)); + Assertions.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("aabaabaa", "", 2)); + Assertions.assertEquals(-1, StrUtil.lastIndexOfIgnoreCase("abc", "", 9)); + Assertions.assertEquals(0, StrUtil.lastIndexOfIgnoreCase("AAAcsd", "aaa")); } @Test public void replaceTest() { String string = StrUtil.replace("aabbccdd", 2, 6, '*'); - Assert.assertEquals("aa****dd", string); + Assertions.assertEquals("aa****dd", string); string = StrUtil.replace("aabbccdd", 2, 12, '*'); - Assert.assertEquals("aa******", string); + Assertions.assertEquals("aa******", string); final String emoji = StrUtil.replace("\uD83D\uDE00aabb\uD83D\uDE00ccdd", 2, 6, '*'); - Assert.assertEquals("\uD83D\uDE00a****ccdd", emoji); + Assertions.assertEquals("\uD83D\uDE00a****ccdd", emoji); } @Test public void replaceTest2() { final String result = StrUtil.replace("123", "2", "3"); - Assert.assertEquals("133", result); + Assertions.assertEquals("133", result); } @Test public void replaceTest4() { final String a = "1039"; final String result = StrUtil.padPre(a, 8, "0"); //在字符串1039前补4个0 - Assert.assertEquals("00001039", result); + Assertions.assertEquals("00001039", result); final String aa = "1039"; final String result1 = StrUtil.padPre(aa, -1, "0"); //在字符串1039前补4个0 - Assert.assertEquals("103", result1); + Assertions.assertEquals("103", result1); } @Test public void replaceTest5() { final String a = "\uD853\uDC09秀秀"; final String result = StrUtil.replace(a, 1, a.length(), '*'); - Assert.assertEquals("\uD853\uDC09**", result); + Assertions.assertEquals("\uD853\uDC09**", result); final String aa = "规划大师"; final String result1 = StrUtil.replace(aa, 2, a.length(), '*'); - Assert.assertEquals("规划**", result1); + Assertions.assertEquals("规划**", result1); } @Test public void upperFirstTest() { final StringBuilder sb = new StringBuilder("KEY"); final String s = StrUtil.upperFirst(sb); - Assert.assertEquals(s, sb.toString()); + Assertions.assertEquals(s, sb.toString()); } @Test public void lowerFirstTest() { final StringBuilder sb = new StringBuilder("KEY"); final String s = StrUtil.lowerFirst(sb); - Assert.assertEquals("kEY", s); + Assertions.assertEquals("kEY", s); } @Test public void subTest() { final String a = "abcderghigh"; final String pre = StrUtil.sub(a, -5, a.length()); - Assert.assertEquals("ghigh", pre); + Assertions.assertEquals("ghigh", pre); } @SuppressWarnings("SimplifiableAssertion") @Test public void subPreTest() { - Assert.assertEquals(StrUtil.subPre(null, 3), null); - Assert.assertEquals(StrUtil.subPre("ab", 3), "ab"); - Assert.assertEquals(StrUtil.subPre("abc", 3), "abc"); - Assert.assertEquals(StrUtil.subPre("abcd", 3), "abc"); - Assert.assertEquals(StrUtil.subPre("abcd", -3), "a"); - Assert.assertEquals(StrUtil.subPre("ab", 3), "ab"); + Assertions.assertEquals(StrUtil.subPre(null, 3), null); + Assertions.assertEquals(StrUtil.subPre("ab", 3), "ab"); + Assertions.assertEquals(StrUtil.subPre("abc", 3), "abc"); + Assertions.assertEquals(StrUtil.subPre("abcd", 3), "abc"); + Assertions.assertEquals(StrUtil.subPre("abcd", -3), "a"); + Assertions.assertEquals(StrUtil.subPre("ab", 3), "ab"); } @Test @@ -247,176 +247,176 @@ public class StrUtilTest { // 不正确的子字符串 final String wrongAnswer = StrUtil.sub(test, 0, 3); - Assert.assertNotEquals("\uD83E\uDD14\uD83D\uDC4D\uD83C\uDF53", wrongAnswer); + Assertions.assertNotEquals("\uD83E\uDD14\uD83D\uDC4D\uD83C\uDF53", wrongAnswer); // 正确的子字符串 final String rightAnswer = StrUtil.subByCodePoint(test, 0, 3); - Assert.assertEquals("\uD83E\uDD14\uD83D\uDC4D\uD83C\uDF53", rightAnswer); + Assertions.assertEquals("\uD83E\uDD14\uD83D\uDC4D\uD83C\uDF53", rightAnswer); } @Test public void subBeforeTest() { final String a = "abcderghigh"; String pre = StrUtil.subBefore(a, "d", false); - Assert.assertEquals("abc", pre); + Assertions.assertEquals("abc", pre); pre = StrUtil.subBefore(a, 'd', false); - Assert.assertEquals("abc", pre); + Assertions.assertEquals("abc", pre); pre = StrUtil.subBefore(a, 'a', false); - Assert.assertEquals("", pre); + Assertions.assertEquals("", pre); //找不到返回原串 pre = StrUtil.subBefore(a, 'k', false); - Assert.assertEquals(a, pre); + Assertions.assertEquals(a, pre); pre = StrUtil.subBefore(a, 'k', true); - Assert.assertEquals(a, pre); + Assertions.assertEquals(a, pre); } @Test public void subAfterTest() { final String a = "abcderghigh"; String pre = StrUtil.subAfter(a, "d", false); - Assert.assertEquals("erghigh", pre); + Assertions.assertEquals("erghigh", pre); pre = StrUtil.subAfter(a, 'd', false); - Assert.assertEquals("erghigh", pre); + Assertions.assertEquals("erghigh", pre); pre = StrUtil.subAfter(a, 'h', true); - Assert.assertEquals("", pre); + Assertions.assertEquals("", pre); //找不到字符返回空串 pre = StrUtil.subAfter(a, 'k', false); - Assert.assertEquals("", pre); + Assertions.assertEquals("", pre); pre = StrUtil.subAfter(a, 'k', true); - Assert.assertEquals("", pre); + Assertions.assertEquals("", pre); } @Test public void subSufByLengthTest() { - Assert.assertEquals("cde", StrUtil.subSufByLength("abcde", 3)); - Assert.assertEquals("", StrUtil.subSufByLength("abcde", -1)); - Assert.assertEquals("", StrUtil.subSufByLength("abcde", 0)); - Assert.assertEquals("abcde", StrUtil.subSufByLength("abcde", 5)); - Assert.assertEquals("abcde", StrUtil.subSufByLength("abcde", 10)); + Assertions.assertEquals("cde", StrUtil.subSufByLength("abcde", 3)); + Assertions.assertEquals("", StrUtil.subSufByLength("abcde", -1)); + Assertions.assertEquals("", StrUtil.subSufByLength("abcde", 0)); + Assertions.assertEquals("abcde", StrUtil.subSufByLength("abcde", 5)); + Assertions.assertEquals("abcde", StrUtil.subSufByLength("abcde", 10)); } @Test public void repeatAndJoinTest() { String repeatAndJoin = StrUtil.repeatAndJoin("?", 5, ","); - Assert.assertEquals("?,?,?,?,?", repeatAndJoin); + Assertions.assertEquals("?,?,?,?,?", repeatAndJoin); repeatAndJoin = StrUtil.repeatAndJoin("?", 0, ","); - Assert.assertEquals("", repeatAndJoin); + Assertions.assertEquals("", repeatAndJoin); repeatAndJoin = StrUtil.repeatAndJoin("?", 5, null); - Assert.assertEquals("?????", repeatAndJoin); + Assertions.assertEquals("?????", repeatAndJoin); } @Test public void moveTest() { final String str = "aaaaaaa22222bbbbbbb"; String result = StrUtil.move(str, 7, 12, -3); - Assert.assertEquals("aaaa22222aaabbbbbbb", result); + Assertions.assertEquals("aaaa22222aaabbbbbbb", result); result = StrUtil.move(str, 7, 12, -4); - Assert.assertEquals("aaa22222aaaabbbbbbb", result); + Assertions.assertEquals("aaa22222aaaabbbbbbb", result); result = StrUtil.move(str, 7, 12, -7); - Assert.assertEquals("22222aaaaaaabbbbbbb", result); + Assertions.assertEquals("22222aaaaaaabbbbbbb", result); result = StrUtil.move(str, 7, 12, -20); - Assert.assertEquals("aaaaaa22222abbbbbbb", result); + Assertions.assertEquals("aaaaaa22222abbbbbbb", result); result = StrUtil.move(str, 7, 12, 3); - Assert.assertEquals("aaaaaaabbb22222bbbb", result); + Assertions.assertEquals("aaaaaaabbb22222bbbb", result); result = StrUtil.move(str, 7, 12, 7); - Assert.assertEquals("aaaaaaabbbbbbb22222", result); + Assertions.assertEquals("aaaaaaabbbbbbb22222", result); result = StrUtil.move(str, 7, 12, 20); - Assert.assertEquals("aaaaaaab22222bbbbbb", result); + Assertions.assertEquals("aaaaaaab22222bbbbbb", result); result = StrUtil.move(str, 7, 12, 0); - Assert.assertEquals("aaaaaaa22222bbbbbbb", result); + Assertions.assertEquals("aaaaaaa22222bbbbbbb", result); } @Test public void removePrefixIgnorecaseTest() { final String a = "aaabbb"; String prefix = "aaa"; - Assert.assertEquals("bbb", StrUtil.removePrefixIgnoreCase(a, prefix)); + Assertions.assertEquals("bbb", StrUtil.removePrefixIgnoreCase(a, prefix)); prefix = "AAA"; - Assert.assertEquals("bbb", StrUtil.removePrefixIgnoreCase(a, prefix)); + Assertions.assertEquals("bbb", StrUtil.removePrefixIgnoreCase(a, prefix)); prefix = "AAABBB"; - Assert.assertEquals("", StrUtil.removePrefixIgnoreCase(a, prefix)); + Assertions.assertEquals("", StrUtil.removePrefixIgnoreCase(a, prefix)); } @Test public void maxLengthTest() { final String text = "我是一段正文,很长的正文,需要截取的正文"; String str = StrUtil.maxLength(text, 5); - Assert.assertEquals("我是一段正...", str); + Assertions.assertEquals("我是一段正...", str); str = StrUtil.maxLength(text, 21); - Assert.assertEquals(text, str); + Assertions.assertEquals(text, str); str = StrUtil.maxLength(text, 50); - Assert.assertEquals(text, str); + Assertions.assertEquals(text, str); } @Test public void containsAnyTest() { //字符 boolean containsAny = StrUtil.containsAny("aaabbbccc", 'a', 'd'); - Assert.assertTrue(containsAny); + Assertions.assertTrue(containsAny); containsAny = StrUtil.containsAny("aaabbbccc", 'e', 'd'); - Assert.assertFalse(containsAny); + Assertions.assertFalse(containsAny); containsAny = StrUtil.containsAny("aaabbbccc", 'd', 'c'); - Assert.assertTrue(containsAny); + Assertions.assertTrue(containsAny); //字符串 containsAny = StrUtil.containsAny("aaabbbccc", "a", "d"); - Assert.assertTrue(containsAny); + Assertions.assertTrue(containsAny); containsAny = StrUtil.containsAny("aaabbbccc", "e", "d"); - Assert.assertFalse(containsAny); + Assertions.assertFalse(containsAny); containsAny = StrUtil.containsAny("aaabbbccc", "d", "c"); - Assert.assertTrue(containsAny); + Assertions.assertTrue(containsAny); } @Test public void centerTest() { - Assert.assertNull(StrUtil.center(null, 10)); - Assert.assertEquals(" ", StrUtil.center("", 4)); - Assert.assertEquals("ab", StrUtil.center("ab", -1)); - Assert.assertEquals(" ab ", StrUtil.center("ab", 4)); - Assert.assertEquals("abcd", StrUtil.center("abcd", 2)); - Assert.assertEquals(" a ", StrUtil.center("a", 4)); + Assertions.assertNull(StrUtil.center(null, 10)); + Assertions.assertEquals(" ", StrUtil.center("", 4)); + Assertions.assertEquals("ab", StrUtil.center("ab", -1)); + Assertions.assertEquals(" ab ", StrUtil.center("ab", 4)); + Assertions.assertEquals("abcd", StrUtil.center("abcd", 2)); + Assertions.assertEquals(" a ", StrUtil.center("a", 4)); } @Test public void padPreTest() { - Assert.assertNull(StrUtil.padPre(null, 10, ' ')); - Assert.assertEquals("001", StrUtil.padPre("1", 3, '0')); - Assert.assertEquals("12", StrUtil.padPre("123", 2, '0')); + Assertions.assertNull(StrUtil.padPre(null, 10, ' ')); + Assertions.assertEquals("001", StrUtil.padPre("1", 3, '0')); + Assertions.assertEquals("12", StrUtil.padPre("123", 2, '0')); - Assert.assertNull(StrUtil.padPre(null, 10, "AA")); - Assert.assertEquals("AB1", StrUtil.padPre("1", 3, "ABC")); - Assert.assertEquals("12", StrUtil.padPre("123", 2, "ABC")); + Assertions.assertNull(StrUtil.padPre(null, 10, "AA")); + Assertions.assertEquals("AB1", StrUtil.padPre("1", 3, "ABC")); + Assertions.assertEquals("12", StrUtil.padPre("123", 2, "ABC")); } @Test public void padAfterTest() { - Assert.assertNull(StrUtil.padAfter(null, 10, ' ')); - Assert.assertEquals("100", StrUtil.padAfter("1", 3, '0')); - Assert.assertEquals("23", StrUtil.padAfter("123", 2, '0')); - Assert.assertEquals("", StrUtil.padAfter("123", -1, '0')); + Assertions.assertNull(StrUtil.padAfter(null, 10, ' ')); + Assertions.assertEquals("100", StrUtil.padAfter("1", 3, '0')); + Assertions.assertEquals("23", StrUtil.padAfter("123", 2, '0')); + Assertions.assertEquals("", StrUtil.padAfter("123", -1, '0')); - Assert.assertNull(StrUtil.padAfter(null, 10, "ABC")); - Assert.assertEquals("1AB", StrUtil.padAfter("1", 3, "ABC")); - Assert.assertEquals("23", StrUtil.padAfter("123", 2, "ABC")); + Assertions.assertNull(StrUtil.padAfter(null, 10, "ABC")); + Assertions.assertEquals("1AB", StrUtil.padAfter("1", 3, "ABC")); + Assertions.assertEquals("23", StrUtil.padAfter("123", 2, "ABC")); } @Test public void subBetweenAllTest() { - Assert.assertArrayEquals(new String[]{"yz", "abc"}, StrUtil.subBetweenAll("saho[yz]fdsadp[abc]a", "[", "]")); - Assert.assertArrayEquals(new String[]{"abc"}, StrUtil.subBetweenAll("saho[yzfdsadp[abc]a]", "[", "]")); - Assert.assertArrayEquals(new String[]{"abc", "abc"}, StrUtil.subBetweenAll("yabczyabcz", "y", "z")); - Assert.assertArrayEquals(new String[0], StrUtil.subBetweenAll(null, "y", "z")); - Assert.assertArrayEquals(new String[0], StrUtil.subBetweenAll("", "y", "z")); - Assert.assertArrayEquals(new String[0], StrUtil.subBetweenAll("abc", null, "z")); - Assert.assertArrayEquals(new String[0], StrUtil.subBetweenAll("abc", "y", null)); + Assertions.assertArrayEquals(new String[]{"yz", "abc"}, StrUtil.subBetweenAll("saho[yz]fdsadp[abc]a", "[", "]")); + Assertions.assertArrayEquals(new String[]{"abc"}, StrUtil.subBetweenAll("saho[yzfdsadp[abc]a]", "[", "]")); + Assertions.assertArrayEquals(new String[]{"abc", "abc"}, StrUtil.subBetweenAll("yabczyabcz", "y", "z")); + Assertions.assertArrayEquals(new String[0], StrUtil.subBetweenAll(null, "y", "z")); + Assertions.assertArrayEquals(new String[0], StrUtil.subBetweenAll("", "y", "z")); + Assertions.assertArrayEquals(new String[0], StrUtil.subBetweenAll("abc", null, "z")); + Assertions.assertArrayEquals(new String[0], StrUtil.subBetweenAll("abc", "y", null)); } @Test @@ -426,38 +426,38 @@ public class StrUtilTest { final String src2 = "/ * hutool */ asdas / * hutool */"; final String[] results1 = StrUtil.subBetweenAll(src1, "/**", "*/"); - Assert.assertEquals(0, results1.length); + Assertions.assertEquals(0, results1.length); final String[] results2 = StrUtil.subBetweenAll(src2, "/*", "*/"); - Assert.assertEquals(0, results2.length); + Assertions.assertEquals(0, results2.length); } @Test public void subBetweenAllTest3() { final String src1 = "'abc'and'123'"; String[] strings = StrUtil.subBetweenAll(src1, "'", "'"); - Assert.assertEquals(2, strings.length); - Assert.assertEquals("abc", strings[0]); - Assert.assertEquals("123", strings[1]); + Assertions.assertEquals(2, strings.length); + Assertions.assertEquals("abc", strings[0]); + Assertions.assertEquals("123", strings[1]); final String src2 = "'abc''123'"; strings = StrUtil.subBetweenAll(src2, "'", "'"); - Assert.assertEquals(2, strings.length); - Assert.assertEquals("abc", strings[0]); - Assert.assertEquals("123", strings[1]); + Assertions.assertEquals(2, strings.length); + Assertions.assertEquals("abc", strings[0]); + Assertions.assertEquals("123", strings[1]); final String src3 = "'abc'123'"; strings = StrUtil.subBetweenAll(src3, "'", "'"); - Assert.assertEquals(1, strings.length); - Assert.assertEquals("abc", strings[0]); + Assertions.assertEquals(1, strings.length); + Assertions.assertEquals("abc", strings[0]); } @Test public void subBetweenAllTest4() { final String str = "你好:1388681xxxx用户已开通,1877275xxxx用户已开通,无法发送业务开通短信"; final String[] strings = StrUtil.subBetweenAll(str, "1877275xxxx", ","); - Assert.assertEquals(1, strings.length); - Assert.assertEquals("用户已开通", strings[0]); + Assertions.assertEquals(1, strings.length); + Assertions.assertEquals("用户已开通", strings[0]); } @Test @@ -466,14 +466,14 @@ public class StrUtilTest { final String str = RandomUtil.randomString(RandomUtil.randomInt(1, 100)); for (int maxLength = 1; maxLength < str.length(); maxLength++) { final String brief = StrUtil.brief(str, maxLength); - Assert.assertEquals(brief.length(), maxLength); + Assertions.assertEquals(brief.length(), maxLength); } // case: 不会格式化的值 - Assert.assertEquals(str, StrUtil.brief(str, 0)); - Assert.assertEquals(str, StrUtil.brief(str, -1)); - Assert.assertEquals(str, StrUtil.brief(str, str.length())); - Assert.assertEquals(str, StrUtil.brief(str, str.length() + 1)); + Assertions.assertEquals(str, StrUtil.brief(str, 0)); + Assertions.assertEquals(str, StrUtil.brief(str, -1)); + Assertions.assertEquals(str, StrUtil.brief(str, str.length())); + Assertions.assertEquals(str, StrUtil.brief(str, str.length() + 1)); } @Test @@ -481,15 +481,15 @@ public class StrUtilTest { final String str = "123"; int maxLength = 3; String brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("123", brief); + Assertions.assertEquals("123", brief); maxLength = 2; brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("1.", brief); + Assertions.assertEquals("1.", brief); maxLength = 1; brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("1", brief); + Assertions.assertEquals("1", brief); } @Test @@ -498,44 +498,44 @@ public class StrUtilTest { int maxLength = 6; String brief = StrUtil.brief(str, maxLength); - Assert.assertEquals(str, brief); + Assertions.assertEquals(str, brief); maxLength = 5; brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("1...c", brief); + Assertions.assertEquals("1...c", brief); maxLength = 4; brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("1..c", brief); + Assertions.assertEquals("1..c", brief); maxLength = 3; brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("1.c", brief); + Assertions.assertEquals("1.c", brief); maxLength = 2; brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("1.", brief); + Assertions.assertEquals("1.", brief); maxLength = 1; brief = StrUtil.brief(str, maxLength); - Assert.assertEquals("1", brief); + Assertions.assertEquals("1", brief); } @Test public void filterTest() { final String filterNumber = StrUtil.filter("hutool678", CharUtil::isNumber); - Assert.assertEquals("678", filterNumber); + Assertions.assertEquals("678", filterNumber); final String cleanBlank = StrUtil.filter(" 你 好 ", c -> !CharUtil.isBlankChar(c)); - Assert.assertEquals("你好", cleanBlank); + Assertions.assertEquals("你好", cleanBlank); } @Test public void wrapAllTest() { String[] strings = StrUtil.wrapAll("`", "`", SplitUtil.splitToArray("1,2,3,4", ",")); - Assert.assertEquals("[`1`, `2`, `3`, `4`]", StrUtil.utf8Str(strings)); + Assertions.assertEquals("[`1`, `2`, `3`, `4`]", StrUtil.utf8Str(strings)); strings = StrUtil.wrapAllWithPair("`", SplitUtil.splitToArray("1,2,3,4", ",")); - Assert.assertEquals("[`1`, `2`, `3`, `4`]", StrUtil.utf8Str(strings)); + Assertions.assertEquals("[`1`, `2`, `3`, `4`]", StrUtil.utf8Str(strings)); } @Test @@ -543,38 +543,38 @@ public class StrUtilTest { final String a = "123"; final String b = "123"; - Assert.assertTrue(StrUtil.startWith(a, b)); - Assert.assertFalse(StrUtil.startWithIgnoreEquals(a, b)); + Assertions.assertTrue(StrUtil.startWith(a, b)); + Assertions.assertFalse(StrUtil.startWithIgnoreEquals(a, b)); } @Test public void indexedFormatTest() { final String ret = StrUtil.indexedFormat("this is {0} for {1}", "a", 1000); - Assert.assertEquals("this is a for 1,000", ret); + Assertions.assertEquals("this is a for 1,000", ret); } @Test public void hideTest() { - Assert.assertNull(StrUtil.hide(null, 1, 1)); - Assert.assertEquals("", StrUtil.hide("", 1, 1)); - Assert.assertEquals("****duan@163.com", StrUtil.hide("jackduan@163.com", -1, 4)); - Assert.assertEquals("ja*kduan@163.com", StrUtil.hide("jackduan@163.com", 2, 3)); - Assert.assertEquals("jackduan@163.com", StrUtil.hide("jackduan@163.com", 3, 2)); - Assert.assertEquals("jackduan@163.com", StrUtil.hide("jackduan@163.com", 16, 16)); - Assert.assertEquals("jackduan@163.com", StrUtil.hide("jackduan@163.com", 16, 17)); + Assertions.assertNull(StrUtil.hide(null, 1, 1)); + Assertions.assertEquals("", StrUtil.hide("", 1, 1)); + Assertions.assertEquals("****duan@163.com", StrUtil.hide("jackduan@163.com", -1, 4)); + Assertions.assertEquals("ja*kduan@163.com", StrUtil.hide("jackduan@163.com", 2, 3)); + Assertions.assertEquals("jackduan@163.com", StrUtil.hide("jackduan@163.com", 3, 2)); + Assertions.assertEquals("jackduan@163.com", StrUtil.hide("jackduan@163.com", 16, 16)); + Assertions.assertEquals("jackduan@163.com", StrUtil.hide("jackduan@163.com", 16, 17)); } @Test public void isCharEqualsTest() { final String a = "aaaaaaaaa"; - Assert.assertTrue(StrUtil.isCharEquals(a)); + Assertions.assertTrue(StrUtil.isCharEquals(a)); } @Test public void isNumericTest() { final String a = "2142342422423423"; - Assert.assertTrue(StrUtil.isNumeric(a)); + Assertions.assertTrue(StrUtil.isNumeric(a)); } @Test @@ -582,40 +582,40 @@ public class StrUtilTest { // https://gitee.com/dromara/hutool/issues/I4M16G final String replace = "#{A}"; final String result = StrUtil.replace(replace, "#{AAAAAAA}", "1"); - Assert.assertEquals(replace, result); + Assertions.assertEquals(replace, result); } @Test public void testReplaceByStr() { final String replace = "SSM15930297701BeryAllen"; final String result = StrUtil.replace(replace, 5, 12, "***"); - Assert.assertEquals("SSM15***01BeryAllen", result); + Assertions.assertEquals("SSM15***01BeryAllen", result); final String emoji = StrUtil.replace("\uD83D\uDE00aabb\uD83D\uDE00ccdd", 2, 6, "***"); - Assert.assertEquals("\uD83D\uDE00a***ccdd", emoji); + Assertions.assertEquals("\uD83D\uDE00a***ccdd", emoji); } @Test public void testAddPrefixIfNot() { final String str = "hutool"; String result = StrUtil.addPrefixIfNot(str, "hu"); - Assert.assertEquals(str, result); + Assertions.assertEquals(str, result); result = StrUtil.addPrefixIfNot(str, "Good"); - Assert.assertEquals("Good" + str, result); + Assertions.assertEquals("Good" + str, result); } @Test public void testAddSuffixIfNot() { final String str = "hutool"; String result = StrUtil.addSuffixIfNot(str, "tool"); - Assert.assertEquals(str, result); + Assertions.assertEquals(str, result); result = StrUtil.addSuffixIfNot(str, " is Good"); - Assert.assertEquals(str + " is Good", result); + Assertions.assertEquals(str + " is Good", result); result = StrUtil.addSuffixIfNot("", "/"); - Assert.assertEquals("/", result); + Assertions.assertEquals("/", result); } @Test @@ -627,44 +627,44 @@ public class StrUtilTest { queue.add("orange"); queue.add("strawberry"); queue.add("watermelon"); - Assert.assertFalse(StrUtil.isAllBlank(queue)); + Assertions.assertFalse(StrUtil.isAllBlank(queue)); - Assert.assertTrue(CharSequenceUtil.isAllBlank("")); - Assert.assertTrue(CharSequenceUtil.isAllBlank(" ")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\t")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\n")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\r")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\f")); - Assert.assertFalse(CharSequenceUtil.isAllBlank("\b")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u00A0")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\uFEFF")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2000")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2001")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2002")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2003")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2004")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2005")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2006")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2007")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2008")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2009")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u200A")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u3000")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\uFEFF")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank(" ")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\t")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\n")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\r")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\f")); + Assertions.assertFalse(CharSequenceUtil.isAllBlank("\b")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u00A0")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\uFEFF")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2000")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2001")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2002")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2003")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2004")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2005")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2006")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2007")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2008")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2009")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u200A")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u3000")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\uFEFF")); // 其他空白字符 - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u000B")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u000C")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u00A0")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u1680")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u180E")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2000")); - Assert.assertTrue(CharSequenceUtil.isAllBlank("\u2001")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u000B")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u000C")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u00A0")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u1680")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u180E")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2000")); + Assertions.assertTrue(CharSequenceUtil.isAllBlank("\u2001")); } @Test public void issue2628Test(){ final String s = StrUtil.indexedFormat("a{0,number,#}", 1234567); - Assert.assertEquals("a1234567", s); + Assertions.assertEquals("a1234567", s); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/TextSimilarityTest.java b/hutool-core/src/test/java/cn/hutool/core/text/TextSimilarityTest.java index 817ab6b5f..16c9a6c9a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/TextSimilarityTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/TextSimilarityTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 文本相似度计算工具类单元测试 @@ -16,10 +16,10 @@ public class TextSimilarityTest { final String b = "一个文本,独一无二的文本"; final double degree = TextSimilarity.similar(a, b); - Assert.assertEquals(0.8461538462D, degree, 0.0000000001); + Assertions.assertEquals(0.8461538462D, degree, 0.0000000001); final String similarPercent = TextSimilarity.similar(a, b, 2); - Assert.assertEquals("84.62%", similarPercent); + Assertions.assertEquals("84.62%", similarPercent); } @Test @@ -28,15 +28,15 @@ public class TextSimilarityTest { final String b = "一个文本,独一无二的文本,#,>>?#$%^%$&^&^%"; final double degree = TextSimilarity.similar(a, b); - Assert.assertEquals(0.8461538462D, degree, 0.0001); + Assertions.assertEquals(0.8461538462D, degree, 0.0001); final String similarPercent = TextSimilarity.similar(a, b, 2); - Assert.assertEquals("84.62%", similarPercent); + Assertions.assertEquals("84.62%", similarPercent); } @Test public void similarTest(){ final double abd = TextSimilarity.similar("abd", "1111"); - Assert.assertEquals(0, abd, 1); + Assertions.assertEquals(0, abd, 1); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/UnicodeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/text/UnicodeUtilTest.java index e5961697d..b8832f9f0 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/UnicodeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/UnicodeUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * UnicodeUtil 单元测试 @@ -13,43 +13,43 @@ public class UnicodeUtilTest { @Test public void convertTest() { final String s = UnicodeUtil.toUnicode("aaa123中文", true); - Assert.assertEquals("aaa123\\u4e2d\\u6587", s); + Assertions.assertEquals("aaa123\\u4e2d\\u6587", s); final String s1 = UnicodeUtil.toString(s); - Assert.assertEquals("aaa123中文", s1); + Assertions.assertEquals("aaa123中文", s1); } @Test public void convertTest2() { final String str = "aaaa\\u0026bbbb\\u0026cccc"; final String unicode = UnicodeUtil.toString(str); - Assert.assertEquals("aaaa&bbbb&cccc", unicode); + Assertions.assertEquals("aaaa&bbbb&cccc", unicode); } @Test public void convertTest3() { final String str = "aaa\\u111"; final String res = UnicodeUtil.toString(str); - Assert.assertEquals("aaa\\u111", res); + Assertions.assertEquals("aaa\\u111", res); } @Test public void convertTest4() { final String str = "aaa\\U4e2d\\u6587\\u111\\urtyu\\u0026"; final String res = UnicodeUtil.toString(str); - Assert.assertEquals("aaa中文\\u111\\urtyu&", res); + Assertions.assertEquals("aaa中文\\u111\\urtyu&", res); } @Test public void convertTest5() { final String str = "{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"\\u4ea7\\u54c1\\u4e0d\\u5b58\\u5728\\uff0c\\u6216\\u5df2\\u5220\\u9664\",\"data\":null}"; final String res = UnicodeUtil.toString(str); - Assert.assertEquals("{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"产品不存在,或已删除\",\"data\":null}", res); + Assertions.assertEquals("{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"产品不存在,或已删除\",\"data\":null}", res); } @Test public void issueI50MI6Test(){ final String s = UnicodeUtil.toUnicode("烟", true); - Assert.assertEquals("\\u70df", s); + Assertions.assertEquals("\\u70df", s); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/bloom/BitMapBloomFilterTest.java b/hutool-core/src/test/java/cn/hutool/core/text/bloom/BitMapBloomFilterTest.java index ee077eca6..6609e02d9 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/bloom/BitMapBloomFilterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/bloom/BitMapBloomFilterTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.text.bloom; import cn.hutool.core.codec.hash.HashUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BitMapBloomFilterTest { @@ -15,8 +15,8 @@ public class BitMapBloomFilterTest { filter.add("abc"); filter.add("ddd"); - Assert.assertTrue(filter.contains("abc")); - Assert.assertTrue(filter.contains("ddd")); - Assert.assertTrue(filter.contains("123")); + Assertions.assertTrue(filter.contains("abc")); + Assertions.assertTrue(filter.contains("ddd")); + Assertions.assertTrue(filter.contains("123")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/dfa/DfaTest.java b/hutool-core/src/test/java/cn/hutool/core/text/dfa/DfaTest.java index 739f02fd0..8662567dd 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/dfa/DfaTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/dfa/DfaTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.text.dfa; 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; @@ -27,7 +27,7 @@ public class DfaTest { // 匹配到【大】,就不再继续匹配了,因此【大土豆】不匹配 // 匹配到【刚出锅】,就跳过这三个字了,因此【出锅】不匹配(由于刚首先被匹配,因此长的被匹配,最短匹配只针对第一个字相同选最短) final List matchAll = tree.matchAll(text, -1, false, false); - Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅")); + Assertions.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅")); } /** @@ -43,7 +43,7 @@ public class DfaTest { // 【大】被匹配,最短匹配原则【大土豆】被跳过,【土豆继续被匹配】 // 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配 final List matchAll = tree.matchAll(text, -1, true, false); - Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅", "出锅")); + Assertions.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅", "出锅")); } /** @@ -59,7 +59,7 @@ public class DfaTest { // 匹配到【大】,由于非密集匹配,因此从下一个字符开始查找,匹配到【土豆】接着被匹配 // 由于【刚出锅】被匹配,由于非密集匹配,【出锅】被跳过 final List matchAll = tree.matchAll(text, -1, false, true); - Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅")); + Assertions.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅")); } @@ -76,7 +76,7 @@ public class DfaTest { // 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配,由于不跳过已经匹配的关键词,土豆继续被匹配 // 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配 final List matchAll = tree.matchAll(text, -1, true, true); - Assert.assertEquals(matchAll, ListUtil.of("大", "大土^豆", "土^豆", "刚出锅", "出锅")); + Assertions.assertEquals(matchAll, ListUtil.of("大", "大土^豆", "土^豆", "刚出锅", "出锅")); } @@ -88,19 +88,19 @@ public class DfaTest { tree.addWord("赵阿三"); final List result = tree.matchAllWords("赵阿三在做什么", -1, true, true); - Assert.assertEquals(3, result.size()); + Assertions.assertEquals(3, result.size()); - Assert.assertEquals("赵", result.get(0).getWord()); - Assert.assertEquals(0, result.get(0).getBeginIndex().intValue()); - Assert.assertEquals(0, result.get(0).getEndIndex().intValue()); + Assertions.assertEquals("赵", result.get(0).getWord()); + Assertions.assertEquals(0, result.get(0).getBeginIndex().intValue()); + Assertions.assertEquals(0, result.get(0).getEndIndex().intValue()); - Assert.assertEquals("赵阿", result.get(1).getWord()); - Assert.assertEquals(0, result.get(1).getBeginIndex().intValue()); - Assert.assertEquals(1, result.get(1).getEndIndex().intValue()); + Assertions.assertEquals("赵阿", result.get(1).getWord()); + Assertions.assertEquals(0, result.get(1).getBeginIndex().intValue()); + Assertions.assertEquals(1, result.get(1).getEndIndex().intValue()); - Assert.assertEquals("赵阿三", result.get(2).getWord()); - Assert.assertEquals(0, result.get(2).getBeginIndex().intValue()); - Assert.assertEquals(2, result.get(2).getEndIndex().intValue()); + Assertions.assertEquals("赵阿三", result.get(2).getWord()); + Assertions.assertEquals(0, result.get(2).getBeginIndex().intValue()); + Assertions.assertEquals(2, result.get(2).getEndIndex().intValue()); } /** @@ -112,7 +112,7 @@ public class DfaTest { tree.addWord("tio"); final List all = tree.matchAll("AAAAAAAt-ioBBBBBBB"); - Assert.assertEquals(all, ListUtil.of("t-io")); + Assertions.assertEquals(all, ListUtil.of("t-io")); } @Test @@ -121,31 +121,31 @@ public class DfaTest { tree.addWord("women"); final String text = "a WOMEN todo.".toLowerCase(); final List matchAll = tree.matchAll(text, -1, false, false); - Assert.assertEquals("[women]", matchAll.toString()); + Assertions.assertEquals("[women]", matchAll.toString()); } @Test public void clearTest(){ WordTree tree = new WordTree(); tree.addWord("黑"); - Assert.assertTrue(tree.matchAll("黑大衣").contains("黑")); + Assertions.assertTrue(tree.matchAll("黑大衣").contains("黑")); //clear时直接调用Map的clear并没有把endCharacterSet清理掉 tree.clear(); tree.addWords("黑大衣","红色大衣"); //clear() 覆写前 这里想匹配到黑大衣,但是却匹配到了黑 -// Assert.assertFalse(tree.matchAll("黑大衣").contains("黑大衣")); -// Assert.assertTrue(tree.matchAll("黑大衣").contains("黑")); +// Assertions.assertFalse(tree.matchAll("黑大衣").contains("黑大衣")); +// Assertions.assertTrue(tree.matchAll("黑大衣").contains("黑")); //clear() 覆写后 - Assert.assertTrue(tree.matchAll("黑大衣").contains("黑大衣")); - Assert.assertFalse(tree.matchAll("黑大衣").contains("黑")); - Assert.assertTrue(tree.matchAll("红色大衣").contains("红色大衣")); + Assertions.assertTrue(tree.matchAll("黑大衣").contains("黑大衣")); + Assertions.assertFalse(tree.matchAll("黑大衣").contains("黑")); + Assertions.assertTrue(tree.matchAll("红色大衣").contains("红色大衣")); //如果不覆写只能通过new出新对象才不会有问题 tree = new WordTree(); tree.addWords("黑大衣","红色大衣"); - Assert.assertTrue(tree.matchAll("黑大衣").contains("黑大衣")); - Assert.assertTrue(tree.matchAll("红色大衣").contains("红色大衣")); + Assertions.assertTrue(tree.matchAll("黑大衣").contains("黑大衣")); + Assertions.assertTrue(tree.matchAll("红色大衣").contains("红色大衣")); } // ---------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/test/java/cn/hutool/core/text/dfa/IssueI5Q4HDTest.java b/hutool-core/src/test/java/cn/hutool/core/text/dfa/IssueI5Q4HDTest.java index 1ce0184d7..1cef5a1ca 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/dfa/IssueI5Q4HDTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/dfa/IssueI5Q4HDTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text.dfa; -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.HashSet; @@ -20,6 +20,6 @@ public class IssueI5Q4HDTest { wordTree.addWords(keyWordSet); //DateUtil.beginOfHour() final List strings = wordTree.matchAll(content, -1, true, true); - Assert.assertEquals("[站房, 站房建设, 面积较小, 不符合规范要求, 辅助设施, 站房]", strings.toString()); + Assertions.assertEquals("[站房, 站房建设, 面积较小, 不符合规范要求, 辅助设施, 站房]", strings.toString()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/dfa/NFATest.java b/hutool-core/src/test/java/cn/hutool/core/text/dfa/NFATest.java index 978d1ee23..d67f2a22f 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/dfa/NFATest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/dfa/NFATest.java @@ -1,8 +1,8 @@ package cn.hutool.core.text.dfa; import cn.hutool.core.date.StopWatch; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; @@ -28,20 +28,20 @@ public class NFATest { final List ans1 = NFA.find(input); stopWatch.stop(); - Assert.assertEquals("she,he,her,say", ans1.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); - Assert.assertEquals(2, ans1.get(0).getBeginIndex().intValue()); - Assert.assertEquals(4, ans1.get(0).getEndIndex().intValue()); - Assert.assertEquals(3, ans1.get(1).getBeginIndex().intValue()); - Assert.assertEquals(4, ans1.get(1).getEndIndex().intValue()); - Assert.assertEquals(3, ans1.get(2).getBeginIndex().intValue()); - Assert.assertEquals(5, ans1.get(2).getEndIndex().intValue()); - Assert.assertEquals(7, ans1.get(3).getBeginIndex().intValue()); - Assert.assertEquals(9, ans1.get(3).getEndIndex().intValue()); + Assertions.assertEquals("she,he,her,say", ans1.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); + Assertions.assertEquals(2, ans1.get(0).getBeginIndex().intValue()); + Assertions.assertEquals(4, ans1.get(0).getEndIndex().intValue()); + Assertions.assertEquals(3, ans1.get(1).getBeginIndex().intValue()); + Assertions.assertEquals(4, ans1.get(1).getEndIndex().intValue()); + Assertions.assertEquals(3, ans1.get(2).getBeginIndex().intValue()); + Assertions.assertEquals(5, ans1.get(2).getEndIndex().intValue()); + Assertions.assertEquals(7, ans1.get(3).getBeginIndex().intValue()); + Assertions.assertEquals(9, ans1.get(3).getEndIndex().intValue()); stopWatch.start("wordtree_char_find"); final List ans2 = wordTree.matchAll(input, -1, true, true); stopWatch.stop(); - Assert.assertEquals("she,he,her,say", String.join(",", ans2)); + Assertions.assertEquals("she,he,her,say", String.join(",", ans2)); //Console.log(stopWatch.prettyPrint()); } @@ -64,16 +64,16 @@ public class NFATest { stopWatch.start("automaton_char_find_not_density"); final List ans1 = NFA.find(input, false); stopWatch.stop(); - Assert.assertEquals("she,say", ans1.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); - Assert.assertEquals(2, ans1.get(0).getBeginIndex().intValue()); - Assert.assertEquals(4, ans1.get(0).getEndIndex().intValue()); - Assert.assertEquals(7, ans1.get(1).getBeginIndex().intValue()); - Assert.assertEquals(9, ans1.get(1).getEndIndex().intValue()); + Assertions.assertEquals("she,say", ans1.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); + Assertions.assertEquals(2, ans1.get(0).getBeginIndex().intValue()); + Assertions.assertEquals(4, ans1.get(0).getEndIndex().intValue()); + Assertions.assertEquals(7, ans1.get(1).getBeginIndex().intValue()); + Assertions.assertEquals(9, ans1.get(1).getEndIndex().intValue()); stopWatch.start("wordtree_char_find_not_density"); final List ans2 = wordTree.matchAll(input, -1, false, true); stopWatch.stop(); - Assert.assertEquals("she,say", String.join(",", ans2)); + Assertions.assertEquals("she,say", String.join(",", ans2)); //Console.log(stopWatch.prettyPrint()); } @@ -93,22 +93,22 @@ public class NFATest { final List ans1 = NFALocal.find(input); stopWatch.stop(); - Assert.assertEquals("she,he,her,say", ans1.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); - Assert.assertEquals(2, ans1.get(0).getBeginIndex().intValue()); - Assert.assertEquals(4, ans1.get(0).getEndIndex().intValue()); - Assert.assertEquals(3, ans1.get(1).getBeginIndex().intValue()); - Assert.assertEquals(4, ans1.get(1).getEndIndex().intValue()); - Assert.assertEquals(3, ans1.get(2).getBeginIndex().intValue()); - Assert.assertEquals(5, ans1.get(2).getEndIndex().intValue()); - Assert.assertEquals(7, ans1.get(3).getBeginIndex().intValue()); - Assert.assertEquals(9, ans1.get(3).getEndIndex().intValue()); + Assertions.assertEquals("she,he,her,say", ans1.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); + Assertions.assertEquals(2, ans1.get(0).getBeginIndex().intValue()); + Assertions.assertEquals(4, ans1.get(0).getEndIndex().intValue()); + Assertions.assertEquals(3, ans1.get(1).getBeginIndex().intValue()); + Assertions.assertEquals(4, ans1.get(1).getEndIndex().intValue()); + Assertions.assertEquals(3, ans1.get(2).getBeginIndex().intValue()); + Assertions.assertEquals(5, ans1.get(2).getEndIndex().intValue()); + Assertions.assertEquals(7, ans1.get(3).getBeginIndex().intValue()); + Assertions.assertEquals(9, ans1.get(3).getEndIndex().intValue()); stopWatch.start("wordtree_char_build_find"); final WordTree wordTreeLocal = new WordTree(); wordTreeLocal.addWords("say", "her", "he", "she", "shr"); final List ans2 = wordTreeLocal.matchAll(input, -1, true, true); stopWatch.stop(); - Assert.assertEquals("she,he,her,say", String.join(",", ans2)); + Assertions.assertEquals("she,he,her,say", String.join(",", ans2)); //Console.log(stopWatch.prettyPrint()); } @@ -129,14 +129,14 @@ public class NFATest { final List result = NFALocal.find(input); stopWatch.stop(); - Assert.assertEquals(3, result.size()); - Assert.assertEquals("赵,赵啊,赵啊三", result.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); - Assert.assertEquals(Integer.valueOf(0), result.get(0).getBeginIndex()); - Assert.assertEquals(Integer.valueOf(0), result.get(0).getEndIndex()); - Assert.assertEquals(Integer.valueOf(0), result.get(1).getBeginIndex()); - Assert.assertEquals(Integer.valueOf(1), result.get(1).getEndIndex()); - Assert.assertEquals(Integer.valueOf(0), result.get(2).getBeginIndex()); - Assert.assertEquals(Integer.valueOf(2), result.get(2).getEndIndex()); + Assertions.assertEquals(3, result.size()); + Assertions.assertEquals("赵,赵啊,赵啊三", result.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); + Assertions.assertEquals(Integer.valueOf(0), result.get(0).getBeginIndex()); + Assertions.assertEquals(Integer.valueOf(0), result.get(0).getEndIndex()); + Assertions.assertEquals(Integer.valueOf(0), result.get(1).getBeginIndex()); + Assertions.assertEquals(Integer.valueOf(1), result.get(1).getEndIndex()); + Assertions.assertEquals(Integer.valueOf(0), result.get(2).getBeginIndex()); + Assertions.assertEquals(Integer.valueOf(2), result.get(2).getEndIndex()); stopWatch.start("wordtree_cn_build_find"); final WordTree wordTreeLocal = new WordTree(); @@ -145,8 +145,8 @@ public class NFATest { final List result1 = wordTreeLocal.matchAll(input, -1, true, true); stopWatch.stop(); - Assert.assertEquals(3, result1.size()); - Assert.assertEquals("赵,赵啊,赵啊三", String.join(",", result1)); + Assertions.assertEquals(3, result1.size()); + Assertions.assertEquals("赵,赵啊,赵啊三", String.join(",", result1)); //Console.log(stopWatch.prettyPrint()); } @@ -167,14 +167,14 @@ public class NFATest { final List result = NFALocal.find(input); stopWatch.stop(); - Assert.assertEquals(3, result.size()); - Assert.assertEquals("赵,赵啊,赵啊三", result.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); - Assert.assertEquals(Integer.valueOf(0), result.get(0).getBeginIndex()); - Assert.assertEquals(Integer.valueOf(0), result.get(0).getEndIndex()); - Assert.assertEquals(Integer.valueOf(0), result.get(1).getBeginIndex()); - Assert.assertEquals(Integer.valueOf(1), result.get(1).getEndIndex()); - Assert.assertEquals(Integer.valueOf(0), result.get(2).getBeginIndex()); - Assert.assertEquals(Integer.valueOf(2), result.get(2).getEndIndex()); + Assertions.assertEquals(3, result.size()); + Assertions.assertEquals("赵,赵啊,赵啊三", result.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); + Assertions.assertEquals(Integer.valueOf(0), result.get(0).getBeginIndex()); + Assertions.assertEquals(Integer.valueOf(0), result.get(0).getEndIndex()); + Assertions.assertEquals(Integer.valueOf(0), result.get(1).getBeginIndex()); + Assertions.assertEquals(Integer.valueOf(1), result.get(1).getEndIndex()); + Assertions.assertEquals(Integer.valueOf(0), result.get(2).getBeginIndex()); + Assertions.assertEquals(Integer.valueOf(2), result.get(2).getEndIndex()); final WordTree wordTreeLocal = new WordTree(); wordTreeLocal.addWords("赵", "赵啊", "赵啊三"); @@ -184,8 +184,8 @@ public class NFATest { .collect(Collectors.toList()); stopWatch.stop(); - Assert.assertEquals(3, result1.size()); - Assert.assertEquals("赵,赵啊,赵啊三", String.join(",", result1)); + Assertions.assertEquals(3, result1.size()); + Assertions.assertEquals("赵,赵啊,赵啊三", String.join(",", result1)); //Console.log(stopWatch.prettyPrint()); } @@ -206,10 +206,10 @@ public class NFATest { final List result = NFALocal.find(input, false); stopWatch.stop(); - Assert.assertEquals(1, result.size()); - Assert.assertEquals("赵", result.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); - Assert.assertEquals(Integer.valueOf(0), result.get(0).getBeginIndex()); - Assert.assertEquals(Integer.valueOf(0), result.get(0).getEndIndex()); + Assertions.assertEquals(1, result.size()); + Assertions.assertEquals("赵", result.stream().map(FoundWord::getWord).collect(Collectors.joining(","))); + Assertions.assertEquals(Integer.valueOf(0), result.get(0).getBeginIndex()); + Assertions.assertEquals(Integer.valueOf(0), result.get(0).getEndIndex()); final WordTree wordTreeLocal = new WordTree(); wordTreeLocal.addWords("赵", "赵啊", "赵啊三"); @@ -220,8 +220,8 @@ public class NFATest { .collect(Collectors.toList()); stopWatch.stop(); - Assert.assertEquals(1, result1.size()); - Assert.assertEquals("赵", String.join(",", result1)); + Assertions.assertEquals(1, result1.size()); + Assertions.assertEquals("赵", String.join(",", result1)); //Console.log(stopWatch.prettyPrint()); } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/dfa/SensitiveUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/text/dfa/SensitiveUtilTest.java index 76755f32a..d9acbde81 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/dfa/SensitiveUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/dfa/SensitiveUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.text.dfa; import cn.hutool.core.collection.ListUtil; 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; @@ -23,7 +23,7 @@ public class SensitiveUtilTest { bean.setNum(100); SensitiveUtil.init(wordList); final String beanStr = SensitiveUtil.sensitiveFilter(bean.getStr(), true, null); - Assert.assertEquals("我有一颗$****,***的", beanStr); + Assertions.assertEquals("我有一颗$****,***的", beanStr); } @Data @@ -37,6 +37,6 @@ public class SensitiveUtilTest { SensitiveUtil.init(ListUtil.view("赵", "赵阿", "赵阿三")); final String result = SensitiveUtil.sensitiveFilter("赵阿三在做什么。", true, null); - Assert.assertEquals("***在做什么。", result); + Assertions.assertEquals("***在做什么。", result); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/escape/EscapeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/text/escape/EscapeUtilTest.java index 3bb9d59b7..20019574e 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/escape/EscapeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/escape/EscapeUtilTest.java @@ -1,31 +1,31 @@ package cn.hutool.core.text.escape; import cn.hutool.core.text.escape.EscapeUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class EscapeUtilTest { @Test public void escapeHtml4Test() { final String escapeHtml4 = EscapeUtil.escapeHtml4("你好"); - Assert.assertEquals("<a>你好</a>", escapeHtml4); + Assertions.assertEquals("<a>你好</a>", escapeHtml4); final String result = EscapeUtil.unescapeHtml4("振荡器类型"); - Assert.assertEquals("振荡器类型", result); + Assertions.assertEquals("振荡器类型", result); final String escape = EscapeUtil.escapeHtml4("*@-_+./(123你好)"); - Assert.assertEquals("*@-_+./(123你好)", escape); + Assertions.assertEquals("*@-_+./(123你好)", escape); } @Test public void escapeTest(){ final String str = "*@-_+./(123你好)ABCabc"; final String escape = EscapeUtil.escape(str); - Assert.assertEquals("*@-_+./%28123%u4f60%u597d%29ABCabc", escape); + Assertions.assertEquals("*@-_+./%28123%u4f60%u597d%29ABCabc", escape); final String unescape = EscapeUtil.unescape(escape); - Assert.assertEquals(str, unescape); + Assertions.assertEquals(str, unescape); } @Test @@ -33,10 +33,10 @@ public class EscapeUtilTest { final String str = "*@-_+./(123你好)ABCabc"; final String escape = EscapeUtil.escapeAll(str); - Assert.assertEquals("%2a%40%2d%5f%2b%2e%2f%28%31%32%33%u4f60%u597d%29%41%42%43%61%62%63", escape); + Assertions.assertEquals("%2a%40%2d%5f%2b%2e%2f%28%31%32%33%u4f60%u597d%29%41%42%43%61%62%63", escape); final String unescape = EscapeUtil.unescape(escape); - Assert.assertEquals(str, unescape); + Assertions.assertEquals(str, unescape); } /** @@ -47,10 +47,10 @@ public class EscapeUtilTest { final String str = "٩"; final String escape = EscapeUtil.escapeAll(str); - Assert.assertEquals("%u0669", escape); + Assertions.assertEquals("%u0669", escape); final String unescape = EscapeUtil.unescape(escape); - Assert.assertEquals(str, unescape); + Assertions.assertEquals(str, unescape); } @Test @@ -58,13 +58,13 @@ public class EscapeUtilTest { // 单引号不做转义 final String str = "'some text with single quotes'"; final String s = EscapeUtil.escapeHtml4(str); - Assert.assertEquals("'some text with single quotes'", s); + Assertions.assertEquals("'some text with single quotes'", s); } @Test public void unescapeSingleQuotesTest(){ final String str = "'some text with single quotes'"; final String s = EscapeUtil.unescapeHtml4(str); - Assert.assertEquals("'some text with single quotes'", s); + Assertions.assertEquals("'some text with single quotes'", s); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/finder/CharFinderTest.java b/hutool-core/src/test/java/cn/hutool/core/text/finder/CharFinderTest.java index 4a2cba983..a708ce2ad 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/finder/CharFinderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/finder/CharFinderTest.java @@ -1,30 +1,30 @@ package cn.hutool.core.text.finder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CharFinderTest { @Test public void startTest(){ int start = new CharFinder('a').setText("cba123").start(2); - Assert.assertEquals(2, start); + Assertions.assertEquals(2, start); start = new CharFinder('c').setText("cba123").start(2); - Assert.assertEquals(-1, start); + Assertions.assertEquals(-1, start); start = new CharFinder('3').setText("cba123").start(2); - Assert.assertEquals(5, start); + Assertions.assertEquals(5, start); } @Test public void negativeStartTest(){ int start = new CharFinder('a').setText("cba123").setNegative(true).start(2); - Assert.assertEquals(2, start); + Assertions.assertEquals(2, start); start = new CharFinder('2').setText("cba123").setNegative(true).start(2); - Assert.assertEquals(-1, start); + Assertions.assertEquals(-1, start); start = new CharFinder('c').setText("cba123").setNegative(true).start(2); - Assert.assertEquals(0, start); + Assertions.assertEquals(0, start); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/replacer/SearchReplacerTest.java b/hutool-core/src/test/java/cn/hutool/core/text/replacer/SearchReplacerTest.java index 04049106b..93666db67 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/replacer/SearchReplacerTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/replacer/SearchReplacerTest.java @@ -2,42 +2,42 @@ package cn.hutool.core.text.replacer; import cn.hutool.core.text.CharSequenceUtil; 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; public class SearchReplacerTest { @Test public void replaceOnlyTest() { final String result = CharSequenceUtil.replace(",", ",", "|"); - Assert.assertEquals("|", result); + Assertions.assertEquals("|", result); } @Test public void replaceTestAtBeginAndEnd() { final String result = CharSequenceUtil.replace(",abcdef,", ",", "|"); - Assert.assertEquals("|abcdef|", result); + Assertions.assertEquals("|abcdef|", result); } @Test public void replaceTest() { final String str = "AAABBCCCBBDDDBB"; String replace = StrUtil.replace(str, 0, "BB", "22", false); - Assert.assertEquals("AAA22CCC22DDD22", replace); + Assertions.assertEquals("AAA22CCC22DDD22", replace); replace = StrUtil.replace(str, 3, "BB", "22", false); - Assert.assertEquals("AAA22CCC22DDD22", replace); + Assertions.assertEquals("AAA22CCC22DDD22", replace); replace = StrUtil.replace(str, 4, "BB", "22", false); - Assert.assertEquals("AAABBCCC22DDD22", replace); + Assertions.assertEquals("AAABBCCC22DDD22", replace); replace = StrUtil.replace(str, 4, "bb", "22", true); - Assert.assertEquals("AAABBCCC22DDD22", replace); + Assertions.assertEquals("AAABBCCC22DDD22", replace); replace = StrUtil.replace(str, 4, "bb", "", true); - Assert.assertEquals("AAABBCCCDDD", replace); + Assertions.assertEquals("AAABBCCCDDD", replace); replace = StrUtil.replace(str, 4, "bb", null, true); - Assert.assertEquals("AAABBCCCDDD", replace); + Assertions.assertEquals("AAABBCCCDDD", replace); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/split/SplitIterTest.java b/hutool-core/src/test/java/cn/hutool/core/text/split/SplitIterTest.java index ddd3262a6..08b2595d2 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/split/SplitIterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/split/SplitIterTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.text.finder.CharFinder; import cn.hutool.core.text.finder.LengthFinder; import cn.hutool.core.text.finder.PatternFinder; import cn.hutool.core.text.finder.StrFinder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.regex.Pattern; @@ -22,7 +22,7 @@ public class SplitIterTest { Integer.MAX_VALUE, false ); - Assert.assertEquals(6, splitIter.toList(false).size()); + Assertions.assertEquals(6, splitIter.toList(false).size()); } @Test @@ -35,7 +35,7 @@ public class SplitIterTest { Integer.MAX_VALUE, false ); - Assert.assertEquals(4, splitIter.toList(false).size()); + Assertions.assertEquals(4, splitIter.toList(false).size()); } @Test @@ -49,7 +49,7 @@ public class SplitIterTest { ); final List strings = splitIter.toList(false); - Assert.assertEquals(4, strings.size()); + Assertions.assertEquals(4, strings.size()); } @Test @@ -63,10 +63,10 @@ public class SplitIterTest { ); final List strings = splitIter.toList(true); - Assert.assertEquals(3, strings.size()); - Assert.assertEquals("a", strings.get(0)); - Assert.assertEquals("efedsfs", strings.get(1)); - Assert.assertEquals("ddf", strings.get(2)); + Assertions.assertEquals(3, strings.size()); + Assertions.assertEquals("a", strings.get(0)); + Assertions.assertEquals("efedsfs", strings.get(1)); + Assertions.assertEquals("ddf", strings.get(2)); } @Test @@ -80,7 +80,7 @@ public class SplitIterTest { ); final List strings = splitIter.toList(false); - Assert.assertEquals(3, strings.size()); + Assertions.assertEquals(3, strings.size()); } @Test @@ -94,7 +94,7 @@ public class SplitIterTest { ); final List strings = splitIter.toList(false); - Assert.assertEquals(3, strings.size()); + Assertions.assertEquals(3, strings.size()); } @Test @@ -107,7 +107,7 @@ public class SplitIterTest { ); final List strings = splitIter.toList(false); - Assert.assertEquals(4, strings.size()); + Assertions.assertEquals(4, strings.size()); } @Test @@ -120,7 +120,7 @@ public class SplitIterTest { ); final List strings = splitIter.toList(false); - Assert.assertEquals(3, strings.size()); + Assertions.assertEquals(3, strings.size()); } @Test @@ -133,20 +133,22 @@ public class SplitIterTest { ); final List strings = splitIter.toList(false); - Assert.assertEquals(1, strings.size()); + Assertions.assertEquals(1, strings.size()); } // 切割字符串是空字符串时报错 - @Test(expected = IllegalArgumentException.class) + @Test public void splitByEmptyTest(){ - final String text = "aa,bb,cc"; - final SplitIter splitIter = new SplitIter(text, + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + final String text = "aa,bb,cc"; + final SplitIter splitIter = new SplitIter(text, StrFinder.of("", false), 3, false - ); + ); - final List strings = splitIter.toList(false); - Assert.assertEquals(1, strings.size()); + final List strings = splitIter.toList(false); + Assertions.assertEquals(1, strings.size()); + }); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/text/split/StrSplitterTest.java b/hutool-core/src/test/java/cn/hutool/core/text/split/StrSplitterTest.java index 5d7433bd9..fbdd6ba3b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/text/split/StrSplitterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/split/StrSplitterTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.text.split; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; @@ -17,41 +17,41 @@ public class StrSplitterTest { final String str1 = "a, ,efedsfs, ddf"; final List split = SplitUtil.split(str1, ",", 0, true, true); - Assert.assertEquals("ddf", split.get(2)); - Assert.assertEquals(3, split.size()); + Assertions.assertEquals("ddf", split.get(2)); + Assertions.assertEquals(3, split.size()); } @Test public void splitByStrTest(){ final String str1 = "aabbccaaddaaee"; final List split = SplitUtil.split(str1, "aa", 0, true, true); - Assert.assertEquals("ee", split.get(2)); - Assert.assertEquals(3, split.size()); + Assertions.assertEquals("ee", split.get(2)); + Assertions.assertEquals(3, split.size()); } @Test public void splitByBlankTest(){ final String str1 = "aa bbccaa ddaaee"; final List split = SplitUtil.splitByBlank(str1); - Assert.assertEquals("ddaaee", split.get(2)); - Assert.assertEquals(3, split.size()); + Assertions.assertEquals("ddaaee", split.get(2)); + Assertions.assertEquals(3, split.size()); } @Test public void splitPathTest(){ final String str1 = "/use/local\\bin"; final List split = SplitUtil.splitPath(str1); - Assert.assertEquals("bin", split.get(2)); - Assert.assertEquals(3, split.size()); + Assertions.assertEquals("bin", split.get(2)); + Assertions.assertEquals(3, split.size()); } @Test public void splitMappingTest() { final String str = "1.2."; final List split = SplitUtil.split(str, ".", 0, true, true, Long::parseLong); - Assert.assertEquals(2, split.size()); - Assert.assertEquals(Long.valueOf(1L), split.get(0)); - Assert.assertEquals(Long.valueOf(2L), split.get(1)); + Assertions.assertEquals(2, split.size()); + Assertions.assertEquals(Long.valueOf(1L), split.get(0)); + Assertions.assertEquals(Long.valueOf(2L), split.get(1)); } @SuppressWarnings("MismatchedReadAndWriteOfArray") @@ -62,12 +62,12 @@ public class StrSplitterTest { final String[] strings = SplitUtil.split(str, ",", -1, false, false) .toArray(new String[0]); - Assert.assertNotNull(strings); - Assert.assertArrayEquals(split, strings); + Assertions.assertNotNull(strings); + Assertions.assertArrayEquals(split, strings); final String[] strings2 = SplitUtil.split(str, ",", -1, false, true) .toArray(new String[0]); - Assert.assertEquals(0, strings2.length); + Assertions.assertEquals(0, strings2.length); } @SuppressWarnings("ConstantValue") @@ -76,13 +76,13 @@ public class StrSplitterTest { final String str = null; final String[] strings = SplitUtil.split(str, ",", -1, false, false) .toArray(new String[0]); - Assert.assertNotNull(strings); - Assert.assertEquals(0, strings.length); + Assertions.assertNotNull(strings); + Assertions.assertEquals(0, strings.length); final String[] strings2 = SplitUtil.split(str, ",", -1, false, true) .toArray(new String[0]); - Assert.assertNotNull(strings2); - Assert.assertEquals(0, strings2.length); + Assertions.assertNotNull(strings2); + Assertions.assertEquals(0, strings2.length); } /** @@ -92,14 +92,14 @@ public class StrSplitterTest { public void splitByRegexTest(){ final String text = "01 821 34567890182345617821"; List strings = SplitUtil.splitByRegex(text, "21", 0, false, true); - Assert.assertEquals(2, strings.size()); - Assert.assertEquals("01 8", strings.get(0)); - Assert.assertEquals(" 345678901823456178", strings.get(1)); + Assertions.assertEquals(2, strings.size()); + Assertions.assertEquals("01 8", strings.get(0)); + Assertions.assertEquals(" 345678901823456178", strings.get(1)); strings = SplitUtil.splitByRegex(text, "21", 0, false, false); - Assert.assertEquals(3, strings.size()); - Assert.assertEquals("01 8", strings.get(0)); - Assert.assertEquals(" 345678901823456178", strings.get(1)); - Assert.assertEquals("", strings.get(2)); + Assertions.assertEquals(3, strings.size()); + Assertions.assertEquals("01 8", strings.get(0)); + Assertions.assertEquals(" 345678901823456178", strings.get(1)); + Assertions.assertEquals("", strings.get(2)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/thread/AsyncUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/thread/AsyncUtilTest.java index 04a7544d5..3e6af8fa1 100644 --- a/hutool-core/src/test/java/cn/hutool/core/thread/AsyncUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/thread/AsyncUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.thread; -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.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit; public class AsyncUtilTest { @Test - @Ignore + @Disabled public void waitAndGetTest() { final CompletableFuture hutool = CompletableFuture.supplyAsync(() -> { ThreadUtil.sleep(1, TimeUnit.SECONDS); @@ -33,6 +33,6 @@ public class AsyncUtilTest { // 等待完成 AsyncUtil.waitAll(hutool, sweater, warm); // 获取结果 - Assert.assertEquals("hutool卫衣真暖和", AsyncUtil.get(hutool) + AsyncUtil.get(sweater) + AsyncUtil.get(warm)); + Assertions.assertEquals("hutool卫衣真暖和", AsyncUtil.get(hutool) + AsyncUtil.get(sweater) + AsyncUtil.get(warm)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/thread/ConcurrencyTesterTest.java b/hutool-core/src/test/java/cn/hutool/core/thread/ConcurrencyTesterTest.java index 94534e6f4..94e473ebb 100755 --- a/hutool-core/src/test/java/cn/hutool/core/thread/ConcurrencyTesterTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/thread/ConcurrencyTesterTest.java @@ -3,13 +3,13 @@ package cn.hutool.core.thread; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.util.RandomUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class ConcurrencyTesterTest { @Test - @Ignore + @Disabled public void concurrencyTesterTest() { final ConcurrencyTester tester = ThreadUtil.concurrencyTest(100, () -> { final long delay = RandomUtil.randomLong(100, 1000); @@ -20,7 +20,7 @@ public class ConcurrencyTesterTest { } @Test - @Ignore + @Disabled public void multiTest(){ final ConcurrencyTester ct = new ConcurrencyTester(5); for(int i=0;i<3;i++){ diff --git a/hutool-core/src/test/java/cn/hutool/core/thread/ThreadUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/thread/ThreadUtilTest.java index b432f77fe..55674355c 100644 --- a/hutool-core/src/test/java/cn/hutool/core/thread/ThreadUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/thread/ThreadUtilTest.java @@ -2,9 +2,9 @@ package cn.hutool.core.thread; import cn.hutool.core.date.TimeUtil; 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.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -20,14 +20,14 @@ public class ThreadUtilTest { public void executeTest() { final boolean isValid = true; - ThreadUtil.execute(() -> Assert.assertTrue(isValid)); + ThreadUtil.execute(() -> Assertions.assertTrue(isValid)); } @Test - @Ignore + @Disabled public void phaserTest(){ LocalDateTime now = TimeUtil.parse("2022-08-04T22:59:59+08:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME); - Assert.assertNotNull(now); + Assertions.assertNotNull(now); int repeat = 30; // 执行的轮数配置 Phaser phaser = new Phaser() { // 进行一些处理方法的覆写 diff --git a/hutool-core/src/test/java/cn/hutool/core/tree/BeanTreeTest.java b/hutool-core/src/test/java/cn/hutool/core/tree/BeanTreeTest.java index 5db467bd9..e3ec881ea 100644 --- a/hutool-core/src/test/java/cn/hutool/core/tree/BeanTreeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/tree/BeanTreeTest.java @@ -4,9 +4,9 @@ import cn.hutool.core.stream.EasyStream; import lombok.Builder; import lombok.Data; import lombok.experimental.Tolerate; -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.Comparator; import java.util.List; @@ -41,7 +41,7 @@ public class BeanTreeTest { List originJavaBeanTree; BeanTree beanTree; - @Before + @BeforeEach public void setUp() { originJavaBeanList = EasyStream .of( @@ -79,22 +79,22 @@ public class BeanTreeTest { @Test public void testToTree() { final List javaBeanTree = beanTree.toTree(originJavaBeanList); - Assert.assertEquals(originJavaBeanTree, javaBeanTree); + Assertions.assertEquals(originJavaBeanTree, javaBeanTree); final BeanTree conditionBeanTree = BeanTree.ofMatch(JavaBean::getId, JavaBean::getParentId, s -> Boolean.TRUE.equals(s.getMatchParent()), JavaBean::getChildren, JavaBean::setChildren); - Assert.assertEquals(originJavaBeanTree, conditionBeanTree.toTree(originJavaBeanList)); + Assertions.assertEquals(originJavaBeanTree, conditionBeanTree.toTree(originJavaBeanList)); } @Test public void testFlat() { final List javaBeanList = beanTree.flat(originJavaBeanTree); javaBeanList.sort(Comparator.comparing(JavaBean::getId)); - Assert.assertEquals(originJavaBeanList, javaBeanList); + Assertions.assertEquals(originJavaBeanList, javaBeanList); } @Test public void testFilter() { final List javaBeanTree = beanTree.filter(originJavaBeanTree, s -> "looly".equals(s.getName())); - Assert.assertEquals(singletonList( + Assertions.assertEquals(singletonList( JavaBean.builder().id(1L).name("dromara").matchParent(true) .children(singletonList(JavaBean.builder().id(3L).name("hutool").parentId(1L) .children(singletonList(JavaBean.builder().id(6L).name("looly").parentId(3L).build())) @@ -106,7 +106,7 @@ public class BeanTreeTest { @Test public void testForeach() { final List javaBeanList = beanTree.forEach(originJavaBeanTree, s -> s.setName("【open source】" + s.getName())); - Assert.assertEquals(asList( + Assertions.assertEquals(asList( JavaBean.builder().id(1L).name("【open source】dromara").matchParent(true) .children(asList(JavaBean.builder().id(3L).name("【open source】hutool").parentId(1L) .children(singletonList(JavaBean.builder().id(6L).name("【open source】looly").parentId(3L).build())) diff --git a/hutool-core/src/test/java/cn/hutool/core/tree/Issue2279Test.java b/hutool-core/src/test/java/cn/hutool/core/tree/Issue2279Test.java index 768e6c696..4a834645f 100755 --- a/hutool-core/src/test/java/cn/hutool/core/tree/Issue2279Test.java +++ b/hutool-core/src/test/java/cn/hutool/core/tree/Issue2279Test.java @@ -2,8 +2,8 @@ package cn.hutool.core.tree; import cn.hutool.core.collection.ListUtil; 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.List; @@ -29,7 +29,7 @@ public class Issue2279Test { ); final MapTree result = stringTree.get(0); - Assert.assertEquals(2, result.getChildren().size()); + Assertions.assertEquals(2, result.getChildren().size()); } @Data diff --git a/hutool-core/src/test/java/cn/hutool/core/tree/IssueI6NR2ZTest.java b/hutool-core/src/test/java/cn/hutool/core/tree/IssueI6NR2ZTest.java index 3acbcea4b..bbf048577 100644 --- a/hutool-core/src/test/java/cn/hutool/core/tree/IssueI6NR2ZTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/tree/IssueI6NR2ZTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.tree; -import cn.hutool.core.lang.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; @@ -43,6 +43,6 @@ public class IssueI6NR2ZTest { final List> build = TreeUtil.build(list); final MapTree node = TreeUtil.getNode(build.get(0), 31); - Assert.notNull(node); + Assertions.assertNotNull(node); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/tree/TreeBuilderTest.java b/hutool-core/src/test/java/cn/hutool/core/tree/TreeBuilderTest.java index 7848a5363..1bd350f97 100755 --- a/hutool-core/src/test/java/cn/hutool/core/tree/TreeBuilderTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/tree/TreeBuilderTest.java @@ -1,16 +1,18 @@ package cn.hutool.core.tree; -import cn.hutool.core.tree.TreeBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.ArrayList; public class TreeBuilderTest { - @Test(expected = IllegalArgumentException.class) + @Test public void checkIsBuiltTest(){ - final TreeBuilder of = TreeBuilder.of(0); - of.build(); - of.append(new ArrayList<>()); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + final TreeBuilder of = TreeBuilder.of(0); + of.build(); + of.append(new ArrayList<>()); + }); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/tree/TreeSearchTest.java b/hutool-core/src/test/java/cn/hutool/core/tree/TreeSearchTest.java index e23fca534..3e3fe069a 100755 --- a/hutool-core/src/test/java/cn/hutool/core/tree/TreeSearchTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/tree/TreeSearchTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.tree; -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; @@ -32,6 +32,6 @@ public class TreeSearchTest { final MapTree tree=treeItems.get(0); final MapTree searchResult=tree.getNode(3L); - Assert.assertEquals("module-B", searchResult.getName()); + Assertions.assertEquals("module-B", searchResult.getName()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/tree/TreeTest.java b/hutool-core/src/test/java/cn/hutool/core/tree/TreeTest.java index 3db1199d0..43077c00a 100755 --- a/hutool-core/src/test/java/cn/hutool/core/tree/TreeTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/tree/TreeTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.tree; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.lang.Console; -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; @@ -33,15 +33,15 @@ public class TreeTest { public void sampleTreeTest() { final List> treeList = TreeUtil.build(nodeList, "0"); for (final MapTree tree : treeList) { - Assert.assertNotNull(tree); - Assert.assertEquals("0", tree.getParentId()); + Assertions.assertNotNull(tree); + Assertions.assertEquals("0", tree.getParentId()); // Console.log(tree); } // 测试通过子节点查找父节点 final MapTree rootNode0 = treeList.get(0); final MapTree parent = rootNode0.getChildren().get(0).getParent(); - Assert.assertEquals(rootNode0, parent); + Assertions.assertEquals(rootNode0, parent); } @Test @@ -66,7 +66,7 @@ public class TreeTest { tree.putExtra("other", new Object()); }); - Assert.assertEquals(treeNodes.size(), 2); + Assertions.assertEquals(treeNodes.size(), 2); } @Test @@ -75,7 +75,7 @@ public class TreeTest { final MapTree tree = TreeUtil.buildSingle(nodeList, "0"); tree.walk((tr)-> ids.add(tr.getId())); - Assert .assertEquals(7, ids.size()); + Assertions.assertEquals(7, ids.size()); } @Test @@ -85,7 +85,7 @@ public class TreeTest { Console.log(tree); tree.walk((tr)-> ids.add(tr.getId()), true); - Assert .assertEquals(7, ids.size()); + Assertions.assertEquals(7, ids.size()); } @Test @@ -96,7 +96,7 @@ public class TreeTest { final List ids = new ArrayList<>(); cloneTree.walk((tr)-> ids.add(tr.getId())); - Assert .assertEquals(7, ids.size()); + Assertions.assertEquals(7, ids.size()); } @Test @@ -110,7 +110,7 @@ public class TreeTest { final List ids = new ArrayList<>(); tree.walk((tr)-> ids.add(tr.getId())); - Assert .assertEquals(4, ids.size()); + Assertions.assertEquals(4, ids.size()); } @Test @@ -125,10 +125,10 @@ public class TreeTest { final List ids = new ArrayList<>(); newTree.walk((tr)-> ids.add(tr.getId())); - Assert .assertEquals(4, ids.size()); + Assertions.assertEquals(4, ids.size()); final List ids2 = new ArrayList<>(); tree.walk((tr)-> ids2.add(tr.getId())); - Assert .assertEquals(7, ids2.size()); + Assertions.assertEquals(7, ids2.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ArrayUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ArrayUtilTest.java index 8469769c1..212589ea2 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/ArrayUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ArrayUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.util; import cn.hutool.core.array.ArrayUtil; 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.math.BigDecimal; import java.util.*; @@ -19,137 +19,137 @@ public class ArrayUtilTest { @Test public void isEmptyTest() { final int[] a = {}; - Assert.assertTrue(ArrayUtil.isEmpty(a)); - Assert.assertTrue(ArrayUtil.isEmpty((Object) a)); + Assertions.assertTrue(ArrayUtil.isEmpty(a)); + Assertions.assertTrue(ArrayUtil.isEmpty((Object) a)); final int[] b = null; //noinspection ConstantConditions - Assert.assertTrue(ArrayUtil.isEmpty(b)); + Assertions.assertTrue(ArrayUtil.isEmpty(b)); final Object c = null; //noinspection ConstantConditions - Assert.assertTrue(ArrayUtil.isEmpty(c)); + Assertions.assertTrue(ArrayUtil.isEmpty(c)); Object d = new Object[]{"1", "2", 3, 4D}; boolean isEmpty = ArrayUtil.isEmpty(d); - Assert.assertFalse(isEmpty); + Assertions.assertFalse(isEmpty); d = new Object[0]; isEmpty = ArrayUtil.isEmpty(d); - Assert.assertTrue(isEmpty); + Assertions.assertTrue(isEmpty); d = null; //noinspection ConstantConditions isEmpty = ArrayUtil.isEmpty(d); //noinspection ConstantConditions - Assert.assertTrue(isEmpty); + Assertions.assertTrue(isEmpty); // Object数组 final Object[] e = new Object[]{"1", "2", 3, 4D}; final boolean empty = ArrayUtil.isEmpty(e); - Assert.assertFalse(empty); + Assertions.assertFalse(empty); } @Test public void isNotEmptyTest() { final int[] a = {1, 2}; - Assert.assertTrue(ArrayUtil.isNotEmpty(a)); + Assertions.assertTrue(ArrayUtil.isNotEmpty(a)); final String[] b = {"a", "b", "c"}; - Assert.assertTrue(ArrayUtil.isNotEmpty(b)); + Assertions.assertTrue(ArrayUtil.isNotEmpty(b)); final Object c = new Object[]{"1", "2", 3, 4D}; - Assert.assertTrue(ArrayUtil.isNotEmpty(c)); + Assertions.assertTrue(ArrayUtil.isNotEmpty(c)); } @Test public void newArrayTest() { final String[] newArray = ArrayUtil.newArray(String.class, 3); - Assert.assertEquals(3, newArray.length); + Assertions.assertEquals(3, newArray.length); final Object[] newArray2 = ArrayUtil.newArray(3); - Assert.assertEquals(3, newArray2.length); + Assertions.assertEquals(3, newArray2.length); } @Test public void cloneTest() { final Integer[] b = {1, 2, 3}; final Integer[] cloneB = ArrayUtil.clone(b); - Assert.assertArrayEquals(b, cloneB); + Assertions.assertArrayEquals(b, cloneB); final int[] a = {1, 2, 3}; final int[] clone = ArrayUtil.clone(a); - Assert.assertArrayEquals(a, clone); + Assertions.assertArrayEquals(a, clone); } @Test public void filterEditTest() { final Integer[] a = {1, 2, 3, 4, 5, 6}; final Integer[] filter = ArrayUtil.edit(a, t -> (t % 2 == 0) ? t : null); - Assert.assertArrayEquals(filter, new Integer[]{2, 4, 6}); + Assertions.assertArrayEquals(filter, new Integer[]{2, 4, 6}); } @Test public void filterTestForFilter() { final Integer[] a = {1, 2, 3, 4, 5, 6}; final Integer[] filter = ArrayUtil.filter(a, t -> t % 2 == 0); - Assert.assertArrayEquals(filter, new Integer[]{2, 4, 6}); + Assertions.assertArrayEquals(filter, new Integer[]{2, 4, 6}); } @Test public void editTest() { final Integer[] a = {1, 2, 3, 4, 5, 6}; final Integer[] filter = ArrayUtil.edit(a, t -> (t % 2 == 0) ? t * 10 : t); - Assert.assertArrayEquals(filter, new Integer[]{1, 20, 3, 40, 5, 60}); + Assertions.assertArrayEquals(filter, new Integer[]{1, 20, 3, 40, 5, 60}); } @Test public void indexOfTest() { final Integer[] a = {1, 2, 3, 4, 5, 6}; final int index = ArrayUtil.indexOf(a, 3); - Assert.assertEquals(2, index); + Assertions.assertEquals(2, index); final long[] b = {1, 2, 3, 4, 5, 6}; final int index2 = ArrayUtil.indexOf(b, 3); - Assert.assertEquals(2, index2); + Assertions.assertEquals(2, index2); } @Test public void lastIndexOfTest() { final Integer[] a = {1, 2, 3, 4, 3, 6}; final int index = ArrayUtil.lastIndexOf(a, 3); - Assert.assertEquals(4, index); + Assertions.assertEquals(4, index); final long[] b = {1, 2, 3, 4, 3, 6}; final int index2 = ArrayUtil.lastIndexOf(b, 3); - Assert.assertEquals(4, index2); + Assertions.assertEquals(4, index2); } @Test public void containsTest() { final Integer[] a = {1, 2, 3, 4, 3, 6}; final boolean contains = ArrayUtil.contains(a, 3); - Assert.assertTrue(contains); + Assertions.assertTrue(contains); final long[] b = {1, 2, 3, 4, 3, 6}; final boolean contains2 = ArrayUtil.contains(b, 3); - Assert.assertTrue(contains2); + Assertions.assertTrue(contains2); } @Test public void containsAnyTest() { final Integer[] a = {1, 2, 3, 4, 3, 6}; boolean contains = ArrayUtil.containsAny(a, 4, 10, 40); - Assert.assertTrue(contains); + Assertions.assertTrue(contains); contains = ArrayUtil.containsAny(a, 10, 40); - Assert.assertFalse(contains); + Assertions.assertFalse(contains); } @Test public void containsAllTest() { final Integer[] a = {1, 2, 3, 4, 3, 6}; boolean contains = ArrayUtil.containsAll(a, 4, 2, 6); - Assert.assertTrue(contains); + Assertions.assertTrue(contains); contains = ArrayUtil.containsAll(a, 1, 2, 3, 5); - Assert.assertFalse(contains); + Assertions.assertFalse(contains); } @Test @@ -157,28 +157,28 @@ public class ArrayUtilTest { final String[] keys = {"a", "b", "c"}; final Integer[] values = {1, 2, 3}; final Map map = ArrayUtil.zip(keys, values, true); - Assert.assertEquals(Objects.requireNonNull(map).toString(), "{a=1, b=2, c=3}"); + Assertions.assertEquals(Objects.requireNonNull(map).toString(), "{a=1, b=2, c=3}"); } @Test public void castTest() { final Object[] values = {"1", "2", "3"}; final String[] cast = (String[]) ArrayUtil.cast(String.class, values); - Assert.assertEquals(values[0], cast[0]); - Assert.assertEquals(values[1], cast[1]); - Assert.assertEquals(values[2], cast[2]); + Assertions.assertEquals(values[0], cast[0]); + Assertions.assertEquals(values[1], cast[1]); + Assertions.assertEquals(values[2], cast[2]); } @Test public void maxTest() { final int max = ArrayUtil.max(1, 2, 13, 4, 5); - Assert.assertEquals(13, max); + Assertions.assertEquals(13, max); final long maxLong = ArrayUtil.max(1L, 2L, 13L, 4L, 5L); - Assert.assertEquals(13, maxLong); + Assertions.assertEquals(13, maxLong); final double maxDouble = ArrayUtil.max(1D, 2.4D, 13.0D, 4.55D, 5D); - Assert.assertEquals(13.0, maxDouble, 0); + Assertions.assertEquals(13.0, maxDouble, 0); final BigDecimal one = new BigDecimal("1.00"); final BigDecimal two = new BigDecimal("2.0"); @@ -186,22 +186,22 @@ public class ArrayUtilTest { final BigDecimal[] bigDecimals = {two, one, three}; final BigDecimal minAccuracy = ArrayUtil.min(bigDecimals, Comparator.comparingInt(BigDecimal::scale)); - Assert.assertEquals(minAccuracy, three); + Assertions.assertEquals(minAccuracy, three); final BigDecimal maxAccuracy = ArrayUtil.max(bigDecimals, Comparator.comparingInt(BigDecimal::scale)); - Assert.assertEquals(maxAccuracy, one); + Assertions.assertEquals(maxAccuracy, one); } @Test public void minTest() { final int min = ArrayUtil.min(1, 2, 13, 4, 5); - Assert.assertEquals(1, min); + Assertions.assertEquals(1, min); final long minLong = ArrayUtil.min(1L, 2L, 13L, 4L, 5L); - Assert.assertEquals(1, minLong); + Assertions.assertEquals(1, minLong); final double minDouble = ArrayUtil.min(1D, 2.4D, 13.0D, 4.55D, 5D); - Assert.assertEquals(1.0, minDouble, 0); + Assertions.assertEquals(1.0, minDouble, 0); } @Test @@ -210,7 +210,7 @@ public class ArrayUtilTest { final String[] b = {"a", "b", "c"}; final String[] result = ArrayUtil.append(a, b); - Assert.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); } @Test @@ -220,50 +220,50 @@ public class ArrayUtilTest { // 在-1的位置插入,相当于在3的位置插入 String[] result = ArrayUtil.insert(a, -1, b); - Assert.assertArrayEquals(new String[]{"1", "2", "3", "a", "b", "c", "4"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "3", "a", "b", "c", "4"}, result); // 在第0个位置插入,即在数组前追加 result = ArrayUtil.insert(a, 0, b); - Assert.assertArrayEquals(new String[]{"a", "b", "c", "1", "2", "3", "4"}, result); + Assertions.assertArrayEquals(new String[]{"a", "b", "c", "1", "2", "3", "4"}, result); // 在第2个位置插入,即"3"之前 result = ArrayUtil.insert(a, 2, b); - Assert.assertArrayEquals(new String[]{"1", "2", "a", "b", "c", "3", "4"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "a", "b", "c", "3", "4"}, result); // 在第4个位置插入,即"4"之后,相当于追加 result = ArrayUtil.insert(a, 4, b); - Assert.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); // 在第5个位置插入,由于数组长度为4,因此补充null result = ArrayUtil.insert(a, 5, b); - Assert.assertArrayEquals(new String[]{"1", "2", "3", "4", null, "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "3", "4", null, "a", "b", "c"}, result); } @Test public void joinTest() { final String[] array = {"aa", "bb", "cc", "dd"}; final String join = ArrayUtil.join(array, ",", "[", "]"); - Assert.assertEquals("[aa],[bb],[cc],[dd]", join); + Assertions.assertEquals("[aa],[bb],[cc],[dd]", join); final Object array2 = new String[]{"aa", "bb", "cc", "dd"}; final String join2 = ArrayUtil.join(array2, ","); - Assert.assertEquals("aa,bb,cc,dd", join2); + Assertions.assertEquals("aa,bb,cc,dd", join2); } @Test public void getArrayTypeTest() { Class arrayType = ArrayUtil.getArrayType(int.class); - Assert.assertSame(int[].class, arrayType); + Assertions.assertSame(int[].class, arrayType); arrayType = ArrayUtil.getArrayType(String.class); - Assert.assertSame(String[].class, arrayType); + Assertions.assertSame(String[].class, arrayType); } @Test public void distinctTest() { final String[] array = {"aa", "bb", "cc", "dd", "bb", "dd"}; final String[] distinct = ArrayUtil.distinct(array); - Assert.assertArrayEquals(new String[]{"aa", "bb", "cc", "dd"}, distinct); + Assertions.assertArrayEquals(new String[]{"aa", "bb", "cc", "dd"}, distinct); } @Test @@ -272,58 +272,58 @@ public class ArrayUtilTest { // 覆盖模式下,保留最后加入的两个元素 String[] distinct = ArrayUtil.distinct(array, String::toLowerCase, true); - Assert.assertArrayEquals(new String[]{"Aa", "bb"}, distinct); + Assertions.assertArrayEquals(new String[]{"Aa", "bb"}, distinct); // 忽略模式下,保留最早加入的两个元素 distinct = ArrayUtil.distinct(array, String::toLowerCase, false); - Assert.assertArrayEquals(new String[]{"aa", "BB"}, distinct); + Assertions.assertArrayEquals(new String[]{"aa", "BB"}, distinct); } @Test public void toStingTest() { final int[] a = {1, 3, 56, 6, 7}; - Assert.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(a)); + Assertions.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(a)); final long[] b = {1, 3, 56, 6, 7}; - Assert.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(b)); + Assertions.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(b)); final short[] c = {1, 3, 56, 6, 7}; - Assert.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(c)); + Assertions.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(c)); final double[] d = {1, 3, 56, 6, 7}; - Assert.assertEquals("[1.0, 3.0, 56.0, 6.0, 7.0]", ArrayUtil.toString(d)); + Assertions.assertEquals("[1.0, 3.0, 56.0, 6.0, 7.0]", ArrayUtil.toString(d)); final byte[] e = {1, 3, 56, 6, 7}; - Assert.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(e)); + Assertions.assertEquals("[1, 3, 56, 6, 7]", ArrayUtil.toString(e)); final boolean[] f = {true, false, true, true, true}; - Assert.assertEquals("[true, false, true, true, true]", ArrayUtil.toString(f)); + Assertions.assertEquals("[true, false, true, true, true]", ArrayUtil.toString(f)); final float[] g = {1, 3, 56, 6, 7}; - Assert.assertEquals("[1.0, 3.0, 56.0, 6.0, 7.0]", ArrayUtil.toString(g)); + Assertions.assertEquals("[1.0, 3.0, 56.0, 6.0, 7.0]", ArrayUtil.toString(g)); final char[] h = {'a', 'b', '你', '好', '1'}; - Assert.assertEquals("[a, b, 你, 好, 1]", ArrayUtil.toString(h)); + Assertions.assertEquals("[a, b, 你, 好, 1]", ArrayUtil.toString(h)); final String[] array = {"aa", "bb", "cc", "dd", "bb", "dd"}; - Assert.assertEquals("[aa, bb, cc, dd, bb, dd]", ArrayUtil.toString(array)); + Assertions.assertEquals("[aa, bb, cc, dd, bb, dd]", ArrayUtil.toString(array)); } @Test public void toArrayTest() { final List list = ListUtil.of("A", "B", "C", "D"); final String[] array = ArrayUtil.toArray(list, String.class); - Assert.assertEquals("A", array[0]); - Assert.assertEquals("B", array[1]); - Assert.assertEquals("C", array[2]); - Assert.assertEquals("D", array[3]); + Assertions.assertEquals("A", array[0]); + Assertions.assertEquals("B", array[1]); + Assertions.assertEquals("C", array[2]); + Assertions.assertEquals("D", array[3]); } @Test public void addAllTest() { final int[] ints = ArrayUtil.addAll(new int[]{1, 2, 3}, new int[]{4, 5, 6}); - Assert.assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6}, ints); + Assertions.assertArrayEquals(new int[]{1, 2, 3, 4, 5, 6}, ints); } @Test public void isAllNotNullTest() { final String[] allNotNull = {"aa", "bb", "cc", "dd", "bb", "dd"}; - Assert.assertTrue(ArrayUtil.isAllNotNull(allNotNull)); + Assertions.assertTrue(ArrayUtil.isAllNotNull(allNotNull)); final String[] hasNull = {"aa", "bb", "cc", null, "bb", "dd"}; - Assert.assertFalse(ArrayUtil.isAllNotNull(hasNull)); + Assertions.assertFalse(ArrayUtil.isAllNotNull(hasNull)); } @Test @@ -335,25 +335,25 @@ public class ArrayUtilTest { final Integer[] e = {0x78, 0x9A, 0x10}; int i = ArrayUtil.indexOfSub(a, b); - Assert.assertEquals(2, i); + Assertions.assertEquals(2, i); i = ArrayUtil.indexOfSub(a, c); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.indexOfSub(a, d); - Assert.assertEquals(3, i); + Assertions.assertEquals(3, i); i = ArrayUtil.indexOfSub(a, e); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.indexOfSub(a, null); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.indexOfSub(null, null); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.indexOfSub(null, b); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); } @Test @@ -361,7 +361,7 @@ public class ArrayUtilTest { final Integer[] a = {0x12, 0x56, 0x34, 0x56, 0x78, 0x9A}; final Integer[] b = {0x56, 0x78}; final int i = ArrayUtil.indexOfSub(a, b); - Assert.assertEquals(3, i); + Assertions.assertEquals(3, i); } @Test @@ -373,25 +373,25 @@ public class ArrayUtilTest { final Integer[] e = {0x78, 0x9A, 0x10}; int i = ArrayUtil.lastIndexOfSub(a, b); - Assert.assertEquals(2, i); + Assertions.assertEquals(2, i); i = ArrayUtil.lastIndexOfSub(a, c); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.lastIndexOfSub(a, d); - Assert.assertEquals(3, i); + Assertions.assertEquals(3, i); i = ArrayUtil.lastIndexOfSub(a, e); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.lastIndexOfSub(a, null); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.lastIndexOfSub(null, null); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); i = ArrayUtil.lastIndexOfSub(null, b); - Assert.assertEquals(-1, i); + Assertions.assertEquals(-1, i); } @Test @@ -399,42 +399,42 @@ public class ArrayUtilTest { final Integer[] a = {0x12, 0x56, 0x78, 0x56, 0x21, 0x9A}; final Integer[] b = {0x56, 0x78}; final int i = ArrayUtil.indexOfSub(a, b); - Assert.assertEquals(1, i); + Assertions.assertEquals(1, i); } @Test public void reverseTest() { final int[] a = {1, 2, 3, 4}; final int[] reverse = ArrayUtil.reverse(a); - Assert.assertArrayEquals(new int[]{4, 3, 2, 1}, reverse); + Assertions.assertArrayEquals(new int[]{4, 3, 2, 1}, reverse); } @Test public void reverseTest2s() { final Object[] a = {"1", '2', "3", 4}; final Object[] reverse = ArrayUtil.reverse(a); - Assert.assertArrayEquals(new Object[]{4, "3", '2', "1"}, reverse); + Assertions.assertArrayEquals(new Object[]{4, "3", '2', "1"}, reverse); } @Test public void removeEmptyTest() { final String[] a = {"a", "b", "", null, " ", "c"}; final String[] resultA = {"a", "b", " ", "c"}; - Assert.assertArrayEquals(ArrayUtil.removeEmpty(a), resultA); + Assertions.assertArrayEquals(ArrayUtil.removeEmpty(a), resultA); } @Test public void removeBlankTest() { final String[] a = {"a", "b", "", null, " ", "c"}; final String[] resultA = {"a", "b", "c"}; - Assert.assertArrayEquals(ArrayUtil.removeBlank(a), resultA); + Assertions.assertArrayEquals(ArrayUtil.removeBlank(a), resultA); } @Test public void nullToEmptyTest() { final String[] a = {"a", "b", "", null, " ", "c"}; final String[] resultA = {"a", "b", "", "", " ", "c"}; - Assert.assertArrayEquals(ArrayUtil.nullToEmpty(a), resultA); + Assertions.assertArrayEquals(ArrayUtil.nullToEmpty(a), resultA); } @Test @@ -442,7 +442,7 @@ public class ArrayUtilTest { final Object a = new int[]{1, 2, 3, 4}; final Object[] wrapA = ArrayUtil.wrap(a); for (final Object o : wrapA) { - Assert.assertTrue(o instanceof Integer); + Assertions.assertTrue(o instanceof Integer); } } @@ -450,23 +450,23 @@ public class ArrayUtilTest { public void splitTest() { final byte[] array = new byte[1024]; final byte[][] arrayAfterSplit = ArrayUtil.split(array, 500); - Assert.assertEquals(3, arrayAfterSplit.length); - Assert.assertEquals(24, arrayAfterSplit[2].length); + Assertions.assertEquals(3, arrayAfterSplit.length); + Assertions.assertEquals(24, arrayAfterSplit[2].length); final byte[] arr = {1, 2, 3, 4, 5, 6, 7}; - Assert.assertArrayEquals(new byte[][]{{1, 2, 3, 4, 5, 6, 7}}, ArrayUtil.split(arr, 8)); - Assert.assertArrayEquals(new byte[][]{{1, 2, 3, 4, 5, 6, 7}}, ArrayUtil.split(arr, 7)); - Assert.assertArrayEquals(new byte[][]{{1, 2, 3, 4}, {5, 6, 7}}, ArrayUtil.split(arr, 4)); - Assert.assertArrayEquals(new byte[][]{{1, 2, 3}, {4, 5, 6}, {7}}, ArrayUtil.split(arr, 3)); - Assert.assertArrayEquals(new byte[][]{{1, 2}, {3, 4}, {5, 6}, {7}}, ArrayUtil.split(arr, 2)); - Assert.assertArrayEquals(new byte[][]{{1}, {2}, {3}, {4}, {5}, {6}, {7}}, ArrayUtil.split(arr, 1)); + Assertions.assertArrayEquals(new byte[][]{{1, 2, 3, 4, 5, 6, 7}}, ArrayUtil.split(arr, 8)); + Assertions.assertArrayEquals(new byte[][]{{1, 2, 3, 4, 5, 6, 7}}, ArrayUtil.split(arr, 7)); + Assertions.assertArrayEquals(new byte[][]{{1, 2, 3, 4}, {5, 6, 7}}, ArrayUtil.split(arr, 4)); + Assertions.assertArrayEquals(new byte[][]{{1, 2, 3}, {4, 5, 6}, {7}}, ArrayUtil.split(arr, 3)); + Assertions.assertArrayEquals(new byte[][]{{1, 2}, {3, 4}, {5, 6}, {7}}, ArrayUtil.split(arr, 2)); + Assertions.assertArrayEquals(new byte[][]{{1}, {2}, {3}, {4}, {5}, {6}, {7}}, ArrayUtil.split(arr, 1)); } @Test public void getTest() { final String[] a = {"a", "b", "c"}; final Object o = ArrayUtil.get(a, -1); - Assert.assertEquals("c", o); + Assertions.assertEquals("c", o); } @Test @@ -476,69 +476,69 @@ public class ArrayUtilTest { // 在小于0的位置,-1的位置插入,返回b+a,新数组 String[] result = ArrayUtil.replace(a, -1, b); - Assert.assertArrayEquals(new String[]{"a", "b", "c", "1", "2", "3", "4"}, result); + Assertions.assertArrayEquals(new String[]{"a", "b", "c", "1", "2", "3", "4"}, result); // 在第0个位置开始替换,返回a result = ArrayUtil.replace(ArrayUtil.clone(a), 0, b); - Assert.assertArrayEquals(new String[]{"a", "b", "c", "4"}, result); + Assertions.assertArrayEquals(new String[]{"a", "b", "c", "4"}, result); // 在第1个位置替换,即"2"开始 result = ArrayUtil.replace(ArrayUtil.clone(a), 1, b); - Assert.assertArrayEquals(new String[]{"1", "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "a", "b", "c"}, result); // 在第2个位置插入,即"3"之后 result = ArrayUtil.replace(ArrayUtil.clone(a), 2, b); - Assert.assertArrayEquals(new String[]{"1", "2", "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "a", "b", "c"}, result); // 在第3个位置插入,即"4"之后 result = ArrayUtil.replace(ArrayUtil.clone(a), 3, b); - Assert.assertArrayEquals(new String[]{"1", "2", "3", "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "3", "a", "b", "c"}, result); // 在第4个位置插入,数组长度为4,在索引4出替换即两个数组相加 result = ArrayUtil.replace(ArrayUtil.clone(a), 4, b); - Assert.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); // 在大于3个位置插入,数组长度为4,即两个数组相加 result = ArrayUtil.replace(ArrayUtil.clone(a), 5, b); - Assert.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); + Assertions.assertArrayEquals(new String[]{"1", "2", "3", "4", "a", "b", "c"}, result); final String[] e = null; final String[] f = {"a", "b", "c"}; // e为null 返回 f result = ArrayUtil.replace(e, -1, f); - Assert.assertArrayEquals(f, result); + Assertions.assertArrayEquals(f, result); final String[] g = {"a", "b", "c"}; final String[] h = null; // h为null 返回 g result = ArrayUtil.replace(g, 0, h); - Assert.assertArrayEquals(g, result); + Assertions.assertArrayEquals(g, result); } @Test public void replaceTest2(){ int[] a = new int[0]; a = ArrayUtil.replace(a, 0, 1); - Assert.assertEquals(1, a.length); + Assertions.assertEquals(1, a.length); } @Test public void setOrAppendTest() { final String[] arr = new String[0]; final String[] newArr = ArrayUtil.setOrAppend(arr, 0, "Good");// ClassCastException - Assert.assertArrayEquals(new String[]{"Good"}, newArr); + Assertions.assertArrayEquals(new String[]{"Good"}, newArr); // 非空数组替换第一个元素 int[] arr2 = new int[]{1}; int[] o = ArrayUtil.setOrAppend(arr2, 0, 2); - Assert.assertArrayEquals(new int[]{2}, o); + Assertions.assertArrayEquals(new int[]{2}, o); // 空数组追加 arr2 = new int[0]; o = ArrayUtil.setOrAppend(arr2, 0, 2); - Assert.assertArrayEquals(new int[]{2}, o); + Assertions.assertArrayEquals(new int[]{2}, o); } @Test @@ -547,49 +547,49 @@ public class ArrayUtilTest { final Object o = ArrayUtil.getAny(a, 3, 4); final String[] resultO = (String[]) o; final String[] c = {"d", "e"}; - Assert.assertTrue(ArrayUtil.containsAll(c, resultO[0], resultO[1])); + Assertions.assertTrue(ArrayUtil.containsAll(c, resultO[0], resultO[1])); } @Test public void hasNonNullTest() { String[] a = {null, "e"}; - Assert.assertTrue(ArrayUtil.hasNonNull(a)); + Assertions.assertTrue(ArrayUtil.hasNonNull(a)); a = new String[]{null, null}; - Assert.assertFalse(ArrayUtil.hasNonNull(a)); + Assertions.assertFalse(ArrayUtil.hasNonNull(a)); a = new String[]{"", null}; - Assert.assertTrue(ArrayUtil.hasNonNull(a)); + Assertions.assertTrue(ArrayUtil.hasNonNull(a)); a = new String[]{null}; - Assert.assertFalse(ArrayUtil.hasNonNull(a)); + Assertions.assertFalse(ArrayUtil.hasNonNull(a)); a = new String[]{}; - Assert.assertFalse(ArrayUtil.hasNonNull(a)); + Assertions.assertFalse(ArrayUtil.hasNonNull(a)); a = null; - Assert.assertFalse(ArrayUtil.hasNonNull(a)); + Assertions.assertFalse(ArrayUtil.hasNonNull(a)); } @Test public void isAllNullTest() { String[] a = {null, "e"}; - Assert.assertFalse(ArrayUtil.isAllNull(a)); + Assertions.assertFalse(ArrayUtil.isAllNull(a)); a = new String[]{null, null}; - Assert.assertTrue(ArrayUtil.isAllNull(a)); + Assertions.assertTrue(ArrayUtil.isAllNull(a)); a = new String[]{"", null}; - Assert.assertFalse(ArrayUtil.isAllNull(a)); + Assertions.assertFalse(ArrayUtil.isAllNull(a)); a = new String[]{null}; - Assert.assertTrue(ArrayUtil.isAllNull(a)); + Assertions.assertTrue(ArrayUtil.isAllNull(a)); a = new String[]{}; - Assert.assertTrue(ArrayUtil.isAllNull(a)); + Assertions.assertTrue(ArrayUtil.isAllNull(a)); a = null; - Assert.assertTrue(ArrayUtil.isAllNull(a)); + Assertions.assertTrue(ArrayUtil.isAllNull(a)); } @Test @@ -606,133 +606,133 @@ public class ArrayUtilTest { final double[] doubles = new double[10]; final boolean[] insert1 = ArrayUtil.insert(booleans, 0, 0, 1, 2); - Assert.assertNotNull(insert1); + Assertions.assertNotNull(insert1); final byte[] insert2 = ArrayUtil.insert(bytes, 0, 1, 2, 3); - Assert.assertNotNull(insert2); + Assertions.assertNotNull(insert2); final char[] insert3 = ArrayUtil.insert(chars, 0, 1, 2, 3); - Assert.assertNotNull(insert3); + Assertions.assertNotNull(insert3); final short[] insert4 = ArrayUtil.insert(shorts, 0, 1, 2, 3); - Assert.assertNotNull(insert4); + Assertions.assertNotNull(insert4); final int[] insert5 = ArrayUtil.insert(ints, 0, 1, 2, 3); - Assert.assertNotNull(insert5); + Assertions.assertNotNull(insert5); final long[] insert6 = ArrayUtil.insert(longs, 0, 1, 2, 3); - Assert.assertNotNull(insert6); + Assertions.assertNotNull(insert6); final float[] insert7 = ArrayUtil.insert(floats, 0, 1, 2, 3); - Assert.assertNotNull(insert7); + Assertions.assertNotNull(insert7); final double[] insert8 = ArrayUtil.insert(doubles, 0, 1, 2, 3); - Assert.assertNotNull(insert8); + Assertions.assertNotNull(insert8); } @Test public void subTest() { final int[] arr = {1, 2, 3, 4, 5}; final int[] empty = new int[0]; - Assert.assertArrayEquals(empty, ArrayUtil.sub(arr, 2, 2)); - Assert.assertArrayEquals(empty, ArrayUtil.sub(arr, 5, 5)); - Assert.assertArrayEquals(empty, ArrayUtil.sub(arr, 5, 7)); - Assert.assertArrayEquals(arr, ArrayUtil.sub(arr, 0, 5)); - Assert.assertArrayEquals(arr, ArrayUtil.sub(arr, 5, 0)); - Assert.assertArrayEquals(arr, ArrayUtil.sub(arr, 0, 7)); - Assert.assertArrayEquals(new int[]{1}, ArrayUtil.sub(arr, 0, 1)); - Assert.assertArrayEquals(new int[]{5}, ArrayUtil.sub(arr, 4, 5)); - Assert.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, 1, 4)); - Assert.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, 4, 1)); - Assert.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, 1, -1)); - Assert.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, -1, 1)); - Assert.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, -1, 1)); - Assert.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, -4, -1)); + Assertions.assertArrayEquals(empty, ArrayUtil.sub(arr, 2, 2)); + Assertions.assertArrayEquals(empty, ArrayUtil.sub(arr, 5, 5)); + Assertions.assertArrayEquals(empty, ArrayUtil.sub(arr, 5, 7)); + Assertions.assertArrayEquals(arr, ArrayUtil.sub(arr, 0, 5)); + Assertions.assertArrayEquals(arr, ArrayUtil.sub(arr, 5, 0)); + Assertions.assertArrayEquals(arr, ArrayUtil.sub(arr, 0, 7)); + Assertions.assertArrayEquals(new int[]{1}, ArrayUtil.sub(arr, 0, 1)); + Assertions.assertArrayEquals(new int[]{5}, ArrayUtil.sub(arr, 4, 5)); + Assertions.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, 1, 4)); + Assertions.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, 4, 1)); + Assertions.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, 1, -1)); + Assertions.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, -1, 1)); + Assertions.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, -1, 1)); + Assertions.assertArrayEquals(new int[]{2, 3, 4}, ArrayUtil.sub(arr, -4, -1)); } @Test public void isSortedTest() { final Integer[] a = {1, 1, 2, 2, 2, 3, 3}; - Assert.assertTrue(ArrayUtil.isSorted(a)); - Assert.assertTrue(ArrayUtil.isSorted(a, Integer::compareTo)); - Assert.assertFalse(ArrayUtil.isSorted(a, null)); + Assertions.assertTrue(ArrayUtil.isSorted(a)); + Assertions.assertTrue(ArrayUtil.isSorted(a, Integer::compareTo)); + Assertions.assertFalse(ArrayUtil.isSorted(a, null)); final Integer[] b = {1, 1, 1, 1, 1, 1}; - Assert.assertTrue(ArrayUtil.isSorted(b)); - Assert.assertTrue(ArrayUtil.isSorted(b, Integer::compareTo)); - Assert.assertFalse(ArrayUtil.isSorted(a, null)); + Assertions.assertTrue(ArrayUtil.isSorted(b)); + Assertions.assertTrue(ArrayUtil.isSorted(b, Integer::compareTo)); + Assertions.assertFalse(ArrayUtil.isSorted(a, null)); final Integer[] c = {3, 3, 2, 2, 2, 1, 1}; - Assert.assertTrue(ArrayUtil.isSorted(c)); - Assert.assertTrue(ArrayUtil.isSorted(c, Integer::compareTo)); - Assert.assertFalse(ArrayUtil.isSorted(a, null)); + Assertions.assertTrue(ArrayUtil.isSorted(c)); + Assertions.assertTrue(ArrayUtil.isSorted(c, Integer::compareTo)); + Assertions.assertFalse(ArrayUtil.isSorted(a, null)); - Assert.assertFalse(ArrayUtil.isSorted(null)); - Assert.assertFalse(ArrayUtil.isSorted(null, Integer::compareTo)); - Assert.assertFalse(ArrayUtil.isSorted(null, null)); + Assertions.assertFalse(ArrayUtil.isSorted(null)); + Assertions.assertFalse(ArrayUtil.isSorted(null, Integer::compareTo)); + Assertions.assertFalse(ArrayUtil.isSorted(null, null)); final Integer[] d = {}; - Assert.assertFalse(ArrayUtil.isSorted(d)); - Assert.assertFalse(ArrayUtil.isSorted(d, Integer::compareTo)); - Assert.assertFalse(ArrayUtil.isSorted(d, null)); + Assertions.assertFalse(ArrayUtil.isSorted(d)); + Assertions.assertFalse(ArrayUtil.isSorted(d, Integer::compareTo)); + Assertions.assertFalse(ArrayUtil.isSorted(d, null)); final Integer[] e = {1}; - Assert.assertTrue(ArrayUtil.isSorted(e)); - Assert.assertTrue(ArrayUtil.isSorted(e, Integer::compareTo)); - Assert.assertFalse(ArrayUtil.isSorted(e, null)); + Assertions.assertTrue(ArrayUtil.isSorted(e)); + Assertions.assertTrue(ArrayUtil.isSorted(e, Integer::compareTo)); + Assertions.assertFalse(ArrayUtil.isSorted(e, null)); final Integer[] f = {1, 2}; - Assert.assertTrue(ArrayUtil.isSorted(f)); - Assert.assertTrue(ArrayUtil.isSorted(f, Integer::compareTo)); - Assert.assertFalse(ArrayUtil.isSorted(f, null)); + Assertions.assertTrue(ArrayUtil.isSorted(f)); + Assertions.assertTrue(ArrayUtil.isSorted(f, Integer::compareTo)); + Assertions.assertFalse(ArrayUtil.isSorted(f, null)); } @Test public void hasSameElementTest() { final Integer[] a = {1, 1}; - Assert.assertTrue(ArrayUtil.hasSameElement(a)); + Assertions.assertTrue(ArrayUtil.hasSameElement(a)); final String[] b = {"a", "b", "c"}; - Assert.assertFalse(ArrayUtil.hasSameElement(b)); + Assertions.assertFalse(ArrayUtil.hasSameElement(b)); final Object[] c = new Object[]{"1", "2", 2, 4D}; - Assert.assertFalse(ArrayUtil.hasSameElement(c)); + Assertions.assertFalse(ArrayUtil.hasSameElement(c)); final Object[] d = new Object[]{"1", "2", "2", 4D}; - Assert.assertTrue(ArrayUtil.hasSameElement(d)); + Assertions.assertTrue(ArrayUtil.hasSameElement(d)); final Object[] e = new Object[]{"1", 2, 2, 4D}; - Assert.assertTrue(ArrayUtil.hasSameElement(e)); + Assertions.assertTrue(ArrayUtil.hasSameElement(e)); } @Test public void startWithTest() { boolean b = ArrayUtil.startWith(new String[]{}, new String[]{}); - Assert.assertTrue(b); + Assertions.assertTrue(b); b = ArrayUtil.startWith(new String[]{"1", "2", "3"}, new String[]{"1"}); - Assert.assertTrue(b); + Assertions.assertTrue(b); b = ArrayUtil.startWith(new String[]{"1"}, new String[]{"1"}); - Assert.assertTrue(b); + Assertions.assertTrue(b); b = ArrayUtil.startWith((String[])null, null); - Assert.assertTrue(b); + Assertions.assertTrue(b); } @Test public void startWithTest2() { boolean b = ArrayUtil.startWith(new int[]{}, new int[]{}); - Assert.assertTrue(b); + Assertions.assertTrue(b); b = ArrayUtil.startWith(new int[]{1,2,3}, new int[]{1}); - Assert.assertTrue(b); + Assertions.assertTrue(b); b = ArrayUtil.startWith(new int[]{1}, new int[]{1}); - Assert.assertTrue(b); + Assertions.assertTrue(b); b = ArrayUtil.startWith((int[])null, null); - Assert.assertTrue(b); + Assertions.assertTrue(b); } @Test public void equalsTest() { final boolean b = ObjUtil.equals(new int[]{1, 2, 3}, new int[]{1, 2, 3}); - Assert.assertTrue(b); + Assertions.assertTrue(b); } @Test @@ -740,7 +740,7 @@ public class ArrayUtilTest { final String a = "aIDAT"; final byte[] bytes1 = Arrays.copyOfRange(a.getBytes(CharsetUtil.UTF_8), 1, 1 + 4); - Assert.assertEquals(new String(bytes1), + Assertions.assertEquals(new String(bytes1), new String(a.getBytes(CharsetUtil.UTF_8), 1, 4)); } @@ -749,12 +749,12 @@ public class ArrayUtilTest { final byte[] a = new byte[]{1, 2, 3, 4, 5}; final byte[] b = new byte[]{2, 3, 4}; - Assert.assertTrue(ArrayUtil.regionMatches(a, 1, b, 0, 1)); - Assert.assertTrue(ArrayUtil.regionMatches(a, 1, b, 0, 2)); - Assert.assertTrue(ArrayUtil.regionMatches(a, 1, b, 0, 3)); - Assert.assertTrue(ArrayUtil.isSubEquals(a, 1, b)); + Assertions.assertTrue(ArrayUtil.regionMatches(a, 1, b, 0, 1)); + Assertions.assertTrue(ArrayUtil.regionMatches(a, 1, b, 0, 2)); + Assertions.assertTrue(ArrayUtil.regionMatches(a, 1, b, 0, 3)); + Assertions.assertTrue(ArrayUtil.isSubEquals(a, 1, b)); - Assert.assertFalse(ArrayUtil.regionMatches(a, 2, b, 0, 2)); - Assert.assertFalse(ArrayUtil.regionMatches(a, 3, b, 0, 2)); + Assertions.assertFalse(ArrayUtil.regionMatches(a, 2, b, 0, 2)); + Assertions.assertFalse(ArrayUtil.regionMatches(a, 3, b, 0, 2)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/BooleanUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/BooleanUtilTest.java index d143ab03b..d51a0325b 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/BooleanUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/BooleanUtilTest.java @@ -1,98 +1,98 @@ package cn.hutool.core.util; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BooleanUtilTest { @Test public void toBooleanTest() { - Assert.assertTrue(BooleanUtil.toBoolean("true")); - Assert.assertTrue(BooleanUtil.toBoolean("yes")); - Assert.assertTrue(BooleanUtil.toBoolean("t")); - Assert.assertTrue(BooleanUtil.toBoolean("OK")); - Assert.assertTrue(BooleanUtil.toBoolean("1")); - Assert.assertTrue(BooleanUtil.toBoolean("On")); - Assert.assertTrue(BooleanUtil.toBoolean("是")); - Assert.assertTrue(BooleanUtil.toBoolean("对")); - Assert.assertTrue(BooleanUtil.toBoolean("真")); + Assertions.assertTrue(BooleanUtil.toBoolean("true")); + Assertions.assertTrue(BooleanUtil.toBoolean("yes")); + Assertions.assertTrue(BooleanUtil.toBoolean("t")); + Assertions.assertTrue(BooleanUtil.toBoolean("OK")); + Assertions.assertTrue(BooleanUtil.toBoolean("1")); + Assertions.assertTrue(BooleanUtil.toBoolean("On")); + Assertions.assertTrue(BooleanUtil.toBoolean("是")); + Assertions.assertTrue(BooleanUtil.toBoolean("对")); + Assertions.assertTrue(BooleanUtil.toBoolean("真")); - Assert.assertFalse(BooleanUtil.toBoolean("false")); - Assert.assertFalse(BooleanUtil.toBoolean("6455434")); - Assert.assertFalse(BooleanUtil.toBoolean("")); + Assertions.assertFalse(BooleanUtil.toBoolean("false")); + Assertions.assertFalse(BooleanUtil.toBoolean("6455434")); + Assertions.assertFalse(BooleanUtil.toBoolean("")); } @Test public void andTest() { - Assert.assertFalse(BooleanUtil.and(true, false)); - Assert.assertFalse(BooleanUtil.andOfWrap(true, false)); + Assertions.assertFalse(BooleanUtil.and(true, false)); + Assertions.assertFalse(BooleanUtil.andOfWrap(true, false)); } @Test public void orTest() { - Assert.assertTrue(BooleanUtil.or(true, false)); - Assert.assertTrue(BooleanUtil.orOfWrap(true, false)); + Assertions.assertTrue(BooleanUtil.or(true, false)); + Assertions.assertTrue(BooleanUtil.orOfWrap(true, false)); } @Test public void xorTest() { - Assert.assertTrue(BooleanUtil.xor(true, false)); - Assert.assertTrue(BooleanUtil.xor(true, true, true)); - Assert.assertFalse(BooleanUtil.xor(true, true, false)); - Assert.assertTrue(BooleanUtil.xor(true, false, false)); - Assert.assertFalse(BooleanUtil.xor(false, false, false)); + Assertions.assertTrue(BooleanUtil.xor(true, false)); + Assertions.assertTrue(BooleanUtil.xor(true, true, true)); + Assertions.assertFalse(BooleanUtil.xor(true, true, false)); + Assertions.assertTrue(BooleanUtil.xor(true, false, false)); + Assertions.assertFalse(BooleanUtil.xor(false, false, false)); - Assert.assertTrue(BooleanUtil.xorOfWrap(true, false)); - Assert.assertTrue(BooleanUtil.xorOfWrap(true, true, true)); - Assert.assertFalse(BooleanUtil.xorOfWrap(true, true, false)); - Assert.assertTrue(BooleanUtil.xorOfWrap(true, false, false)); - Assert.assertFalse(BooleanUtil.xorOfWrap(false, false, false)); + Assertions.assertTrue(BooleanUtil.xorOfWrap(true, false)); + Assertions.assertTrue(BooleanUtil.xorOfWrap(true, true, true)); + Assertions.assertFalse(BooleanUtil.xorOfWrap(true, true, false)); + Assertions.assertTrue(BooleanUtil.xorOfWrap(true, false, false)); + Assertions.assertFalse(BooleanUtil.xorOfWrap(false, false, false)); } @SuppressWarnings("ConstantConditions") @Test public void isTrueIsFalseTest() { - Assert.assertFalse(BooleanUtil.isTrue(null)); - Assert.assertFalse(BooleanUtil.isFalse(null)); + Assertions.assertFalse(BooleanUtil.isTrue(null)); + Assertions.assertFalse(BooleanUtil.isFalse(null)); } @Test public void orOfWrapTest() { - Assert.assertFalse(BooleanUtil.orOfWrap(Boolean.FALSE, null)); - Assert.assertTrue(BooleanUtil.orOfWrap(Boolean.TRUE, null)); + Assertions.assertFalse(BooleanUtil.orOfWrap(Boolean.FALSE, null)); + Assertions.assertTrue(BooleanUtil.orOfWrap(Boolean.TRUE, null)); } @SuppressWarnings("ConstantConditions") @Test public void negateTest() { - Assert.assertFalse(BooleanUtil.negate(Boolean.TRUE)); - Assert.assertTrue(BooleanUtil.negate(Boolean.FALSE)); + Assertions.assertFalse(BooleanUtil.negate(Boolean.TRUE)); + Assertions.assertTrue(BooleanUtil.negate(Boolean.FALSE)); - Assert.assertFalse(BooleanUtil.negate(Boolean.TRUE.booleanValue())); - Assert.assertTrue(BooleanUtil.negate(Boolean.FALSE.booleanValue())); + Assertions.assertFalse(BooleanUtil.negate(Boolean.TRUE.booleanValue())); + Assertions.assertTrue(BooleanUtil.negate(Boolean.FALSE.booleanValue())); } @Test public void toStringTest() { - Assert.assertEquals("true", BooleanUtil.toStringTrueFalse(true)); - Assert.assertEquals("false", BooleanUtil.toStringTrueFalse(false)); + Assertions.assertEquals("true", BooleanUtil.toStringTrueFalse(true)); + Assertions.assertEquals("false", BooleanUtil.toStringTrueFalse(false)); - Assert.assertEquals("yes", BooleanUtil.toStringYesNo(true)); - Assert.assertEquals("no", BooleanUtil.toStringYesNo(false)); + Assertions.assertEquals("yes", BooleanUtil.toStringYesNo(true)); + Assertions.assertEquals("no", BooleanUtil.toStringYesNo(false)); - Assert.assertEquals("on", BooleanUtil.toStringOnOff(true)); - Assert.assertEquals("off", BooleanUtil.toStringOnOff(false)); + Assertions.assertEquals("on", BooleanUtil.toStringOnOff(true)); + Assertions.assertEquals("off", BooleanUtil.toStringOnOff(false)); } @SuppressWarnings("ConstantConditions") @Test public void toBooleanObjectTest(){ - Assert.assertTrue(BooleanUtil.toBooleanObject("yes")); - Assert.assertTrue(BooleanUtil.toBooleanObject("真")); - Assert.assertTrue(BooleanUtil.toBooleanObject("是")); - Assert.assertTrue(BooleanUtil.toBooleanObject("√")); + Assertions.assertTrue(BooleanUtil.toBooleanObject("yes")); + Assertions.assertTrue(BooleanUtil.toBooleanObject("真")); + Assertions.assertTrue(BooleanUtil.toBooleanObject("是")); + Assertions.assertTrue(BooleanUtil.toBooleanObject("√")); - Assert.assertNull(BooleanUtil.toBooleanObject(null)); - Assert.assertNull(BooleanUtil.toBooleanObject("不识别")); + Assertions.assertNull(BooleanUtil.toBooleanObject(null)); + Assertions.assertNull(BooleanUtil.toBooleanObject("不识别")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ByteUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ByteUtilTest.java index 848c482fe..17dafd297 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/ByteUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ByteUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.util; -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; @@ -18,18 +18,18 @@ public class ByteUtilTest { final byte[] bytesIntFromBuffer = buffer.array(); final byte[] bytesInt = ByteUtil.toBytes(int1, ByteOrder.LITTLE_ENDIAN); - Assert.assertArrayEquals(bytesIntFromBuffer, bytesInt); + Assertions.assertArrayEquals(bytesIntFromBuffer, bytesInt); final int int2 = ByteUtil.toInt(bytesInt, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(int1, int2); + Assertions.assertEquals(int1, int2); final byte[] bytesInt2 = ByteUtil.toBytes(int1, ByteOrder.LITTLE_ENDIAN); final int int3 = ByteUtil.toInt(bytesInt2, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(int1, int3); + Assertions.assertEquals(int1, int3); final byte[] bytesInt3 = ByteUtil.toBytes(int1, ByteOrder.LITTLE_ENDIAN); final int int4 = ByteUtil.toInt(bytesInt3, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(int1, int4); + Assertions.assertEquals(int1, int4); } @Test @@ -42,11 +42,11 @@ public class ByteUtilTest { final byte[] bytesIntFromBuffer = buffer.array(); final byte[] bytesInt = ByteUtil.toBytes(int2, ByteOrder.BIG_ENDIAN); - Assert.assertArrayEquals(bytesIntFromBuffer, bytesInt); + Assertions.assertArrayEquals(bytesIntFromBuffer, bytesInt); // 测试大端序 byte 数组转 int final int int3 = ByteUtil.toInt(bytesInt, ByteOrder.BIG_ENDIAN); - Assert.assertEquals(int2, int3); + Assertions.assertEquals(int2, int3); } @Test @@ -60,18 +60,18 @@ public class ByteUtilTest { final byte[] bytesLongFromBuffer = buffer.array(); final byte[] bytesLong = ByteUtil.toBytes(long1, ByteOrder.LITTLE_ENDIAN); - Assert.assertArrayEquals(bytesLongFromBuffer, bytesLong); + Assertions.assertArrayEquals(bytesLongFromBuffer, bytesLong); final long long2 = ByteUtil.toLong(bytesLong, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(long1, long2); + Assertions.assertEquals(long1, long2); final byte[] bytesLong2 = ByteUtil.toBytes(long1); final long long3 = ByteUtil.toLong(bytesLong2, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(long1, long3); + Assertions.assertEquals(long1, long3); final byte[] bytesLong3 = ByteUtil.toBytes(long1, ByteOrder.LITTLE_ENDIAN); final long long4 = ByteUtil.toLong(bytesLong3); - Assert.assertEquals(long1, long4); + Assertions.assertEquals(long1, long4); } @Test @@ -84,10 +84,10 @@ public class ByteUtilTest { final byte[] bytesLongFromBuffer = buffer.array(); final byte[] bytesLong = ByteUtil.toBytes(long1, ByteOrder.BIG_ENDIAN); - Assert.assertArrayEquals(bytesLongFromBuffer, bytesLong); + Assertions.assertArrayEquals(bytesLongFromBuffer, bytesLong); final long long2 = ByteUtil.toLong(bytesLong, ByteOrder.BIG_ENDIAN); - Assert.assertEquals(long1, long2); + Assertions.assertEquals(long1, long2); } @Test @@ -97,7 +97,7 @@ public class ByteUtilTest { final byte[] bytesLong = ByteUtil.toBytes(f1, ByteOrder.LITTLE_ENDIAN); final float f2 = ByteUtil.toFloat(bytesLong, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(f1, f2, 0); + Assertions.assertEquals(f1, f2, 0); } @Test @@ -108,7 +108,7 @@ public class ByteUtilTest { final byte[] bytesLong = ByteUtil.toBytes(f1, ByteOrder.BIG_ENDIAN); final float f2 = ByteUtil.toFloat(bytesLong, ByteOrder.BIG_ENDIAN); - Assert.assertEquals(f1, f2, 0); + Assertions.assertEquals(f1, f2, 0); } @Test @@ -117,15 +117,15 @@ public class ByteUtilTest { final byte[] bytes = ByteUtil.toBytes(short1, ByteOrder.LITTLE_ENDIAN); final short short2 = ByteUtil.toShort(bytes, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(short2, short1); + Assertions.assertEquals(short2, short1); final byte[] bytes2 = ByteUtil.toBytes(short1); final short short3 = ByteUtil.toShort(bytes2, ByteOrder.LITTLE_ENDIAN); - Assert.assertEquals(short3, short1); + Assertions.assertEquals(short3, short1); final byte[] bytes3 = ByteUtil.toBytes(short1, ByteOrder.LITTLE_ENDIAN); final short short4 = ByteUtil.toShort(bytes3); - Assert.assertEquals(short4, short1); + Assertions.assertEquals(short4, short1); } @Test @@ -134,7 +134,7 @@ public class ByteUtilTest { final byte[] bytes = ByteUtil.toBytes(short1, ByteOrder.BIG_ENDIAN); final short short2 = ByteUtil.toShort(bytes, ByteOrder.BIG_ENDIAN); - Assert.assertEquals(short2, short1); + Assertions.assertEquals(short2, short1); } @Test @@ -143,12 +143,12 @@ public class ByteUtilTest { ByteBuffer wrap = ByteBuffer.wrap(ByteUtil.toBytes(a)); wrap.order(ByteOrder.LITTLE_ENDIAN); long aLong = wrap.getLong(); - Assert.assertEquals(a, aLong); + Assertions.assertEquals(a, aLong); wrap = ByteBuffer.wrap(ByteUtil.toBytes(a, ByteOrder.BIG_ENDIAN)); wrap.order(ByteOrder.BIG_ENDIAN); aLong = wrap.getLong(); - Assert.assertEquals(a, aLong); + Assertions.assertEquals(a, aLong); } @Test @@ -157,12 +157,12 @@ public class ByteUtilTest { ByteBuffer wrap = ByteBuffer.wrap(ByteUtil.toBytes(a)); wrap.order(ByteOrder.LITTLE_ENDIAN); int aInt = wrap.getInt(); - Assert.assertEquals(a, aInt); + Assertions.assertEquals(a, aInt); wrap = ByteBuffer.wrap(ByteUtil.toBytes(a, ByteOrder.BIG_ENDIAN)); wrap.order(ByteOrder.BIG_ENDIAN); aInt = wrap.getInt(); - Assert.assertEquals(a, aInt); + Assertions.assertEquals(a, aInt); } @Test @@ -172,11 +172,11 @@ public class ByteUtilTest { ByteBuffer wrap = ByteBuffer.wrap(ByteUtil.toBytes(a)); wrap.order(ByteOrder.LITTLE_ENDIAN); short aShort = wrap.getShort(); - Assert.assertEquals(a, aShort); + Assertions.assertEquals(a, aShort); wrap = ByteBuffer.wrap(ByteUtil.toBytes(a, ByteOrder.BIG_ENDIAN)); wrap.order(ByteOrder.BIG_ENDIAN); aShort = wrap.getShort(); - Assert.assertEquals(a, aShort); + Assertions.assertEquals(a, aShort); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/CharUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/CharUtilTest.java index 14334fc0b..65aca8d60 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/CharUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/CharUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.util; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CharUtilTest { @@ -9,61 +9,61 @@ public class CharUtilTest { public void trimTest() { //此字符串中的第一个字符为不可见字符: '\u202a' final String str = "‪C:/Users/maple/Desktop/tone.txt"; - Assert.assertEquals('\u202a', str.charAt(0)); - Assert.assertTrue(CharUtil.isBlankChar(str.charAt(0))); + Assertions.assertEquals('\u202a', str.charAt(0)); + Assertions.assertTrue(CharUtil.isBlankChar(str.charAt(0))); } @Test public void isEmojiTest() { final String a = "莉🌹"; - Assert.assertFalse(CharUtil.isEmoji(a.charAt(0))); - Assert.assertTrue(CharUtil.isEmoji(a.charAt(1))); + Assertions.assertFalse(CharUtil.isEmoji(a.charAt(0))); + Assertions.assertTrue(CharUtil.isEmoji(a.charAt(1))); } @Test public void isCharTest(){ final char a = 'a'; - Assert.assertTrue(CharUtil.isChar(a)); + Assertions.assertTrue(CharUtil.isChar(a)); } @SuppressWarnings("UnnecessaryUnicodeEscape") @Test public void isBlankCharTest(){ final char a = '\u00A0'; - Assert.assertTrue(CharUtil.isBlankChar(a)); + Assertions.assertTrue(CharUtil.isBlankChar(a)); final char a2 = '\u0020'; - Assert.assertTrue(CharUtil.isBlankChar(a2)); + Assertions.assertTrue(CharUtil.isBlankChar(a2)); final char a3 = '\u3000'; - Assert.assertTrue(CharUtil.isBlankChar(a3)); + Assertions.assertTrue(CharUtil.isBlankChar(a3)); final char a4 = '\u0000'; - Assert.assertTrue(CharUtil.isBlankChar(a4)); + Assertions.assertTrue(CharUtil.isBlankChar(a4)); } @Test public void toCloseCharTest(){ - Assert.assertEquals('②', CharUtil.toCloseChar('2')); - Assert.assertEquals('Ⓜ', CharUtil.toCloseChar('M')); - Assert.assertEquals('ⓡ', CharUtil.toCloseChar('r')); + Assertions.assertEquals('②', CharUtil.toCloseChar('2')); + Assertions.assertEquals('Ⓜ', CharUtil.toCloseChar('M')); + Assertions.assertEquals('ⓡ', CharUtil.toCloseChar('r')); } @Test public void toCloseByNumberTest(){ - Assert.assertEquals('②', CharUtil.toCloseByNumber(2)); - Assert.assertEquals('⑫', CharUtil.toCloseByNumber(12)); - Assert.assertEquals('⑳', CharUtil.toCloseByNumber(20)); + Assertions.assertEquals('②', CharUtil.toCloseByNumber(2)); + Assertions.assertEquals('⑫', CharUtil.toCloseByNumber(12)); + Assertions.assertEquals('⑳', CharUtil.toCloseByNumber(20)); } @SuppressWarnings("UnnecessaryUnicodeEscape") @Test public void issueI5UGSQTest(){ char c = '\u3164'; - Assert.assertTrue(CharUtil.isBlankChar(c)); + Assertions.assertTrue(CharUtil.isBlankChar(c)); c = '\u2800'; - Assert.assertTrue(CharUtil.isBlankChar(c)); + Assertions.assertTrue(CharUtil.isBlankChar(c)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ClassUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ClassUtilTest.java index 151b4fc74..65b6dcf86 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/ClassUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ClassUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.util; import cn.hutool.core.reflect.ClassUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Objects; @@ -17,35 +17,35 @@ public class ClassUtilTest { @Test public void getClassNameTest() { final String className = ClassUtil.getClassName(ClassUtil.class, false); - Assert.assertEquals("cn.hutool.core.reflect.ClassUtil", className); + Assertions.assertEquals("cn.hutool.core.reflect.ClassUtil", className); final String simpleClassName = ClassUtil.getClassName(ClassUtil.class, true); - Assert.assertEquals("ClassUtil", simpleClassName); + Assertions.assertEquals("ClassUtil", simpleClassName); } @Test public void getClassPathTest() { final String classPath = ClassUtil.getClassPath(); - Assert.assertNotNull(classPath); + Assertions.assertNotNull(classPath); } @Test public void getShortClassNameTest() { final String className = "cn.hutool.core.text.StrUtil"; final String result = ClassUtil.getShortClassName(className); - Assert.assertEquals("c.h.c.t.StrUtil", result); + Assertions.assertEquals("c.h.c.t.StrUtil", result); } @Test public void getLocationPathTest(){ final String classDir = ClassUtil.getLocationPath(ClassUtilTest.class); - Assert.assertTrue(Objects.requireNonNull(classDir).endsWith("/hutool-core/target/test-classes/")); + Assertions.assertTrue(Objects.requireNonNull(classDir).endsWith("/hutool-core/target/test-classes/")); } @Test public void isAssignableTest(){ - Assert.assertTrue(ClassUtil.isAssignable(int.class, int.class)); - Assert.assertTrue(ClassUtil.isAssignable(int.class, Integer.class)); - Assert.assertFalse(ClassUtil.isAssignable(int.class, String.class)); + Assertions.assertTrue(ClassUtil.isAssignable(int.class, int.class)); + Assertions.assertTrue(ClassUtil.isAssignable(int.class, Integer.class)); + Assertions.assertFalse(ClassUtil.isAssignable(int.class, String.class)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/CloneTest.java b/hutool-core/src/test/java/cn/hutool/core/util/CloneTest.java index f7e9b575f..6f96e344a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/CloneTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/CloneTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.util; import cn.hutool.core.exceptions.CloneRuntimeException; import lombok.Data; import lombok.EqualsAndHashCode; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 克隆单元测试 @@ -19,7 +19,7 @@ public class CloneTest { //实现Cloneable接口 final Cat cat = new Cat(); final Cat cat2 = cat.clone(); - Assert.assertEquals(cat, cat2); + Assertions.assertEquals(cat, cat2); } @Test @@ -27,7 +27,7 @@ public class CloneTest { //继承CloneSupport类 final Dog dog = new Dog(); final Dog dog2 = dog.clone(); - Assert.assertEquals(dog, dog2); + Assertions.assertEquals(dog, dog2); } //------------------------------------------------------------------------------- private Class for test diff --git a/hutool-core/src/test/java/cn/hutool/core/util/CoordinateUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/CoordinateUtilTest.java index f034b70dc..c8816c151 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/CoordinateUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/CoordinateUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.util; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 坐标转换工具类单元测试
@@ -14,51 +14,51 @@ public class CoordinateUtilTest { @Test public void wgs84ToGcj02Test() { final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToGcj02(116.404, 39.915); - Assert.assertEquals(116.41024449916938D, coordinate.getLng(), 0); - Assert.assertEquals(39.91640428150164D, coordinate.getLat(), 0); + Assertions.assertEquals(116.41024449916938D, coordinate.getLng(), 0); + Assertions.assertEquals(39.91640428150164D, coordinate.getLat(), 0); } @Test public void gcj02ToWgs84Test() { final CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(116.404, 39.915); - Assert.assertEquals(116.39775550083061D, coordinate.getLng(), 0); - Assert.assertEquals(39.91359571849836D, coordinate.getLat(), 0); + Assertions.assertEquals(116.39775550083061D, coordinate.getLng(), 0); + Assertions.assertEquals(39.91359571849836D, coordinate.getLat(), 0); } @Test public void wgs84toBd09Test() { final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToBd09(116.404, 39.915); - Assert.assertEquals(116.41662724378733D, coordinate.getLng(), 0); - Assert.assertEquals(39.922699552216216D, coordinate.getLat(), 0); + Assertions.assertEquals(116.41662724378733D, coordinate.getLng(), 0); + Assertions.assertEquals(39.922699552216216D, coordinate.getLat(), 0); } @Test public void wgs84toBd09Test2() { // https://tool.lu/coordinate/ final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToBd09(122.99395597D, 44.99804071D); - Assert.assertEquals(123.00636516028885D, coordinate.getLng(), 0); - Assert.assertEquals(45.0063690918959D, coordinate.getLat(), 0); + Assertions.assertEquals(123.00636516028885D, coordinate.getLng(), 0); + Assertions.assertEquals(45.0063690918959D, coordinate.getLat(), 0); } @Test public void bd09toWgs84Test() { final CoordinateUtil.Coordinate coordinate = CoordinateUtil.bd09toWgs84(116.404, 39.915); - Assert.assertEquals(116.3913836995125D, coordinate.getLng(), 0); - Assert.assertEquals(39.907253214522164D, coordinate.getLat(), 0); + Assertions.assertEquals(116.3913836995125D, coordinate.getLng(), 0); + Assertions.assertEquals(39.907253214522164D, coordinate.getLat(), 0); } @Test public void gcj02ToBd09Test() { final CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToBd09(116.404, 39.915); - Assert.assertEquals(116.41036949371029D, coordinate.getLng(), 0); - Assert.assertEquals(39.92133699351022D, coordinate.getLat(), 0); + Assertions.assertEquals(116.41036949371029D, coordinate.getLng(), 0); + Assertions.assertEquals(39.92133699351022D, coordinate.getLat(), 0); } @Test public void bd09toGcj02Test() { final CoordinateUtil.Coordinate coordinate = CoordinateUtil.bd09ToGcj02(116.404, 39.915); - Assert.assertEquals(116.39762729119315D, coordinate.getLng(), 0); - Assert.assertEquals(39.90865673957631D, coordinate.getLat(), 0); + Assertions.assertEquals(116.39762729119315D, coordinate.getLng(), 0); + Assertions.assertEquals(39.90865673957631D, coordinate.getLat(), 0); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/CreditCodeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/CreditCodeUtilTest.java index 87f86e458..978dda3a5 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/CreditCodeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/CreditCodeUtilTest.java @@ -1,20 +1,20 @@ package cn.hutool.core.util; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CreditCodeUtilTest { @Test public void isCreditCodeBySimple() { final String testCreditCode = "91310115591693856A"; - Assert.assertTrue(CreditCodeUtil.isCreditCodeSimple(testCreditCode)); + Assertions.assertTrue(CreditCodeUtil.isCreditCodeSimple(testCreditCode)); } @Test public void isCreditCode() { final String testCreditCode = "91310110666007217T"; - Assert.assertTrue(CreditCodeUtil.isCreditCode(testCreditCode)); + Assertions.assertTrue(CreditCodeUtil.isCreditCode(testCreditCode)); } @Test @@ -22,12 +22,12 @@ public class CreditCodeUtilTest { // 由于早期部分试点地区推行 法人和其他组织统一社会信用代码 较早,会存在部分代码不符合国家标准的情况。 // 见:https://github.com/bluesky335/IDCheck final String testCreditCode = "91350211M00013FA1N"; - Assert.assertFalse(CreditCodeUtil.isCreditCode(testCreditCode)); + Assertions.assertFalse(CreditCodeUtil.isCreditCode(testCreditCode)); } @Test public void randomCreditCode() { final String s = CreditCodeUtil.randomCreditCode(); - Assert.assertTrue(CreditCodeUtil.isCreditCode(s)); + Assertions.assertTrue(CreditCodeUtil.isCreditCode(s)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/DefaultCloneTest.java b/hutool-core/src/test/java/cn/hutool/core/util/DefaultCloneTest.java index 822389b5c..677f555b3 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/DefaultCloneTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/DefaultCloneTest.java @@ -4,8 +4,8 @@ package cn.hutool.core.util; import cn.hutool.core.exceptions.CloneRuntimeException; 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.List; import java.util.stream.Collectors; @@ -20,14 +20,14 @@ public class DefaultCloneTest { oldCar.setWheelList(Stream.of(new Wheel("h")).collect(Collectors.toList())); final Car newCar = oldCar.clone(); - Assert.assertEquals(oldCar.getId(), newCar.getId()); - Assert.assertEquals(oldCar.getWheelList(), newCar.getWheelList()); + Assertions.assertEquals(oldCar.getId(), newCar.getId()); + Assertions.assertEquals(oldCar.getWheelList(), newCar.getWheelList()); newCar.setId(2); - Assert.assertNotEquals(oldCar.getId(), newCar.getId()); + Assertions.assertNotEquals(oldCar.getId(), newCar.getId()); newCar.getWheelList().add(new Wheel("s")); - Assert.assertNotSame(oldCar, newCar); + Assertions.assertNotSame(oldCar, newCar); } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/EnumUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/EnumUtilTest.java index 7856c736a..3a96eaf2d 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/EnumUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/EnumUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.util; 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; import java.util.Map; @@ -18,56 +18,56 @@ public class EnumUtilTest { @Test public void getNamesTest() { final List names = EnumUtil.getNames(TestEnum.class); - Assert.assertEquals(ListUtil.of("TEST1", "TEST2", "TEST3"), names); + Assertions.assertEquals(ListUtil.of("TEST1", "TEST2", "TEST3"), names); } @Test public void getFieldValuesTest() { final List types = EnumUtil.getFieldValues(TestEnum.class, "type"); - Assert.assertEquals(ListUtil.of("type1", "type2", "type3"), types); + Assertions.assertEquals(ListUtil.of("type1", "type2", "type3"), types); } @Test public void getFieldNamesTest() { final List names = EnumUtil.getFieldNames(TestEnum.class); - Assert.assertTrue(names.contains("type")); - Assert.assertTrue(names.contains("name")); + Assertions.assertTrue(names.contains("type")); + Assertions.assertTrue(names.contains("name")); } @Test public void getByTest() { // 枚举中字段互相映射使用 final TestEnum testEnum = EnumUtil.getBy(TestEnum::ordinal, 1); - Assert.assertEquals("TEST2", testEnum.name()); + Assertions.assertEquals("TEST2", testEnum.name()); } @Test public void getFieldByTest() { // 枚举中字段互相映射使用 final String type = EnumUtil.getFieldBy(TestEnum::getType, Enum::ordinal, 1); - Assert.assertEquals("type2", type); + Assertions.assertEquals("type2", type); final int ordinal = EnumUtil.getFieldBy(TestEnum::ordinal, Enum::ordinal, 1); - Assert.assertEquals(1, ordinal); + Assertions.assertEquals(1, ordinal); } @Test public void likeValueOfTest() { final TestEnum value = EnumUtil.likeValueOf(TestEnum.class, "type2"); - Assert.assertEquals(TestEnum.TEST2, value); + Assertions.assertEquals(TestEnum.TEST2, value); } @Test public void getEnumMapTest() { final Map enumMap = EnumUtil.getEnumMap(TestEnum.class); - Assert.assertEquals(TestEnum.TEST1, enumMap.get("TEST1")); + Assertions.assertEquals(TestEnum.TEST1, enumMap.get("TEST1")); } @Test public void getNameFieldMapTest() { final Map enumMap = EnumUtil.getNameFieldMap(TestEnum.class, "type"); assert enumMap != null; - Assert.assertEquals("type1", enumMap.get("TEST1")); + Assertions.assertEquals("type1", enumMap.get("TEST1")); } public enum TestEnum{ diff --git a/hutool-core/src/test/java/cn/hutool/core/util/HashUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/HashUtilTest.java index b169eedac..88093755c 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/HashUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/HashUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.util; import cn.hutool.core.codec.hash.HashUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class HashUtilTest { @@ -10,21 +10,21 @@ public class HashUtilTest { public void cityHash128Test(){ final String s="Google发布的Hash计算算法:CityHash64 与 CityHash128"; final long[] hash = HashUtil.cityHash128(ByteUtil.toUtf8Bytes(s)); - Assert.assertEquals(0x5944f1e788a18db0L, hash[0]); - Assert.assertEquals(0xc2f68d8b2bf4a5cfL, hash[1]); + Assertions.assertEquals(0x5944f1e788a18db0L, hash[0]); + Assertions.assertEquals(0xc2f68d8b2bf4a5cfL, hash[1]); } @Test public void cityHash64Test(){ final String s="Google发布的Hash计算算法:CityHash64 与 CityHash128"; final long hash = HashUtil.cityHash64(ByteUtil.toUtf8Bytes(s)); - Assert.assertEquals(0x1d408f2bbf967e2aL, hash); + Assertions.assertEquals(0x1d408f2bbf967e2aL, hash); } @Test public void cityHash32Test(){ final String s="Google发布的Hash计算算法:CityHash64 与 CityHash128"; final int hash = HashUtil.cityHash32(ByteUtil.toUtf8Bytes(s)); - Assert.assertEquals(0xa8944fbe, hash); + Assertions.assertEquals(0xa8944fbe, hash); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/HexUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/HexUtilTest.java index e9cba0936..f776bfc87 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/HexUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/HexUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.util; import cn.hutool.core.codec.HexUtil; -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; @@ -20,46 +20,46 @@ public class HexUtilTest { final String hex = HexUtil.encodeHexStr(str, CharsetUtil.UTF_8); final String decodedStr = HexUtil.decodeHexStr(hex); - Assert.assertEquals(str, decodedStr); + Assertions.assertEquals(str, decodedStr); } @Test public void issueI50MI6Test(){ final String s = HexUtil.encodeHexStr("烟".getBytes(StandardCharsets.UTF_16BE)); - Assert.assertEquals("70df", s); + Assertions.assertEquals("70df", s); } @Test public void toUnicodeHexTest() { String unicodeHex = HexUtil.toUnicodeHex('\u2001'); - Assert.assertEquals("\\u2001", unicodeHex); + Assertions.assertEquals("\\u2001", unicodeHex); unicodeHex = HexUtil.toUnicodeHex('你'); - Assert.assertEquals("\\u4f60", unicodeHex); + Assertions.assertEquals("\\u4f60", unicodeHex); } @Test public void isHexNumberTest() { String a = "0x3544534F444"; - Assert.assertTrue(HexUtil.isHexNumber(a)); + Assertions.assertTrue(HexUtil.isHexNumber(a)); // https://gitee.com/dromara/hutool/issues/I62H7K a = "0x0000000000000001158e460913d00000"; - Assert.assertTrue(HexUtil.isHexNumber(a)); + Assertions.assertTrue(HexUtil.isHexNumber(a)); // 错误的 a = "0x0000001000T00001158e460913d00000"; - Assert.assertFalse(HexUtil.isHexNumber(a)); + Assertions.assertFalse(HexUtil.isHexNumber(a)); // 错误的,https://github.com/dromara/hutool/issues/2857 a = "-1"; - Assert.assertFalse(HexUtil.isHexNumber(a)); + Assertions.assertFalse(HexUtil.isHexNumber(a)); } @Test public void decodeTest(){ final String str = "e8c670380cb220095268f40221fc748fa6ac39d6e930e63c30da68bad97f885d"; - Assert.assertArrayEquals(HexUtil.decodeHex(str), + Assertions.assertArrayEquals(HexUtil.decodeHex(str), HexUtil.decodeHex(str.toUpperCase())); } @@ -67,13 +67,13 @@ public class HexUtilTest { public void formatHexTest(){ final String hex = "e8c670380cb220095268f40221fc748fa6ac39d6e930e63c30da68bad97f885d"; final String formatHex = HexUtil.format(hex); - Assert.assertEquals("e8 c6 70 38 0c b2 20 09 52 68 f4 02 21 fc 74 8f a6 ac 39 d6 e9 30 e6 3c 30 da 68 ba d9 7f 88 5d", formatHex); + Assertions.assertEquals("e8 c6 70 38 0c b2 20 09 52 68 f4 02 21 fc 74 8f a6 ac 39 d6 e9 30 e6 3c 30 da 68 ba d9 7f 88 5d", formatHex); } @Test public void decodeHexTest(){ final String s = HexUtil.encodeHexStr("6"); final String s1 = HexUtil.decodeHexStr(s); - Assert.assertEquals("6", s1); + Assertions.assertEquals("6", s1); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/IdUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/IdUtilTest.java index 97bd67699..4521573c1 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/IdUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/IdUtilTest.java @@ -8,9 +8,9 @@ import cn.hutool.core.lang.Console; import cn.hutool.core.lang.id.IdUtil; import cn.hutool.core.lang.id.Snowflake; 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.Set; import java.util.UUID; @@ -27,26 +27,26 @@ public class IdUtilTest { @Test public void randomUUIDTest() { final String simpleUUID = IdUtil.simpleUUID(); - Assert.assertEquals(32, simpleUUID.length()); + Assertions.assertEquals(32, simpleUUID.length()); final String randomUUID = IdUtil.randomUUID(); - Assert.assertEquals(36, randomUUID.length()); + Assertions.assertEquals(36, randomUUID.length()); } @Test public void fastUUIDTest() { final String simpleUUID = IdUtil.fastSimpleUUID(); - Assert.assertEquals(32, simpleUUID.length()); + Assertions.assertEquals(32, simpleUUID.length()); final String randomUUID = IdUtil.fastUUID(); - Assert.assertEquals(36, randomUUID.length()); + Assertions.assertEquals(36, randomUUID.length()); } /** * UUID的性能测试 */ @Test - @Ignore + @Disabled public void benchTest() { final StopWatch timer = DateUtil.createStopWatch(); timer.start(); @@ -68,18 +68,18 @@ public class IdUtilTest { @Test public void objectIdTest() { final String id = IdUtil.objectId(); - Assert.assertEquals(24, id.length()); + Assertions.assertEquals(24, id.length()); } @Test public void getSnowflakeTest() { final Snowflake snowflake = IdUtil.getSnowflake(1, 1); final long id = snowflake.nextId(); - Assert.assertTrue(id > 0); + Assertions.assertTrue(id > 0); } @Test - @Ignore + @Disabled public void snowflakeBenchTest() { final Set set = new ConcurrentHashSet<>(); final Snowflake snowflake = IdUtil.getSnowflake(1, 1); @@ -106,11 +106,11 @@ public class IdUtilTest { } catch (final InterruptedException e) { throw new UtilException(e); } - Assert.assertEquals(threadCount * idCountPerThread, set.size()); + Assertions.assertEquals(threadCount * idCountPerThread, set.size()); } @Test - @Ignore + @Disabled public void snowflakeBenchTest2() { final Set set = new ConcurrentHashSet<>(); @@ -136,13 +136,13 @@ public class IdUtilTest { } catch (final InterruptedException e) { throw new UtilException(e); } - Assert.assertEquals(threadCount * idCountPerThread, set.size()); + Assertions.assertEquals(threadCount * idCountPerThread, set.size()); } @Test public void getDataCenterIdTest(){ //按照mac地址算法拼接的算法,maxDatacenterId应该是0xffffffffL>>6-1此处暂时按照0x7fffffffffffffffL-1,防止最后取模溢出 final long dataCenterId = IdUtil.getDataCenterId(Long.MAX_VALUE); - Assert.assertTrue(dataCenterId >= 0); + Assertions.assertTrue(dataCenterId >= 0); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/IdcardUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/IdcardUtilTest.java index 5a8e332ed..abc575700 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/IdcardUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/IdcardUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.util; 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; /** * 身份证单元测试 @@ -19,37 +19,37 @@ public class IdcardUtilTest { @Test public void isValidCardTest() { final boolean valid = IdcardUtil.isValidCard(ID_18); - Assert.assertTrue(valid); + Assertions.assertTrue(valid); final boolean valid15 = IdcardUtil.isValidCard(ID_15); - Assert.assertTrue(valid15); + Assertions.assertTrue(valid15); // 无效 String idCard = "360198910283844"; - Assert.assertFalse(IdcardUtil.isValidCard(idCard)); + Assertions.assertFalse(IdcardUtil.isValidCard(idCard)); // 生日无效 idCard = "201511221897205960"; - Assert.assertFalse(IdcardUtil.isValidCard(idCard)); + Assertions.assertFalse(IdcardUtil.isValidCard(idCard)); // 生日无效 idCard = "815727834224151"; - Assert.assertFalse(IdcardUtil.isValidCard(idCard)); + Assertions.assertFalse(IdcardUtil.isValidCard(idCard)); } @Test public void convert15To18Test() { final String convert15To18 = IdcardUtil.convert15To18(ID_15); - Assert.assertEquals("150102198807303035", convert15To18); + Assertions.assertEquals("150102198807303035", convert15To18); final String convert15To18Second = IdcardUtil.convert15To18("330102200403064"); - Assert.assertEquals("33010219200403064X", convert15To18Second); + Assertions.assertEquals("33010219200403064X", convert15To18Second); } @Test public void convert18To15Test() { String idcard15 = IdcardUtil.convert18To15("150102198807303035"); - Assert.assertEquals(ID_15, idcard15); + Assertions.assertEquals(ID_15, idcard15); } @Test @@ -57,99 +57,99 @@ public class IdcardUtilTest { final DateTime date = DateUtil.parse("2017-04-10"); final int age = IdcardUtil.getAge(ID_18, date); - Assert.assertEquals(age, 38); + Assertions.assertEquals(age, 38); final int age2 = IdcardUtil.getAge(ID_15, date); - Assert.assertEquals(age2, 28); + Assertions.assertEquals(age2, 28); } @Test public void getBirthTest() { final String birth = IdcardUtil.getBirth(ID_18); - Assert.assertEquals(birth, "19781216"); + Assertions.assertEquals(birth, "19781216"); final String birth2 = IdcardUtil.getBirth(ID_15); - Assert.assertEquals(birth2, "19880730"); + Assertions.assertEquals(birth2, "19880730"); } @Test public void getProvinceTest() { final String province = IdcardUtil.getProvince(ID_18); - Assert.assertEquals(province, "江苏"); + Assertions.assertEquals(province, "江苏"); final String province2 = IdcardUtil.getProvince(ID_15); - Assert.assertEquals(province2, "内蒙古"); + Assertions.assertEquals(province2, "内蒙古"); } @Test public void getCityCodeTest() { final String code = IdcardUtil.getCityCode(ID_18); - Assert.assertEquals("3210", code); + Assertions.assertEquals("3210", code); } @Test public void getDistrictCodeTest() { final String code = IdcardUtil.getDistrictCode(ID_18); - Assert.assertEquals("321083", code); + Assertions.assertEquals("321083", code); } @Test public void getGenderTest() { final int gender = IdcardUtil.getGender(ID_18); - Assert.assertEquals(1, gender); + Assertions.assertEquals(1, gender); } @Test public void isValidCard18Test(){ boolean isValidCard18 = IdcardUtil.isValidCard18("3301022011022000D6"); - Assert.assertFalse(isValidCard18); + Assertions.assertFalse(isValidCard18); // 不忽略大小写情况下,X严格校验必须大写 isValidCard18 = IdcardUtil.isValidCard18("33010219200403064x", false); - Assert.assertFalse(isValidCard18); + Assertions.assertFalse(isValidCard18); isValidCard18 = IdcardUtil.isValidCard18("33010219200403064X", false); - Assert.assertTrue(isValidCard18); + Assertions.assertTrue(isValidCard18); // 非严格校验下大小写皆可 isValidCard18 = IdcardUtil.isValidCard18("33010219200403064x"); - Assert.assertTrue(isValidCard18); + Assertions.assertTrue(isValidCard18); isValidCard18 = IdcardUtil.isValidCard18("33010219200403064X"); - Assert.assertTrue(isValidCard18); + Assertions.assertTrue(isValidCard18); // 香港人在大陆身份证 isValidCard18 = IdcardUtil.isValidCard18("81000019980902013X"); - Assert.assertTrue(isValidCard18); + Assertions.assertTrue(isValidCard18); // 澳门人在大陆身份证 isValidCard18 = IdcardUtil.isValidCard18("820000200009100032"); - Assert.assertTrue(isValidCard18); + Assertions.assertTrue(isValidCard18); // 台湾人在大陆身份证 isValidCard18 = IdcardUtil.isValidCard18("830000200209060065"); - Assert.assertTrue(isValidCard18); + Assertions.assertTrue(isValidCard18); // 身份证允许调用为空null isValidCard18 = !IdcardUtil.isValidCard18(null); - Assert.assertTrue(isValidCard18); + Assertions.assertTrue(isValidCard18); } @Test public void isValidHKCardIdTest(){ final String hkCard="P174468(6)"; final boolean flag=IdcardUtil.isValidHKCard(hkCard); - Assert.assertTrue(flag); + Assertions.assertTrue(flag); } @Test public void isValidTWCardIdTest() { final String twCard = "B221690311"; boolean flag = IdcardUtil.isValidTWCard(twCard); - Assert.assertTrue(flag); + Assertions.assertTrue(flag); final String errTwCard1 = "M517086311"; flag = IdcardUtil.isValidTWCard(errTwCard1); - Assert.assertFalse(flag); + Assertions.assertFalse(flag); final String errTwCard2 = "B2216903112"; flag = IdcardUtil.isValidTWCard(errTwCard2); - Assert.assertFalse(flag); + Assertions.assertFalse(flag); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/JNDIUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/JNDIUtilTest.java index 8dd55a994..28c421898 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/JNDIUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/JNDIUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.util; import cn.hutool.core.collection.iter.EnumerationIter; 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 javax.naming.NamingException; import javax.naming.directory.Attribute; @@ -12,7 +12,7 @@ import javax.naming.directory.Attributes; public class JNDIUtilTest { @Test - @Ignore + @Disabled public void getDnsTest() throws NamingException { final Attributes attributes = JNDIUtil.getAttributes("dns:paypal.com", "TXT"); for (final Attribute attribute: new EnumerationIter<>(attributes.getAll())){ diff --git a/hutool-core/src/test/java/cn/hutool/core/util/JdkUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/JdkUtilTest.java index cc5936a88..ae39e17aa 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/JdkUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/JdkUtilTest.java @@ -1,19 +1,19 @@ package cn.hutool.core.util; 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 JdkUtilTest { @Test public void jvmVersionTest() { final int jvmVersion = JdkUtil.JVM_VERSION; - Assert.assertTrue(jvmVersion >= 8); + Assertions.assertTrue(jvmVersion >= 8); } @Test - @Ignore + @Disabled public void getJvmNameTest() { Console.log(JdkUtil.IS_AT_LEAST_JDK17); } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/MaskingUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/MaskingUtilTest.java index cee07c711..215d36372 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/MaskingUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/MaskingUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.core.util; import cn.hutool.core.text.MaskingUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 脱敏工具类 MaskingUtil 安全测试 @@ -14,80 +14,80 @@ public class MaskingUtilTest { @Test public void desensitizedTest() { - Assert.assertEquals("0", MaskingUtil.masking("100", MaskingUtil.MaskingType.USER_ID)); - Assert.assertEquals("段**", MaskingUtil.masking("段正淳", MaskingUtil.MaskingType.CHINESE_NAME)); - Assert.assertEquals("5***************1X", MaskingUtil.masking("51343620000320711X", MaskingUtil.MaskingType.ID_CARD)); - Assert.assertEquals("0915*****79", MaskingUtil.masking("09157518479", MaskingUtil.MaskingType.FIXED_PHONE)); - Assert.assertEquals("180****1999", MaskingUtil.masking("18049531999", MaskingUtil.MaskingType.MOBILE_PHONE)); - Assert.assertEquals("北京市海淀区马********", MaskingUtil.masking("北京市海淀区马连洼街道289号", MaskingUtil.MaskingType.ADDRESS)); - Assert.assertEquals("d*************@gmail.com.cn", MaskingUtil.masking("duandazhi-jack@gmail.com.cn", MaskingUtil.MaskingType.EMAIL)); - Assert.assertEquals("**********", MaskingUtil.masking("1234567890", MaskingUtil.MaskingType.PASSWORD)); + Assertions.assertEquals("0", MaskingUtil.masking("100", MaskingUtil.MaskingType.USER_ID)); + Assertions.assertEquals("段**", MaskingUtil.masking("段正淳", MaskingUtil.MaskingType.CHINESE_NAME)); + Assertions.assertEquals("5***************1X", MaskingUtil.masking("51343620000320711X", MaskingUtil.MaskingType.ID_CARD)); + Assertions.assertEquals("0915*****79", MaskingUtil.masking("09157518479", MaskingUtil.MaskingType.FIXED_PHONE)); + Assertions.assertEquals("180****1999", MaskingUtil.masking("18049531999", MaskingUtil.MaskingType.MOBILE_PHONE)); + Assertions.assertEquals("北京市海淀区马********", MaskingUtil.masking("北京市海淀区马连洼街道289号", MaskingUtil.MaskingType.ADDRESS)); + Assertions.assertEquals("d*************@gmail.com.cn", MaskingUtil.masking("duandazhi-jack@gmail.com.cn", MaskingUtil.MaskingType.EMAIL)); + Assertions.assertEquals("**********", MaskingUtil.masking("1234567890", MaskingUtil.MaskingType.PASSWORD)); - Assert.assertEquals("0", MaskingUtil.masking("100", MaskingUtil.MaskingType.USER_ID)); - Assert.assertEquals("段**", MaskingUtil.masking("段正淳", MaskingUtil.MaskingType.CHINESE_NAME)); - Assert.assertEquals("5***************1X", MaskingUtil.masking("51343620000320711X", MaskingUtil.MaskingType.ID_CARD)); - Assert.assertEquals("0915*****79", MaskingUtil.masking("09157518479", MaskingUtil.MaskingType.FIXED_PHONE)); - Assert.assertEquals("180****1999", MaskingUtil.masking("18049531999", MaskingUtil.MaskingType.MOBILE_PHONE)); - Assert.assertEquals("北京市海淀区马********", MaskingUtil.masking("北京市海淀区马连洼街道289号", MaskingUtil.MaskingType.ADDRESS)); - Assert.assertEquals("d*************@gmail.com.cn", MaskingUtil.masking("duandazhi-jack@gmail.com.cn", MaskingUtil.MaskingType.EMAIL)); - Assert.assertEquals("**********", MaskingUtil.masking("1234567890", MaskingUtil.MaskingType.PASSWORD)); - Assert.assertEquals("1101 **** **** **** 3256", MaskingUtil.masking("11011111222233333256", MaskingUtil.MaskingType.BANK_CARD)); - Assert.assertEquals("6227 **** **** *** 5123", MaskingUtil.masking("6227880100100105123", MaskingUtil.MaskingType.BANK_CARD)); - Assert.assertEquals("192.*.*.*", MaskingUtil.masking("192.168.1.1", MaskingUtil.MaskingType.IPV4)); - Assert.assertEquals("2001:*:*:*:*:*:*:*", MaskingUtil.masking("2001:0db8:86a3:08d3:1319:8a2e:0370:7344", MaskingUtil.MaskingType.IPV6)); + Assertions.assertEquals("0", MaskingUtil.masking("100", MaskingUtil.MaskingType.USER_ID)); + Assertions.assertEquals("段**", MaskingUtil.masking("段正淳", MaskingUtil.MaskingType.CHINESE_NAME)); + Assertions.assertEquals("5***************1X", MaskingUtil.masking("51343620000320711X", MaskingUtil.MaskingType.ID_CARD)); + Assertions.assertEquals("0915*****79", MaskingUtil.masking("09157518479", MaskingUtil.MaskingType.FIXED_PHONE)); + Assertions.assertEquals("180****1999", MaskingUtil.masking("18049531999", MaskingUtil.MaskingType.MOBILE_PHONE)); + Assertions.assertEquals("北京市海淀区马********", MaskingUtil.masking("北京市海淀区马连洼街道289号", MaskingUtil.MaskingType.ADDRESS)); + Assertions.assertEquals("d*************@gmail.com.cn", MaskingUtil.masking("duandazhi-jack@gmail.com.cn", MaskingUtil.MaskingType.EMAIL)); + Assertions.assertEquals("**********", MaskingUtil.masking("1234567890", MaskingUtil.MaskingType.PASSWORD)); + Assertions.assertEquals("1101 **** **** **** 3256", MaskingUtil.masking("11011111222233333256", MaskingUtil.MaskingType.BANK_CARD)); + Assertions.assertEquals("6227 **** **** *** 5123", MaskingUtil.masking("6227880100100105123", MaskingUtil.MaskingType.BANK_CARD)); + Assertions.assertEquals("192.*.*.*", MaskingUtil.masking("192.168.1.1", MaskingUtil.MaskingType.IPV4)); + Assertions.assertEquals("2001:*:*:*:*:*:*:*", MaskingUtil.masking("2001:0db8:86a3:08d3:1319:8a2e:0370:7344", MaskingUtil.MaskingType.IPV6)); } @Test public void userIdTest() { - Assert.assertEquals(Long.valueOf(0L), MaskingUtil.userId()); + Assertions.assertEquals(Long.valueOf(0L), MaskingUtil.userId()); } @Test public void chineseNameTest() { - Assert.assertEquals("段**", MaskingUtil.chineseName("段正淳")); + Assertions.assertEquals("段**", MaskingUtil.chineseName("段正淳")); } @Test public void idCardNumTest() { - Assert.assertEquals("5***************1X", MaskingUtil.idCardNum("51343620000320711X", 1, 2)); + Assertions.assertEquals("5***************1X", MaskingUtil.idCardNum("51343620000320711X", 1, 2)); } @Test public void fixedPhoneTest() { - Assert.assertEquals("0915*****79", MaskingUtil.fixedPhone("09157518479")); + Assertions.assertEquals("0915*****79", MaskingUtil.fixedPhone("09157518479")); } @Test public void mobilePhoneTest() { - Assert.assertEquals("180****1999", MaskingUtil.mobilePhone("18049531999")); + Assertions.assertEquals("180****1999", MaskingUtil.mobilePhone("18049531999")); } @Test public void addressTest() { - Assert.assertEquals("北京市海淀区马连洼街*****", MaskingUtil.address("北京市海淀区马连洼街道289号", 5)); - Assert.assertEquals("***************", MaskingUtil.address("北京市海淀区马连洼街道289号", 50)); - Assert.assertEquals("北京市海淀区马连洼街道289号", MaskingUtil.address("北京市海淀区马连洼街道289号", 0)); - Assert.assertEquals("北京市海淀区马连洼街道289号", MaskingUtil.address("北京市海淀区马连洼街道289号", -1)); + Assertions.assertEquals("北京市海淀区马连洼街*****", MaskingUtil.address("北京市海淀区马连洼街道289号", 5)); + Assertions.assertEquals("***************", MaskingUtil.address("北京市海淀区马连洼街道289号", 50)); + Assertions.assertEquals("北京市海淀区马连洼街道289号", MaskingUtil.address("北京市海淀区马连洼街道289号", 0)); + Assertions.assertEquals("北京市海淀区马连洼街道289号", MaskingUtil.address("北京市海淀区马连洼街道289号", -1)); } @Test public void emailTest() { - Assert.assertEquals("d********@126.com", MaskingUtil.email("duandazhi@126.com")); - Assert.assertEquals("d********@gmail.com.cn", MaskingUtil.email("duandazhi@gmail.com.cn")); - Assert.assertEquals("d*************@gmail.com.cn", MaskingUtil.email("duandazhi-jack@gmail.com.cn")); + Assertions.assertEquals("d********@126.com", MaskingUtil.email("duandazhi@126.com")); + Assertions.assertEquals("d********@gmail.com.cn", MaskingUtil.email("duandazhi@gmail.com.cn")); + Assertions.assertEquals("d*************@gmail.com.cn", MaskingUtil.email("duandazhi-jack@gmail.com.cn")); } @Test public void passwordTest() { - Assert.assertEquals("**********", MaskingUtil.password("1234567890")); + Assertions.assertEquals("**********", MaskingUtil.password("1234567890")); } @Test public void carLicenseTest() { - Assert.assertEquals("", MaskingUtil.carLicense(null)); - Assert.assertEquals("", MaskingUtil.carLicense("")); - Assert.assertEquals("苏D4***0", MaskingUtil.carLicense("苏D40000")); - Assert.assertEquals("陕A1****D", MaskingUtil.carLicense("陕A12345D")); - Assert.assertEquals("京A123", MaskingUtil.carLicense("京A123")); + Assertions.assertEquals("", MaskingUtil.carLicense(null)); + Assertions.assertEquals("", MaskingUtil.carLicense("")); + Assertions.assertEquals("苏D4***0", MaskingUtil.carLicense("苏D40000")); + Assertions.assertEquals("陕A1****D", MaskingUtil.carLicense("陕A12345D")); + Assertions.assertEquals("京A123", MaskingUtil.carLicense("京A123")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ModifierUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ModifierUtilTest.java index a7385ce13..c46c6b853 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/ModifierUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ModifierUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.core.util; import cn.hutool.core.reflect.FieldUtil; import cn.hutool.core.reflect.ModifierUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -15,8 +15,8 @@ public class ModifierUtilTest { @Test public void hasModifierTest() throws NoSuchMethodException { final Method method = ModifierUtilTest.class.getDeclaredMethod("ddd"); - Assert.assertTrue(ModifierUtil.hasModifier(method, ModifierUtil.ModifierType.PRIVATE)); - Assert.assertTrue(ModifierUtil.hasModifier(method, + Assertions.assertTrue(ModifierUtil.hasModifier(method, ModifierUtil.ModifierType.PRIVATE)); + Assertions.assertTrue(ModifierUtil.hasModifier(method, ModifierUtil.ModifierType.PRIVATE, ModifierUtil.ModifierType.STATIC) ); @@ -39,7 +39,7 @@ public class ModifierUtilTest { ModifierUtil.removeFinalModify(field); FieldUtil.setFieldValue(JdbcDialects.class, fieldName, dialects); - Assert.assertEquals(dialects, FieldUtil.getFieldValue(JdbcDialects.class, fieldName)); + Assertions.assertEquals(dialects, FieldUtil.getFieldValue(JdbcDialects.class, fieldName)); } @SuppressWarnings("unused") diff --git a/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java index 7aece89f2..170c881e3 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java @@ -3,18 +3,14 @@ package cn.hutool.core.util; import cn.hutool.core.lang.Console; import cn.hutool.core.math.NumberUtil; 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.math.BigDecimal; import java.math.RoundingMode; import java.text.NumberFormat; import java.text.ParseException; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; - /** * {@link NumberUtil} 单元测试类 * @@ -27,7 +23,7 @@ public class NumberUtilTest { final Float a = 3.15f; final Double b = 4.22; final double result = NumberUtil.add(a, b).doubleValue(); - Assert.assertEquals(7.37, result, 0); + Assertions.assertEquals(7.37, result, 0); } @Test @@ -35,7 +31,7 @@ public class NumberUtilTest { final double a = 3.15f;// 转换丢失精度 final double b = 4.22; final double result = NumberUtil.add(a, b).doubleValue(); - Assert.assertEquals(7.37, result, 0.0001); + Assertions.assertEquals(7.37, result, 0.0001); } @Test @@ -43,46 +39,46 @@ public class NumberUtilTest { final float a = 3.15f; final double b = 4.22; final double result = NumberUtil.add(a, b, a, b).doubleValue(); - Assert.assertEquals(14.74, result, 0); + Assertions.assertEquals(14.74, result, 0); } @Test public void addTest4() { BigDecimal result = NumberUtil.add(new BigDecimal("133"), new BigDecimal("331")); - Assert.assertEquals(new BigDecimal("464"), result); + Assertions.assertEquals(new BigDecimal("464"), result); result = NumberUtil.add(new BigDecimal[]{new BigDecimal("133"), new BigDecimal("331")}); - Assert.assertEquals(new BigDecimal("464"), result); + Assertions.assertEquals(new BigDecimal("464"), result); } @Test public void addBlankTest() { final BigDecimal result = NumberUtil.add("123", " "); - Assert.assertEquals(new BigDecimal("123"), result); + Assertions.assertEquals(new BigDecimal("123"), result); } @Test public void subTest() { BigDecimal result = NumberUtil.sub(new BigDecimal("133"), new BigDecimal("331")); - Assert.assertEquals(new BigDecimal("-198"), result); + Assertions.assertEquals(new BigDecimal("-198"), result); result = NumberUtil.sub(new BigDecimal[]{new BigDecimal("133"), new BigDecimal("331")}); - Assert.assertEquals(new BigDecimal("-198"), result); + Assertions.assertEquals(new BigDecimal("-198"), result); } @Test public void mulTest() { BigDecimal result = NumberUtil.mul(new BigDecimal("133"), new BigDecimal("331")); - Assert.assertEquals(new BigDecimal("44023"), result); + Assertions.assertEquals(new BigDecimal("44023"), result); result = NumberUtil.mul(new BigDecimal[]{new BigDecimal("133"), new BigDecimal("331")}); - Assert.assertEquals(new BigDecimal("44023"), result); + Assertions.assertEquals(new BigDecimal("44023"), result); } @Test public void mulNullTest() { final BigDecimal mul = NumberUtil.mul(new BigDecimal("10"), null); - Assert.assertEquals(BigDecimal.ZERO, mul); + Assertions.assertEquals(BigDecimal.ZERO, mul); } @Test @@ -102,7 +98,7 @@ public class NumberUtilTest { private void privateIsIntegerTest(final String[] numStrArr, final boolean expected) { for (final String numStr : numStrArr) { - Assert.assertEquals("未通过的数字为: " + numStr, expected, NumberUtil.isInteger(numStr)); + Assertions.assertEquals(expected, NumberUtil.isInteger(numStr), "未通过的数字为: " + numStr); } } @@ -129,7 +125,7 @@ public class NumberUtilTest { private void privateIsLongTest(final String[] numStrArr, final boolean expected) { for (final String numStr : numStrArr) { - Assert.assertEquals("未通过的数字为: " + numStr, expected, NumberUtil.isLong(numStr)); + Assertions.assertEquals(expected, NumberUtil.isLong(numStr), "未通过的数字为: " + numStr); } } @@ -201,19 +197,19 @@ public class NumberUtilTest { } private void privateIsNumberTest(final String numStr, final boolean expected) { - Assert.assertEquals(expected, NumberUtil.isNumber(numStr)); + Assertions.assertEquals(expected, NumberUtil.isNumber(numStr)); } @Test public void divTest() { final double result = NumberUtil.div(0, 1).doubleValue(); - Assert.assertEquals(0.0, result, 0); + Assertions.assertEquals(0.0, result, 0); } @Test public void divBigDecimalTest() { final BigDecimal result = NumberUtil.div(BigDecimal.ZERO, BigDecimal.ONE); - Assert.assertEquals(BigDecimal.ZERO, result.stripTrailingZeros()); + Assertions.assertEquals(BigDecimal.ZERO, result.stripTrailingZeros()); } @Test @@ -222,74 +218,74 @@ public class NumberUtilTest { // 四舍 final String round1 = NumberUtil.roundStr(2.674, 2); final String round2 = NumberUtil.roundStr("2.674", 2); - Assert.assertEquals("2.67", round1); - Assert.assertEquals("2.67", round2); + Assertions.assertEquals("2.67", round1); + Assertions.assertEquals("2.67", round2); // 五入 final String round3 = NumberUtil.roundStr(2.675, 2); final String round4 = NumberUtil.roundStr("2.675", 2); - Assert.assertEquals("2.68", round3); - Assert.assertEquals("2.68", round4); + Assertions.assertEquals("2.68", round3); + Assertions.assertEquals("2.68", round4); // 四舍六入五成双 final String round31 = NumberUtil.roundStr(4.245, 2, RoundingMode.HALF_EVEN); final String round41 = NumberUtil.roundStr("4.2451", 2, RoundingMode.HALF_EVEN); - Assert.assertEquals("4.24", round31); - Assert.assertEquals("4.25", round41); + Assertions.assertEquals("4.24", round31); + Assertions.assertEquals("4.25", round41); // 补0 final String round5 = NumberUtil.roundStr(2.6005, 2); final String round6 = NumberUtil.roundStr("2.6005", 2); - Assert.assertEquals("2.60", round5); - Assert.assertEquals("2.60", round6); + Assertions.assertEquals("2.60", round5); + Assertions.assertEquals("2.60", round6); // 补0 final String round7 = NumberUtil.roundStr(2.600, 2); final String round8 = NumberUtil.roundStr("2.600", 2); - Assert.assertEquals("2.60", round7); - Assert.assertEquals("2.60", round8); + Assertions.assertEquals("2.60", round7); + Assertions.assertEquals("2.60", round8); } @Test public void roundStrTest() { final String roundStr = NumberUtil.roundStr(2.647, 2); - Assert.assertEquals(roundStr, "2.65"); + Assertions.assertEquals(roundStr, "2.65"); final String roundStr1 = NumberUtil.roundStr(0, 10); - Assert.assertEquals(roundStr1, "0.0000000000"); + Assertions.assertEquals(roundStr1, "0.0000000000"); } @Test public void roundHalfEvenTest() { String roundStr = NumberUtil.roundHalfEven(4.245, 2).toString(); - Assert.assertEquals(roundStr, "4.24"); + Assertions.assertEquals(roundStr, "4.24"); roundStr = NumberUtil.roundHalfEven(4.2450, 2).toString(); - Assert.assertEquals(roundStr, "4.24"); + Assertions.assertEquals(roundStr, "4.24"); roundStr = NumberUtil.roundHalfEven(4.2451, 2).toString(); - Assert.assertEquals(roundStr, "4.25"); + Assertions.assertEquals(roundStr, "4.25"); roundStr = NumberUtil.roundHalfEven(4.2250, 2).toString(); - Assert.assertEquals(roundStr, "4.22"); + Assertions.assertEquals(roundStr, "4.22"); roundStr = NumberUtil.roundHalfEven(1.2050, 2).toString(); - Assert.assertEquals(roundStr, "1.20"); + Assertions.assertEquals(roundStr, "1.20"); roundStr = NumberUtil.roundHalfEven(1.2150, 2).toString(); - Assert.assertEquals(roundStr, "1.22"); + Assertions.assertEquals(roundStr, "1.22"); roundStr = NumberUtil.roundHalfEven(1.2250, 2).toString(); - Assert.assertEquals(roundStr, "1.22"); + Assertions.assertEquals(roundStr, "1.22"); roundStr = NumberUtil.roundHalfEven(1.2350, 2).toString(); - Assert.assertEquals(roundStr, "1.24"); + Assertions.assertEquals(roundStr, "1.24"); roundStr = NumberUtil.roundHalfEven(1.2450, 2).toString(); - Assert.assertEquals(roundStr, "1.24"); + Assertions.assertEquals(roundStr, "1.24"); roundStr = NumberUtil.roundHalfEven(1.2550, 2).toString(); - Assert.assertEquals(roundStr, "1.26"); + Assertions.assertEquals(roundStr, "1.26"); roundStr = NumberUtil.roundHalfEven(1.2650, 2).toString(); - Assert.assertEquals(roundStr, "1.26"); + Assertions.assertEquals(roundStr, "1.26"); roundStr = NumberUtil.roundHalfEven(1.2750, 2).toString(); - Assert.assertEquals(roundStr, "1.28"); + Assertions.assertEquals(roundStr, "1.28"); roundStr = NumberUtil.roundHalfEven(1.2850, 2).toString(); - Assert.assertEquals(roundStr, "1.28"); + Assertions.assertEquals(roundStr, "1.28"); roundStr = NumberUtil.roundHalfEven(1.2950, 2).toString(); - Assert.assertEquals(roundStr, "1.30"); + Assertions.assertEquals(roundStr, "1.30"); } @Test @@ -297,24 +293,28 @@ public class NumberUtilTest { final long c = 299792458;// 光速 final String format = NumberUtil.format(",###", c); - Assert.assertEquals("299,792,458", format); + Assertions.assertEquals("299,792,458", format); } - @Test(expected = IllegalArgumentException.class) + @Test public void decimalFormatNaNTest() { - final Double a = 0D; - final Double b = 0D; + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + final Double a = 0D; + final Double b = 0D; - final Double c = a / b; - Console.log(NumberUtil.format("#%", c)); + final Double c = a / b; + Console.log(NumberUtil.format("#%", c)); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void decimalFormatNaNTest2() { - final Double a = 0D; - final Double b = 0D; + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + final Double a = 0D; + final Double b = 0D; - Console.log(NumberUtil.format("#%", a / b)); + Console.log(NumberUtil.format("#%", a / b)); + }); } @Test @@ -322,7 +322,7 @@ public class NumberUtilTest { final Double c = 467.8101; final String format = NumberUtil.format("0.00", c); - Assert.assertEquals("467.81", format); + Assertions.assertEquals("467.81", format); } @Test @@ -330,16 +330,16 @@ public class NumberUtilTest { final double c = 299792400.543534534; final String format = NumberUtil.formatMoney(c); - Assert.assertEquals("299,792,400.54", format); + Assertions.assertEquals("299,792,400.54", format); final double value = 0.5; final String money = NumberUtil.formatMoney(value); - Assert.assertEquals("0.50", money); + Assertions.assertEquals("0.50", money); } @Test public void equalsTest() { - Assert.assertTrue(NumberUtil.equals(new BigDecimal("0.00"), BigDecimal.ZERO)); + Assertions.assertTrue(NumberUtil.equals(new BigDecimal("0.00"), BigDecimal.ZERO)); } @Test @@ -347,13 +347,13 @@ public class NumberUtilTest { final double a = 3.14; BigDecimal bigDecimal = NumberUtil.toBigDecimal(a); - Assert.assertEquals("3.14", bigDecimal.toString()); + Assertions.assertEquals("3.14", bigDecimal.toString()); bigDecimal = NumberUtil.toBigDecimal("1,234.55"); - Assert.assertEquals("1234.55", bigDecimal.toString()); + Assertions.assertEquals("1234.55", bigDecimal.toString()); bigDecimal = NumberUtil.toBigDecimal("1,234.56D"); - Assert.assertEquals("1234.56", bigDecimal.toString()); + Assertions.assertEquals("1234.56", bigDecimal.toString()); } @Test @@ -361,38 +361,38 @@ public class NumberUtilTest { // https://github.com/dromara/hutool/issues/2878 // 当数字中包含一些非数字字符时,按照JDK的规则,不做修改。 final BigDecimal bigDecimal = NumberUtil.toBigDecimal("345.sdf"); - Assert.assertEquals(NumberFormat.getInstance().parse("345.sdf"), bigDecimal.longValue()); + Assertions.assertEquals(NumberFormat.getInstance().parse("345.sdf"), bigDecimal.longValue()); } @Test public void parseIntTest() { int number = NumberUtil.parseInt("0xFF"); - Assert.assertEquals(255, number); + Assertions.assertEquals(255, number); // 0开头 number = NumberUtil.parseInt("010"); - Assert.assertEquals(10, number); + Assertions.assertEquals(10, number); number = NumberUtil.parseInt("10"); - Assert.assertEquals(10, number); + Assertions.assertEquals(10, number); number = NumberUtil.parseInt(" "); - Assert.assertEquals(0, number); + Assertions.assertEquals(0, number); number = NumberUtil.parseInt("10F"); - Assert.assertEquals(10, number); + Assertions.assertEquals(10, number); number = NumberUtil.parseInt("22.4D"); - Assert.assertEquals(22, number); + Assertions.assertEquals(22, number); number = NumberUtil.parseInt("22.6D"); - Assert.assertEquals(22, number); + Assertions.assertEquals(22, number); number = NumberUtil.parseInt("0"); - Assert.assertEquals(0, number); + Assertions.assertEquals(0, number); number = NumberUtil.parseInt(".123"); - Assert.assertEquals(0, number); + Assertions.assertEquals(0, number); } @Test @@ -400,21 +400,25 @@ public class NumberUtilTest { // from 5.4.8 issue#I23ORQ@Gitee // 千位分隔符去掉 final int v1 = NumberUtil.parseInt("1,482.00"); - Assert.assertEquals(1482, v1); + Assertions.assertEquals(1482, v1); } - @Test(expected = NumberFormatException.class) + @Test public void parseIntTest3() { - final int v1 = NumberUtil.parseInt("d"); - Assert.assertEquals(0, v1); + Assertions.assertThrows(NumberFormatException.class, ()->{ + final int v1 = NumberUtil.parseInt("d"); + Assertions.assertEquals(0, v1); + }); } - @Test(expected = NumberFormatException.class) + @Test public void parseIntTest4() { - // issue#I5M55F - // 科学计数法忽略支持,科学计数法一般用于表示非常小和非常大的数字,这类数字转换为int后精度丢失,没有意义。 - final String numberStr = "429900013E20220812163344551"; - NumberUtil.parseInt(numberStr); + Assertions.assertThrows(NumberFormatException.class, ()->{ + // issue#I5M55F + // 科学计数法忽略支持,科学计数法一般用于表示非常小和非常大的数字,这类数字转换为int后精度丢失,没有意义。 + final String numberStr = "429900013E20220812163344551"; + NumberUtil.parseInt(numberStr); + }); } @Test @@ -422,15 +426,15 @@ public class NumberUtilTest { // -------------------------- Parse failed ----------------------- - assertThat(NumberUtil.parseInt("abc", null), nullValue()); + Assertions.assertNull(NumberUtil.parseInt("abc", null)); - assertThat(NumberUtil.parseInt("abc", 456), equalTo(456)); + Assertions.assertEquals(456, NumberUtil.parseInt("abc", 456)); // -------------------------- Parse success ----------------------- - assertThat(NumberUtil.parseInt("123.abc", 789), equalTo(123)); + Assertions.assertEquals(123, NumberUtil.parseInt("123.abc", 789)); - assertThat(NumberUtil.parseInt("123.3", null), equalTo(123)); + Assertions.assertEquals(123, NumberUtil.parseInt("123.3", null)); } @@ -439,10 +443,10 @@ public class NumberUtilTest { // from 5.4.8 issue#I23ORQ@Gitee // 千位分隔符去掉 final int v1 = NumberUtil.parseNumber("1,482.00").intValue(); - Assert.assertEquals(1482, v1); + Assertions.assertEquals(1482, v1); final Number v2 = NumberUtil.parseNumber("1,482.00D"); - Assert.assertEquals(1482L, v2.longValue()); + Assertions.assertEquals(1482L, v2.longValue()); } @Test @@ -450,8 +454,8 @@ public class NumberUtilTest { // issue#I5M55F final String numberStr = "429900013E20220812163344551"; final Number number = NumberUtil.parseNumber(numberStr); - Assert.assertNotNull(number); - Assert.assertTrue(number instanceof BigDecimal); + Assertions.assertNotNull(number); + Assertions.assertTrue(number instanceof BigDecimal); } @Test @@ -459,21 +463,21 @@ public class NumberUtilTest { // -------------------------- Parse failed ----------------------- - assertThat(NumberUtil.parseNumber("abc", (Number) null), nullValue()); + Assertions.assertNull(NumberUtil.parseNumber("abc", (Number) null)); - assertThat(NumberUtil.parseNumber(StrUtil.EMPTY, (Number) null), nullValue()); + Assertions.assertNull(NumberUtil.parseNumber(StrUtil.EMPTY, (Number) null)); - assertThat(NumberUtil.parseNumber(StrUtil.repeat(StrUtil.SPACE, 10), (Number) null), nullValue()); + Assertions.assertNull(NumberUtil.parseNumber(StrUtil.repeat(StrUtil.SPACE, 10), (Number) null)); - assertThat(NumberUtil.parseNumber("abc", 456).intValue(), equalTo(456)); + Assertions.assertEquals(456, NumberUtil.parseNumber("abc", 456).intValue()); // -------------------------- Parse success ----------------------- - assertThat(NumberUtil.parseNumber("123.abc", 789).intValue(), equalTo(123)); + Assertions.assertEquals(123, NumberUtil.parseNumber("123.abc", 789).intValue()); - assertThat(NumberUtil.parseNumber("123.3", (Number) null).doubleValue(), equalTo(123.3D)); + Assertions.assertEquals(123.3D, NumberUtil.parseNumber("123.3", (Number) null).doubleValue()); - assertThat(NumberUtil.parseNumber("0.123.3", (Number) null).doubleValue(), equalTo(0.123D)); + Assertions.assertEquals(0.123D, NumberUtil.parseNumber("0.123.3", (Number) null).doubleValue()); } @@ -481,38 +485,38 @@ public class NumberUtilTest { public void parseHexNumberTest() { // 千位分隔符去掉 final int v1 = NumberUtil.parseNumber("0xff").intValue(); - Assert.assertEquals(255, v1); + Assertions.assertEquals(255, v1); } @Test public void parseLongTest() { long number = NumberUtil.parseLong("0xFF"); - Assert.assertEquals(255, number); + Assertions.assertEquals(255, number); // 0开头 number = NumberUtil.parseLong("010"); - Assert.assertEquals(10, number); + Assertions.assertEquals(10, number); number = NumberUtil.parseLong("10"); - Assert.assertEquals(10, number); + Assertions.assertEquals(10, number); number = NumberUtil.parseLong(" "); - Assert.assertEquals(0, number); + Assertions.assertEquals(0, number); number = NumberUtil.parseLong("10F"); - Assert.assertEquals(10, number); + Assertions.assertEquals(10, number); number = NumberUtil.parseLong("22.4D"); - Assert.assertEquals(22, number); + Assertions.assertEquals(22, number); number = NumberUtil.parseLong("22.6D"); - Assert.assertEquals(22, number); + Assertions.assertEquals(22, number); number = NumberUtil.parseLong("0"); - Assert.assertEquals(0, number); + Assertions.assertEquals(0, number); number = NumberUtil.parseLong(".123"); - Assert.assertEquals(0, number); + Assertions.assertEquals(0, number); } @Test @@ -521,135 +525,136 @@ public class NumberUtilTest { // -------------------------- Parse failed ----------------------- final Long v1 = NumberUtil.parseLong(null, null); - assertThat(v1, nullValue()); + Assertions.assertNull(v1); final Long v2 = NumberUtil.parseLong(StrUtil.EMPTY, null); - assertThat(v2, nullValue()); + Assertions.assertNull(v2); final Long v3 = NumberUtil.parseLong("L3221", 1233L); - assertThat(v3, equalTo(1233L)); + Assertions.assertEquals(1233L, v3); // -------------------------- Parse success ----------------------- final Long v4 = NumberUtil.parseLong("1233L", null); - assertThat(v4, equalTo(1233L)); + Assertions.assertEquals(1233L, v4); } @Test public void isPowerOfTwoTest() { - Assert.assertFalse(NumberUtil.isPowerOfTwo(-1)); - Assert.assertTrue(NumberUtil.isPowerOfTwo(16)); - Assert.assertTrue(NumberUtil.isPowerOfTwo(65536)); - Assert.assertTrue(NumberUtil.isPowerOfTwo(1)); - Assert.assertFalse(NumberUtil.isPowerOfTwo(17)); + Assertions.assertFalse(NumberUtil.isPowerOfTwo(-1)); + Assertions.assertTrue(NumberUtil.isPowerOfTwo(16)); + Assertions.assertTrue(NumberUtil.isPowerOfTwo(65536)); + Assertions.assertTrue(NumberUtil.isPowerOfTwo(1)); + Assertions.assertFalse(NumberUtil.isPowerOfTwo(17)); } @Test public void toStrTest() { - Assert.assertEquals("1", NumberUtil.toStr(new BigDecimal("1.0000000000"))); - Assert.assertEquals("0", NumberUtil.toStr(NumberUtil.sub(new BigDecimal("9600.00000"), new BigDecimal("9600.00000")))); - Assert.assertEquals("0", NumberUtil.toStr(NumberUtil.sub(new BigDecimal("9600.0000000000"), new BigDecimal("9600.000000")))); - Assert.assertEquals("0", NumberUtil.toStr(new BigDecimal("9600.00000").subtract(new BigDecimal("9600.000000000")))); + Assertions.assertEquals("1", NumberUtil.toStr(new BigDecimal("1.0000000000"))); + Assertions.assertEquals("0", NumberUtil.toStr(NumberUtil.sub(new BigDecimal("9600.00000"), new BigDecimal("9600.00000")))); + Assertions.assertEquals("0", NumberUtil.toStr(NumberUtil.sub(new BigDecimal("9600.0000000000"), new BigDecimal("9600.000000")))); + Assertions.assertEquals("0", NumberUtil.toStr(new BigDecimal("9600.00000").subtract(new BigDecimal("9600.000000000")))); } @Test public void toPlainNumberTest() { final String num = "5344.34234e3"; final String s = new BigDecimal(num).toPlainString(); - Assert.assertEquals("5344342.34", s); + Assertions.assertEquals("5344342.34", s); } @Test public void isOddOrEvenTest() { final int[] a = {0, 32, -32, 123, -123}; - Assert.assertFalse(NumberUtil.isOdd(a[0])); - Assert.assertTrue(NumberUtil.isEven(a[0])); + Assertions.assertFalse(NumberUtil.isOdd(a[0])); + Assertions.assertTrue(NumberUtil.isEven(a[0])); - Assert.assertFalse(NumberUtil.isOdd(a[1])); - Assert.assertTrue(NumberUtil.isEven(a[1])); + Assertions.assertFalse(NumberUtil.isOdd(a[1])); + Assertions.assertTrue(NumberUtil.isEven(a[1])); - Assert.assertFalse(NumberUtil.isOdd(a[2])); - Assert.assertTrue(NumberUtil.isEven(a[2])); + Assertions.assertFalse(NumberUtil.isOdd(a[2])); + Assertions.assertTrue(NumberUtil.isEven(a[2])); - Assert.assertTrue(NumberUtil.isOdd(a[3])); - Assert.assertFalse(NumberUtil.isEven(a[3])); + Assertions.assertTrue(NumberUtil.isOdd(a[3])); + Assertions.assertFalse(NumberUtil.isEven(a[3])); - Assert.assertTrue(NumberUtil.isOdd(a[4])); - Assert.assertFalse(NumberUtil.isEven(a[4])); + Assertions.assertTrue(NumberUtil.isOdd(a[4])); + Assertions.assertFalse(NumberUtil.isEven(a[4])); } @Test public void toBigIntegerTest() { final Number number = 1123123; final Number number2 = 1123123.123; - Assert.assertNotNull(NumberUtil.toBigInteger(number)); - Assert.assertNotNull(NumberUtil.toBigInteger(number2)); + Assertions.assertNotNull(NumberUtil.toBigInteger(number)); + Assertions.assertNotNull(NumberUtil.toBigInteger(number2)); } @Test public void divIntegerTest() { final BigDecimal div = NumberUtil.div(100101300, 100); - Assert.assertEquals(1001013, div.intValue()); + Assertions.assertEquals(1001013, div.intValue()); } @Test public void isDoubleTest() { - Assert.assertFalse(NumberUtil.isDouble(null)); - Assert.assertFalse(NumberUtil.isDouble("")); - Assert.assertFalse(NumberUtil.isDouble(" ")); - Assert.assertFalse(NumberUtil.isDouble("1")); - Assert.assertFalse(NumberUtil.isDouble("-1")); - Assert.assertFalse(NumberUtil.isDouble("+1")); - Assert.assertFalse(NumberUtil.isDouble("0.1.")); - Assert.assertFalse(NumberUtil.isDouble("01")); - Assert.assertFalse(NumberUtil.isDouble("NaN")); - Assert.assertFalse(NumberUtil.isDouble("-NaN")); - Assert.assertFalse(NumberUtil.isDouble("-Infinity")); + Assertions.assertFalse(NumberUtil.isDouble(null)); + Assertions.assertFalse(NumberUtil.isDouble("")); + Assertions.assertFalse(NumberUtil.isDouble(" ")); + Assertions.assertFalse(NumberUtil.isDouble("1")); + Assertions.assertFalse(NumberUtil.isDouble("-1")); + Assertions.assertFalse(NumberUtil.isDouble("+1")); + Assertions.assertFalse(NumberUtil.isDouble("0.1.")); + Assertions.assertFalse(NumberUtil.isDouble("01")); + Assertions.assertFalse(NumberUtil.isDouble("NaN")); + Assertions.assertFalse(NumberUtil.isDouble("-NaN")); + Assertions.assertFalse(NumberUtil.isDouble("-Infinity")); - Assert.assertTrue(NumberUtil.isDouble("0.")); - Assert.assertTrue(NumberUtil.isDouble("0.1")); - Assert.assertTrue(NumberUtil.isDouble("-0.1")); - Assert.assertTrue(NumberUtil.isDouble("+0.1")); - Assert.assertTrue(NumberUtil.isDouble("0.110")); - Assert.assertTrue(NumberUtil.isDouble("00.1")); - Assert.assertTrue(NumberUtil.isDouble("01.1")); + Assertions.assertTrue(NumberUtil.isDouble("0.")); + Assertions.assertTrue(NumberUtil.isDouble("0.1")); + Assertions.assertTrue(NumberUtil.isDouble("-0.1")); + Assertions.assertTrue(NumberUtil.isDouble("+0.1")); + Assertions.assertTrue(NumberUtil.isDouble("0.110")); + Assertions.assertTrue(NumberUtil.isDouble("00.1")); + Assertions.assertTrue(NumberUtil.isDouble("01.1")); } @Test public void rangeTest() { final int[] range = NumberUtil.range(0, 10); - Assert.assertEquals(0, range[0]); - Assert.assertEquals(1, range[1]); - Assert.assertEquals(2, range[2]); - Assert.assertEquals(3, range[3]); - Assert.assertEquals(4, range[4]); - Assert.assertEquals(5, range[5]); - Assert.assertEquals(6, range[6]); - Assert.assertEquals(7, range[7]); - Assert.assertEquals(8, range[8]); - Assert.assertEquals(9, range[9]); - Assert.assertEquals(10, range[10]); + Assertions.assertEquals(0, range[0]); + Assertions.assertEquals(1, range[1]); + Assertions.assertEquals(2, range[2]); + Assertions.assertEquals(3, range[3]); + Assertions.assertEquals(4, range[4]); + Assertions.assertEquals(5, range[5]); + Assertions.assertEquals(6, range[6]); + Assertions.assertEquals(7, range[7]); + Assertions.assertEquals(8, range[8]); + Assertions.assertEquals(9, range[9]); + Assertions.assertEquals(10, range[10]); } - @Test(expected = NegativeArraySizeException.class) + @Test public void rangeMinTest() { - //noinspection ResultOfMethodCallIgnored - NumberUtil.range(0, Integer.MIN_VALUE); + Assertions.assertThrows(NegativeArraySizeException.class, ()->{ + NumberUtil.range(0, Integer.MIN_VALUE); + }); } @Test public void isPrimeTest(){ - Assert.assertTrue(NumberUtil.isPrime(2)); - Assert.assertTrue(NumberUtil.isPrime(3)); - Assert.assertTrue(NumberUtil.isPrime(7)); - Assert.assertTrue(NumberUtil.isPrime(17)); - Assert.assertTrue(NumberUtil.isPrime(296731)); - Assert.assertTrue(NumberUtil.isPrime(99999989)); + Assertions.assertTrue(NumberUtil.isPrime(2)); + Assertions.assertTrue(NumberUtil.isPrime(3)); + Assertions.assertTrue(NumberUtil.isPrime(7)); + Assertions.assertTrue(NumberUtil.isPrime(17)); + Assertions.assertTrue(NumberUtil.isPrime(296731)); + Assertions.assertTrue(NumberUtil.isPrime(99999989)); - Assert.assertFalse(NumberUtil.isPrime(4)); - Assert.assertFalse(NumberUtil.isPrime(296733)); - Assert.assertFalse(NumberUtil.isPrime(20_4123_2399)); + Assertions.assertFalse(NumberUtil.isPrime(4)); + Assertions.assertFalse(NumberUtil.isPrime(296733)); + Assertions.assertFalse(NumberUtil.isPrime(20_4123_2399)); } @Test @@ -657,19 +662,19 @@ public class NumberUtilTest { // -------------------------- Parse failed ----------------------- - assertThat(NumberUtil.parseFloat("abc", null), nullValue()); + Assertions.assertNull(NumberUtil.parseFloat("abc", null)); - assertThat(NumberUtil.parseFloat("a123.33", null), nullValue()); + Assertions.assertNull(NumberUtil.parseFloat("a123.33", null)); - assertThat(NumberUtil.parseFloat("..123", null), nullValue()); + Assertions.assertNull(NumberUtil.parseFloat("..123", null)); - assertThat(NumberUtil.parseFloat(StrUtil.EMPTY, 1233F), equalTo(1233F)); + Assertions.assertEquals(1233F, NumberUtil.parseFloat(StrUtil.EMPTY, 1233F)); // -------------------------- Parse success ----------------------- - assertThat(NumberUtil.parseFloat("123.33a", null), equalTo(123.33F)); + Assertions.assertEquals(123.33F, NumberUtil.parseFloat("123.33a", null)); - assertThat(NumberUtil.parseFloat(".123", null), equalTo(0.123F)); + Assertions.assertEquals(0.123F, NumberUtil.parseFloat(".123", null)); } @@ -678,19 +683,19 @@ public class NumberUtilTest { // -------------------------- Parse failed ----------------------- - assertThat(NumberUtil.parseDouble("abc", null), nullValue()); + Assertions.assertNull(NumberUtil.parseDouble("abc", null)); - assertThat(NumberUtil.parseDouble("a123.33", null), nullValue()); + Assertions.assertNull(NumberUtil.parseDouble("a123.33", null)); - assertThat(NumberUtil.parseDouble("..123", null), nullValue()); + Assertions.assertNull(NumberUtil.parseDouble("..123", null)); - assertThat(NumberUtil.parseDouble(StrUtil.EMPTY, 1233D), equalTo(1233D)); + Assertions.assertEquals(1233D, NumberUtil.parseDouble(StrUtil.EMPTY, 1233D)); // -------------------------- Parse success ----------------------- - assertThat(NumberUtil.parseDouble("123.33a", null), equalTo(123.33D)); + Assertions.assertEquals(123.33D, NumberUtil.parseDouble("123.33a", null)); - assertThat(NumberUtil.parseDouble(".123", null), equalTo(0.123D)); + Assertions.assertEquals(0.123D, NumberUtil.parseDouble(".123", null)); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ObjUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ObjUtilTest.java index a4c4a5a1b..628fa91f8 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/ObjUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ObjUtilTest.java @@ -3,8 +3,8 @@ package cn.hutool.core.util; import cn.hutool.core.collection.ListUtil; import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; -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; @@ -25,89 +25,89 @@ public class ObjUtilTest { public void equalsTest() { Object a = null; Object b = null; - Assert.assertTrue(ObjUtil.equals(a, b)); + Assertions.assertTrue(ObjUtil.equals(a, b)); a = new BigDecimal("1.1"); b = new BigDecimal("1.10"); - Assert.assertTrue(ObjUtil.equals(a, b)); + Assertions.assertTrue(ObjUtil.equals(a, b)); a = 127; b = 127; - Assert.assertTrue(ObjUtil.equals(a, b)); + Assertions.assertTrue(ObjUtil.equals(a, b)); a = 128; b = 128; - Assert.assertTrue(ObjUtil.equals(a, b)); + Assertions.assertTrue(ObjUtil.equals(a, b)); a = LocalDateTime.of(2022, 5, 29, 22, 11); b = LocalDateTime.of(2022, 5, 29, 22, 11); - Assert.assertTrue(ObjUtil.equals(a, b)); + Assertions.assertTrue(ObjUtil.equals(a, b)); a = 1; b = 1.0; - Assert.assertFalse(ObjUtil.equals(a, b)); + Assertions.assertFalse(ObjUtil.equals(a, b)); } @Test public void lengthTest(){ final int[] array = new int[]{1,2,3,4,5}; int length = ObjUtil.length(array); - Assert.assertEquals(5, length); + Assertions.assertEquals(5, length); final Map map = new HashMap<>(); map.put("a", "a1"); map.put("b", "b1"); map.put("c", "c1"); length = ObjUtil.length(map); - Assert.assertEquals(3, length); + Assertions.assertEquals(3, length); final Iterable list = ListUtil.of(1, 2, 3); - Assert.assertEquals(3, ObjUtil.length(list)); - Assert.assertEquals(3, ObjUtil.length(Arrays.asList(1, 2, 3).iterator())); + Assertions.assertEquals(3, ObjUtil.length(list)); + Assertions.assertEquals(3, ObjUtil.length(Arrays.asList(1, 2, 3).iterator())); } @Test public void containsTest(){ - Assert.assertTrue(ObjUtil.contains(new int[]{1,2,3,4,5}, 1)); - Assert.assertFalse(ObjUtil.contains(null, 1)); - Assert.assertTrue(ObjUtil.contains("123", "3")); + Assertions.assertTrue(ObjUtil.contains(new int[]{1,2,3,4,5}, 1)); + Assertions.assertFalse(ObjUtil.contains(null, 1)); + Assertions.assertTrue(ObjUtil.contains("123", "3")); final Map map = new HashMap<>(); map.put(1, 1); map.put(2, 2); - Assert.assertTrue(ObjUtil.contains(map, 1)); - Assert.assertTrue(ObjUtil.contains(Arrays.asList(1, 2, 3).iterator(), 2)); + Assertions.assertTrue(ObjUtil.contains(map, 1)); + Assertions.assertTrue(ObjUtil.contains(Arrays.asList(1, 2, 3).iterator(), 2)); } @SuppressWarnings("ConstantConditions") @Test public void isNullTest() { - Assert.assertTrue(ObjUtil.isNull(null)); + Assertions.assertTrue(ObjUtil.isNull(null)); } @SuppressWarnings("ConstantConditions") @Test public void isNotNullTest() { - Assert.assertFalse(ObjUtil.isNotNull(null)); + Assertions.assertFalse(ObjUtil.isNotNull(null)); } @Test public void isEmptyTest() { - Assert.assertTrue(ObjUtil.isEmpty(null)); - Assert.assertTrue(ObjUtil.isEmpty(new int[0])); - Assert.assertTrue(ObjUtil.isEmpty("")); - Assert.assertTrue(ObjUtil.isEmpty(Collections.emptyList())); - Assert.assertTrue(ObjUtil.isEmpty(Collections.emptyMap())); - Assert.assertTrue(ObjUtil.isEmpty(Collections.emptyIterator())); + Assertions.assertTrue(ObjUtil.isEmpty(null)); + Assertions.assertTrue(ObjUtil.isEmpty(new int[0])); + Assertions.assertTrue(ObjUtil.isEmpty("")); + Assertions.assertTrue(ObjUtil.isEmpty(Collections.emptyList())); + Assertions.assertTrue(ObjUtil.isEmpty(Collections.emptyMap())); + Assertions.assertTrue(ObjUtil.isEmpty(Collections.emptyIterator())); } @Test public void isNotEmptyTest() { - Assert.assertFalse(ObjUtil.isNotEmpty(null)); - Assert.assertFalse(ObjUtil.isNotEmpty(new int[0])); - Assert.assertFalse(ObjUtil.isNotEmpty("")); - Assert.assertFalse(ObjUtil.isNotEmpty(Collections.emptyList())); - Assert.assertFalse(ObjUtil.isNotEmpty(Collections.emptyMap())); - Assert.assertFalse(ObjUtil.isNotEmpty(Collections.emptyIterator())); + Assertions.assertFalse(ObjUtil.isNotEmpty(null)); + Assertions.assertFalse(ObjUtil.isNotEmpty(new int[0])); + Assertions.assertFalse(ObjUtil.isNotEmpty("")); + Assertions.assertFalse(ObjUtil.isNotEmpty(Collections.emptyList())); + Assertions.assertFalse(ObjUtil.isNotEmpty(Collections.emptyMap())); + Assertions.assertFalse(ObjUtil.isNotEmpty(Collections.emptyIterator())); } @SuppressWarnings("ConstantValue") @@ -116,101 +116,101 @@ public class ObjUtilTest { final Object val1 = new Object(); final Object val2 = new Object(); - Assert.assertSame(val1, ObjUtil.defaultIfNull(val1, () -> val2)); - Assert.assertSame(val2, ObjUtil.defaultIfNull(null, () -> val2)); + Assertions.assertSame(val1, ObjUtil.defaultIfNull(val1, () -> val2)); + Assertions.assertSame(val2, ObjUtil.defaultIfNull(null, () -> val2)); - Assert.assertSame(val1, ObjUtil.defaultIfNull(val1, val2)); - Assert.assertSame(val2, ObjUtil.defaultIfNull(null, val2)); + Assertions.assertSame(val1, ObjUtil.defaultIfNull(val1, val2)); + Assertions.assertSame(val2, ObjUtil.defaultIfNull(null, val2)); - Assert.assertSame(val1, ObjUtil.defaultIfNull(val1, Function.identity(), () -> val2)); - Assert.assertSame(val2, ObjUtil.defaultIfNull(null, Function.identity(), () -> val2)); + Assertions.assertSame(val1, ObjUtil.defaultIfNull(val1, Function.identity(), () -> val2)); + Assertions.assertSame(val2, ObjUtil.defaultIfNull(null, Function.identity(), () -> val2)); - Assert.assertSame(val1, ObjUtil.defaultIfNull(val1, Function.identity(), val2)); - Assert.assertSame(val2, ObjUtil.defaultIfNull(null, Function.identity(), val2)); + Assertions.assertSame(val1, ObjUtil.defaultIfNull(val1, Function.identity(), val2)); + Assertions.assertSame(val2, ObjUtil.defaultIfNull(null, Function.identity(), val2)); final SerializableBean obj = new SerializableBean(null); final SerializableBean objNull = null; final String result3 = ObjUtil.defaultIfNull(obj, Object::toString, "fail"); - Assert.assertNotNull(result3); + Assertions.assertNotNull(result3); final String result4 = ObjUtil.defaultIfNull(objNull, Object::toString, () -> "fail"); - Assert.assertNotNull(result4); + Assertions.assertNotNull(result4); } @Test public void cloneTest() { - Assert.assertNull(ObjUtil.clone(null)); + Assertions.assertNull(ObjUtil.clone(null)); final CloneableBean cloneableBean1 = new CloneableBean(1); final CloneableBean cloneableBean2 = ObjUtil.clone(cloneableBean1); - Assert.assertEquals(cloneableBean1, cloneableBean2); + Assertions.assertEquals(cloneableBean1, cloneableBean2); final SerializableBean serializableBean1 = new SerializableBean(2); final SerializableBean serializableBean2 = ObjUtil.clone(serializableBean1); - Assert.assertEquals(serializableBean1, serializableBean2); + Assertions.assertEquals(serializableBean1, serializableBean2); final Bean bean1 = new Bean(3); - Assert.assertNull(ObjUtil.clone(bean1)); + Assertions.assertNull(ObjUtil.clone(bean1)); } @Test public void cloneIfPossibleTest() { - Assert.assertNull(ObjUtil.clone(null)); + Assertions.assertNull(ObjUtil.clone(null)); final CloneableBean cloneableBean1 = new CloneableBean(1); - Assert.assertEquals(cloneableBean1, ObjUtil.cloneIfPossible(cloneableBean1)); + Assertions.assertEquals(cloneableBean1, ObjUtil.cloneIfPossible(cloneableBean1)); final SerializableBean serializableBean1 = new SerializableBean(2); - Assert.assertEquals(serializableBean1, ObjUtil.cloneIfPossible(serializableBean1)); + Assertions.assertEquals(serializableBean1, ObjUtil.cloneIfPossible(serializableBean1)); final Bean bean1 = new Bean(3); - Assert.assertSame(bean1, ObjUtil.cloneIfPossible(bean1)); + Assertions.assertSame(bean1, ObjUtil.cloneIfPossible(bean1)); final ExceptionCloneableBean exceptionBean1 = new ExceptionCloneableBean(3); - Assert.assertSame(exceptionBean1, ObjUtil.cloneIfPossible(exceptionBean1)); + Assertions.assertSame(exceptionBean1, ObjUtil.cloneIfPossible(exceptionBean1)); } @Test public void cloneByStreamTest() { - Assert.assertNull(ObjUtil.cloneByStream(null)); - Assert.assertNull(ObjUtil.cloneByStream(new CloneableBean(1))); + Assertions.assertNull(ObjUtil.cloneByStream(null)); + Assertions.assertNull(ObjUtil.cloneByStream(new CloneableBean(1))); final SerializableBean serializableBean1 = new SerializableBean(2); - Assert.assertEquals(serializableBean1, ObjUtil.cloneByStream(serializableBean1)); - Assert.assertNull(ObjUtil.cloneByStream(new Bean(1))); + Assertions.assertEquals(serializableBean1, ObjUtil.cloneByStream(serializableBean1)); + Assertions.assertNull(ObjUtil.cloneByStream(new Bean(1))); } @Test public void isBasicTypeTest(){ final int a = 1; final boolean basicType = ObjUtil.isBasicType(a); - Assert.assertTrue(basicType); + Assertions.assertTrue(basicType); } @Test public void isValidIfNumberTest() { - Assert.assertTrue(ObjUtil.isValidIfNumber(null)); - Assert.assertFalse(ObjUtil.isValidIfNumber(Double.NEGATIVE_INFINITY)); - Assert.assertFalse(ObjUtil.isValidIfNumber(Double.NaN)); - Assert.assertTrue(ObjUtil.isValidIfNumber(Double.MIN_VALUE)); - Assert.assertFalse(ObjUtil.isValidIfNumber(Float.NEGATIVE_INFINITY)); - Assert.assertFalse(ObjUtil.isValidIfNumber(Float.NaN)); - Assert.assertTrue(ObjUtil.isValidIfNumber(Float.MIN_VALUE)); + Assertions.assertTrue(ObjUtil.isValidIfNumber(null)); + Assertions.assertFalse(ObjUtil.isValidIfNumber(Double.NEGATIVE_INFINITY)); + Assertions.assertFalse(ObjUtil.isValidIfNumber(Double.NaN)); + Assertions.assertTrue(ObjUtil.isValidIfNumber(Double.MIN_VALUE)); + Assertions.assertFalse(ObjUtil.isValidIfNumber(Float.NEGATIVE_INFINITY)); + Assertions.assertFalse(ObjUtil.isValidIfNumber(Float.NaN)); + Assertions.assertTrue(ObjUtil.isValidIfNumber(Float.MIN_VALUE)); } @Test public void getTypeArgumentTest() { final Bean bean = new Bean(1); - Assert.assertEquals(Integer.class, ObjUtil.getTypeArgument(bean)); - Assert.assertEquals(String.class, ObjUtil.getTypeArgument(bean, 1)); + Assertions.assertEquals(Integer.class, ObjUtil.getTypeArgument(bean)); + Assertions.assertEquals(String.class, ObjUtil.getTypeArgument(bean, 1)); } @Test public void toStringTest() { - Assert.assertEquals("null", ObjUtil.toString(null)); - Assert.assertEquals(Collections.emptyMap().toString(), ObjUtil.toString(Collections.emptyMap())); - Assert.assertEquals("[1, 2]", Arrays.asList("1", "2").toString()); + Assertions.assertEquals("null", ObjUtil.toString(null)); + Assertions.assertEquals(Collections.emptyMap().toString(), ObjUtil.toString(Collections.emptyMap())); + Assertions.assertEquals("[1, 2]", Arrays.asList("1", "2").toString()); } @RequiredArgsConstructor diff --git a/hutool-core/src/test/java/cn/hutool/core/util/PhoneUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/PhoneUtilTest.java index fde5a3ad3..312aa94b4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/PhoneUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/PhoneUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.core.util; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -19,15 +19,15 @@ public class PhoneUtilTest { final String errMobile = "136123456781"; final String errTel = "010-889931081"; - Assert.assertTrue(PhoneUtil.isMobile(mobile)); - Assert.assertTrue(PhoneUtil.isTel(tel)); - Assert.assertTrue(PhoneUtil.isPhone(mobile)); - Assert.assertTrue(PhoneUtil.isPhone(tel)); + Assertions.assertTrue(PhoneUtil.isMobile(mobile)); + Assertions.assertTrue(PhoneUtil.isTel(tel)); + Assertions.assertTrue(PhoneUtil.isPhone(mobile)); + Assertions.assertTrue(PhoneUtil.isPhone(tel)); - Assert.assertFalse(PhoneUtil.isMobile(errMobile)); - Assert.assertFalse(PhoneUtil.isTel(errTel)); - Assert.assertFalse(PhoneUtil.isPhone(errMobile)); - Assert.assertFalse(PhoneUtil.isPhone(errTel)); + Assertions.assertFalse(PhoneUtil.isMobile(errMobile)); + Assertions.assertFalse(PhoneUtil.isTel(errTel)); + Assertions.assertFalse(PhoneUtil.isPhone(errMobile)); + Assertions.assertFalse(PhoneUtil.isPhone(errTel)); } @Test @@ -42,10 +42,10 @@ public class PhoneUtilTest { errTels.add("0755-7654.321"); errTels.add("13619887123"); for (final String s : tels) { - Assert.assertTrue(PhoneUtil.isTel(s)); + Assertions.assertTrue(PhoneUtil.isTel(s)); } for (final String s : errTels) { - Assert.assertFalse(PhoneUtil.isTel(s)); + Assertions.assertFalse(PhoneUtil.isTel(s)); } } @@ -53,17 +53,17 @@ public class PhoneUtilTest { public void testHide() { final String mobile = "13612345678"; - Assert.assertEquals("*******5678", PhoneUtil.hideBefore(mobile)); - Assert.assertEquals("136****5678", PhoneUtil.hideBetween(mobile)); - Assert.assertEquals("1361234****", PhoneUtil.hideAfter(mobile)); + Assertions.assertEquals("*******5678", PhoneUtil.hideBefore(mobile)); + Assertions.assertEquals("136****5678", PhoneUtil.hideBetween(mobile)); + Assertions.assertEquals("1361234****", PhoneUtil.hideAfter(mobile)); } @Test public void testSubString() { final String mobile = "13612345678"; - Assert.assertEquals("136", PhoneUtil.subBefore(mobile)); - Assert.assertEquals("1234", PhoneUtil.subBetween(mobile)); - Assert.assertEquals("5678", PhoneUtil.subAfter(mobile)); + Assertions.assertEquals("136", PhoneUtil.subBefore(mobile)); + Assertions.assertEquals("1234", PhoneUtil.subBetween(mobile)); + Assertions.assertEquals("5678", PhoneUtil.subAfter(mobile)); } @Test @@ -81,28 +81,28 @@ public class PhoneUtilTest { errTels.add("0755-7654.321"); errTels.add("13619887123"); for (final String s : tels) { - Assert.assertTrue(PhoneUtil.isTel(s)); + Assertions.assertTrue(PhoneUtil.isTel(s)); } for (final String s : errTels) { - Assert.assertFalse(PhoneUtil.isTel(s)); + Assertions.assertFalse(PhoneUtil.isTel(s)); } - Assert.assertEquals("010", PhoneUtil.subTelBefore("010-12345678")); - Assert.assertEquals("010", PhoneUtil.subTelBefore("01012345678")); - Assert.assertEquals("12345678", PhoneUtil.subTelAfter("010-12345678")); - Assert.assertEquals("12345678", PhoneUtil.subTelAfter("01012345678")); + Assertions.assertEquals("010", PhoneUtil.subTelBefore("010-12345678")); + Assertions.assertEquals("010", PhoneUtil.subTelBefore("01012345678")); + Assertions.assertEquals("12345678", PhoneUtil.subTelAfter("010-12345678")); + Assertions.assertEquals("12345678", PhoneUtil.subTelAfter("01012345678")); - Assert.assertEquals("0755", PhoneUtil.subTelBefore("0755-7654321")); - Assert.assertEquals("0755", PhoneUtil.subTelBefore("07557654321")); - Assert.assertEquals("7654321", PhoneUtil.subTelAfter("0755-7654321")); - Assert.assertEquals("7654321", PhoneUtil.subTelAfter("07557654321")); + Assertions.assertEquals("0755", PhoneUtil.subTelBefore("0755-7654321")); + Assertions.assertEquals("0755", PhoneUtil.subTelBefore("07557654321")); + Assertions.assertEquals("7654321", PhoneUtil.subTelAfter("0755-7654321")); + Assertions.assertEquals("7654321", PhoneUtil.subTelAfter("07557654321")); } @Test public void isTel400800Test() { boolean tel400800 = PhoneUtil.isTel400800("400-860-8608");//800-830-3811 - Assert.assertTrue(tel400800); + Assertions.assertTrue(tel400800); tel400800 = PhoneUtil.isTel400800("400-8608608");//800-830-3811 - Assert.assertTrue(tel400800); + Assertions.assertTrue(tel400800); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/RandomUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/RandomUtilTest.java index 1fc845ee9..f096e70d7 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/RandomUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/RandomUtilTest.java @@ -4,9 +4,9 @@ import cn.hutool.core.collection.ListUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.lang.Console; import cn.hutool.core.math.NumberUtil; -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.math.RoundingMode; import java.util.List; @@ -18,23 +18,23 @@ public class RandomUtilTest { @Test public void randomEleSetTest(){ final Set set = RandomUtil.randomEleSet(ListUtil.of(1, 2, 3, 4, 5, 6), 2); - Assert.assertEquals(set.size(), 2); + Assertions.assertEquals(set.size(), 2); } @Test public void randomElesTest(){ final List result = RandomUtil.randomEles(ListUtil.of(1, 2, 3, 4, 5, 6), 2); - Assert.assertEquals(result.size(), 2); + Assertions.assertEquals(result.size(), 2); } @Test public void randomDoubleTest() { final double randomDouble = RandomUtil.randomDouble(0, 1, 0, RoundingMode.HALF_UP); - Assert.assertTrue(randomDouble <= 1); + Assertions.assertTrue(randomDouble <= 1); } @Test - @Ignore + @Disabled public void randomBooleanTest() { Console.log(RandomUtil.randomBoolean()); } @@ -42,35 +42,35 @@ public class RandomUtilTest { @Test public void randomNumberTest() { final char c = RandomUtil.randomNumber(); - Assert.assertTrue(c <= '9'); + Assertions.assertTrue(c <= '9'); } @Test public void randomIntTest() { final int c = RandomUtil.randomInt(10, 100); - Assert.assertTrue(c >= 10 && c < 100); + Assertions.assertTrue(c >= 10 && c < 100); } @Test public void randomBytesTest() { final byte[] c = RandomUtil.randomBytes(10); - Assert.assertNotNull(c); + Assertions.assertNotNull(c); } @Test public void randomChineseTest(){ final char c = RandomUtil.randomChinese(); - Assert.assertTrue(c > 0); + Assertions.assertTrue(c > 0); } @Test - @Ignore + @Disabled public void randomStringWithoutStrTest() { for (int i = 0; i < 100; i++) { final String s = RandomUtil.randomStringWithoutStr(8, "0IPOL"); System.out.println(s); for (final char c : "0IPOL".toCharArray()) { - Assert.assertFalse(s.contains((String.valueOf(c).toLowerCase(Locale.ROOT)))); + Assertions.assertFalse(s.contains((String.valueOf(c).toLowerCase(Locale.ROOT)))); } } } @@ -78,14 +78,14 @@ public class RandomUtilTest { @Test public void randomStringOfLengthTest(){ final String s = RandomUtil.randomString("123", -1); - Assert.assertNotNull(s); + Assertions.assertNotNull(s); } @Test public void generateRandomNumberTest(){ final int[] ints = RandomUtil.randomPickInts(5, NumberUtil.range(5, 20)); - Assert.assertEquals(5, ints.length); + Assertions.assertEquals(5, ints.length); final Set set = Convert.convert(Set.class, ints); - Assert.assertEquals(5, set.size()); + Assertions.assertEquals(5, set.size()); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ReUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ReUtilTest.java index 526a43cca..4d010ffc4 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/ReUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ReUtilTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.lang.Console; import cn.hutool.core.regex.PatternPool; import cn.hutool.core.regex.ReUtil; 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.ArrayList; import java.util.List; @@ -20,28 +20,28 @@ public class ReUtilTest { @Test public void getTest() { final String resultGet = ReUtil.get("\\w{2}", content, 0); - Assert.assertEquals("ZZ", resultGet); + Assertions.assertEquals("ZZ", resultGet); } @Test public void extractMultiTest() { // 抽取多个分组然后把它们拼接起来 final String resultExtractMulti = ReUtil.extractMulti("(\\w)aa(\\w)", content, "$1-$2"); - Assert.assertEquals("Z-a", resultExtractMulti); + Assertions.assertEquals("Z-a", resultExtractMulti); } @Test public void extractMultiTest2() { // 抽取多个分组然后把它们拼接起来 final String resultExtractMulti = ReUtil.extractMulti("(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)(\\w)", content, "$1-$2-$3-$4-$5-$6-$7-$8-$9-$10"); - Assert.assertEquals("Z-Z-Z-a-a-a-b-b-b-c", resultExtractMulti); + Assertions.assertEquals("Z-Z-Z-a-a-a-b-b-b-c", resultExtractMulti); } @Test public void delFirstTest() { // 删除第一个匹配到的内容 final String resultDelFirst = ReUtil.delFirst("(\\w)aa(\\w)", content); - Assert.assertEquals("ZZbbbccc中文1234", resultDelFirst); + Assertions.assertEquals("ZZbbbccc中文1234", resultDelFirst); } @Test @@ -50,27 +50,27 @@ public class ReUtilTest { final String word = "180公斤"; final String sentence = "10.商品KLS100021型号xxl适合身高180体重130斤的用户"; //空字符串兼容 - Assert.assertEquals(blank,ReUtil.delLast("\\d+", blank)); - Assert.assertEquals(blank,ReUtil.delLast(PatternPool.NUMBERS, blank)); + Assertions.assertEquals(blank,ReUtil.delLast("\\d+", blank)); + Assertions.assertEquals(blank,ReUtil.delLast(PatternPool.NUMBERS, blank)); //去除数字 - Assert.assertEquals("公斤",ReUtil.delLast("\\d+", word)); - Assert.assertEquals("公斤",ReUtil.delLast(PatternPool.NUMBERS, word)); + Assertions.assertEquals("公斤",ReUtil.delLast("\\d+", word)); + Assertions.assertEquals("公斤",ReUtil.delLast(PatternPool.NUMBERS, word)); //去除汉字 //noinspection UnnecessaryUnicodeEscape - Assert.assertEquals("180",ReUtil.delLast("[\u4E00-\u9FFF]+", word)); - Assert.assertEquals("180",ReUtil.delLast(PatternPool.CHINESES, word)); + Assertions.assertEquals("180",ReUtil.delLast("[\u4E00-\u9FFF]+", word)); + Assertions.assertEquals("180",ReUtil.delLast(PatternPool.CHINESES, word)); //多个匹配删除最后一个 判断是否不在包含最后的数字 String s = ReUtil.delLast("\\d+", sentence); - Assert.assertEquals("10.商品KLS100021型号xxl适合身高180体重斤的用户", s); + Assertions.assertEquals("10.商品KLS100021型号xxl适合身高180体重斤的用户", s); s = ReUtil.delLast(PatternPool.NUMBERS, sentence); - Assert.assertEquals("10.商品KLS100021型号xxl适合身高180体重斤的用户", s); + Assertions.assertEquals("10.商品KLS100021型号xxl适合身高180体重斤的用户", s); //多个匹配删除最后一个 判断是否不在包含最后的数字 //noinspection UnnecessaryUnicodeEscape - Assert.assertFalse(ReUtil.delLast("[\u4E00-\u9FFF]+", sentence).contains("斤的用户")); - Assert.assertFalse(ReUtil.delLast(PatternPool.CHINESES, sentence).contains("斤的用户")); + Assertions.assertFalse(ReUtil.delLast("[\u4E00-\u9FFF]+", sentence).contains("斤的用户")); + Assertions.assertFalse(ReUtil.delLast(PatternPool.CHINESES, sentence).contains("斤的用户")); } @Test @@ -78,7 +78,7 @@ public class ReUtilTest { // 删除所有匹配到的内容 final String content = "发东方大厦eee![images]http://abc.com/2.gpg]好机会eee![images]http://abc.com/2.gpg]好机会"; final String resultDelAll = ReUtil.delAll("!\\[images\\][^\\u4e00-\\u9fa5\\\\s]*", content); - Assert.assertEquals("发东方大厦eee好机会eee好机会", resultDelAll); + Assertions.assertEquals("发东方大厦eee好机会eee好机会", resultDelAll); } @Test @@ -86,14 +86,14 @@ public class ReUtilTest { // 查找所有匹配文本 final List resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<>()); final List expected = ListUtil.of("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34"); - Assert.assertEquals(expected, resultFindAll); + Assertions.assertEquals(expected, resultFindAll); } @Test public void getFirstNumberTest() { // 找到匹配的第一个数字 final Integer resultGetFirstNumber = ReUtil.getFirstNumber(content); - Assert.assertEquals(Integer.valueOf(1234), resultGetFirstNumber); + Assertions.assertEquals(Integer.valueOf(1234), resultGetFirstNumber); } @Test @@ -101,7 +101,7 @@ public class ReUtilTest { // 给定字符串是否匹配给定正则 //noinspection UnnecessaryUnicodeEscape final boolean isMatch = ReUtil.isMatch("\\w+[\u4E00-\u9FFF]+\\d+", content); - Assert.assertTrue(isMatch); + Assertions.assertTrue(isMatch); } @Test @@ -109,14 +109,14 @@ public class ReUtilTest { //通过正则查找到字符串,然后把匹配到的字符串加入到replacementTemplate中,$1表示分组1的字符串 //此处把1234替换为 ->1234<- final String replaceAll = ReUtil.replaceAll(content, "(\\d+)", "->$1<-"); - Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll); + Assertions.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll); } @Test public void replaceAllTest2() { //此处把1234替换为 ->1234<- final String replaceAll = ReUtil.replaceAll(content, "(\\d+)", parameters -> "->" + parameters.group(1) + "<-"); - Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll); + Assertions.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll); } @Test @@ -124,21 +124,21 @@ public class ReUtilTest { // 修改前:ReUtil.replaceAll()方法,当replacementTemplate为null对象时,出现空指针异常 final String str = null; final Pattern pattern = Pattern.compile("(\\d+)"); - // Assert.assertThrows(NullPointerException.class, () -> ReUtil.replaceAll(content, pattern, str)); + // Assertions.assertThrows(NullPointerException.class, () -> ReUtil.replaceAll(content, pattern, str)); // 修改后:测试正常的方法访问是否有效 final String replaceAll = ReUtil.replaceAll(content, pattern, parameters -> "->" + parameters.group(1) + "<-"); - Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll); + Assertions.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll); // 修改后:判断ReUtil.replaceAll()方法,当replacementTemplate为null对象时,提示为非法的参数异常:ReplacementTemplate must be not null ! - Assert.assertThrows(IllegalArgumentException.class, () -> ReUtil.replaceAll(content, pattern, str)); + Assertions.assertThrows(IllegalArgumentException.class, () -> ReUtil.replaceAll(content, pattern, str)); } @Test public void escapeTest() { //转义给定字符串,为正则相关的特殊符号转义 final String escape = ReUtil.escape("我有个$符号{}"); - Assert.assertEquals("我有个\\$符号\\{\\}", escape); + Assertions.assertEquals("我有个\\$符号\\{\\}", escape); } @Test @@ -146,7 +146,7 @@ public class ReUtilTest { final String str = "a[bbbc"; final String re = "["; final String s = ReUtil.get(ReUtil.escape(re), str, 0); - Assert.assertEquals("[", s); + Assertions.assertEquals("[", s); } @Test @@ -154,7 +154,7 @@ public class ReUtilTest { final String context = "{prefix}_"; final String regex = "{prefix}_"; final boolean b = ReUtil.isMatch(ReUtil.escape(regex), context); - Assert.assertTrue(b); + Assertions.assertTrue(b); } @Test @@ -162,15 +162,15 @@ public class ReUtilTest { //转义给定字符串,为正则相关的特殊符号转义 final Pattern pattern = Pattern.compile("(\\d+)-(\\d+)-(\\d+)"); List allGroups = ReUtil.getAllGroups(pattern, "192-168-1-1"); - Assert.assertEquals("192-168-1", allGroups.get(0)); - Assert.assertEquals("192", allGroups.get(1)); - Assert.assertEquals("168", allGroups.get(2)); - Assert.assertEquals("1", allGroups.get(3)); + Assertions.assertEquals("192-168-1", allGroups.get(0)); + Assertions.assertEquals("192", allGroups.get(1)); + Assertions.assertEquals("168", allGroups.get(2)); + Assertions.assertEquals("1", allGroups.get(3)); allGroups = ReUtil.getAllGroups(pattern, "192-168-1-1", false); - Assert.assertEquals("192", allGroups.get(0)); - Assert.assertEquals("168", allGroups.get(1)); - Assert.assertEquals("1", allGroups.get(2)); + Assertions.assertEquals("192", allGroups.get(0)); + Assertions.assertEquals("168", allGroups.get(1)); + Assertions.assertEquals("1", allGroups.get(2)); } @Test @@ -185,11 +185,11 @@ public class ReUtilTest { final String content = "2021-10-11"; final String regex = "(?\\d+)-(?\\d+)-(?\\d+)"; final String year = ReUtil.get(regex, content, "year"); - Assert.assertEquals("2021", year); + Assertions.assertEquals("2021", year); final String month = ReUtil.get(regex, content, "month"); - Assert.assertEquals("10", month); + Assertions.assertEquals("10", month); final String day = ReUtil.get(regex, content, "day"); - Assert.assertEquals("11", day); + Assertions.assertEquals("11", day); } @Test @@ -197,9 +197,9 @@ public class ReUtilTest { final String content = "2021-10-11"; final String regex = "(?\\d+)-(?\\d+)-(?\\d+)"; final Map map = ReUtil.getAllGroupNames(PatternPool.get(regex, Pattern.DOTALL), content); - Assert.assertEquals(map.get("year"), "2021"); - Assert.assertEquals(map.get("month"), "10"); - Assert.assertEquals(map.get("day"), "11"); + Assertions.assertEquals(map.get("year"), "2021"); + Assertions.assertEquals(map.get("month"), "10"); + Assertions.assertEquals(map.get("day"), "11"); } @Test @@ -207,11 +207,11 @@ public class ReUtilTest { final Pattern patternIp = Pattern.compile("((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})\\.((2(5[0-5]|[0-4]\\d))" + "|[0-1]?\\d{1,2})\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})"); final String s = ReUtil.replaceAll("1.2.3.4", patternIp, "$1.**.**.$10"); - Assert.assertEquals("1.**.**.4", s); + Assertions.assertEquals("1.**.**.4", s); } @Test public void issueI6GIMTTest(){ - Assert.assertEquals(StrUtil.EMPTY, ReUtil.delAll("[\\s]*", " ")); + Assertions.assertEquals(StrUtil.EMPTY, ReUtil.delAll("[\\s]*", " ")); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ReferenceUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ReferenceUtilTest.java index a8fe7a7e5..05f2bfbef 100755 --- a/hutool-core/src/test/java/cn/hutool/core/util/ReferenceUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ReferenceUtilTest.java @@ -2,9 +2,9 @@ package cn.hutool.core.util; import cn.hutool.core.lang.Console; import cn.hutool.core.lang.mutable.MutableObj; -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.lang.ref.PhantomReference; import java.lang.ref.Reference; @@ -16,27 +16,27 @@ public class ReferenceUtilTest { @Test public void createWeakTest(){ final Reference integerReference = ReferenceUtil.of(ReferenceUtil.ReferenceType.WEAK, 1); - Assert.assertTrue(integerReference instanceof WeakReference); - Assert.assertEquals(new Integer(1), integerReference.get()); + Assertions.assertTrue(integerReference instanceof WeakReference); + Assertions.assertEquals(new Integer(1), integerReference.get()); } @Test public void createSoftTest(){ final Reference integerReference = ReferenceUtil.of(ReferenceUtil.ReferenceType.SOFT, 1); - Assert.assertTrue(integerReference instanceof SoftReference); - Assert.assertEquals(new Integer(1), integerReference.get()); + Assertions.assertTrue(integerReference instanceof SoftReference); + Assertions.assertEquals(new Integer(1), integerReference.get()); } @Test public void createPhantomTest(){ final Reference integerReference = ReferenceUtil.of(ReferenceUtil.ReferenceType.PHANTOM, 1); - Assert.assertTrue(integerReference instanceof PhantomReference); + Assertions.assertTrue(integerReference instanceof PhantomReference); // get方法永远都返回null,PhantomReference只能用来监控对象的GC状况 - Assert.assertNull(integerReference.get()); + Assertions.assertNull(integerReference.get()); } @Test - @Ignore + @Disabled public void gcTest(){ // https://blog.csdn.net/zmx729618/article/details/54093532 // 弱引用的对象必须使用可变对象,不能使用常量对象(比如String) diff --git a/hutool-core/src/test/java/cn/hutool/core/util/RuntimeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/RuntimeUtilTest.java index d76d316e8..d07001265 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/RuntimeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/RuntimeUtilTest.java @@ -1,9 +1,9 @@ package cn.hutool.core.util; 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; /** * 命令行单元测试 @@ -13,21 +13,21 @@ import org.junit.Test; public class RuntimeUtilTest { @Test - @Ignore + @Disabled public void execTest() { final String str = RuntimeUtil.execForStr("ipconfig"); Console.log(str); } @Test - @Ignore + @Disabled public void execCmdTest() { final String str = RuntimeUtil.execForStr("cmd /c dir"); Console.log(str); } @Test - @Ignore + @Disabled public void execCmdTest2() { final String str = RuntimeUtil.execForStr("cmd /c", "cd \"C:\\Program Files (x86)\"", "chdir"); Console.log(str); @@ -35,19 +35,19 @@ public class RuntimeUtilTest { @Test public void getUsableMemoryTest(){ - Assert.assertTrue(RuntimeUtil.getUsableMemory() > 0); + Assertions.assertTrue(RuntimeUtil.getUsableMemory() > 0); } @Test public void getPidTest(){ final int pid = RuntimeUtil.getPid(); - Assert.assertTrue(pid > 0); + Assertions.assertTrue(pid > 0); } @Test public void getProcessorCountTest(){ int cpu = RuntimeUtil.getProcessorCount(); Console.log("cpu个数:{}", cpu); - Assert.assertTrue(cpu > 0); + Assertions.assertTrue(cpu > 0); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/util/TypeUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/TypeUtilTest.java index a41f290a3..262958e3a 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/TypeUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/TypeUtilTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.reflect.FieldUtil; import cn.hutool.core.reflect.MethodUtil; import cn.hutool.core.reflect.TypeUtil; 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.lang.reflect.Method; import java.lang.reflect.Type; @@ -18,20 +18,20 @@ public class TypeUtilTest { public void getEleTypeTest() { final Method method = MethodUtil.getMethod(TestClass.class, "getList"); final Type type = TypeUtil.getReturnType(method); - Assert.assertEquals("java.util.List", type.toString()); + Assertions.assertEquals("java.util.List", type.toString()); final Type type2 = TypeUtil.getTypeArgument(type); - Assert.assertEquals(String.class, type2); + Assertions.assertEquals(String.class, type2); } @Test public void getParamTypeTest() { final Method method = MethodUtil.getMethod(TestClass.class, "intTest", Integer.class); final Type type = TypeUtil.getParamType(method, 0); - Assert.assertEquals(Integer.class, type); + Assertions.assertEquals(Integer.class, type); final Type returnType = TypeUtil.getReturnType(method); - Assert.assertEquals(Integer.class, returnType); + Assertions.assertEquals(Integer.class, returnType); } public static class TestClass { @@ -48,7 +48,7 @@ public class TypeUtilTest { public void getTypeArgumentTest(){ // 测试不继承父类,而是实现泛型接口时是否可以获取成功。 final Type typeArgument = TypeUtil.getTypeArgument(IPService.class); - Assert.assertEquals(String.class, typeArgument); + Assertions.assertEquals(String.class, typeArgument); } public interface OperateService { @@ -67,7 +67,7 @@ public class TypeUtilTest { final Type idType = TypeUtil.getActualType(Level3.class, FieldUtil.getField(Level3.class, "id")); - Assert.assertEquals(Long.class, idType); + Assertions.assertEquals(Long.class, idType); } public static class Level3 extends Level2{ diff --git a/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java index 99d1666f4..ea0bc97e9 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java @@ -8,9 +8,9 @@ import cn.hutool.core.lang.Console; import cn.hutool.core.map.MapBuilder; import cn.hutool.core.map.MapUtil; 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 org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -41,11 +41,11 @@ public class XmlUtilTest { + ""; final Document docResult = XmlUtil.parseXml(result); final String elementText = XmlUtil.elementText(docResult.getDocumentElement(), "returnstatus"); - Assert.assertEquals("Success", elementText); + Assertions.assertEquals("Success", elementText); } @Test - @Ignore + @Disabled public void writeTest() { final String result = ""// + ""// @@ -71,7 +71,7 @@ public class XmlUtilTest { + ""; final Document docResult = XmlUtil.parseXml(result); final Object value = XmlUtil.getByXPath("//returnsms/message", docResult, XPathConstants.STRING); - Assert.assertEquals("ok", value); + Assertions.assertEquals("ok", value); } @Test @@ -79,7 +79,7 @@ public class XmlUtilTest { final String result = ResourceUtil.readUtf8Str("test.xml"); final Document docResult = XmlUtil.parseXml(result); final Object value = XmlUtil.getByXPath("//returnsms/message", docResult, XPathConstants.STRING); - Assert.assertEquals("ok", value); + Assertions.assertEquals("ok", value); } @Test @@ -95,13 +95,13 @@ public class XmlUtilTest { + ""; final Map map = XmlUtil.xmlToMap(xml); - Assert.assertEquals(6, map.size()); - Assert.assertEquals("Success", map.get("returnstatus")); - Assert.assertEquals("ok", map.get("message")); - Assert.assertEquals("1490", map.get("remainpoint")); - Assert.assertEquals("885", map.get("taskID")); - Assert.assertEquals("1", map.get("successCounts")); - Assert.assertEquals("subText", ((Map) map.get("newNode")).get("sub")); + Assertions.assertEquals(6, map.size()); + Assertions.assertEquals("Success", map.get("returnstatus")); + Assertions.assertEquals("ok", map.get("message")); + Assertions.assertEquals("1490", map.get("remainpoint")); + Assertions.assertEquals("885", map.get("taskID")); + Assertions.assertEquals("1", map.get("successCounts")); + Assertions.assertEquals("subText", ((Map) map.get("newNode")).get("sub")); } @Test @@ -109,8 +109,8 @@ public class XmlUtilTest { final String xml = "张三李四"; final Map map = XmlUtil.xmlToMap(xml); - Assert.assertEquals(1, map.size()); - Assert.assertEquals(ListUtil.of("张三", "李四"), map.get("name")); + Assertions.assertEquals(1, map.size()); + Assertions.assertEquals(ListUtil.of("张三", "李四"), map.get("name")); } @Test @@ -122,7 +122,7 @@ public class XmlUtilTest { .build(); final Document doc = XmlUtil.mapToXml(map, "user"); // Console.log(XmlUtil.toStr(doc, false)); - Assert.assertEquals(""// + Assertions.assertEquals(""// + ""// + "张三"// + "12"// @@ -142,7 +142,7 @@ public class XmlUtilTest { .build(); final Document doc = XmlUtil.mapToXml(map, "City"); - Assert.assertEquals("" + + Assertions.assertEquals("" + "" + "town1" + "town2" + @@ -153,7 +153,7 @@ public class XmlUtilTest { @Test public void readTest() { final Document doc = XmlUtil.readXML("test.xml"); - Assert.assertNotNull(doc); + Assertions.assertNotNull(doc); } @Test @@ -163,7 +163,7 @@ public class XmlUtilTest { XmlUtil.readBySax(ResourceUtil.getStream("test.xml"), new DefaultHandler(){ @Override public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { - Assert.assertTrue(eles.contains(localName)); + Assertions.assertTrue(eles.contains(localName)); } }); } @@ -175,7 +175,7 @@ public class XmlUtilTest { .put("name", "ddatsh") .build(); final String xml = XmlUtil.mapToXmlStr(map, true); - Assert.assertEquals("ddatsh", xml); + Assertions.assertEquals("ddatsh", xml); } @Test @@ -193,7 +193,7 @@ public class XmlUtilTest { final Object value = XmlUtil.getByXPath( "//soap:Envelope/soap:Body/ns2:testResponse/return", document, XPathConstants.STRING);// - Assert.assertEquals("2020/04/15 21:01:21", value); + Assertions.assertEquals("2020/04/15 21:01:21", value); } @Test @@ -216,11 +216,11 @@ public class XmlUtilTest { // 不忽略空字段情况下保留自闭标签 Document doc = XmlUtil.beanToXml(testBean, null, false); - Assert.assertNotNull(XmlUtil.getElement(doc.getDocumentElement(), "ProjectCode")); + Assertions.assertNotNull(XmlUtil.getElement(doc.getDocumentElement(), "ProjectCode")); // 忽略空字段情况下无自闭标签 doc = XmlUtil.beanToXml(testBean, null, true); - Assert.assertNull(XmlUtil.getElement(doc.getDocumentElement(), "ProjectCode")); + Assertions.assertNull(XmlUtil.getElement(doc.getDocumentElement(), "ProjectCode")); } @Test @@ -242,14 +242,14 @@ public class XmlUtilTest { testBean.setBankCode("00001"); final Document doc = XmlUtil.beanToXml(testBean); - Assert.assertEquals(TestBean.class.getSimpleName(), doc.getDocumentElement().getTagName()); + Assertions.assertEquals(TestBean.class.getSimpleName(), doc.getDocumentElement().getTagName()); final TestBean testBean2 = XmlUtil.xmlToBean(doc, TestBean.class); - Assert.assertEquals(testBean.getReqCode(), testBean2.getReqCode()); - Assert.assertEquals(testBean.getAccountName(), testBean2.getAccountName()); - Assert.assertEquals(testBean.getOperator(), testBean2.getOperator()); - Assert.assertEquals(testBean.getProjectCode(), testBean2.getProjectCode()); - Assert.assertEquals(testBean.getBankCode(), testBean2.getBankCode()); + Assertions.assertEquals(testBean.getReqCode(), testBean2.getReqCode()); + Assertions.assertEquals(testBean.getAccountName(), testBean2.getAccountName()); + Assertions.assertEquals(testBean.getOperator(), testBean2.getOperator()); + Assertions.assertEquals(testBean.getProjectCode(), testBean2.getProjectCode()); + Assertions.assertEquals(testBean.getBankCode(), testBean2.getBankCode()); } @Test @@ -272,18 +272,18 @@ public class XmlUtilTest { // toBean方式 final SmsRes res1 = XmlUtil.xmlToBean(doc.getFirstChild(), SmsRes.class); - Assert.assertEquals(res.toString(), res1.toString()); + Assertions.assertEquals(res.toString(), res1.toString()); } @Test public void cleanCommentTest() { final String xmlContent = "hutooljava"; final String ret = XmlUtil.cleanComment(xmlContent); - Assert.assertEquals("hutooljava", ret); + Assertions.assertEquals("hutooljava", ret); } @Test - @Ignore + @Disabled public void formatTest(){ // https://github.com/looly/hutool/pull/1234 final Document xml = XmlUtil.createXml("NODES"); @@ -330,11 +330,11 @@ public class XmlUtilTest { final Document doc = XmlUtil.parseXml(xml); final String name = doc.getDocumentElement().getAttribute("name"); - Assert.assertEquals("aaaa", name); + Assertions.assertEquals("aaaa", name); } @Test - @Ignore + @Disabled public void issueI5DO8ETest(){ // 增加子节点后,格式会错乱,JDK的bug XmlUtil.setNamespaceAware(false); @@ -354,9 +354,9 @@ public class XmlUtilTest { final String xml = "张三20zhangsan@example.com"; final Document document = XmlUtil.readXML(xml); final UserInfo userInfo = XmlUtil.xmlToBean(document, UserInfo.class); - Assert.assertEquals("张三", userInfo.getName()); - Assert.assertEquals("20", userInfo.getAge()); - Assert.assertEquals("zhangsan@example.com", userInfo.getEmail()); + Assertions.assertEquals("张三", userInfo.getName()); + Assertions.assertEquals("20", userInfo.getAge()); + Assertions.assertEquals("zhangsan@example.com", userInfo.getEmail()); } @Data diff --git a/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java index 87259df6a..a6ad34777 100644 --- a/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/util/ZipUtilTest.java @@ -6,9 +6,9 @@ import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.text.StrUtil; -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.io.IOException; @@ -44,9 +44,9 @@ public class ZipUtilTest { List afterNames = zipEntryNames(tempZipFile); // 确认增加了文件 - Assert.assertEquals(beforeNames.size() + 1, afterNames.size()); - Assert.assertTrue(afterNames.containsAll(beforeNames)); - Assert.assertTrue(afterNames.contains(appendFile.getName())); + Assertions.assertEquals(beforeNames.size() + 1, afterNames.size()); + Assertions.assertTrue(afterNames.containsAll(beforeNames)); + Assertions.assertTrue(afterNames.contains(appendFile.getName())); // test dir add beforeNames = zipEntryNames(tempZipFile); @@ -55,12 +55,12 @@ public class ZipUtilTest { afterNames = zipEntryNames(tempZipFile); // 确认增加了文件和目录,增加目录和目录下一个文件,故此处+2 - Assert.assertEquals(beforeNames.size() + 2, afterNames.size()); - Assert.assertTrue(afterNames.containsAll(beforeNames)); - Assert.assertTrue(afterNames.contains(appendFile.getName())); + Assertions.assertEquals(beforeNames.size() + 2, afterNames.size()); + Assertions.assertTrue(afterNames.containsAll(beforeNames)); + Assertions.assertTrue(afterNames.contains(appendFile.getName())); // rollback - Assert.assertTrue(String.format("delete temp file %s failed", tempZipFile.getCanonicalPath()), tempZipFile.delete()); + Assertions.assertTrue(tempZipFile.delete(), String.format("delete temp file %s failed", tempZipFile.getCanonicalPath())); } /** @@ -78,43 +78,43 @@ public class ZipUtilTest { } @Test - @Ignore + @Disabled public void zipDirTest() { ZipUtil.zip(new File("d:/test")); } @Test - @Ignore + @Disabled public void unzipTest() { final File unzip = ZipUtil.unzip("f:/test/apache-maven-3.6.2.zip", "f:\\test"); Console.log(unzip); } @Test - @Ignore + @Disabled public void unzipTest2() { final File unzip = ZipUtil.unzip("f:/test/各种资源.zip", "f:/test/各种资源", CharsetUtil.GBK); Console.log(unzip); } @Test - @Ignore + @Disabled public void unzipFromStreamTest() { final File unzip = ZipUtil.unzip(FileUtil.getInputStream("e:/test/hutool-core-5.1.0.jar"), FileUtil.file("e:/test/"), CharsetUtil.UTF_8); Console.log(unzip); } @Test - @Ignore + @Disabled public void unzipChineseTest() { ZipUtil.unzip("d:/测试.zip"); } @Test - @Ignore + @Disabled public void unzipFileBytesTest() { final byte[] fileBytes = ZipUtil.unzipFileBytes(FileUtil.file("e:/02 电力相关设备及服务2-241-.zip"), CharsetUtil.GBK, "images/CE-EP-HY-MH01-ES-0001.jpg"); - Assert.assertNotNull(fileBytes); + Assertions.assertNotNull(fileBytes); } @Test @@ -124,11 +124,11 @@ public class ZipUtilTest { final byte[] gzip = ZipUtil.gzip(bytes); //保证gzip长度正常 - Assert.assertEquals(68, gzip.length); + Assertions.assertEquals(68, gzip.length); final byte[] unGzip = ZipUtil.unGzip(gzip); //保证正常还原 - Assert.assertEquals(data, StrUtil.utf8Str(unGzip)); + Assertions.assertEquals(data, StrUtil.utf8Str(unGzip)); } @Test @@ -138,21 +138,21 @@ public class ZipUtilTest { byte[] gzip = ZipUtil.zlib(bytes, 0); //保证zlib长度正常 - Assert.assertEquals(62, gzip.length); + Assertions.assertEquals(62, gzip.length); final byte[] unGzip = ZipUtil.unZlib(gzip); //保证正常还原 - Assert.assertEquals(data, StrUtil.utf8Str(unGzip)); + Assertions.assertEquals(data, StrUtil.utf8Str(unGzip)); gzip = ZipUtil.zlib(bytes, 9); //保证zlib长度正常 - Assert.assertEquals(56, gzip.length); + Assertions.assertEquals(56, gzip.length); final byte[] unGzip2 = ZipUtil.unZlib(gzip); //保证正常还原 - Assert.assertEquals(data, StrUtil.utf8Str(unGzip2)); + Assertions.assertEquals(data, StrUtil.utf8Str(unGzip2)); } @Test - @Ignore + @Disabled public void zipStreamTest(){ //https://github.com/dromara/hutool/issues/944 final String dir = "d:/test"; @@ -166,7 +166,7 @@ public class ZipUtilTest { } @Test - @Ignore + @Disabled public void zipStreamTest2(){ // https://github.com/dromara/hutool/issues/944 final String file1 = "d:/test/a.txt"; @@ -183,7 +183,7 @@ public class ZipUtilTest { } @Test - @Ignore + @Disabled public void zipToStreamTest(){ final String zip = "d:/test/testToStream.zip"; final OutputStream out = FileUtil.getOutputStream(zip); @@ -192,7 +192,7 @@ public class ZipUtilTest { } @Test - @Ignore + @Disabled public void zipMultiFileTest(){ final File[] dd={FileUtil.file("d:\\test\\qr_a.jpg") ,FileUtil.file("d:\\test\\qr_b.jpg")}; @@ -201,7 +201,7 @@ public class ZipUtilTest { } @Test - @Ignore + @Disabled public void sizeUnzip() throws IOException { final String zipPath = "F:\\BaiduNetdiskDownload\\demo.zip"; final String outPath = "F:\\BaiduNetdiskDownload\\test"; @@ -216,7 +216,7 @@ public class ZipUtilTest { } @Test - @Ignore + @Disabled public void unzipTest3() { // https://github.com/dromara/hutool/issues/3018 ZipUtil.unzip("d:/test/default.zip", "d:/test/"); diff --git a/hutool-cron/src/test/java/cn/hutool/cron/TaskTableTest.java b/hutool-cron/src/test/java/cn/hutool/cron/TaskTableTest.java index 8612b3956..226afc07c 100755 --- a/hutool-cron/src/test/java/cn/hutool/cron/TaskTableTest.java +++ b/hutool-cron/src/test/java/cn/hutool/cron/TaskTableTest.java @@ -3,13 +3,13 @@ package cn.hutool.cron; import cn.hutool.core.lang.Console; import cn.hutool.core.lang.id.IdUtil; import cn.hutool.cron.pattern.CronPattern; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class TaskTableTest { @Test - @Ignore + @Disabled public void toStringTest(){ final TaskTable taskTable = new TaskTable(); taskTable.add(IdUtil.fastUUID(), new CronPattern("*/10 * * * * *"), ()-> Console.log("Task 1")); diff --git a/hutool-cron/src/test/java/cn/hutool/cron/demo/CronTest.java b/hutool-cron/src/test/java/cn/hutool/cron/demo/CronTest.java index ee59698d2..e66c770b3 100644 --- a/hutool-cron/src/test/java/cn/hutool/cron/demo/CronTest.java +++ b/hutool-cron/src/test/java/cn/hutool/cron/demo/CronTest.java @@ -6,8 +6,8 @@ import cn.hutool.cron.CronUtil; import cn.hutool.cron.TaskExecutor; import cn.hutool.cron.listener.TaskListener; import cn.hutool.cron.task.Task; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * 定时任务样例 @@ -15,7 +15,7 @@ import org.junit.Test; public class CronTest { @Test - @Ignore + @Disabled public void customCronTest() { CronUtil.schedule("*/2 * * * * *", (Task) () -> Console.log("Task excuted.")); @@ -28,7 +28,7 @@ public class CronTest { } @Test - @Ignore + @Disabled public void cronTest() { // 支持秒级别定时任务 CronUtil.setMatchSecond(true); @@ -40,7 +40,7 @@ public class CronTest { } @Test - @Ignore + @Disabled public void cronWithListenerTest() { CronUtil.getScheduler().addListener(new TaskListener() { @Override @@ -68,7 +68,7 @@ public class CronTest { } @Test - @Ignore + @Disabled public void addAndRemoveTest() { final String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s")); diff --git a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternBuilderTest.java b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternBuilderTest.java index 6943ac975..330937128 100755 --- a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternBuilderTest.java +++ b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternBuilderTest.java @@ -1,26 +1,26 @@ package cn.hutool.cron.pattern; import cn.hutool.cron.CronException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CronPatternBuilderTest { @Test public void buildMatchAllTest(){ String build = CronPatternBuilder.of().build(); - Assert.assertEquals("* * * * *", build); + Assertions.assertEquals("* * * * *", build); build = CronPatternBuilder.of() .set(Part.SECOND, "*") .build(); - Assert.assertEquals("* * * * * *", build); + Assertions.assertEquals("* * * * * *", build); build = CronPatternBuilder.of() .set(Part.SECOND, "*") .set(Part.YEAR, "*") .build(); - Assert.assertEquals("* * * * * * *", build); + Assertions.assertEquals("* * * * * * *", build); } @Test @@ -29,16 +29,18 @@ public class CronPatternBuilderTest { .set(Part.SECOND, "*") .setRange(Part.HOUR, 2, 9) .build(); - Assert.assertEquals("* * 2-9 * * *", build); + Assertions.assertEquals("* * 2-9 * * *", build); } - @Test(expected = CronException.class) + @Test public void buildRangeErrorTest(){ - final String build = CronPatternBuilder.of() + Assertions.assertThrows(CronException.class, ()->{ + final String build = CronPatternBuilder.of() .set(Part.SECOND, "*") // 55无效值 .setRange(Part.HOUR, 2, 55) .build(); - Assert.assertEquals("* * 2-9 * * *", build); + Assertions.assertEquals("* * 2-9 * * *", build); + }); } } diff --git a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternNextMatchTest.java b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternNextMatchTest.java index 59ff77cfd..f928e8891 100644 --- a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternNextMatchTest.java +++ b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternNextMatchTest.java @@ -3,8 +3,8 @@ package cn.hutool.cron.pattern; import cn.hutool.core.date.DateField; 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.util.Calendar; @@ -16,35 +16,35 @@ public class CronPatternNextMatchTest { CronPattern pattern = new CronPattern("* * * * * * *"); DateTime date = DateUtil.truncate(DateUtil.now(), DateField.SECOND); Calendar calendar = pattern.nextMatchAfter(date.toCalendar()); - Assert.assertEquals(date.getTime(), DateUtil.date(calendar).getTime()); + Assertions.assertEquals(date.getTime(), DateUtil.date(calendar).getTime()); // 匹配所有分,返回下一分钟 pattern = new CronPattern("0 * * * * * *"); date = DateUtil.parse("2022-04-08 07:44:16"); //noinspection ConstantConditions calendar = pattern.nextMatchAfter(date.toCalendar()); - Assert.assertEquals(DateUtil.parse("2022-04-08 07:45:00"), DateUtil.date(calendar)); + Assertions.assertEquals(DateUtil.parse("2022-04-08 07:45:00"), DateUtil.date(calendar)); // 匹配所有时,返回下一小时 pattern = new CronPattern("0 0 * * * * *"); date = DateUtil.parse("2022-04-08 07:44:16"); //noinspection ConstantConditions calendar = pattern.nextMatchAfter(date.toCalendar()); - Assert.assertEquals(DateUtil.parse("2022-04-08 08:00:00"), DateUtil.date(calendar)); + Assertions.assertEquals(DateUtil.parse("2022-04-08 08:00:00"), DateUtil.date(calendar)); // 匹配所有天,返回明日 pattern = new CronPattern("0 0 0 * * * *"); date = DateUtil.parse("2022-04-08 07:44:16"); //noinspection ConstantConditions calendar = pattern.nextMatchAfter(date.toCalendar()); - Assert.assertEquals(DateUtil.parse("2022-04-09 00:00:00"), DateUtil.date(calendar)); + Assertions.assertEquals(DateUtil.parse("2022-04-09 00:00:00"), DateUtil.date(calendar)); // 匹配所有月,返回下一月 pattern = new CronPattern("0 0 0 1 * * *"); date = DateUtil.parse("2022-04-08 07:44:16"); //noinspection ConstantConditions calendar = pattern.nextMatchAfter(date.toCalendar()); - Assert.assertEquals(DateUtil.parse("2022-05-01 00:00:00"), DateUtil.date(calendar)); + Assertions.assertEquals(DateUtil.parse("2022-05-01 00:00:00"), DateUtil.date(calendar)); } @Test @@ -56,36 +56,36 @@ public class CronPatternNextMatchTest { Calendar calendar = pattern.nextMatchAfter( DateUtil.parse("2022-04-12 09:12:12").toCalendar()); - Assert.assertTrue(pattern.match(calendar, true)); - Assert.assertEquals("2022-04-12 09:12:23", DateUtil.date(calendar).toString()); + Assertions.assertTrue(pattern.match(calendar, true)); + Assertions.assertEquals("2022-04-12 09:12:23", DateUtil.date(calendar).toString()); // 秒超出规定值的最大值,分+1,秒取最小值 //noinspection ConstantConditions calendar = pattern.nextMatchAfter( DateUtil.parse("2022-04-12 09:09:24").toCalendar()); - Assert.assertTrue(pattern.match(calendar, true)); - Assert.assertEquals("2022-04-12 09:12:23", DateUtil.date(calendar).toString()); + Assertions.assertTrue(pattern.match(calendar, true)); + Assertions.assertEquals("2022-04-12 09:12:23", DateUtil.date(calendar).toString()); // 秒超出规定值的最大值,分不变,小时+1,秒和分使用最小值 //noinspection ConstantConditions calendar = pattern.nextMatchAfter( DateUtil.parse("2022-04-12 09:12:24").toCalendar()); - Assert.assertTrue(pattern.match(calendar, true)); - Assert.assertEquals("2022-04-12 10:12:23", DateUtil.date(calendar).toString()); + Assertions.assertTrue(pattern.match(calendar, true)); + Assertions.assertEquals("2022-04-12 10:12:23", DateUtil.date(calendar).toString()); // 天超出规定值的最大值,月+1,天、时、分、秒取最小值 //noinspection ConstantConditions calendar = pattern.nextMatchAfter( DateUtil.parse("2022-04-13 09:12:24").toCalendar()); - Assert.assertTrue(pattern.match(calendar, true)); - Assert.assertEquals("2022-05-12 00:12:23", DateUtil.date(calendar).toString()); + Assertions.assertTrue(pattern.match(calendar, true)); + Assertions.assertEquals("2022-05-12 00:12:23", DateUtil.date(calendar).toString()); // 跨年 //noinspection ConstantConditions calendar = pattern.nextMatchAfter( DateUtil.parse("2021-12-22 00:00:00").toCalendar()); - Assert.assertTrue(pattern.match(calendar, true)); - Assert.assertEquals("2022-01-12 00:12:23", DateUtil.date(calendar).toString()); + Assertions.assertTrue(pattern.match(calendar, true)); + Assertions.assertEquals("2022-01-12 00:12:23", DateUtil.date(calendar).toString()); } @Test @@ -95,6 +95,6 @@ public class CronPatternNextMatchTest { final DateTime time = DateUtil.parse("2022-04-03"); assert time != null; final Calendar calendar = pattern.nextMatchAfter(time.toCalendar()); - Assert.assertEquals("2022-04-09 01:01:01", DateUtil.date(calendar).toString()); + Assertions.assertEquals("2022-04-09 01:01:01", DateUtil.date(calendar).toString()); } } diff --git a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternTest.java b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternTest.java index 2cb73ee6d..9c3c8f810 100755 --- a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternTest.java +++ b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternTest.java @@ -2,8 +2,8 @@ package cn.hutool.cron.pattern; import cn.hutool.core.date.DateUtil; import cn.hutool.cron.CronException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 定时任务单元测试类 @@ -103,11 +103,11 @@ public class CronPatternTest { @Test public void CronPatternTest2() { CronPattern pattern = CronPattern.of("0/30 * * * *"); - Assert.assertTrue(pattern.match(DateUtil.parse("2018-10-09 12:00:00").getTime(), false)); - Assert.assertTrue(pattern.match(DateUtil.parse("2018-10-09 12:30:00").getTime(), false)); + Assertions.assertTrue(pattern.match(DateUtil.parse("2018-10-09 12:00:00").getTime(), false)); + Assertions.assertTrue(pattern.match(DateUtil.parse("2018-10-09 12:30:00").getTime(), false)); pattern = CronPattern.of("32 * * * *"); - Assert.assertTrue(pattern.match(DateUtil.parse("2018-10-09 12:32:00").getTime(), false)); + Assertions.assertTrue(pattern.match(DateUtil.parse("2018-10-09 12:32:00").getTime(), false)); } @Test @@ -159,10 +159,12 @@ public class CronPatternTest { assertMatch(pattern, "2017-12-02 23:59:59"); } - @Test(expected = CronException.class) + @Test public void rangeYearTest() { - // year的范围是1970~2099年,超出报错 - CronPattern.of("0/1 * * * 1/1 ? 2020-2120"); + Assertions.assertThrows(CronException.class, ()->{ + // year的范围是1970~2099年,超出报错 + CronPattern.of("0/1 * * * 1/1 ? 2020-2120"); + }); } /** @@ -173,7 +175,7 @@ public class CronPatternTest { */ @SuppressWarnings("ConstantConditions") private void assertMatch(final CronPattern pattern, final String date) { - Assert.assertTrue(pattern.match(DateUtil.parse(date).toCalendar(), false)); - Assert.assertTrue(pattern.match(DateUtil.parse(date).toCalendar(), true)); + Assertions.assertTrue(pattern.match(DateUtil.parse(date).toCalendar(), false)); + Assertions.assertTrue(pattern.match(DateUtil.parse(date).toCalendar(), true)); } } diff --git a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternUtilTest.java b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternUtilTest.java index ba02abe35..45e65c9b6 100644 --- a/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternUtilTest.java +++ b/hutool-cron/src/test/java/cn/hutool/cron/pattern/CronPatternUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.cron.pattern; 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.util.Date; import java.util.List; @@ -13,35 +13,35 @@ public class CronPatternUtilTest { public void matchedDatesTest() { //测试每30秒执行 final List matchedDates = CronPatternUtil.matchedDates("0/30 * 8-18 * * ?", DateUtil.parse("2018-10-15 14:33:22"), 5, true); - Assert.assertEquals(5, matchedDates.size()); - Assert.assertEquals("2018-10-15 14:33:30", matchedDates.get(0).toString()); - Assert.assertEquals("2018-10-15 14:34:00", matchedDates.get(1).toString()); - Assert.assertEquals("2018-10-15 14:34:30", matchedDates.get(2).toString()); - Assert.assertEquals("2018-10-15 14:35:00", matchedDates.get(3).toString()); - Assert.assertEquals("2018-10-15 14:35:30", matchedDates.get(4).toString()); + Assertions.assertEquals(5, matchedDates.size()); + Assertions.assertEquals("2018-10-15 14:33:30", matchedDates.get(0).toString()); + Assertions.assertEquals("2018-10-15 14:34:00", matchedDates.get(1).toString()); + Assertions.assertEquals("2018-10-15 14:34:30", matchedDates.get(2).toString()); + Assertions.assertEquals("2018-10-15 14:35:00", matchedDates.get(3).toString()); + Assertions.assertEquals("2018-10-15 14:35:30", matchedDates.get(4).toString()); } @Test public void matchedDatesTest2() { //测试每小时执行 final List matchedDates = CronPatternUtil.matchedDates("0 0 */1 * * *", DateUtil.parse("2018-10-15 14:33:22"), 5, true); - Assert.assertEquals(5, matchedDates.size()); - Assert.assertEquals("2018-10-15 15:00:00", matchedDates.get(0).toString()); - Assert.assertEquals("2018-10-15 16:00:00", matchedDates.get(1).toString()); - Assert.assertEquals("2018-10-15 17:00:00", matchedDates.get(2).toString()); - Assert.assertEquals("2018-10-15 18:00:00", matchedDates.get(3).toString()); - Assert.assertEquals("2018-10-15 19:00:00", matchedDates.get(4).toString()); + Assertions.assertEquals(5, matchedDates.size()); + Assertions.assertEquals("2018-10-15 15:00:00", matchedDates.get(0).toString()); + Assertions.assertEquals("2018-10-15 16:00:00", matchedDates.get(1).toString()); + Assertions.assertEquals("2018-10-15 17:00:00", matchedDates.get(2).toString()); + Assertions.assertEquals("2018-10-15 18:00:00", matchedDates.get(3).toString()); + Assertions.assertEquals("2018-10-15 19:00:00", matchedDates.get(4).toString()); } @Test public void matchedDatesTest3() { //测试最后一天 final List matchedDates = CronPatternUtil.matchedDates("0 0 */1 L * *", DateUtil.parse("2018-10-30 23:33:22"), 5, true); - Assert.assertEquals(5, matchedDates.size()); - Assert.assertEquals("2018-10-31 00:00:00", matchedDates.get(0).toString()); - Assert.assertEquals("2018-10-31 01:00:00", matchedDates.get(1).toString()); - Assert.assertEquals("2018-10-31 02:00:00", matchedDates.get(2).toString()); - Assert.assertEquals("2018-10-31 03:00:00", matchedDates.get(3).toString()); - Assert.assertEquals("2018-10-31 04:00:00", matchedDates.get(4).toString()); + Assertions.assertEquals(5, matchedDates.size()); + Assertions.assertEquals("2018-10-31 00:00:00", matchedDates.get(0).toString()); + Assertions.assertEquals("2018-10-31 01:00:00", matchedDates.get(1).toString()); + Assertions.assertEquals("2018-10-31 02:00:00", matchedDates.get(2).toString()); + Assertions.assertEquals("2018-10-31 03:00:00", matchedDates.get(3).toString()); + Assertions.assertEquals("2018-10-31 04:00:00", matchedDates.get(4).toString()); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/BCUtilTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/BCUtilTest.java index 55887b2fe..bf499c12f 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/BCUtilTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/BCUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.crypto; import org.bouncycastle.crypto.params.ECPrivateKeyParameters; import org.bouncycastle.crypto.params.ECPublicKeyParameters; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BCUtilTest { @@ -16,7 +16,7 @@ public class BCUtilTest { final String y = "F7E938B02EED7280277493B8556E5B01CB436E018A562DFDC53342BF41FDF728"; final ECPublicKeyParameters keyParameters = BCUtil.toSm2Params(x, y); - Assert.assertNotNull(keyParameters); + Assertions.assertNotNull(keyParameters); } @Test @@ -24,6 +24,6 @@ public class BCUtilTest { final String privateKeyHex = "5F6CA5BB044C40ED2355F0372BF72A5B3AE6943712F9FDB7C1FFBAECC06F3829"; final ECPrivateKeyParameters keyParameters = BCUtil.toSm2Params(privateKeyHex); - Assert.assertNotNull(keyParameters); + Assertions.assertNotNull(keyParameters); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java index 95e36a38c..50e12ae79 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/KeyUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.crypto; -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.security.KeyPair; import java.security.PrivateKey; @@ -13,12 +13,14 @@ public class KeyUtilTest { /** * 测试关闭BouncyCastle支持时是否会正常抛出异常,即关闭是否有效 */ - @Test(expected = CryptoException.class) - @Ignore + @Test + @Disabled public void generateKeyPairTest() { - GlobalBouncyCastleProvider.setUseBouncyCastle(false); - final KeyPair pair = KeyUtil.generateKeyPair("SM2"); - Assert.assertNotNull(pair); + Assertions.assertThrows(CryptoException.class, ()->{ + GlobalBouncyCastleProvider.setUseBouncyCastle(false); + final KeyPair pair = KeyUtil.generateKeyPair("SM2"); + Assertions.assertNotNull(pair); + }); } @Test @@ -26,7 +28,7 @@ public class KeyUtilTest { final KeyPair keyPair = KeyUtil.generateKeyPair("RSA"); final PrivateKey aPrivate = keyPair.getPrivate(); final PublicKey rsaPublicKey = KeyUtil.getRSAPublicKey(aPrivate); - Assert.assertEquals(rsaPublicKey, keyPair.getPublic()); + Assertions.assertEquals(rsaPublicKey, keyPair.getPublic()); } /** @@ -35,31 +37,31 @@ public class KeyUtilTest { @Test public void generateECIESKeyTest(){ final KeyPair ecies = KeyUtil.generateKeyPair("ECIES"); - Assert.assertNotNull(ecies.getPrivate()); - Assert.assertNotNull(ecies.getPublic()); + Assertions.assertNotNull(ecies.getPrivate()); + Assertions.assertNotNull(ecies.getPublic()); final byte[] privateKeyBytes = ecies.getPrivate().getEncoded(); final PrivateKey privateKey = KeyUtil.generatePrivateKey("EC", privateKeyBytes); - Assert.assertEquals(ecies.getPrivate(), privateKey); + Assertions.assertEquals(ecies.getPrivate(), privateKey); } @Test public void generateDHTest(){ final KeyPair dh = KeyUtil.generateKeyPair("DH"); - Assert.assertNotNull(dh.getPrivate()); - Assert.assertNotNull(dh.getPublic()); + Assertions.assertNotNull(dh.getPrivate()); + Assertions.assertNotNull(dh.getPublic()); final byte[] privateKeyBytes = dh.getPrivate().getEncoded(); final PrivateKey privateKey = KeyUtil.generatePrivateKey("DH", privateKeyBytes); - Assert.assertEquals(dh.getPrivate(), privateKey); + Assertions.assertEquals(dh.getPrivate(), privateKey); } @Test public void generateSm4KeyTest(){ // https://github.com/dromara/hutool/issues/2150 - Assert.assertEquals(16, KeyUtil.generateKey("sm4").getEncoded().length); - Assert.assertEquals(32, KeyUtil.generateKey("sm4", 256).getEncoded().length); + Assertions.assertEquals(16, KeyUtil.generateKey("sm4").getEncoded().length); + Assertions.assertEquals(32, KeyUtil.generateKey("sm4", 256).getEncoded().length); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/OpensslKeyUtilTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/OpensslKeyUtilTest.java index 12a1f815f..26d7ae828 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/OpensslKeyUtilTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/OpensslKeyUtilTest.java @@ -3,8 +3,8 @@ package cn.hutool.crypto; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.util.ByteUtil; import cn.hutool.crypto.asymmetric.SM2; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.security.PrivateKey; import java.security.PublicKey; @@ -49,7 +49,7 @@ public class OpensslKeyUtilTest { final String content = "我是Hanley."; final byte[] sign = genSm2.sign(ByteUtil.toUtf8Bytes(content)); final boolean verify = genSm2.verify(ByteUtil.toUtf8Bytes(content), sign); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/PemUtilTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/PemUtilTest.java index 2fc820c8e..3ba62f0ee 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/PemUtilTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/PemUtilTest.java @@ -6,9 +6,9 @@ import cn.hutool.core.util.ByteUtil; import cn.hutool.crypto.asymmetric.KeyType; import cn.hutool.crypto.asymmetric.RSA; import cn.hutool.crypto.asymmetric.SM2; -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.nio.charset.StandardCharsets; import java.security.PrivateKey; @@ -19,19 +19,19 @@ public class PemUtilTest { @Test public void readPrivateKeyTest() { final PrivateKey privateKey = PemUtil.readPemPrivateKey(ResourceUtil.getStream("test_private_key.pem")); - Assert.assertNotNull(privateKey); + Assertions.assertNotNull(privateKey); } @Test public void readPublicKeyTest() { final PublicKey publicKey = PemUtil.readPemPublicKey(ResourceUtil.getStream("test_public_key.csr")); - Assert.assertNotNull(publicKey); + Assertions.assertNotNull(publicKey); } @Test public void readPemKeyTest() { final PublicKey publicKey = (PublicKey) PemUtil.readPemKey(ResourceUtil.getStream("test_public_key.csr")); - Assert.assertNotNull(publicKey); + Assertions.assertNotNull(publicKey); } @Test @@ -44,7 +44,7 @@ public class PemUtilTest { final String encryptStr = rsa.encryptBase64(str, KeyType.PublicKey); final String decryptStr = rsa.decryptStr(encryptStr, KeyType.PrivateKey); - Assert.assertEquals(str, decryptStr); + Assertions.assertEquals(str, decryptStr); } @Test @@ -58,7 +58,7 @@ public class PemUtilTest { final byte[] sign = sm2.sign(dataBytes, null); // 64位签名 - Assert.assertEquals(64, sign.length); + Assertions.assertEquals(64, sign.length); } @Test @@ -72,11 +72,11 @@ public class PemUtilTest { final byte[] sign = sm2.sign(dataBytes, null); // 64位签名 - Assert.assertEquals(64, sign.length); + Assertions.assertEquals(64, sign.length); } @Test - @Ignore + @Disabled public void readECPrivateKeyTest2() { // https://gitee.com/dromara/hutool/issues/I37Z75 final byte[] d = PemUtil.readPem(FileUtil.getInputStream("d:/test/keys/priv.key")); @@ -88,6 +88,6 @@ public class PemUtilTest { final String content = "我是Hanley."; final byte[] sign = sm2.sign(ByteUtil.toUtf8Bytes(content)); final boolean verify = sm2.verify(ByteUtil.toUtf8Bytes(content), sign); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/SmTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/SmTest.java index 2805cee9f..ed883e5a1 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/SmTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/SmTest.java @@ -3,8 +3,8 @@ package cn.hutool.crypto; import cn.hutool.core.util.CharsetUtil; import cn.hutool.crypto.digest.HMac; import cn.hutool.crypto.symmetric.SM4; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.crypto.SecretKey; @@ -19,7 +19,7 @@ public class SmTest { @Test public void sm3Test() { final String digestHex = SmUtil.sm3("aaaaa"); - Assert.assertEquals("136ce3c86e4ed909b76082055a61586af20b4dab674732ebd4b599eef080c9be", digestHex); + Assertions.assertEquals("136ce3c86e4ed909b76082055a61586af20b4dab674732ebd4b599eef080c9be", digestHex); } @Test @@ -30,7 +30,7 @@ public class SmTest { final String encryptHex = sm4.encryptHex(content); final String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -42,18 +42,18 @@ public class SmTest { final String encryptHex = sm4.encryptHex(content); final String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test public void sm4ECBPKCS5PaddingTest2() { final String content = "test中文"; final SM4 sm4 = new SM4(Mode.ECB, Padding.PKCS5Padding); - Assert.assertEquals("SM4/ECB/PKCS5Padding", sm4.getCipher().getAlgorithm()); + Assertions.assertEquals("SM4/ECB/PKCS5Padding", sm4.getCipher().getAlgorithm()); final String encryptHex = sm4.encryptHex(content); final String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -63,11 +63,11 @@ public class SmTest { final SecretKey key = KeyUtil.generateKey(SM4.ALGORITHM_NAME); final SM4 sm4 = new SM4(Mode.ECB, Padding.PKCS5Padding, key); - Assert.assertEquals("SM4/ECB/PKCS5Padding", sm4.getCipher().getAlgorithm()); + Assertions.assertEquals("SM4/ECB/PKCS5Padding", sm4.getCipher().getAlgorithm()); final String encryptHex = sm4.encryptHex(content); final String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -77,11 +77,11 @@ public class SmTest { final byte[] key = KeyUtil.generateKey(SM4.ALGORITHM_NAME, 128).getEncoded(); final SM4 sm4 = SmUtil.sm4(key); - Assert.assertEquals("SM4", sm4.getCipher().getAlgorithm()); + Assertions.assertEquals("SM4", sm4.getCipher().getAlgorithm()); final String encryptHex = sm4.encryptHex(content); final String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -89,7 +89,7 @@ public class SmTest { final String content = "test中文"; final HMac hMac = SmUtil.hmacSm3("password".getBytes()); final String digest = hMac.digestHex(content); - Assert.assertEquals("493e3f9a1896b43075fbe54658076727960d69632ac6b6ed932195857a6840c6", digest); + Assertions.assertEquals("493e3f9a1896b43075fbe54658076727960d69632ac6b6ed932195857a6840c6", digest); } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/ECIESTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/ECIESTest.java index f1c28950f..8bc0445d7 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/ECIESTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/ECIESTest.java @@ -1,8 +1,8 @@ package cn.hutool.crypto.asymmetric; 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; public class ECIESTest { @@ -39,6 +39,6 @@ public class ECIESTest { final String encryptStr = cryptoForEncrypt.encryptBase64(text.toString(), KeyType.PublicKey); final String decryptStr = StrUtil.utf8Str(cryptoForDecrypt.decrypt(encryptStr, KeyType.PrivateKey)); - Assert.assertEquals(text.toString(), decryptStr); + Assertions.assertEquals(text.toString(), decryptStr); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/RSATest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/RSATest.java index 7bcef92e6..8217be7ca 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/RSATest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/RSATest.java @@ -9,8 +9,8 @@ import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.SecureUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.crypto.Cipher; import java.math.BigInteger; @@ -27,8 +27,8 @@ public class RSATest { @Test public void generateKeyPairTest() { final KeyPair pair = KeyUtil.generateKeyPair("RSA"); - Assert.assertNotNull(pair.getPrivate()); - Assert.assertNotNull(pair.getPublic()); + Assertions.assertNotNull(pair.getPrivate()); + Assertions.assertNotNull(pair.getPublic()); } @Test @@ -42,12 +42,12 @@ public class RSATest { // 公钥加密,私钥解密 final byte[] encrypt = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey); final byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); // 私钥加密,公钥解密 final byte[] encrypt2 = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey); final byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); } @Test @@ -55,21 +55,21 @@ public class RSATest { final RSA rsa = new RSA(); // 获取私钥和公钥 - Assert.assertNotNull(rsa.getPrivateKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); - Assert.assertNotNull(rsa.getPublicKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPrivateKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPublicKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); // 公钥加密,私钥解密 final byte[] encrypt = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey); final byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); // 私钥加密,公钥解密 final byte[] encrypt2 = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey); final byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); } @Test @@ -77,21 +77,21 @@ public class RSATest { final RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB.getValue()); // 获取私钥和公钥 - Assert.assertNotNull(rsa.getPrivateKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); - Assert.assertNotNull(rsa.getPublicKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPrivateKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPublicKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); // 公钥加密,私钥解密 final byte[] encrypt = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey); final byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); // 私钥加密,公钥解密 final byte[] encrypt2 = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey); final byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); } @Test @@ -99,21 +99,21 @@ public class RSATest { final RSA rsa = new RSA(AsymmetricAlgorithm.RSA_None.getValue()); // 获取私钥和公钥 - Assert.assertNotNull(rsa.getPrivateKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); - Assert.assertNotNull(rsa.getPublicKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPrivateKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPublicKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); // 公钥加密,私钥解密 final byte[] encrypt = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey); final byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); // 私钥加密,公钥解密 final byte[] encrypt2 = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey); final byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); } @Test @@ -122,20 +122,20 @@ public class RSATest { rsa.setEncryptBlockSize(3); // 获取私钥和公钥 - Assert.assertNotNull(rsa.getPrivateKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); - Assert.assertNotNull(rsa.getPublicKey()); - Assert.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPrivateKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); + Assertions.assertNotNull(rsa.getPublicKey()); + Assertions.assertNotNull(rsa.getPrivateKeyBase64()); // 公钥加密,私钥解密 final byte[] encrypt = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey); final byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); // 私钥加密,公钥解密 final byte[] encrypt2 = rsa.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey); final byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8)); } @Test @@ -151,12 +151,12 @@ public class RSATest { // 公钥加密,私钥解密 final String encryptStr = rsa.encryptBase64(text.toString(), KeyType.PublicKey); final String decryptStr = StrUtil.utf8Str(rsa.decrypt(encryptStr, KeyType.PrivateKey)); - Assert.assertEquals(text.toString(), decryptStr); + Assertions.assertEquals(text.toString(), decryptStr); // 私钥加密,公钥解密 final String encrypt2 = rsa.encryptBase64(text.toString(), KeyType.PrivateKey); final String decrypt2 = StrUtil.utf8Str(rsa.decrypt(encrypt2, KeyType.PublicKey)); - Assert.assertEquals(text.toString(), decrypt2); + Assertions.assertEquals(text.toString(), decrypt2); } @Test @@ -181,7 +181,7 @@ public class RSATest { final byte[] aByte = HexUtil.decodeHex(a); final byte[] decrypt = rsa.decrypt(aByte, KeyType.PrivateKey); - Assert.assertEquals("虎头闯杭州,多抬头看天,切勿只管种地", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("虎头闯杭州,多抬头看天,切勿只管种地", StrUtil.str(decrypt, CharsetUtil.UTF_8)); } @Test @@ -207,7 +207,7 @@ public class RSATest { rsa.setEncryptBlockSize(128); final String result2 = rsa.encryptHex(finalData, KeyType.PublicKey); - Assert.assertEquals(result1, result2); + Assertions.assertEquals(result1, result2); } @Test @@ -220,6 +220,6 @@ public class RSATest { final RSA rsa = new RSA(new BigInteger(modulus, 16), null, new BigInteger(publicExponent)); final String encryptBase64 = rsa.encryptBase64("测试内容", KeyType.PublicKey); - Assert.assertNotNull(encryptBase64); + Assertions.assertNotNull(encryptBase64); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java index b6adccfe2..e930956d0 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SM2Test.java @@ -12,8 +12,8 @@ import cn.hutool.crypto.SmUtil; import org.bouncycastle.crypto.engines.SM2Engine; import org.bouncycastle.crypto.params.ECPrivateKeyParameters; import org.bouncycastle.jcajce.spec.OpenSSHPrivateKeySpec; -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; import java.security.KeyPair; @@ -30,8 +30,8 @@ public class SM2Test { @Test public void generateKeyPairTest() { final KeyPair pair = KeyUtil.generateKeyPair("SM2"); - Assert.assertNotNull(pair.getPrivate()); - Assert.assertNotNull(pair.getPublic()); + Assertions.assertNotNull(pair.getPrivate()); + Assertions.assertNotNull(pair.getPublic()); new SM2(pair.getPrivate(), pair.getPublic()); } @@ -41,8 +41,8 @@ public class SM2Test { // OBJECT IDENTIFIER 1.2.156.10197.1.301 final String OID = "06082A811CCF5501822D"; final KeyPair pair = KeyUtil.generateKeyPair("SM2"); - Assert.assertTrue(HexUtil.encodeHexStr(pair.getPrivate().getEncoded()).toUpperCase().contains(OID)); - Assert.assertTrue(HexUtil.encodeHexStr(pair.getPublic().getEncoded()).toUpperCase().contains(OID)); + Assertions.assertTrue(HexUtil.encodeHexStr(pair.getPrivate().getEncoded()).toUpperCase().contains(OID)); + Assertions.assertTrue(HexUtil.encodeHexStr(pair.getPublic().getEncoded()).toUpperCase().contains(OID)); } @Test @@ -57,7 +57,7 @@ public class SM2Test { // 公钥加密,私钥解密 final byte[] encrypt = sm2.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey); final byte[] decrypt = sm2.decrypt(encrypt, KeyType.PrivateKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); } @Test @@ -65,15 +65,15 @@ public class SM2Test { final SM2 sm2 = SmUtil.sm2(); // 获取私钥和公钥 - Assert.assertNotNull(sm2.getPrivateKey()); - Assert.assertNotNull(sm2.getPrivateKeyBase64()); - Assert.assertNotNull(sm2.getPublicKey()); - Assert.assertNotNull(sm2.getPrivateKeyBase64()); + Assertions.assertNotNull(sm2.getPrivateKey()); + Assertions.assertNotNull(sm2.getPrivateKeyBase64()); + Assertions.assertNotNull(sm2.getPublicKey()); + Assertions.assertNotNull(sm2.getPrivateKeyBase64()); // 公钥加密,私钥解密 final byte[] encrypt = sm2.encrypt(ByteUtil.toBytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey); final byte[] decrypt = sm2.decrypt(encrypt, KeyType.PrivateKey); - Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8)); } @Test @@ -89,7 +89,7 @@ public class SM2Test { // 公钥加密,私钥解密 final String encryptStr = sm2.encryptBase64(text.toString(), KeyType.PublicKey); final String decryptStr = StrUtil.utf8Str(sm2.decrypt(encryptStr, KeyType.PrivateKey)); - Assert.assertEquals(text.toString(), decryptStr); + Assertions.assertEquals(text.toString(), decryptStr); // 测试自定义密钥后是否生效 final PrivateKey privateKey = sm2.getPrivateKey(); @@ -99,7 +99,7 @@ public class SM2Test { sm2.setPrivateKey(privateKey); sm2.setPublicKey(publicKey); final String decryptStr2 = StrUtil.utf8Str(sm2.decrypt(encryptStr, KeyType.PrivateKey)); - Assert.assertEquals(text.toString(), decryptStr2); + Assertions.assertEquals(text.toString(), decryptStr2); } @Test @@ -113,7 +113,7 @@ public class SM2Test { sm2.usePlainEncoding(); final byte[] sign = sm2.sign(dataBytes, null); // 64位签名 - Assert.assertEquals(64, sign.length); + Assertions.assertEquals(64, sign.length); } @Test @@ -129,7 +129,7 @@ public class SM2Test { sm2.usePlainEncoding(); final boolean verify = sm2.verify(dataBytes, HexUtil.decodeHex(signHex)); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Test @@ -140,7 +140,7 @@ public class SM2Test { final byte[] sign = sm2.sign(ByteUtil.toUtf8Bytes(content)); final boolean verify = sm2.verify(ByteUtil.toUtf8Bytes(content), sign); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Test @@ -151,7 +151,7 @@ public class SM2Test { final String sign = sm2.signHex(HexUtil.encodeHexStr(content)); final boolean verify = sm2.verifyHex(HexUtil.encodeHexStr(content), sign); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Test @@ -164,7 +164,7 @@ public class SM2Test { final byte[] sign = sm2.sign(content.getBytes(StandardCharsets.UTF_8)); final boolean verify = sm2.verify(content.getBytes(StandardCharsets.UTF_8), sign); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Test @@ -180,7 +180,7 @@ public class SM2Test { final byte[] sign = sm2.sign(content.getBytes(StandardCharsets.UTF_8)); final boolean verify = sm2.verify(content.getBytes(StandardCharsets.UTF_8), sign); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Test @@ -192,8 +192,8 @@ public class SM2Test { final String encodeB64 = Base64.encode(data); final PublicKey Hexdecode = KeyUtil.decodeECPoint(encodeHex, KeyUtil.SM2_DEFAULT_CURVE); final PublicKey B64decode = KeyUtil.decodeECPoint(encodeB64, KeyUtil.SM2_DEFAULT_CURVE); - Assert.assertEquals(HexUtil.encodeHexStr(publicKey.getEncoded()), HexUtil.encodeHexStr(Hexdecode.getEncoded())); - Assert.assertEquals(HexUtil.encodeHexStr(publicKey.getEncoded()), HexUtil.encodeHexStr(B64decode.getEncoded())); + Assertions.assertEquals(HexUtil.encodeHexStr(publicKey.getEncoded()), HexUtil.encodeHexStr(Hexdecode.getEncoded())); + Assertions.assertEquals(HexUtil.encodeHexStr(publicKey.getEncoded()), HexUtil.encodeHexStr(B64decode.getEncoded())); } @Test @@ -207,7 +207,7 @@ public class SM2Test { final SM2 sm2 = new SM2(d, x, y); final String sign = sm2.signHex(data, id); - Assert.assertTrue(sm2.verifyHex(data, sign)); + Assertions.assertTrue(sm2.verifyHex(data, sign)); } @Test @@ -227,10 +227,10 @@ public class SM2Test { final String sign = "DCA0E80A7F46C93714B51C3EFC55A922BCEF7ECF0FE9E62B53BA6A7438B543A76C145A452CA9036F3CB70D7E6C67D4D9D7FE114E5367A2F6F5A4D39F2B10F3D6"; - Assert.assertTrue(sm2.verifyHex(data, sign)); + Assertions.assertTrue(sm2.verifyHex(data, sign)); final String sign2 = sm2.signHex(data, id); - Assert.assertTrue(sm2.verifyHex(data, sign2)); + Assertions.assertTrue(sm2.verifyHex(data, sign2)); } @Test @@ -245,7 +245,7 @@ public class SM2Test { final String encryptHex = sm2.encryptHex(data, KeyType.PublicKey); final String decryptStr = sm2.decryptStr(encryptHex, KeyType.PrivateKey); - Assert.assertEquals(data, decryptStr); + Assertions.assertEquals(data, decryptStr); } @Test @@ -256,10 +256,10 @@ public class SM2Test { final byte[] data = sm2.encrypt(src, KeyType.PublicKey); final byte[] sign = sm2.sign(src.getBytes(StandardCharsets.UTF_8)); - Assert.assertTrue(sm2.verify( src.getBytes(StandardCharsets.UTF_8), sign)); + Assertions.assertTrue(sm2.verify( src.getBytes(StandardCharsets.UTF_8), sign)); final byte[] dec = sm2.decrypt(data, KeyType.PrivateKey); - Assert.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8)); + Assertions.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8)); } @Test @@ -277,10 +277,10 @@ public class SM2Test { final byte[] data = sm2.encrypt(src, KeyType.PublicKey); final byte[] sign = sm2.sign(src.getBytes(StandardCharsets.UTF_8)); - Assert.assertTrue(sm2.verify( src.getBytes(StandardCharsets.UTF_8), sign)); + Assertions.assertTrue(sm2.verify( src.getBytes(StandardCharsets.UTF_8), sign)); final byte[] dec = sm2.decrypt(data, KeyType.PrivateKey); - Assert.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8)); + Assertions.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8)); } @Test @@ -295,20 +295,20 @@ public class SM2Test { final byte[] data = sm2.encrypt(src, KeyType.PublicKey); final byte[] sign = sm2.sign(src.getBytes(StandardCharsets.UTF_8)); - Assert.assertTrue(sm2.verify( src.getBytes(StandardCharsets.UTF_8), sign)); + Assertions.assertTrue(sm2.verify( src.getBytes(StandardCharsets.UTF_8), sign)); final byte[] dec = sm2.decrypt(data, KeyType.PrivateKey); - Assert.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8)); + Assertions.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8)); } @Test public void dLengthTest(){ final SM2 sm2 = SmUtil.sm2(); - Assert.assertEquals(64, sm2.getDHex().length()); - Assert.assertEquals(32, sm2.getD().length); + Assertions.assertEquals(64, sm2.getDHex().length()); + Assertions.assertEquals(32, sm2.getD().length); // 04占位一个字节 - Assert.assertEquals(65, sm2.getQ(false).length); + Assertions.assertEquals(65, sm2.getQ(false).length); } @Test @@ -318,7 +318,7 @@ public class SM2Test { final String q = "04" + x + y; final SM2 sm1 = new SM2(null, x, y); final SM2 sm2 = new SM2(null, q); - Assert.assertNotNull(sm1); - Assert.assertNotNull(sm2); + Assertions.assertNotNull(sm1); + Assertions.assertNotNull(sm2); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SignTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SignTest.java index b90e72f47..b24fb7812 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SignTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/asymmetric/SignTest.java @@ -3,8 +3,8 @@ package cn.hutool.crypto.asymmetric; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ByteUtil; import cn.hutool.crypto.SignUtil; -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; @@ -22,7 +22,7 @@ public class SignTest { final String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJ4fG8vJ0tzu7tjXMSJhyNjlE5B7GkTKMKEQlR6LY3IhIhMFVjuA6W+DqH1VMxl9h3GIM4yCKG2VRZEYEPazgVxa5/ifO8W0pfmrzWCPrddUq4t0Slz5u2lLKymLpPjCzboHoDb8VlF+1HOxjKQckAXq9q7U7dV5VxOzJDuZXlz3AgMBAAECgYABo2LfVqT3owYYewpIR+kTzjPIsG3SPqIIWSqiWWFbYlp/BfQhw7EndZ6+Ra602ecYVwfpscOHdx90ZGJwm+WAMkKT4HiWYwyb0ZqQzRBGYDHFjPpfCBxrzSIJ3QL+B8c8YHq4HaLKRKmq7VUF1gtyWaek87rETWAmQoGjt8DyAQJBAOG4OxsT901zjfxrgKwCv6fV8wGXrNfDSViP1t9r3u6tRPsE6Gli0dfMyzxwENDTI75sOEAfyu6xBlemQGmNsfcCQQCzVWQkl9YUoVDWEitvI5MpkvVKYsFLRXKvLfyxLcY3LxpLKBcEeJ/n5wLxjH0GorhJMmM2Rw3hkjUTJCoqqe0BAkATt8FKC0N2O5ryqv1xiUfuxGzW/cX2jzOwDdiqacTuuqok93fKBPzpyhUS8YM2iss7jj6Xs29JzKMOMxK7ZcpfAkAf21lwzrAu9gEgJhYlJhKsXfjJAAYKUwnuaKLs7o65mtp242ZDWxI85eK1+hjzptBJ4HOTXsfufESFY/VBovIBAkAltO886qQRoNSc0OsVlCi4X1DGo6x2RqQ9EsWPrxWEZGYuyEdODrc54b8L+zaUJLfMJdsCIHEUbM7WXxvFVXNv"; Sign sign = SignUtil.sign(SignAlgorithm.SHA1withRSA, privateKey, null); - Assert.assertNull(sign.getPublicKeyBase64()); + Assertions.assertNull(sign.getPublicKeyBase64()); // 签名 final byte[] signed = sign.sign(content.getBytes()); @@ -30,7 +30,7 @@ public class SignTest { sign = SignUtil.sign(SignAlgorithm.SHA1withRSA, null, publicKey); // 验证签名 final boolean verify = sign.verify(content.getBytes(), signed); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Test @@ -69,7 +69,7 @@ public class SignTest { // 验证签名 final boolean verify = sign.verify(data, signed); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } /** @@ -86,7 +86,7 @@ public class SignTest { // 验证签名 final boolean verify = sign.verify(data, signed); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Test @@ -96,11 +96,11 @@ public class SignTest { .put("key2", "value2").build(); final String sign1 = SignUtil.signParamsSha1(build); - Assert.assertEquals("9ed30bfe2efbc7038a824b6c55c24a11bfc0dce5", sign1); + Assertions.assertEquals("9ed30bfe2efbc7038a824b6c55c24a11bfc0dce5", sign1); final String sign2 = SignUtil.signParamsSha1(build, "12345678"); - Assert.assertEquals("944b68d94c952ec178c4caf16b9416b6661f7720", sign2); + Assertions.assertEquals("944b68d94c952ec178c4caf16b9416b6661f7720", sign2); final String sign3 = SignUtil.signParamsSha1(build, "12345678", "abc"); - Assert.assertEquals("edee1b477af1b96ebd20fdf08d818f352928d25d", sign3); + Assertions.assertEquals("edee1b477af1b96ebd20fdf08d818f352928d25d", sign3); } /** @@ -117,6 +117,6 @@ public class SignTest { // 验证签名 final boolean verify = sign.verify(data, signed); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/BCryptTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/BCryptTest.java index 7ab03177b..9d9f34a96 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/BCryptTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/BCryptTest.java @@ -1,13 +1,13 @@ package cn.hutool.crypto.digest; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class BCryptTest { @Test public void checkpwTest(){ - Assert.assertFalse(BCrypt.checkpw("xxx", + Assertions.assertFalse(BCrypt.checkpw("xxx", "$2a$2a$10$e4lBTlZ019KhuAFyqAlgB.Jxc6cM66GwkSR/5/xXNQuHUItPLyhzy")); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/CBCBlockCipherMacEngineTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/CBCBlockCipherMacEngineTest.java index 16a98cb6c..e1d6c5696 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/CBCBlockCipherMacEngineTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/CBCBlockCipherMacEngineTest.java @@ -6,8 +6,8 @@ import cn.hutool.crypto.digest.mac.SM4MacEngine; import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.params.ParametersWithIV; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CBCBlockCipherMacEngineTest { @@ -22,7 +22,7 @@ public class CBCBlockCipherMacEngineTest { final String testStr = "test中文"; final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("3212e848db7f816a4bd591ad9948debf", macHex1); + Assertions.assertEquals("3212e848db7f816a4bd591ad9948debf", macHex1); } @Test @@ -38,6 +38,6 @@ public class CBCBlockCipherMacEngineTest { final String testStr = "test中文"; final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("3212e848db7f816a4bd591ad9948debf", macHex1); + Assertions.assertEquals("3212e848db7f816a4bd591ad9948debf", macHex1); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/DigestTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/DigestTest.java index 3fb1525da..e3f1a0a9e 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/DigestTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/DigestTest.java @@ -1,7 +1,7 @@ package cn.hutool.crypto.digest; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.CharsetUtil; @@ -19,7 +19,7 @@ public class DigestTest { final Digester md5 = new Digester(DigestAlgorithm.MD5); final String digestHex = md5.digestHex(testStr); - Assert.assertEquals("5393554e94bf0eb6436f240a4fd71282", digestHex); + Assertions.assertEquals("5393554e94bf0eb6436f240a4fd71282", digestHex); } @Test @@ -27,10 +27,10 @@ public class DigestTest { final String testStr = "test中文"; final String md5Hex1 = DigestUtil.md5Hex(testStr); - Assert.assertEquals("5393554e94bf0eb6436f240a4fd71282", md5Hex1); + Assertions.assertEquals("5393554e94bf0eb6436f240a4fd71282", md5Hex1); final String md5Hex2 = DigestUtil.md5Hex(IoUtil.toStream(testStr, CharsetUtil.UTF_8)); - Assert.assertEquals("5393554e94bf0eb6436f240a4fd71282", md5Hex2); + Assertions.assertEquals("5393554e94bf0eb6436f240a4fd71282", md5Hex2); } @Test @@ -42,16 +42,16 @@ public class DigestTest { //加盐 md5.setSalt("saltTest".getBytes()); final String md5Hex1 = md5.digestHex(testStr); - Assert.assertEquals("762f7335200299dfa09bebbb601a5bc6", md5Hex1); + Assertions.assertEquals("762f7335200299dfa09bebbb601a5bc6", md5Hex1); final String md5Hex2 = md5.digestHex(IoUtil.toUtf8Stream(testStr)); - Assert.assertEquals("762f7335200299dfa09bebbb601a5bc6", md5Hex2); + Assertions.assertEquals("762f7335200299dfa09bebbb601a5bc6", md5Hex2); //重复2次 md5.setDigestCount(2); final String md5Hex3 = md5.digestHex(testStr); - Assert.assertEquals("2b0616296f6755d25efc07f90afe9684", md5Hex3); + Assertions.assertEquals("2b0616296f6755d25efc07f90afe9684", md5Hex3); final String md5Hex4 = md5.digestHex(IoUtil.toUtf8Stream(testStr)); - Assert.assertEquals("2b0616296f6755d25efc07f90afe9684", md5Hex4); + Assertions.assertEquals("2b0616296f6755d25efc07f90afe9684", md5Hex4); } @Test @@ -59,23 +59,23 @@ public class DigestTest { final String testStr = "test中文"; final String sha1Hex1 = DigestUtil.sha1Hex(testStr); - Assert.assertEquals("ecabf586cef0d3b11c56549433ad50b81110a836", sha1Hex1); + Assertions.assertEquals("ecabf586cef0d3b11c56549433ad50b81110a836", sha1Hex1); final String sha1Hex2 = DigestUtil.sha1Hex(IoUtil.toStream(testStr, CharsetUtil.UTF_8)); - Assert.assertEquals("ecabf586cef0d3b11c56549433ad50b81110a836", sha1Hex2); + Assertions.assertEquals("ecabf586cef0d3b11c56549433ad50b81110a836", sha1Hex2); } @Test public void hash256Test() { final String testStr = "Test中文"; final String hex = DigestUtil.sha256Hex(testStr); - Assert.assertEquals(64, hex.length()); + Assertions.assertEquals(64, hex.length()); } @Test public void hash512Test() { final String testStr = "Test中文"; final String hex = DigestUtil.sha512Hex(testStr); - Assert.assertEquals(128, hex.length()); + Assertions.assertEquals(128, hex.length()); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/HmacTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/HmacTest.java index 3b26d461b..991f70d8c 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/HmacTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/HmacTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.util.CharsetUtil; import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.symmetric.ZUC; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.crypto.spec.IvParameterSpec; @@ -25,10 +25,10 @@ public class HmacTest { final HMac mac = new HMac(HmacAlgorithm.HmacMD5, key); final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex1); + Assertions.assertEquals("b977f4b13f93f549e06140971bded384", macHex1); final String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.UTF_8)); - Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex2); + Assertions.assertEquals("b977f4b13f93f549e06140971bded384", macHex2); } @Test @@ -38,10 +38,10 @@ public class HmacTest { final HMac mac = SecureUtil.hmacMd5("password"); final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex1); + Assertions.assertEquals("b977f4b13f93f549e06140971bded384", macHex1); final String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.UTF_8)); - Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex2); + Assertions.assertEquals("b977f4b13f93f549e06140971bded384", macHex2); } @Test @@ -50,10 +50,10 @@ public class HmacTest { final String testStr = "test中文"; final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("1dd68d2f119d5640f0d416e99d3f42408b88d511", macHex1); + Assertions.assertEquals("1dd68d2f119d5640f0d416e99d3f42408b88d511", macHex1); final String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.UTF_8)); - Assert.assertEquals("1dd68d2f119d5640f0d416e99d3f42408b88d511", macHex2); + Assertions.assertEquals("1dd68d2f119d5640f0d416e99d3f42408b88d511", macHex2); } @Test @@ -66,7 +66,7 @@ public class HmacTest { final String testStr = "test中文"; final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("1e0b9455", macHex1); + Assertions.assertEquals("1e0b9455", macHex1); } @Test @@ -79,7 +79,7 @@ public class HmacTest { final String testStr = "test中文"; final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("d9ad618357c1bfb1d9d1200a763d5eaa", macHex1); + Assertions.assertEquals("d9ad618357c1bfb1d9d1200a763d5eaa", macHex1); } @Test @@ -93,6 +93,6 @@ public class HmacTest { final String testStr = "test中文"; final String macHex1 = mac.digestHex(testStr); - Assert.assertEquals("58a0d231315664af51b858a174eabc21", macHex1); + Assertions.assertEquals("58a0d231315664af51b858a174eabc21", macHex1); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/Md5Test.java b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/Md5Test.java index 52e2b2c8d..067c343e7 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/Md5Test.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/Md5Test.java @@ -1,7 +1,7 @@ package cn.hutool.crypto.digest; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * MD5 单元测试 @@ -14,7 +14,7 @@ public class Md5Test { @Test public void md5To16Test() { final String hex16 = new MD5().digestHex16("中国"); - Assert.assertEquals(16, hex16.length()); - Assert.assertEquals("cb143acd6c929826", hex16); + Assertions.assertEquals(16, hex16.length()); + Assertions.assertEquals("cb143acd6c929826", hex16); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/OTPTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/OTPTest.java index 71e694da0..2c1ab4676 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/digest/OTPTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/digest/OTPTest.java @@ -3,8 +3,8 @@ package cn.hutool.crypto.digest; import cn.hutool.core.codec.binary.Base32; import cn.hutool.crypto.digest.otp.HOTP; import cn.hutool.crypto.digest.otp.TOTP; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.time.Duration; import java.time.Instant; @@ -18,49 +18,49 @@ public class OTPTest { @Test public void genKeyTest() { final String key = TOTP.generateSecretKey(8); - Assert.assertEquals(8, Base32.decode(key).length); + Assertions.assertEquals(8, Base32.decode(key).length); } @Test public void validTest() { final String key = "VYCFSW2QZ3WZO"; // 2021/7/1下午6:29:54 显示code为 106659 - //Assert.assertEquals(new TOTP(Base32.decode(key)).generate(Instant.ofEpochSecond(1625135394L)),106659); + //Assertions.assertEquals(new TOTP(Base32.decode(key)).generate(Instant.ofEpochSecond(1625135394L)),106659); final TOTP totp = new TOTP(Base32.decode(key)); final Instant instant = Instant.ofEpochSecond(1625135394L); - Assert.assertTrue(totp.validate(instant, 0, 106659)); - Assert.assertTrue(totp.validate(instant.plusSeconds(30), 1, 106659)); - Assert.assertTrue(totp.validate(instant.plusSeconds(60), 2, 106659)); + Assertions.assertTrue(totp.validate(instant, 0, 106659)); + Assertions.assertTrue(totp.validate(instant.plusSeconds(30), 1, 106659)); + Assertions.assertTrue(totp.validate(instant.plusSeconds(60), 2, 106659)); - Assert.assertFalse(totp.validate(instant.plusSeconds(60), 1, 106659)); - Assert.assertFalse(totp.validate(instant.plusSeconds(90), 2, 106659)); + Assertions.assertFalse(totp.validate(instant.plusSeconds(60), 1, 106659)); + Assertions.assertFalse(totp.validate(instant.plusSeconds(90), 2, 106659)); } @Test public void googleAuthTest() { final String str = TOTP.generateGoogleSecretKey("xl7@qq.com", 10); - Assert.assertTrue(str.startsWith("otpauth://totp/xl7@qq.com?secret=")); + Assertions.assertTrue(str.startsWith("otpauth://totp/xl7@qq.com?secret=")); } @Test public void longPasswordLengthTest() { - Assert.assertThrows(IllegalArgumentException.class, () -> new HOTP(9, "123".getBytes())); + Assertions.assertThrows(IllegalArgumentException.class, () -> new HOTP(9, "123".getBytes())); } @Test public void generateHOPTTest(){ final byte[] key = "12345678901234567890".getBytes(); final HOTP hotp = new HOTP(key); - Assert.assertEquals(755224, hotp.generate(0)); - Assert.assertEquals(287082, hotp.generate(1)); - Assert.assertEquals(359152, hotp.generate(2)); - Assert.assertEquals(969429, hotp.generate(3)); - Assert.assertEquals(338314, hotp.generate(4)); - Assert.assertEquals(254676, hotp.generate(5)); - Assert.assertEquals(287922, hotp.generate(6)); - Assert.assertEquals(162583, hotp.generate(7)); - Assert.assertEquals(399871, hotp.generate(8)); - Assert.assertEquals(520489, hotp.generate(9)); + Assertions.assertEquals(755224, hotp.generate(0)); + Assertions.assertEquals(287082, hotp.generate(1)); + Assertions.assertEquals(359152, hotp.generate(2)); + Assertions.assertEquals(969429, hotp.generate(3)); + Assertions.assertEquals(338314, hotp.generate(4)); + Assertions.assertEquals(254676, hotp.generate(5)); + Assertions.assertEquals(287922, hotp.generate(6)); + Assertions.assertEquals(162583, hotp.generate(7)); + Assertions.assertEquals(399871, hotp.generate(8)); + Assertions.assertEquals(520489, hotp.generate(9)); } @Test @@ -69,7 +69,7 @@ public class OTPTest { final TOTP totp = new TOTP(timeStep, "123".getBytes()); - Assert.assertEquals(timeStep, totp.getTimeStep()); + Assertions.assertEquals(timeStep, totp.getTimeStep()); } @Test @@ -79,17 +79,17 @@ public class OTPTest { final TOTP totp = new TOTP(Duration.ofSeconds(30), 8, algorithm, key); int generate = totp.generate(Instant.ofEpochSecond(59L)); - Assert.assertEquals(94287082, generate); + Assertions.assertEquals(94287082, generate); generate = totp.generate(Instant.ofEpochSecond(1111111109L)); - Assert.assertEquals(7081804, generate); + Assertions.assertEquals(7081804, generate); generate = totp.generate(Instant.ofEpochSecond(1111111111L)); - Assert.assertEquals(14050471, generate); + Assertions.assertEquals(14050471, generate); generate = totp.generate(Instant.ofEpochSecond(1234567890L)); - Assert.assertEquals(89005924, generate); + Assertions.assertEquals(89005924, generate); generate = totp.generate(Instant.ofEpochSecond(2000000000L)); - Assert.assertEquals(69279037, generate); + Assertions.assertEquals(69279037, generate); generate = totp.generate(Instant.ofEpochSecond(20000000000L)); - Assert.assertEquals(65353130, generate); + Assertions.assertEquals(65353130, generate); } @Test @@ -99,17 +99,17 @@ public class OTPTest { final TOTP totp = new TOTP(Duration.ofSeconds(30), 8, algorithm, key); int generate = totp.generate(Instant.ofEpochSecond(59L)); - Assert.assertEquals(46119246, generate); + Assertions.assertEquals(46119246, generate); generate = totp.generate(Instant.ofEpochSecond(1111111109L)); - Assert.assertEquals(68084774, generate); + Assertions.assertEquals(68084774, generate); generate = totp.generate(Instant.ofEpochSecond(1111111111L)); - Assert.assertEquals(67062674, generate); + Assertions.assertEquals(67062674, generate); generate = totp.generate(Instant.ofEpochSecond(1234567890L)); - Assert.assertEquals(91819424, generate); + Assertions.assertEquals(91819424, generate); generate = totp.generate(Instant.ofEpochSecond(2000000000L)); - Assert.assertEquals(90698825, generate); + Assertions.assertEquals(90698825, generate); generate = totp.generate(Instant.ofEpochSecond(20000000000L)); - Assert.assertEquals(77737706, generate); + Assertions.assertEquals(77737706, generate); } @Test @@ -119,16 +119,16 @@ public class OTPTest { final TOTP totp = new TOTP(Duration.ofSeconds(30), 8, algorithm, key); int generate = totp.generate(Instant.ofEpochSecond(59L)); - Assert.assertEquals(90693936, generate); + Assertions.assertEquals(90693936, generate); generate = totp.generate(Instant.ofEpochSecond(1111111109L)); - Assert.assertEquals(25091201, generate); + Assertions.assertEquals(25091201, generate); generate = totp.generate(Instant.ofEpochSecond(1111111111L)); - Assert.assertEquals(99943326, generate); + Assertions.assertEquals(99943326, generate); generate = totp.generate(Instant.ofEpochSecond(1234567890L)); - Assert.assertEquals(93441116, generate); + Assertions.assertEquals(93441116, generate); generate = totp.generate(Instant.ofEpochSecond(2000000000L)); - Assert.assertEquals(38618901, generate); + Assertions.assertEquals(38618901, generate); generate = totp.generate(Instant.ofEpochSecond(20000000000L)); - Assert.assertEquals(47863826, generate); + Assertions.assertEquals(47863826, generate); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/AESTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/AESTest.java index ed35a56e7..e17e99636 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/AESTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/AESTest.java @@ -6,8 +6,8 @@ import cn.hutool.core.util.RandomUtil; import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.Mode; import cn.hutool.crypto.Padding; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.crypto.SecretKey; import javax.crypto.spec.GCMParameterSpec; @@ -21,7 +21,7 @@ public class AESTest { final AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, "1234567890123456".getBytes(), "1234567890123456".getBytes()); final String encryptHex = aes.encryptHex("123456"); - Assert.assertEquals("d637735ae9e21ba50cb686b74fab8d2c", encryptHex); + Assertions.assertEquals("d637735ae9e21ba50cb686b74fab8d2c", encryptHex); } @Test @@ -30,7 +30,7 @@ public class AESTest { final AES aes = new AES(Mode.CTS, Padding.PKCS5Padding, "0CoJUm6Qyw8W8jue".getBytes(), "0102030405060708".getBytes()); final String encryptHex = aes.encryptHex(content); - Assert.assertEquals("8dc9de7f050e86ca2c8261dde56dfec9", encryptHex); + Assertions.assertEquals("8dc9de7f050e86ca2c8261dde56dfec9", encryptHex); } @Test @@ -39,7 +39,7 @@ public class AESTest { final AES aes = new AES(Mode.CBC.name(), "pkcs7padding", "1234567890123456".getBytes(), "1234567890123456".getBytes()); final String encryptHex = aes.encryptHex("123456"); - Assert.assertEquals("d637735ae9e21ba50cb686b74fab8d2c", encryptHex); + Assertions.assertEquals("d637735ae9e21ba50cb686b74fab8d2c", encryptHex); } /** @@ -71,32 +71,32 @@ public class AESTest { // 加密数据为16进制字符串 final String encryptHex = aes.encryptHex(HexUtil.decodeHex("16c5")); // 加密后的Hex - Assert.assertEquals("25869eb3ff227d9e34b3512d3c3c92ed", encryptHex); + Assertions.assertEquals("25869eb3ff227d9e34b3512d3c3c92ed", encryptHex); // 加密数据为16进制字符串 final String encryptHex2 = aes.encryptBase64(HexUtil.decodeHex("16c5")); // 加密后的Base64 - Assert.assertEquals("JYaes/8ifZ40s1EtPDyS7Q==", encryptHex2); + Assertions.assertEquals("JYaes/8ifZ40s1EtPDyS7Q==", encryptHex2); // 解密 - Assert.assertEquals("16c5", HexUtil.encodeHexStr(aes.decrypt("25869eb3ff227d9e34b3512d3c3c92ed"))); - Assert.assertEquals("16c5", HexUtil.encodeHexStr(aes.decrypt(HexUtil.encodeHexStr(Base64.decode("JYaes/8ifZ40s1EtPDyS7Q=="))))); + Assertions.assertEquals("16c5", HexUtil.encodeHexStr(aes.decrypt("25869eb3ff227d9e34b3512d3c3c92ed"))); + Assertions.assertEquals("16c5", HexUtil.encodeHexStr(aes.decrypt(HexUtil.encodeHexStr(Base64.decode("JYaes/8ifZ40s1EtPDyS7Q=="))))); // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // 加密数据为字符串(UTF-8) final String encryptStr = aes.encryptHex("16c5"); // 加密后的Hex - Assert.assertEquals("79c210d3e304932cf9ea6a9c887c6d7c", encryptStr); + Assertions.assertEquals("79c210d3e304932cf9ea6a9c887c6d7c", encryptStr); // 加密数据为字符串(UTF-8) final String encryptStr2 = aes.encryptBase64("16c5"); // 加密后的Base64 - Assert.assertEquals("ecIQ0+MEkyz56mqciHxtfA==", encryptStr2); + Assertions.assertEquals("ecIQ0+MEkyz56mqciHxtfA==", encryptStr2); // 解密 - Assert.assertEquals("16c5", aes.decryptStr("79c210d3e304932cf9ea6a9c887c6d7c")); - Assert.assertEquals("16c5", aes.decryptStr(Base64.decode("ecIQ0+MEkyz56mqciHxtfA=="))); + Assertions.assertEquals("16c5", aes.decryptStr("79c210d3e304932cf9ea6a9c887c6d7c")); + Assertions.assertEquals("16c5", aes.decryptStr(Base64.decode("ecIQ0+MEkyz56mqciHxtfA=="))); // ------------------------------------------------------------------------ } @@ -110,7 +110,7 @@ public class AESTest { final String result1 = aes.encryptBase64(content); final String decryptStr = aes.decryptStr(result1); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } /** @@ -130,6 +130,6 @@ public class AESTest { // 加密 final byte[] encrypt = aes.encrypt(phone); final String decryptStr = aes.decryptStr(encrypt); - Assert.assertEquals(phone, decryptStr); + Assertions.assertEquals(phone, decryptStr); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ChaCha20Test.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ChaCha20Test.java index 1dc090ae1..38dbcabd4 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ChaCha20Test.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ChaCha20Test.java @@ -2,8 +2,8 @@ package cn.hutool.crypto.symmetric; 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; /** * 见:https://stackoverflow.com/questions/32672241/using-bouncycastles-chacha-for-file-encryption @@ -25,6 +25,6 @@ public class ChaCha20Test { // 解密为字符串 final String decryptStr = chacha.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/DesTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/DesTest.java index 6657b274b..2ba75c5ee 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/DesTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/DesTest.java @@ -6,8 +6,8 @@ import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.Mode; import cn.hutool.crypto.Padding; import cn.hutool.crypto.SecureUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * DES加密解密单元测试 @@ -24,12 +24,12 @@ public class DesTest { final byte[] encrypt = des.encrypt(content); final byte[] decrypt = des.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.utf8Str(decrypt)); + Assertions.assertEquals(content, StrUtil.utf8Str(decrypt)); final String encryptHex = des.encryptHex(content); final String decryptStr = des.decryptStr(encryptHex); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -42,12 +42,12 @@ public class DesTest { final byte[] encrypt = des.encrypt(content); final byte[] decrypt = des.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.utf8Str(decrypt)); + Assertions.assertEquals(content, StrUtil.utf8Str(decrypt)); final String encryptHex = des.encryptHex(content); final String decryptStr = des.decryptStr(encryptHex); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -59,12 +59,12 @@ public class DesTest { final byte[] encrypt = des.encrypt(content); final byte[] decrypt = des.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.utf8Str(decrypt)); + Assertions.assertEquals(content, StrUtil.utf8Str(decrypt)); final String encryptHex = des.encryptHex(content); final String decryptStr = des.decryptStr(encryptHex); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -75,7 +75,7 @@ public class DesTest { final String encryptHex = des.encryptHex(content); final String result = des.decryptStr(encryptHex); - Assert.assertEquals(content, result); + Assertions.assertEquals(content, result); } @Test @@ -91,7 +91,7 @@ public class DesTest { final String encryptHex = des.encryptHex(content); final String result = des.decryptStr(encryptHex); - Assert.assertEquals(content, result); + Assertions.assertEquals(content, result); } @Test diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Issue2613Test.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Issue2613Test.java index d0e251f18..02fb5b959 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Issue2613Test.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Issue2613Test.java @@ -1,8 +1,8 @@ package cn.hutool.crypto.symmetric; import cn.hutool.crypto.Padding; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Issue2613Test { @@ -14,6 +14,6 @@ public class Issue2613Test { final String encryptHex = aes.encryptHex("123456"); final String s = aes.decryptStr(encryptHex); - Assert.assertEquals("123456", s); + Assertions.assertEquals("123456", s); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/PBKDF2Test.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/PBKDF2Test.java index 7e6c2138a..5e98c9a3b 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/PBKDF2Test.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/PBKDF2Test.java @@ -2,14 +2,14 @@ package cn.hutool.crypto.symmetric; import cn.hutool.core.util.RandomUtil; import cn.hutool.crypto.SecureUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PBKDF2Test { @Test public void encryptTest(){ final String s = SecureUtil.pbkdf2("123456".toCharArray(), RandomUtil.randomBytes(16)); - Assert.assertEquals(128, s.length()); + Assertions.assertEquals(128, s.length()); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/RC4Test.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/RC4Test.java index 1c8aa80e4..474ad6e14 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/RC4Test.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/RC4Test.java @@ -1,8 +1,8 @@ package cn.hutool.crypto.symmetric; 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; public class RC4Test { @@ -13,12 +13,12 @@ public class RC4Test { final String message = "Hello, World!"; final byte[] crypt = rc4.encrypt(message); final String msg = rc4.decrypt(crypt); - Assert.assertEquals(message, msg); + Assertions.assertEquals(message, msg); final String message2 = "Hello, World, this is megssage 2"; final byte[] crypt2 = rc4.encrypt(message2); final String msg2 = rc4.decrypt(crypt2); - Assert.assertEquals(message2, msg2); + Assertions.assertEquals(message2, msg2); } @Test @@ -28,12 +28,12 @@ public class RC4Test { final RC4 rc4 = new RC4(key); final byte[] crypt = rc4.encrypt(message); final String msg = rc4.decrypt(crypt); - Assert.assertEquals(message, msg); + Assertions.assertEquals(message, msg); final String message2 = "这是第二个中文消息!"; final byte[] crypt2 = rc4.encrypt(message2); final String msg2 = rc4.decrypt(crypt2); - Assert.assertEquals(message2, msg2); + Assertions.assertEquals(message2, msg2); } @Test @@ -43,12 +43,12 @@ public class RC4Test { final RC4 rc4 = new RC4(key); final String encryptHex = rc4.encryptHex(message, CharsetUtil.UTF_8); final String msg = rc4.decrypt(encryptHex); - Assert.assertEquals(message, msg); + Assertions.assertEquals(message, msg); final String message2 = "这是第二个用来测试密文为十六进制字符串的消息!"; final String encryptHex2 = rc4.encryptHex(message2); final String msg2 = rc4.decrypt(encryptHex2); - Assert.assertEquals(message2, msg2); + Assertions.assertEquals(message2, msg2); } @@ -59,11 +59,11 @@ public class RC4Test { final RC4 rc4 = new RC4(key); final String encryptHex = rc4.encryptBase64(message, CharsetUtil.UTF_8); final String msg = rc4.decrypt(encryptHex); - Assert.assertEquals(message, msg); + Assertions.assertEquals(message, msg); final String message2 = "这是第一个用来测试密文为Base64编码的消息!"; final String encryptHex2 = rc4.encryptBase64(message2); final String msg2 = rc4.decrypt(encryptHex2); - Assert.assertEquals(message2, msg2); + Assertions.assertEquals(message2, msg2); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Sm4StreamTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Sm4StreamTest.java index afedd4423..aeb599131 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Sm4StreamTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/Sm4StreamTest.java @@ -1,7 +1,7 @@ package cn.hutool.crypto.symmetric; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; @@ -19,7 +19,7 @@ public class Sm4StreamTest { private static final boolean IS_CLOSE = false; @Test - @Ignore + @Disabled public void sm4Test(){ final String source = "d:/test/sm4_1.txt"; final String target = "d:/test/sm4_2.data"; diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/SymmetricTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/SymmetricTest.java index 3717d00ab..e0eeba95a 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/SymmetricTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/SymmetricTest.java @@ -9,8 +9,8 @@ import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.Mode; import cn.hutool.crypto.Padding; import cn.hutool.crypto.SecureUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; @@ -37,14 +37,14 @@ public class SymmetricTest { // 解密 final byte[] decrypt = aes.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.str(decrypt, CharsetUtil.UTF_8)); + Assertions.assertEquals(content, StrUtil.str(decrypt, CharsetUtil.UTF_8)); // 加密为16进制表示 final String encryptHex = aes.encryptHex(content); // 解密为字符串 final String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -62,14 +62,14 @@ public class SymmetricTest { // 解密 final byte[] decrypt = aes.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.utf8Str(decrypt)); + Assertions.assertEquals(content, StrUtil.utf8Str(decrypt)); // 加密为16进制表示 final String encryptHex = aes.encryptHex(content); // 解密为字符串 final String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -83,14 +83,14 @@ public class SymmetricTest { // 解密 final byte[] decrypt = aes.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.utf8Str(decrypt)); + Assertions.assertEquals(content, StrUtil.utf8Str(decrypt)); // 加密为16进制表示 final String encryptHex = aes.encryptHex(content); // 解密为字符串 final String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.UTF_8); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -101,7 +101,7 @@ public class SymmetricTest { // 加密为16进制表示 final String encryptHex = aes.encryptHex(content); - Assert.assertEquals("cd0e3a249eaf0ed80c330338508898c4bddcfd665a1b414622164a273ca5daf7b4ebd2c00aaa66b84dd0a237708dac8e", encryptHex); + Assertions.assertEquals("cd0e3a249eaf0ed80c330338508898c4bddcfd665a1b414622164a273ca5daf7b4ebd2c00aaa66b84dd0a237708dac8e", encryptHex); } @Test @@ -114,7 +114,7 @@ public class SymmetricTest { final String encryptHex = crypto.encryptHex(content); final String data = crypto.decryptStr(encryptHex); - Assert.assertEquals(content, data); + Assertions.assertEquals(content, data); } @Test @@ -127,8 +127,8 @@ public class SymmetricTest { final String randomData = aes.updateHex(content.getBytes(StandardCharsets.UTF_8)); aes.setMode(CipherMode.encrypt); final String randomData2 = aes.updateHex(content.getBytes(StandardCharsets.UTF_8)); - Assert.assertEquals(randomData2, randomData); - Assert.assertEquals(randomData, "cd0e3a249eaf0ed80c330338508898c4"); + Assertions.assertEquals(randomData2, randomData); + Assertions.assertEquals(randomData, "cd0e3a249eaf0ed80c330338508898c4"); } @@ -141,7 +141,7 @@ public class SymmetricTest { final String encryptHex = aes.encryptHex(content); // 解密 final String decryptStr = aes.decryptStr(encryptHex); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -155,7 +155,7 @@ public class SymmetricTest { final ByteArrayOutputStream contentStream = new ByteArrayOutputStream(); aes.decrypt(IoUtil.toStream(encryptStream), contentStream, true); - Assert.assertEquals(content, StrUtil.utf8Str(contentStream.toByteArray())); + Assertions.assertEquals(content, StrUtil.utf8Str(contentStream.toByteArray())); } @Test @@ -169,7 +169,7 @@ public class SymmetricTest { final String encryptHex = aes.encryptHex(content); // 解密 final String decryptStr = aes.decryptStr(encryptHex); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -183,12 +183,12 @@ public class SymmetricTest { final byte[] encrypt = des.encrypt(content); final byte[] decrypt = des.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.utf8Str(decrypt)); + Assertions.assertEquals(content, StrUtil.utf8Str(decrypt)); final String encryptHex = des.encryptHex(content); final String decryptStr = des.decryptStr(encryptHex); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -202,12 +202,12 @@ public class SymmetricTest { final byte[] encrypt = des.encrypt(content); final byte[] decrypt = des.decrypt(encrypt); - Assert.assertEquals(content, StrUtil.utf8Str(decrypt)); + Assertions.assertEquals(content, StrUtil.utf8Str(decrypt)); final String encryptHex = des.encryptHex(content); final String decryptStr = des.decryptStr(encryptHex); - Assert.assertEquals(content, decryptStr); + Assertions.assertEquals(content, decryptStr); } @Test @@ -216,8 +216,8 @@ public class SymmetricTest { final String key = "CompleteVictory"; final String encrypt = Vigenere.encrypt(content, key); - Assert.assertEquals("zXScRZ]KIOMhQjc0\\bYRXZOJK[Vi", encrypt); + Assertions.assertEquals("zXScRZ]KIOMhQjc0\\bYRXZOJK[Vi", encrypt); final String decrypt = Vigenere.decrypt(encrypt, key); - Assert.assertEquals(content, decrypt); + Assertions.assertEquals(content, decrypt); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/TEATest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/TEATest.java index 05ef3c864..9c2d2eeac 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/TEATest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/TEATest.java @@ -1,7 +1,7 @@ package cn.hutool.crypto.symmetric; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * TEA(Tiny Encryption Algorithm)和 XTEA算法单元测试 @@ -19,7 +19,7 @@ public class TEATest { // 解密 final String decryptStr = tea.decryptStr(encrypt); - Assert.assertEquals(data, decryptStr); + Assertions.assertEquals(data, decryptStr); } @Test @@ -33,7 +33,7 @@ public class TEATest { // 解密 final String decryptStr = tea.decryptStr(encrypt); - Assert.assertEquals(data, decryptStr); + Assertions.assertEquals(data, decryptStr); } @Test @@ -47,6 +47,6 @@ public class TEATest { // 解密 final String decryptStr = tea.decryptStr(encrypt); - Assert.assertEquals(data, decryptStr); + Assertions.assertEquals(data, decryptStr); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ZucTest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ZucTest.java index e9288b4c6..e758bf659 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ZucTest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/ZucTest.java @@ -2,8 +2,8 @@ package cn.hutool.crypto.symmetric; 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; public class ZucTest { @@ -16,7 +16,7 @@ public class ZucTest { final String msg = RandomUtil.randomString(500); final byte[] crypt2 = zuc.encrypt(msg); final String msg2 = zuc.decryptStr(crypt2, CharsetUtil.UTF_8); - Assert.assertEquals(msg, msg2); + Assertions.assertEquals(msg, msg2); } @Test @@ -28,6 +28,6 @@ public class ZucTest { final String msg = RandomUtil.randomString(500); final byte[] crypt2 = zuc.encrypt(msg); final String msg2 = zuc.decryptStr(crypt2, CharsetUtil.UTF_8); - Assert.assertEquals(msg, msg2); + Assertions.assertEquals(msg, msg2); } } diff --git a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/fpe/FPETest.java b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/fpe/FPETest.java index cc68a1408..291caa2c5 100644 --- a/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/fpe/FPETest.java +++ b/hutool-crypto/src/test/java/cn/hutool/crypto/symmetric/fpe/FPETest.java @@ -3,8 +3,8 @@ package cn.hutool.crypto.symmetric.fpe; import cn.hutool.core.util.RandomUtil; import cn.hutool.crypto.symmetric.FPE; import org.bouncycastle.crypto.util.BasicAlphabetMapper; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class FPETest { @@ -21,10 +21,10 @@ public class FPETest { final String phone = RandomUtil.randomString("A0123456789", 13); final String encrypt = fpe.encrypt(phone); // 加密后与原密文长度一致 - Assert.assertEquals(phone.length(), encrypt.length()); + Assertions.assertEquals(phone.length(), encrypt.length()); final String decrypt = fpe.decrypt(encrypt); - Assert.assertEquals(phone, decrypt); + Assertions.assertEquals(phone, decrypt); } @Test @@ -40,9 +40,9 @@ public class FPETest { final String phone = RandomUtil.randomString("A0123456789", 13); final String encrypt = fpe.encrypt(phone); // 加密后与原密文长度一致 - Assert.assertEquals(phone.length(), encrypt.length()); + Assertions.assertEquals(phone.length(), encrypt.length()); final String decrypt = fpe.decrypt(encrypt); - Assert.assertEquals(phone, decrypt); + Assertions.assertEquals(phone, decrypt); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/CRUDTest.java b/hutool-db/src/test/java/cn/hutool/db/CRUDTest.java index 91847cf65..002c61ba0 100644 --- a/hutool-db/src/test/java/cn/hutool/db/CRUDTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/CRUDTest.java @@ -7,9 +7,9 @@ import cn.hutool.db.handler.EntityListHandler; import cn.hutool.db.pojo.User; import cn.hutool.db.sql.Condition; import cn.hutool.db.sql.Condition.LikeType; -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.math.BigDecimal; import java.math.BigInteger; @@ -27,103 +27,103 @@ public class CRUDTest { @Test public void findIsNullTest() { final List results = db.findAll(Entity.of("user").set("age", "is null")); - Assert.assertEquals(0, results.size()); + Assertions.assertEquals(0, results.size()); } @Test public void findIsNullTest2() { final List results = db.findAll(Entity.of("user").set("age", "= null")); - Assert.assertEquals(0, results.size()); + Assertions.assertEquals(0, results.size()); } @Test public void findIsNullTest3() { final List results = db.findAll(Entity.of("user").set("age", null)); - Assert.assertEquals(0, results.size()); + Assertions.assertEquals(0, results.size()); } @Test public void findBetweenTest() { final List results = db.findAll(Entity.of("user").set("age", "between '18' and '40'")); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); } @Test public void findByBigIntegerTest() { final List results = db.findAll(Entity.of("user").set("age", new BigInteger("12"))); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findByBigDecimalTest() { final List results = db.findAll(Entity.of("user").set("age", new BigDecimal("12"))); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findLikeTest() { final List results = db.findAll(Entity.of("user").set("name", "like \"%三%\"")); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findLikeTest2() { final List results = db.findAll(Entity.of("user").set("name", new Condition("name", "三", LikeType.Contains))); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findLikeTest3() { final List results = db.findAll(Entity.of("user").set("name", new Condition("name", null, LikeType.Contains))); - Assert.assertEquals(0, results.size()); + Assertions.assertEquals(0, results.size()); } @Test public void findInTest() { final List results = db.findAll(Entity.of("user").set("id", "in 1,2,3")); Console.log(results); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findInTest2() { final List results = db.findAll(Entity.of("user") .set("id", new Condition("id", new long[]{1, 2, 3}))); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findInTest3() { final List results = db.findAll(Entity.of("user") .set("id", new long[]{1, 2, 3})); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findInTest4() { final List results = db.findAll(Entity.of("user") .set("id", new String[]{"1", "2", "3"})); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test public void findAllTest() { final List results = db.findAll("user"); - Assert.assertEquals(4, results.size()); + Assertions.assertEquals(4, results.size()); } @Test public void findTest() { final List find = db.find(ListUtil.of("name AS name2"), Entity.of("user"), new EntityListHandler()); - Assert.assertFalse(find.isEmpty()); + Assertions.assertFalse(find.isEmpty()); } @Test public void findActiveTest() { final ActiveEntity entity = new ActiveEntity(db, "user"); entity.setFieldNames("name AS name2").load(); - Assert.assertEquals("user", entity.getTableName()); - Assert.assertFalse(entity.isEmpty()); + Assertions.assertEquals("user", entity.getTableName()); + Assertions.assertFalse(entity.isEmpty()); } /** @@ -131,30 +131,30 @@ public class CRUDTest { * */ @Test - @Ignore + @Disabled public void crudTest() { // 增 final Long id = db.insertForGeneratedKey(Entity.of("user").set("name", "unitTestUser").set("age", 66)); - Assert.assertTrue(id > 0); + Assertions.assertTrue(id > 0); final Entity result = db.get("user", "name", "unitTestUser"); - Assert.assertSame(66, result.getInt("age")); + Assertions.assertSame(66, result.getInt("age")); // 改 final int update = db.update(Entity.of().set("age", 88), Entity.of("user").set("name", "unitTestUser")); - Assert.assertTrue(update > 0); + Assertions.assertTrue(update > 0); final Entity result2 = db.get("user", "name", "unitTestUser"); - Assert.assertSame(88, result2.getInt("age")); + Assertions.assertSame(88, result2.getInt("age")); // 删 final int del = db.del("user", "name", "unitTestUser"); - Assert.assertTrue(del > 0); + Assertions.assertTrue(del > 0); final Entity result3 = db.get("user", "name", "unitTestUser"); - Assert.assertNull(result3); + Assertions.assertNull(result3); } @Test - @Ignore + @Disabled public void insertBatchTest() { final User user1 = new User(); user1.setName("张三"); @@ -180,7 +180,7 @@ public class CRUDTest { } @Test - @Ignore + @Disabled public void insertBatchOneTest() { final User user1 = new User(); user1.setName("张三"); @@ -200,11 +200,11 @@ public class CRUDTest { public void selectInTest() { final List results = db.query("select * from user where id in (:ids)", MapUtil.of("ids", new int[]{1, 2, 3})); - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); } @Test - @Ignore + @Disabled public void findWithDotTest(){ db.find(Entity.of("user").set("WTUR.Other.Rg.S.WTName", "value")); } diff --git a/hutool-db/src/test/java/cn/hutool/db/ConcurentTest.java b/hutool-db/src/test/java/cn/hutool/db/ConcurentTest.java index 4a26b2d3e..6514efd80 100755 --- a/hutool-db/src/test/java/cn/hutool/db/ConcurentTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/ConcurentTest.java @@ -4,9 +4,9 @@ import cn.hutool.core.collection.ListUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.db.handler.EntityListHandler; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.List; @@ -16,12 +16,12 @@ import java.util.List; * @author looly * */ -@Ignore +@Disabled public class ConcurentTest { private Db db; - @Before + @BeforeEach public void init() { db = Db.of("test"); } diff --git a/hutool-db/src/test/java/cn/hutool/db/DbTest.java b/hutool-db/src/test/java/cn/hutool/db/DbTest.java index 5e3019570..0469116f5 100644 --- a/hutool-db/src/test/java/cn/hutool/db/DbTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/DbTest.java @@ -3,9 +3,9 @@ package cn.hutool.db; import cn.hutool.db.handler.EntityListHandler; import cn.hutool.db.sql.Condition; import cn.hutool.log.StaticLog; -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.sql.PreparedStatement; import java.sql.ResultSet; @@ -22,13 +22,13 @@ public class DbTest { @Test public void queryTest() { final List find = Db.of().query("select * from user where age = ?", 18); - Assert.assertEquals("王五", find.get(0).get("name")); + Assertions.assertEquals("王五", find.get(0).get("name")); } @Test public void findTest() { final List find = Db.of().find(Entity.of("user").set("age", 18)); - Assert.assertEquals("王五", find.get(0).get("name")); + Assertions.assertEquals("王五", find.get(0).get("name")); } @Test @@ -36,10 +36,10 @@ public class DbTest { // 测试数据库中一共4条数据,第0页有3条,第1页有1条 final List page0 = Db.of().page(Entity.of("user"), Page.of(0, 3)); - Assert.assertEquals(3, page0.size()); + Assertions.assertEquals(3, page0.size()); final List page1 = Db.of().page(Entity.of("user"), Page.of(1, 3)); - Assert.assertEquals(1, page1.size()); + Assertions.assertEquals(1, page1.size()); } @Test @@ -48,11 +48,11 @@ public class DbTest { // 测试数据库中一共4条数据,第0页有3条,第1页有1条 final List page0 = Db.of().page( sql, Page.of(0, 3)); - Assert.assertEquals(3, page0.size()); + Assertions.assertEquals(3, page0.size()); final List page1 = Db.of().page( sql, Page.of(1, 3)); - Assert.assertEquals(1, page1.size()); + Assertions.assertEquals(1, page1.size()); } @Test @@ -65,7 +65,7 @@ public class DbTest { Entity.of().set("age", 12) .set("names", new String[]{"张三", "王五"}) ); - Assert.assertEquals(1, page0.size()); + Assertions.assertEquals(1, page0.size()); } @Test @@ -74,42 +74,42 @@ public class DbTest { final PageResult result = Db.of().page( sql, Page.of(0, 3), "张三"); - Assert.assertEquals(2, result.getTotal()); - Assert.assertEquals(1, result.getTotalPage()); - Assert.assertEquals(2, result.size()); + Assertions.assertEquals(2, result.getTotal()); + Assertions.assertEquals(1, result.getTotalPage()); + Assertions.assertEquals(2, result.size()); } @Test public void countTest() { final long count = Db.of().count("select * from user"); - Assert.assertEquals(4, count); + Assertions.assertEquals(4, count); } @Test public void countByQueryTest() { final long count = Db.of().count(Entity.of("user")); - Assert.assertEquals(4, count); + Assertions.assertEquals(4, count); } @Test public void countTest2() { final long count = Db.of().count("select * from user order by name DESC"); - Assert.assertEquals(4, count); + Assertions.assertEquals(4, count); } @Test public void findLikeTest() { // 方式1 List find = Db.of().find(Entity.of("user").set("name", "like 王%")); - Assert.assertEquals("王五", find.get(0).get("name")); + Assertions.assertEquals("王五", find.get(0).get("name")); // 方式2 find = Db.of().findLike("user", "name", "王", Condition.LikeType.StartWith); - Assert.assertEquals("王五", find.get(0).get("name")); + Assertions.assertEquals("王五", find.get(0).get("name")); // 方式3 find = Db.of().query("select * from user where name like ?", "王%"); - Assert.assertEquals("王五", find.get(0).get("name")); + Assertions.assertEquals("王五", find.get(0).get("name")); } @Test @@ -121,11 +121,11 @@ public class DbTest { for (final Entity entity : find) { StaticLog.debug("{}", entity); } - Assert.assertEquals("unitTestUser", find.get(0).get("name")); + Assertions.assertEquals("unitTestUser", find.get(0).get("name")); } @Test - @Ignore + @Disabled public void txTest() throws SQLException { Db.of().tx(db -> { db.insert(Entity.of("user").set("name", "unitTestuser2")); @@ -135,7 +135,7 @@ public class DbTest { } @Test - @Ignore + @Disabled public void queryFetchTest() { // https://gitee.com/dromara/hutool/issues/I4JXWN Db.of().query((conn->{ @@ -149,7 +149,7 @@ public class DbTest { } @Test - @Ignore + @Disabled public void findWithDotTest() { // 当字段带有点时,导致被拆分分别wrap了,因此此时关闭自动包装即可 Db.of().disableWrapper().find(Entity.of("user").set("a.b", "1")); diff --git a/hutool-db/src/test/java/cn/hutool/db/DerbyTest.java b/hutool-db/src/test/java/cn/hutool/db/DerbyTest.java index 7c7dc10db..4dcad1bdd 100644 --- a/hutool-db/src/test/java/cn/hutool/db/DerbyTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/DerbyTest.java @@ -1,9 +1,8 @@ package cn.hutool.db; -import org.junit.Assert; -import org.junit.BeforeClass; -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.List; @@ -17,7 +16,7 @@ public class DerbyTest { private static final String DS_GROUP_NAME = "derby"; - @BeforeClass + //@BeforeAll public static void init() { final Db db = Db.of(DS_GROUP_NAME); db.execute("CREATE TABLE test(a INTEGER, b BIGINT)"); @@ -29,16 +28,16 @@ public class DerbyTest { } @Test - @Ignore + @Disabled public void queryTest() { final List query = Db.of(DS_GROUP_NAME).query("select * from test"); - Assert.assertEquals(4, query.size()); + Assertions.assertEquals(4, query.size()); } @Test - @Ignore + @Disabled public void findTest() { final List query = Db.of(DS_GROUP_NAME).find(Entity.of("test")); - Assert.assertEquals(4, query.size()); + Assertions.assertEquals(4, query.size()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/DsTest.java b/hutool-db/src/test/java/cn/hutool/db/DsTest.java index d9ed488f4..14f264d96 100644 --- a/hutool-db/src/test/java/cn/hutool/db/DsTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/DsTest.java @@ -11,8 +11,8 @@ import cn.hutool.db.ds.hikari.HikariDSFactory; import cn.hutool.db.ds.pooled.PooledDSFactory; import cn.hutool.db.ds.tomcat.TomcatDSFactory; import com.mchange.v2.c3p0.ComboPooledDataSource; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.sql.DataSource; import java.util.List; @@ -30,7 +30,7 @@ public class DsTest { final DataSource ds = DSUtil.getDS("test"); final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } @Test @@ -39,7 +39,7 @@ public class DsTest { final DataSource ds = DSUtil.getDS("test"); final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } @Test @@ -49,7 +49,7 @@ public class DsTest { final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } @Test @@ -58,7 +58,7 @@ public class DsTest { final DataSource ds = DSUtil.getDS("test"); final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } @Test @@ -67,7 +67,7 @@ public class DsTest { final DataSource ds = DSUtil.getDS("test"); final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } @Test @@ -76,7 +76,7 @@ public class DsTest { final DataSource ds = DSUtil.getDS("test"); final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } @Test @@ -85,7 +85,7 @@ public class DsTest { final DataSource ds = DSUtil.getDS("test"); final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } @Test @@ -93,8 +93,8 @@ public class DsTest { // https://gitee.com/dromara/hutool/issues/I4T7XZ DSUtil.setGlobalDSFactory(new C3p0DSFactory()); final ComboPooledDataSource ds = (ComboPooledDataSource) ((DSWrapper) DSUtil.getDS("mysql")).getRaw(); - Assert.assertEquals("root", ds.getUser()); - Assert.assertEquals("123456", ds.getPassword()); + Assertions.assertEquals("root", ds.getUser()); + Assertions.assertEquals("123456", ds.getPassword()); } @Test @@ -103,6 +103,6 @@ public class DsTest { final DataSource ds = DSUtil.getDS("test"); final Db db = Db.of(ds); final List all = db.findAll("user"); - Assert.assertTrue(CollUtil.isNotEmpty(all)); + Assertions.assertTrue(CollUtil.isNotEmpty(all)); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/EntityTest.java b/hutool-db/src/test/java/cn/hutool/db/EntityTest.java index 0ba97fb46..76a432ab9 100644 --- a/hutool-db/src/test/java/cn/hutool/db/EntityTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/EntityTest.java @@ -1,8 +1,8 @@ package cn.hutool.db; import cn.hutool.db.pojo.User; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Entity测试 @@ -19,8 +19,8 @@ public class EntityTest { user.setName("test"); final Entity entity = Entity.of("testTable").parseBean(user); - Assert.assertEquals(Integer.valueOf(1), entity.getInt("id")); - Assert.assertEquals("test", entity.getStr("name")); + Assertions.assertEquals(Integer.valueOf(1), entity.getInt("id")); + Assertions.assertEquals("test", entity.getStr("name")); } @Test @@ -30,9 +30,9 @@ public class EntityTest { user.setName("test"); final Entity entity = Entity.of().parseBean(user); - Assert.assertEquals(Integer.valueOf(1), entity.getInt("id")); - Assert.assertEquals("test", entity.getStr("name")); - Assert.assertEquals("user", entity.getTableName()); + Assertions.assertEquals(Integer.valueOf(1), entity.getInt("id")); + Assertions.assertEquals("test", entity.getStr("name")); + Assertions.assertEquals("user", entity.getTableName()); } @Test @@ -42,9 +42,9 @@ public class EntityTest { final Entity entity = Entity.of().parseBean(user, false, true); - Assert.assertFalse(entity.containsKey("id")); - Assert.assertEquals("test", entity.getStr("name")); - Assert.assertEquals("user", entity.getTableName()); + Assertions.assertFalse(entity.containsKey("id")); + Assertions.assertEquals("test", entity.getStr("name")); + Assertions.assertEquals("user", entity.getTableName()); } @Test @@ -52,7 +52,7 @@ public class EntityTest { final Entity entity = Entity.of().set("ID", 2).set("NAME", "testName"); final User user = entity.toBeanIgnoreCase(User.class); - Assert.assertEquals(Integer.valueOf(2), user.getId()); - Assert.assertEquals("testName", user.getName()); + Assertions.assertEquals(Integer.valueOf(2), user.getId()); + Assertions.assertEquals("testName", user.getName()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/FindBeanTest.java b/hutool-db/src/test/java/cn/hutool/db/FindBeanTest.java index ee40c07c2..11b186717 100644 --- a/hutool-db/src/test/java/cn/hutool/db/FindBeanTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/FindBeanTest.java @@ -1,9 +1,9 @@ package cn.hutool.db; import cn.hutool.db.pojo.User; -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.List; @@ -17,7 +17,7 @@ public class FindBeanTest { Db db; - @Before + @BeforeEach public void init() { db = Db.of("test"); } @@ -26,9 +26,9 @@ public class FindBeanTest { public void findAllBeanTest() { final List results = db.findAll(Entity.of("user"), User.class); - Assert.assertEquals(4, results.size()); - Assert.assertEquals(Integer.valueOf(1), results.get(0).getId()); - Assert.assertEquals("张三", results.get(0).getName()); + Assertions.assertEquals(4, results.size()); + Assertions.assertEquals(Integer.valueOf(1), results.get(0).getId()); + Assertions.assertEquals("张三", results.get(0).getName()); } @Test @@ -36,32 +36,32 @@ public class FindBeanTest { public void findAllListTest() { final List results = db.findAll(Entity.of("user"), List.class); - Assert.assertEquals(4, results.size()); - Assert.assertEquals(1, results.get(0).get(0)); - Assert.assertEquals("张三", results.get(0).get(1)); + Assertions.assertEquals(4, results.size()); + Assertions.assertEquals(1, results.get(0).get(0)); + Assertions.assertEquals("张三", results.get(0).get(1)); } @Test public void findAllArrayTest() { final List results = db.findAll(Entity.of("user"), Object[].class); - Assert.assertEquals(4, results.size()); - Assert.assertEquals(1, results.get(0)[0]); - Assert.assertEquals("张三", results.get(0)[1]); + Assertions.assertEquals(4, results.size()); + Assertions.assertEquals(1, results.get(0)[0]); + Assertions.assertEquals("张三", results.get(0)[1]); } @Test public void findAllStringTest() { final List results = db.findAll(Entity.of("user"), String.class); - Assert.assertEquals(4, results.size()); + Assertions.assertEquals(4, results.size()); } @Test public void findAllStringArrayTest() { final List results = db.findAll(Entity.of("user"), String[].class); - Assert.assertEquals(4, results.size()); - Assert.assertEquals("1", results.get(0)[0]); - Assert.assertEquals("张三", results.get(0)[1]); + Assertions.assertEquals(4, results.size()); + Assertions.assertEquals("1", results.get(0)[0]); + Assertions.assertEquals("张三", results.get(0)[1]); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/H2Test.java b/hutool-db/src/test/java/cn/hutool/db/H2Test.java index 9bb13afbe..43a56341e 100644 --- a/hutool-db/src/test/java/cn/hutool/db/H2Test.java +++ b/hutool-db/src/test/java/cn/hutool/db/H2Test.java @@ -2,9 +2,9 @@ package cn.hutool.db; import cn.hutool.core.map.CaseInsensitiveMap; import cn.hutool.core.map.MapUtil; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; @@ -19,7 +19,7 @@ public class H2Test { private static final String DS_GROUP_NAME = "h2"; - @BeforeClass + @BeforeAll public static void init() { final Db db = Db.of(DS_GROUP_NAME); db.execute("CREATE TABLE test(a INTEGER, b BIGINT)"); @@ -33,13 +33,13 @@ public class H2Test { @Test public void queryTest() { final List query = Db.of(DS_GROUP_NAME).query("select * from test"); - Assert.assertEquals(4, query.size()); + Assertions.assertEquals(4, query.size()); } @Test public void findTest() { final List query = Db.of(DS_GROUP_NAME).find(Entity.of("test")); - Assert.assertEquals(4, query.size()); + Assertions.assertEquals(4, query.size()); } @Test @@ -47,17 +47,17 @@ public class H2Test { final Db db=Db.of(DS_GROUP_NAME); db.upsert(Entity.of("test").set("a",1).set("b",111),"a"); final Entity a1=db.get("test","a",1); - Assert.assertEquals(Long.valueOf(111),a1.getLong("b")); + Assertions.assertEquals(Long.valueOf(111),a1.getLong("b")); } @Test public void pageTest() { - String sql = "select * from test where a = @a and b = :b"; - Map paramMap = MapUtil.builder(new CaseInsensitiveMap()) + final String sql = "select * from test where a = @a and b = :b"; + final Map paramMap = MapUtil.builder(new CaseInsensitiveMap()) .put("A", 3) .put("b", 31) .build(); final List query = Db.of(DS_GROUP_NAME).page(sql, Page.of(0, 3), paramMap); - Assert.assertEquals(1, query.size()); + Assertions.assertEquals(1, query.size()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java b/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java index 049758ced..a856de181 100644 --- a/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/HsqldbTest.java @@ -1,8 +1,8 @@ package cn.hutool.db; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.List; @@ -16,7 +16,7 @@ public class HsqldbTest { private static final String DS_GROUP_NAME = "hsqldb"; - @BeforeClass + @BeforeAll public static void init() { final Db db = Db.of(DS_GROUP_NAME); db.execute("CREATE TABLE test(a INTEGER, b BIGINT)"); @@ -29,12 +29,12 @@ public class HsqldbTest { @Test public void connTest() { final List query = Db.of(DS_GROUP_NAME).query("select * from test"); - Assert.assertEquals(4, query.size()); + Assertions.assertEquals(4, query.size()); } @Test public void findTest() { final List query = Db.of(DS_GROUP_NAME).find(Entity.of("test")); - Assert.assertEquals(4, query.size()); + Assertions.assertEquals(4, query.size()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java b/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java index 88757d74b..ab16a51ef 100755 --- a/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java @@ -1,10 +1,9 @@ package cn.hutool.db; import cn.hutool.core.lang.Console; -import org.junit.Assert; -import org.junit.BeforeClass; -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.sql.SQLException; import java.util.List; @@ -15,15 +14,14 @@ import java.util.List; * @author looly */ public class MySQLTest { - @BeforeClass - @Ignore + //@BeforeAll public static void createTable() { final Db db = Db.of("mysql"); db.executeBatch("drop table if exists testuser", "CREATE TABLE if not exists `testuser` ( `id` int(11) NOT NULL, `account` varchar(255) DEFAULT NULL, `pass` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); } @Test - @Ignore + @Disabled public void insertTest() { for (int id = 100; id < 200; id++) { Db.of("mysql").insert(Entity.of("user")// @@ -41,22 +39,24 @@ public class MySQLTest { * * @throws SQLException SQL异常 */ - @Test(expected = SQLException.class) - @Ignore + @Test + @Disabled public void txTest() throws SQLException { - Db.of("mysql").tx(db -> { - final int update = db.update(Entity.of("user").set("text", "描述100"), Entity.of().set("id", 100)); - db.update(Entity.of("user").set("text", "描述101"), Entity.of().set("id", 101)); - if (1 == update) { - // 手动指定异常,然后测试回滚触发 - throw new RuntimeException("Error"); - } - db.update(Entity.of("user").set("text", "描述102"), Entity.of().set("id", 102)); + Assertions.assertThrows(SQLException.class, ()->{ + Db.of("mysql").tx(db -> { + final int update = db.update(Entity.of("user").set("text", "描述100"), Entity.of().set("id", 100)); + db.update(Entity.of("user").set("text", "描述101"), Entity.of().set("id", 101)); + if (1 == update) { + // 手动指定异常,然后测试回滚触发 + throw new RuntimeException("Error"); + } + db.update(Entity.of("user").set("text", "描述102"), Entity.of().set("id", 102)); + }); }); } @Test - @Ignore + @Disabled public void pageTest() { final PageResult result = Db.of("mysql").page(Entity.of("user"), new Page(2, 10)); for (final Entity entity : result) { @@ -65,20 +65,20 @@ public class MySQLTest { } @Test - @Ignore + @Disabled public void getTimeStampTest() { final List all = Db.of("mysql").findAll("test"); Console.log(all); } @Test - @Ignore + @Disabled public void upsertTest() { final Db db = Db.of("mysql"); db.insert(Entity.of("testuser").set("id", 1).set("account", "ice").set("pass", "123456")); db.upsert(Entity.of("testuser").set("id", 1).set("account", "icefairy").set("pass", "a123456")); final Entity user = db.get(Entity.of("testuser").set("id", 1)); System.out.println("user======="+user.getStr("account")+"___"+user.getStr("pass")); - Assert.assertEquals(user.getStr("account"), "icefairy"); + Assertions.assertEquals(user.getStr("account"), "icefairy"); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/NamedSqlTest.java b/hutool-db/src/test/java/cn/hutool/db/NamedSqlTest.java index d7f3c1be3..dd018f444 100644 --- a/hutool-db/src/test/java/cn/hutool/db/NamedSqlTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/NamedSqlTest.java @@ -2,8 +2,8 @@ package cn.hutool.db; import cn.hutool.core.map.MapUtil; import cn.hutool.db.sql.NamedSql; -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.List; @@ -23,9 +23,9 @@ public class NamedSqlTest { final NamedSql namedSql = new NamedSql(sql, paramMap); //未指定参数原样输出 - Assert.assertEquals("select * from table where id=@id and name = ? and nickName = ?", namedSql.getSql()); - Assert.assertEquals("张三", namedSql.getParams()[0]); - Assert.assertEquals("小豆豆", namedSql.getParams()[1]); + Assertions.assertEquals("select * from table where id=@id and name = ? and nickName = ?", namedSql.getSql()); + Assertions.assertEquals("张三", namedSql.getParams()[0]); + Assertions.assertEquals("小豆豆", namedSql.getParams()[1]); } @Test @@ -40,11 +40,11 @@ public class NamedSqlTest { .build(); final NamedSql namedSql = new NamedSql(sql, paramMap); - Assert.assertEquals("select * from table where id=? and name = ? and nickName = ?", namedSql.getSql()); + Assertions.assertEquals("select * from table where id=? and name = ? and nickName = ?", namedSql.getSql()); //指定了null参数的依旧替换,参数值为null - Assert.assertNull(namedSql.getParams()[0]); - Assert.assertEquals("张三", namedSql.getParams()[1]); - Assert.assertEquals("小豆豆", namedSql.getParams()[2]); + Assertions.assertNull(namedSql.getParams()[0]); + Assertions.assertEquals("张三", namedSql.getParams()[1]); + Assertions.assertEquals("小豆豆", namedSql.getParams()[2]); } @Test @@ -57,7 +57,7 @@ public class NamedSqlTest { .build(); final NamedSql namedSql = new NamedSql(sql, paramMap); - Assert.assertEquals(sql, namedSql.getSql()); + Assertions.assertEquals(sql, namedSql.getSql()); } @Test @@ -70,7 +70,7 @@ public class NamedSqlTest { .build(); final NamedSql namedSql = new NamedSql(sql, paramMap); - Assert.assertEquals(sql, namedSql.getSql()); + Assertions.assertEquals(sql, namedSql.getSql()); } @Test @@ -79,10 +79,10 @@ public class NamedSqlTest { final HashMap paramMap = MapUtil.of("ids", new int[]{1, 2, 3}); final NamedSql namedSql = new NamedSql(sql, paramMap); - Assert.assertEquals("select * from user where id in (?,?,?)", namedSql.getSql()); - Assert.assertEquals(1, namedSql.getParams()[0]); - Assert.assertEquals(2, namedSql.getParams()[1]); - Assert.assertEquals(3, namedSql.getParams()[2]); + Assertions.assertEquals("select * from user where id in (?,?,?)", namedSql.getSql()); + Assertions.assertEquals(1, namedSql.getParams()[0]); + Assertions.assertEquals(2, namedSql.getParams()[1]); + Assertions.assertEquals(3, namedSql.getParams()[2]); } @Test @@ -93,10 +93,10 @@ public class NamedSqlTest { final String sql = "select * from user where name = @name1 and age = @age1"; List query = Db.of().query(sql, paramMap); - Assert.assertEquals(1, query.size()); + Assertions.assertEquals(1, query.size()); // 采用传统方式查询是否能识别Map类型参数 query = Db.of().query(sql, new Object[]{paramMap}); - Assert.assertEquals(1, query.size()); + Assertions.assertEquals(1, query.size()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/OracleTest.java b/hutool-db/src/test/java/cn/hutool/db/OracleTest.java index e4be266c5..ee0337b5d 100755 --- a/hutool-db/src/test/java/cn/hutool/db/OracleTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/OracleTest.java @@ -4,9 +4,9 @@ import cn.hutool.core.lang.Console; import cn.hutool.db.sql.Query; import cn.hutool.db.sql.SqlBuilder; import cn.hutool.db.sql.SqlUtil; -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; /** * Oracle操作单元测试 @@ -34,11 +34,11 @@ public class OracleTest { final String ok = "SELECT * FROM "// + "( SELECT row_.*, rownum rownum_ from ( SELECT * FROM PMCPERFORMANCEINFO WHERE yearPI = ? ) row_ "// + "where rownum <= 10) table_alias where table_alias.rownum_ >= 0";// - Assert.assertEquals(ok, builder.toString()); + Assertions.assertEquals(ok, builder.toString()); } @Test - @Ignore + @Disabled public void insertTest() { for (int id = 100; id < 200; id++) { Db.of("orcl").insert(Entity.of("T_USER")// @@ -51,7 +51,7 @@ public class OracleTest { } @Test - @Ignore + @Disabled public void pageTest() { final PageResult result = Db.of("orcl").page(Entity.of("T_USER"), new Page(2, 10)); for (final Entity entity : result) { diff --git a/hutool-db/src/test/java/cn/hutool/db/PageResultTest.java b/hutool-db/src/test/java/cn/hutool/db/PageResultTest.java index 43c1835fe..db3379ca1 100644 --- a/hutool-db/src/test/java/cn/hutool/db/PageResultTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/PageResultTest.java @@ -1,7 +1,7 @@ package cn.hutool.db; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PageResultTest { @@ -9,6 +9,6 @@ public class PageResultTest { public void isLastTest(){ // 每页2条,共10条,总共5页,第一页是0,最后一页应该是4 final PageResult result = new PageResult<>(4, 2, 10); - Assert.assertTrue(result.isLast()); + Assertions.assertTrue(result.isLast()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/PageTest.java b/hutool-db/src/test/java/cn/hutool/db/PageTest.java index e34973a43..ab77da262 100644 --- a/hutool-db/src/test/java/cn/hutool/db/PageTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/PageTest.java @@ -1,8 +1,8 @@ package cn.hutool.db; import cn.hutool.db.sql.Order; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PageTest { @@ -10,8 +10,8 @@ public class PageTest { public void addOrderTest() { final Page page = new Page(); page.addOrder(new Order("aaa")); - Assert.assertEquals(page.getOrders().length, 1); + Assertions.assertEquals(page.getOrders().length, 1); page.addOrder(new Order("aaa")); - Assert.assertEquals(page.getOrders().length, 2); + Assertions.assertEquals(page.getOrders().length, 2); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/PicTransferTest.java b/hutool-db/src/test/java/cn/hutool/db/PicTransferTest.java index 71f85f6d7..0239b1419 100644 --- a/hutool-db/src/test/java/cn/hutool/db/PicTransferTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/PicTransferTest.java @@ -3,8 +3,8 @@ package cn.hutool.db; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.text.StrUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.sql.ResultSet; import java.sql.SQLException; @@ -12,7 +12,7 @@ import java.sql.SQLException; public class PicTransferTest { @Test - @Ignore + @Disabled public void findTest() { Db.of().find( ListUtil.view("NAME", "TYPE", "GROUP", "PIC"), diff --git a/hutool-db/src/test/java/cn/hutool/db/PostgreTest.java b/hutool-db/src/test/java/cn/hutool/db/PostgreTest.java index 18d4d82f0..a90000830 100644 --- a/hutool-db/src/test/java/cn/hutool/db/PostgreTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/PostgreTest.java @@ -1,9 +1,9 @@ package cn.hutool.db; 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; /** * PostgreSQL 单元测试 @@ -13,7 +13,7 @@ import org.junit.Test; public class PostgreTest { @Test - @Ignore + @Disabled public void insertTest() { for (int id = 100; id < 200; id++) { Db.of("postgre").insert(Entity.of("user")// @@ -24,7 +24,7 @@ public class PostgreTest { } @Test - @Ignore + @Disabled public void pageTest() { final PageResult result = Db.of("postgre").page(Entity.of("user"), new Page(2, 10)); for (final Entity entity : result) { @@ -33,7 +33,7 @@ public class PostgreTest { } @Test - @Ignore + @Disabled public void upsertTest() { final Db db = Db.of("postgre"); db.executeBatch("drop table if exists ctest", @@ -41,6 +41,6 @@ public class PostgreTest { db.insert(Entity.of("ctest").set("id", 1).set("t1", "111").set("t2", "222").set("t3", "333")); db.upsert(Entity.of("ctest").set("id", 1).set("t1", "new111").set("t2", "new222").set("t3", "bew333"),"id"); final Entity et=db.get(Entity.of("ctest").set("id", 1)); - Assert.assertEquals("new111",et.getStr("t1")); + Assertions.assertEquals("new111",et.getStr("t1")); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/SessionTest.java b/hutool-db/src/test/java/cn/hutool/db/SessionTest.java index 1dec67074..66aca432c 100644 --- a/hutool-db/src/test/java/cn/hutool/db/SessionTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/SessionTest.java @@ -1,7 +1,7 @@ package cn.hutool.db; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * 事务性数据库操作单元测试 @@ -11,7 +11,7 @@ import org.junit.Test; public class SessionTest { @Test - @Ignore + @Disabled public void transTest() { final Session session = Session.of("test"); session.beginTransaction(); @@ -20,7 +20,7 @@ public class SessionTest { } @Test - @Ignore + @Disabled public void txTest() { Session.of("test").tx(session -> session.update(Entity.of().set("age", 78), Entity.of("user").set("name", "unitTestUser"))); } diff --git a/hutool-db/src/test/java/cn/hutool/db/SqlServerTest.java b/hutool-db/src/test/java/cn/hutool/db/SqlServerTest.java index ed790572f..d93ff8017 100755 --- a/hutool-db/src/test/java/cn/hutool/db/SqlServerTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/SqlServerTest.java @@ -1,8 +1,8 @@ package cn.hutool.db; 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; /** * SQL Server操作单元测试 @@ -13,13 +13,13 @@ import org.junit.Test; public class SqlServerTest { @Test - @Ignore + @Disabled public void createTableTest() { Db.of("sqlserver").execute("create table T_USER(ID bigint, name varchar(255))"); } @Test - @Ignore + @Disabled public void insertTest() { for (int id = 100; id < 200; id++) { Db.of("sqlserver").insert(Entity.of("T_USER")// @@ -30,7 +30,7 @@ public class SqlServerTest { } @Test - @Ignore + @Disabled public void pageTest() { final PageResult result = Db.of("sqlserver").page(Entity.of("T_USER"), new Page(2, 10)); for (final Entity entity : result) { diff --git a/hutool-db/src/test/java/cn/hutool/db/UpdateTest.java b/hutool-db/src/test/java/cn/hutool/db/UpdateTest.java index 9243bf1a2..b53452bf4 100644 --- a/hutool-db/src/test/java/cn/hutool/db/UpdateTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/UpdateTest.java @@ -1,15 +1,15 @@ package cn.hutool.db; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class UpdateTest { Db db; - @Before + @BeforeEach public void init() { db = Db.of("test"); } @@ -19,13 +19,13 @@ public class UpdateTest { * */ @Test - @Ignore + @Disabled public void updateTest() { // 改 final int update = db.update(Entity.of("user").set("age", 88), Entity.of().set("name", "unitTestUser")); - Assert.assertTrue(update > 0); + Assertions.assertTrue(update > 0); final Entity result2 = db.get("user", "name", "unitTestUser"); - Assert.assertSame(88, result2.getInt("age")); + Assertions.assertSame(88, result2.getInt("age")); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/dialect/DialectFactoryTest.java b/hutool-db/src/test/java/cn/hutool/db/dialect/DialectFactoryTest.java index a0e390f82..f01dcd20a 100755 --- a/hutool-db/src/test/java/cn/hutool/db/dialect/DialectFactoryTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/dialect/DialectFactoryTest.java @@ -1,8 +1,8 @@ package cn.hutool.db.dialect; 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; import java.util.HashMap; import java.util.Map; @@ -41,7 +41,7 @@ public class DialectFactoryTest { map.put("mariadb",DRIVER_MARIADB); - map.forEach((k,v) -> Assert.assertEquals(v, + map.forEach((k,v) -> Assertions.assertEquals(v, DialectFactory.identifyDriver(k+ RandomUtil.randomString(2),null) )); } diff --git a/hutool-db/src/test/java/cn/hutool/db/dialect/DriverUtilTest.java b/hutool-db/src/test/java/cn/hutool/db/dialect/DriverUtilTest.java index 9255c2156..46cfd08e2 100644 --- a/hutool-db/src/test/java/cn/hutool/db/dialect/DriverUtilTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/dialect/DriverUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.db.dialect; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DriverUtilTest { @@ -9,6 +9,6 @@ public class DriverUtilTest { public void identifyDriverTest(){ final String url = "jdbc:h2:file:./db/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL"; final String driver = DriverUtil.identifyDriver(url); // driver 返回 mysql 的 driver - Assert.assertEquals("org.h2.Driver", driver); + Assertions.assertEquals("org.h2.Driver", driver); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/ds/DataSourceWrapperTest.java b/hutool-db/src/test/java/cn/hutool/db/ds/DataSourceWrapperTest.java index 09f3f8da1..f9478f984 100644 --- a/hutool-db/src/test/java/cn/hutool/db/ds/DataSourceWrapperTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/ds/DataSourceWrapperTest.java @@ -1,8 +1,8 @@ package cn.hutool.db.ds; import cn.hutool.db.ds.simple.SimpleDataSource; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DataSourceWrapperTest { @@ -12,7 +12,7 @@ public class DataSourceWrapperTest { final DSWrapper wrapper = new DSWrapper(simpleDataSource, "test.driver"); final DSWrapper clone = wrapper.clone(); - Assert.assertEquals("test.driver", clone.getDriver()); - Assert.assertEquals(simpleDataSource, clone.getRaw()); + Assertions.assertEquals("test.driver", clone.getDriver()); + Assertions.assertEquals(simpleDataSource, clone.getRaw()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/meta/MetaUtilTest.java b/hutool-db/src/test/java/cn/hutool/db/meta/MetaUtilTest.java index f4c4bfb04..973bf662d 100644 --- a/hutool-db/src/test/java/cn/hutool/db/meta/MetaUtilTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/meta/MetaUtilTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.collection.SetUtil; import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.split.SplitUtil; import cn.hutool.db.ds.DSUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.sql.DataSource; import java.util.List; @@ -22,24 +22,24 @@ public class MetaUtilTest { @Test public void getTablesTest() { final List tables = MetaUtil.getTables(ds); - Assert.assertEquals("user", tables.get(0)); + Assertions.assertEquals("user", tables.get(0)); } @Test public void getTableMetaTest() { final Table table = MetaUtil.getTableMeta(ds, "user"); - Assert.assertEquals(SetUtil.of("id"), table.getPkNames()); + Assertions.assertEquals(SetUtil.of("id"), table.getPkNames()); } @Test public void getColumnNamesTest() { final String[] names = MetaUtil.getColumnNames(ds, "user"); - Assert.assertArrayEquals(SplitUtil.splitToArray("id,name,age,birthday,gender", StrUtil.COMMA), names); + Assertions.assertArrayEquals(SplitUtil.splitToArray("id,name,age,birthday,gender", StrUtil.COMMA), names); } @Test public void getTableIndexInfoTest() { final Table table = MetaUtil.getTableMeta(ds, "user_1"); - Assert.assertEquals(table.getIndexInfoList().size(), 2); + Assertions.assertEquals(table.getIndexInfoList().size(), 2); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/pojo/User.java b/hutool-db/src/test/java/cn/hutool/db/pojo/User.java index 3f89abb13..d3a3d8daa 100644 --- a/hutool-db/src/test/java/cn/hutool/db/pojo/User.java +++ b/hutool-db/src/test/java/cn/hutool/db/pojo/User.java @@ -1,60 +1,18 @@ package cn.hutool.db.pojo; +import lombok.Data; + /** * 测试用POJO,与测试数据库中的user表对应 * * @author looly * */ +@Data public class User { private Integer id; private String name; private int age; private String birthday; private boolean gender; - - public Integer getId() { - return id; - } - - public void setId(final Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(final int age) { - this.age = age; - } - - public String getBirthday() { - return birthday; - } - - public void setBirthday(final String birthday) { - this.birthday = birthday; - } - - public boolean isGender() { - return gender; - } - - public void setGender(final boolean gender) { - this.gender = gender; - } - - @Override - public String toString() { - return "User [id=" + id + ", name=" + name + ", age=" + age + ", birthday=" + birthday + ", gender=" + gender + "]"; - } } diff --git a/hutool-db/src/test/java/cn/hutool/db/pojo/package-info.java b/hutool-db/src/test/java/cn/hutool/db/pojo/package-info.java new file mode 100644 index 000000000..cb14388b8 --- /dev/null +++ b/hutool-db/src/test/java/cn/hutool/db/pojo/package-info.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * 测试pojo + */ +package cn.hutool.db.pojo; diff --git a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionBuilderTest.java b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionBuilderTest.java index 88aaff1eb..4cef47d0f 100644 --- a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionBuilderTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionBuilderTest.java @@ -1,7 +1,7 @@ package cn.hutool.db.sql; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ConditionBuilderTest { @@ -14,8 +14,8 @@ public class ConditionBuilderTest { final ConditionBuilder builder = ConditionBuilder.of(c1, c2, c3); final String sql = builder.build(); - Assert.assertEquals("user IS NULL OR name IS NOT NULL AND group LIKE ?", sql); - Assert.assertEquals(1, builder.getParamValues().size()); - Assert.assertEquals("%aaa", builder.getParamValues().get(0)); + Assertions.assertEquals("user IS NULL OR name IS NOT NULL AND group LIKE ?", sql); + Assertions.assertEquals(1, builder.getParamValues().size()); + Assertions.assertEquals("%aaa", builder.getParamValues().get(0)); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionGroupTest.java b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionGroupTest.java index 1e57695b7..bc5e89f0c 100644 --- a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionGroupTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionGroupTest.java @@ -1,8 +1,8 @@ package cn.hutool.db.sql; 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; public class ConditionGroupTest { @Test @@ -22,7 +22,7 @@ public class ConditionGroupTest { final ConditionBuilder conditionBuilder = ConditionBuilder.of(cg2, condition4); - Assert.assertEquals("((a = ? OR b = ?) AND c = ?) AND d = ?", conditionBuilder.build()); - Assert.assertEquals(ListUtil.view("A", "B", "C", "D"), conditionBuilder.getParamValues()); + Assertions.assertEquals("((a = ? OR b = ?) AND c = ?) AND d = ?", conditionBuilder.build()); + Assertions.assertEquals(ListUtil.view("A", "B", "C", "D"), conditionBuilder.getParamValues()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java index 587473b72..a723abf3d 100644 --- a/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java @@ -1,7 +1,7 @@ package cn.hutool.db.sql; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; @@ -10,62 +10,62 @@ public class ConditionTest { @Test public void toStringTest() { final Condition conditionNull = new Condition("user", null); - Assert.assertEquals("user IS NULL", conditionNull.toString()); + Assertions.assertEquals("user IS NULL", conditionNull.toString()); final Condition conditionNotNull = new Condition("user", "!= null"); - Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString()); + Assertions.assertEquals("user IS NOT NULL", conditionNotNull.toString()); final Condition condition2 = new Condition("user", "= zhangsan"); - Assert.assertEquals("user = ?", condition2.toString()); + Assertions.assertEquals("user = ?", condition2.toString()); final Condition conditionLike = new Condition("user", "like %aaa"); - Assert.assertEquals("user LIKE ?", conditionLike.toString()); + Assertions.assertEquals("user LIKE ?", conditionLike.toString()); final Condition conditionIn = new Condition("user", "in 1,2,3"); - Assert.assertEquals("user IN (?,?,?)", conditionIn.toString()); + Assertions.assertEquals("user IN (?,?,?)", conditionIn.toString()); final Condition conditionBetween = new Condition("user", "between 12 and 13"); - Assert.assertEquals("user BETWEEN ? AND ?", conditionBetween.toString()); + Assertions.assertEquals("user BETWEEN ? AND ?", conditionBetween.toString()); } @Test public void toStringNoPlaceHolderTest() { final Condition conditionNull = new Condition("user", null); conditionNull.setPlaceHolder(false); - Assert.assertEquals("user IS NULL", conditionNull.toString()); + Assertions.assertEquals("user IS NULL", conditionNull.toString()); final Condition conditionNotNull = new Condition("user", "!= null"); conditionNotNull.setPlaceHolder(false); - Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString()); + Assertions.assertEquals("user IS NOT NULL", conditionNotNull.toString()); final Condition conditionEquals = new Condition("user", "= zhangsan"); conditionEquals.setPlaceHolder(false); - Assert.assertEquals("user = zhangsan", conditionEquals.toString()); + Assertions.assertEquals("user = zhangsan", conditionEquals.toString()); final Condition conditionLike = new Condition("user", "like %aaa"); conditionLike.setPlaceHolder(false); - Assert.assertEquals("user LIKE '%aaa'", conditionLike.toString()); + Assertions.assertEquals("user LIKE '%aaa'", conditionLike.toString()); final Condition conditionIn = new Condition("user", "in 1,2,3"); conditionIn.setPlaceHolder(false); - Assert.assertEquals("user IN (1,2,3)", conditionIn.toString()); + Assertions.assertEquals("user IN (1,2,3)", conditionIn.toString()); final Condition conditionBetween = new Condition("user", "between 12 and 13"); conditionBetween.setPlaceHolder(false); - Assert.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString()); + Assertions.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString()); } @Test public void parseTest(){ final Condition age = Condition.parse("age", "< 10"); - Assert.assertEquals("age < ?", age.toString()); + Assertions.assertEquals("age < ?", age.toString()); // issue I38LTM - Assert.assertSame(BigDecimal.class, age.getValue().getClass()); + Assertions.assertSame(BigDecimal.class, age.getValue().getClass()); } @Test public void parseInTest(){ final Condition age = Condition.parse("age", "in 1,2,3"); - Assert.assertEquals("age IN (?,?,?)", age.toString()); + Assertions.assertEquals("age IN (?,?,?)", age.toString()); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/sql/SqlBuilderTest.java b/hutool-db/src/test/java/cn/hutool/db/sql/SqlBuilderTest.java index 9ee2a9bb2..abf0388d3 100644 --- a/hutool-db/src/test/java/cn/hutool/db/sql/SqlBuilderTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/sql/SqlBuilderTest.java @@ -1,23 +1,23 @@ package cn.hutool.db.sql; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SqlBuilderTest { @Test public void queryNullTest() { final SqlBuilder builder = SqlBuilder.of().select().from("user").where(new Condition("name", "= null")); - Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder.build()); + Assertions.assertEquals("SELECT * FROM user WHERE name IS NULL", builder.build()); final SqlBuilder builder2 = SqlBuilder.of().select().from("user").where(new Condition("name", "is null")); - Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build()); + Assertions.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build()); final SqlBuilder builder3 = SqlBuilder.of().select().from("user").where(new Condition("name", "!= null")); - Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build()); + Assertions.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build()); final SqlBuilder builder4 = SqlBuilder.of().select().from("user").where(new Condition("name", "is not null")); - Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build()); + Assertions.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build()); } @Test @@ -29,7 +29,7 @@ public class SqlBuilderTest { new Condition("username", "abc", Condition.LikeType.Contains) ).orderBy(new Order("id")); - Assert.assertEquals("SELECT id,username FROM user INNER JOIN role ON user.id = role.user_id WHERE age >= ? AND username LIKE ? ORDER BY id", builder.build()); + Assertions.assertEquals("SELECT id,username FROM user INNER JOIN role ON user.id = role.user_id WHERE age >= ? AND username LIKE ? ORDER BY id", builder.build()); } @Test @@ -42,6 +42,6 @@ public class SqlBuilderTest { sqlBuilder.from("user"); sqlBuilder.where(conditionEquals); final String s1 = sqlBuilder.build(); - Assert.assertEquals("SELECT id FROM user WHERE user LIKE '%123%'", s1); + Assertions.assertEquals("SELECT id FROM user WHERE user LIKE '%123%'", s1); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/sql/SqlFormatterTest.java b/hutool-db/src/test/java/cn/hutool/db/sql/SqlFormatterTest.java index 21958ba14..676cebf09 100755 --- a/hutool-db/src/test/java/cn/hutool/db/sql/SqlFormatterTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/sql/SqlFormatterTest.java @@ -1,6 +1,6 @@ package cn.hutool.db.sql; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SqlFormatterTest { diff --git a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java index ec4dbe0eb..44d9c0b83 100755 --- a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrCodeUtil.java @@ -12,7 +12,6 @@ package cn.hutool.extra.qrcode; -import cn.hutool.core.codec.binary.Base64; import cn.hutool.core.util.ObjUtil; import cn.hutool.swing.img.ImgUtil; import com.google.zxing.BarcodeFormat; @@ -50,32 +49,6 @@ public class QrCodeUtil { */ public static final String QR_TYPE_TXT = "txt"; - /** - * 生成代 logo 图片的 Base64 编码格式的二维码,以 String 形式表示 - * - * @param content 内容 - * @param qrConfig 二维码配置,包括宽度、高度、边距、颜色等 - * @param targetType 类型(图片扩展名),见{@link #QR_TYPE_SVG}、 {@link #QR_TYPE_TXT}、{@link ImgUtil} - * @param logoBase64 logo 图片的 base64 编码 - * @return 图片 Base64 编码字符串 - */ - public static String generateAsBase64(final String content, final QrConfig qrConfig, final String targetType, final String logoBase64) { - return generateAsBase64DataUri(content, qrConfig, targetType, Base64.decode(logoBase64)); - } - - /** - * 生成代 logo 图片的 Base64 编码格式的二维码,以 String 形式表示 - * - * @param content 内容 - * @param qrConfig 二维码配置,包括宽度、高度、边距、颜色等 - * @param targetType 类型(图片扩展名),见{@link #QR_TYPE_SVG}、 {@link #QR_TYPE_TXT}、{@link ImgUtil} - * @param logo logo 图片的byte[] - * @return 图片 Base64 编码字符串 - */ - public static String generateAsBase64DataUri(final String content, final QrConfig qrConfig, final String targetType, final byte[] logo) { - return generateAsBase64DataUri(content, qrConfig.setImg(ImgUtil.toImage(logo)), targetType); - } - /** * 生成 Base64 编码格式的二维码,以 String 形式表示 * diff --git a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java index 5ba43c95c..7da65ab5a 100755 --- a/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/qrcode/QrConfig.java @@ -316,6 +316,16 @@ public class QrConfig { return setImg(FileUtil.file(imgPath)); } + /** + * 设置二维码中的Logo文件 + * + * @param imageBytes 二维码中的Logo图片bytes表示形式 + * @return this; + */ + public QrConfig setImg(final byte[] imageBytes) { + return setImg(ImgUtil.toImage(imageBytes)); + } + /** * 设置二维码中的Logo文件 * diff --git a/hutool-extra/src/test/java/cn/hutool/extra/aop/AopTest.java b/hutool-extra/src/test/java/cn/hutool/extra/aop/AopTest.java index 2e61fde5b..209f4ae8e 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/aop/AopTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/aop/AopTest.java @@ -3,8 +3,8 @@ package cn.hutool.extra.aop; import cn.hutool.core.lang.Console; import cn.hutool.extra.aop.aspects.TimeIntervalAspect; import lombok.Data; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * AOP模块单元测试 @@ -17,7 +17,7 @@ public class AopTest { public void aopTest() { final Animal cat = ProxyUtil.proxy(new Cat(), TimeIntervalAspect.class); final String result = cat.eat(); - Assert.assertEquals("猫吃鱼", result); + Assertions.assertEquals("猫吃鱼", result); cat.seize(); } @@ -25,7 +25,7 @@ public class AopTest { public void aopByAutoCglibTest() { final Dog dog = ProxyUtil.proxy(new Dog(), TimeIntervalAspect.class); final String result = dog.eat(); - Assert.assertEquals("狗吃肉", result); + Assertions.assertEquals("狗吃肉", result); dog.seize(); } @@ -77,7 +77,7 @@ public class AopTest { final TagObj proxy = ProxyUtil.proxy(target, TimeIntervalAspect.class); //代理类获取标记tag (断言错误) - Assert.assertEquals("tag", proxy.getTag()); + Assertions.assertEquals("tag", proxy.getTag()); } @Data diff --git a/hutool-extra/src/test/java/cn/hutool/extra/cglib/CglibUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/cglib/CglibUtilTest.java index 293298946..54088d7e7 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/cglib/CglibUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/cglib/CglibUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.extra.cglib; import cn.hutool.core.convert.Convert; 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 CglibUtilTest { @@ -15,20 +15,20 @@ public class CglibUtilTest { bean.setValue2("123"); CglibUtil.copy(bean, otherBean); - Assert.assertEquals("Hello world", otherBean.getValue()); + Assertions.assertEquals("Hello world", otherBean.getValue()); // 无定义转换器,转换失败 - Assert.assertEquals(0, otherBean.getValue2()); + Assertions.assertEquals(0, otherBean.getValue2()); final OtherSampleBean otherBean2 = CglibUtil.copy(bean, OtherSampleBean.class); - Assert.assertEquals("Hello world", otherBean2.getValue()); + Assertions.assertEquals("Hello world", otherBean2.getValue()); // 无定义转换器,转换失败 - Assert.assertEquals(0, otherBean.getValue2()); + Assertions.assertEquals(0, otherBean.getValue2()); otherBean = new OtherSampleBean(); //自定义转换器 CglibUtil.copy(bean, otherBean, (value, target, context) -> Convert.convertQuietly(target, value)); - Assert.assertEquals("Hello world", otherBean.getValue()); - Assert.assertEquals(123, otherBean.getValue2()); + Assertions.assertEquals("Hello world", otherBean.getValue()); + Assertions.assertEquals(123, otherBean.getValue2()); } @Data diff --git a/hutool-extra/src/test/java/cn/hutool/extra/compress/ArchiverTest.java b/hutool-extra/src/test/java/cn/hutool/extra/compress/ArchiverTest.java index a180f4a7f..68613b0ee 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/compress/ArchiverTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/compress/ArchiverTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.lang.Console; import cn.hutool.core.util.CharsetUtil; import cn.hutool.extra.compress.archiver.StreamArchiver; import org.apache.commons.compress.archivers.ArchiveStreamFactory; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.File; @@ -14,7 +14,7 @@ import java.io.File; public class ArchiverTest { @Test - @Ignore + @Disabled public void zipTest() { final File file = FileUtil.file("d:/test/compress/test.zip"); StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.ZIP, file) @@ -26,7 +26,7 @@ public class ArchiverTest { } @Test - @Ignore + @Disabled public void tarTest() { final File file = FileUtil.file("d:/test/compress/test.tar"); StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.TAR, file) @@ -38,7 +38,7 @@ public class ArchiverTest { } @Test - @Ignore + @Disabled public void cpioTest() { final File file = FileUtil.file("d:/test/compress/test.cpio"); StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.CPIO, file) @@ -50,7 +50,7 @@ public class ArchiverTest { } @Test - @Ignore + @Disabled public void sevenZTest() { final File file = FileUtil.file("d:/test/compress/test.7z"); CompressUtil.createArchiver(CharsetUtil.UTF_8, ArchiveStreamFactory.SEVEN_Z, file) @@ -62,7 +62,7 @@ public class ArchiverTest { } @Test - @Ignore + @Disabled public void tgzTest() { final File file = FileUtil.file("d:/test/compress/test.tgz"); CompressUtil.createArchiver(CharsetUtil.UTF_8, "tgz", file) diff --git a/hutool-extra/src/test/java/cn/hutool/extra/compress/ExtractorTest.java b/hutool-extra/src/test/java/cn/hutool/extra/compress/ExtractorTest.java index bf2407e5f..c264acb19 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/compress/ExtractorTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/compress/ExtractorTest.java @@ -3,13 +3,13 @@ package cn.hutool.extra.compress; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.extra.compress.extractor.Extractor; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class ExtractorTest { @Test - @Ignore + @Disabled public void zipTest(){ final Extractor extractor = CompressUtil.createExtractor( CharsetUtil.defaultCharset(), @@ -19,7 +19,7 @@ public class ExtractorTest { } @Test - @Ignore + @Disabled public void sevenZTest(){ final Extractor extractor = CompressUtil.createExtractor( CharsetUtil.defaultCharset(), @@ -29,7 +29,7 @@ public class ExtractorTest { } @Test - @Ignore + @Disabled public void tgzTest(){ Extractor extractor = CompressUtil.createExtractor( CharsetUtil.defaultCharset(), diff --git a/hutool-extra/src/test/java/cn/hutool/extra/emoji/EmojiUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/emoji/EmojiUtilTest.java index f97a50b84..6182089c1 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/emoji/EmojiUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/emoji/EmojiUtilTest.java @@ -1,28 +1,28 @@ package cn.hutool.extra.emoji; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class EmojiUtilTest { @Test public void toUnicodeTest() { final String emoji = EmojiUtil.toUnicode(":smile:"); - Assert.assertEquals("😄", emoji); + Assertions.assertEquals("😄", emoji); } @Test public void toAliasTest() { final String alias = EmojiUtil.toAlias("😄"); - Assert.assertEquals(":smile:", alias); + Assertions.assertEquals(":smile:", alias); } @Test public void containsEmojiTest() { final boolean containsEmoji = EmojiUtil.containsEmoji("测试一下是否包含EMOJ:😄"); - Assert.assertTrue(containsEmoji); + Assertions.assertTrue(containsEmoji); final boolean notContainsEmoji = EmojiUtil.containsEmoji("不包含EMOJ:^_^"); - Assert.assertFalse(notContainsEmoji); + Assertions.assertFalse(notContainsEmoji); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/expression/AviatorTest.java b/hutool-extra/src/test/java/cn/hutool/extra/expression/AviatorTest.java index 41a3a7236..705987480 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/expression/AviatorTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/expression/AviatorTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.lang.Console; import cn.hutool.core.map.Dict; import cn.hutool.extra.expression.engine.aviator.AviatorEngine; 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.Date; @@ -22,19 +22,19 @@ public class AviatorTest { String exp = "\"[foo i=\"+ foo.i + \", f=\" + foo.f + \", date.year=\" + (foo.date.year+1900) + \", date.month=\" + foo.date.month + \", bars[0].name=\" + #foo.bars[0].name + \"]\""; String result = (String) engine.eval(exp, Dict.of().set("foo", foo)); - Assert.assertEquals("[foo i=100, f=3.14, date.year=2020, date.month=10, bars[0].name=bar]", result); + Assertions.assertEquals("[foo i=100, f=3.14, date.year=2020, date.month=10, bars[0].name=bar]", result); // Assignment. exp = "#foo.bars[0].name='hello aviator' ; #foo.bars[0].name"; result = (String) engine.eval(exp, Dict.of().set("foo", foo)); - Assert.assertEquals("hello aviator", result); - Assert.assertEquals("hello aviator", foo.bars[0].getName()); + Assertions.assertEquals("hello aviator", result); + Assertions.assertEquals("hello aviator", foo.bars[0].getName()); exp = "foo.bars[0] = nil ; foo.bars[0]"; result = (String) engine.eval(exp, Dict.of().set("foo", foo)); Console.log("Execute expression: " + exp); - Assert.assertNull(result); - Assert.assertNull(foo.bars[0]); + Assertions.assertNull(result); + Assertions.assertNull(foo.bars[0]); } @Data diff --git a/hutool-extra/src/test/java/cn/hutool/extra/expression/ExpressionUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/expression/ExpressionUtilTest.java index fc169d55e..e7ce4557c 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/expression/ExpressionUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/expression/ExpressionUtilTest.java @@ -7,8 +7,8 @@ import cn.hutool.extra.expression.engine.mvel.MvelEngine; import cn.hutool.extra.expression.engine.qlexpress.QLExpressEngine; import cn.hutool.extra.expression.engine.rhino.RhinoEngine; import cn.hutool.extra.expression.engine.spel.SpELEngine; -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; @@ -22,7 +22,7 @@ public class ExpressionUtilTest { .set("b", 45) .set("c", -199.100); final Object eval = ExpressionUtil.eval("a-(b-c)", dict); - Assert.assertEquals(-143.8, (double)eval, 0); + Assertions.assertEquals(-143.8, (double)eval, 0); } @Test @@ -34,7 +34,7 @@ public class ExpressionUtilTest { .set("b", 45) .set("c", -199.100); final Object eval = engine.eval("a-(b-c)", dict); - Assert.assertEquals(-143.8, (double)eval, 0); + Assertions.assertEquals(-143.8, (double)eval, 0); } @Test @@ -45,7 +45,7 @@ public class ExpressionUtilTest { final Map map2=new HashMap<>(); map2.put("a", 1); final Object eval1 = engine.eval(exps2, map2); - Assert.assertEquals(100, eval1); + Assertions.assertEquals(100, eval1); } @Test @@ -57,7 +57,7 @@ public class ExpressionUtilTest { .set("b", 45) .set("c", -199.100); final Object eval = engine.eval("a-(b-c)", dict); - Assert.assertEquals(-143.8, (double)eval, 0); + Assertions.assertEquals(-143.8, (double)eval, 0); } @Test @@ -69,7 +69,7 @@ public class ExpressionUtilTest { .set("b", 45) .set("c", -199.100); final Object eval = engine.eval("a-(b-c)", dict); - Assert.assertEquals(-143.8, (double)eval, 0); + Assertions.assertEquals(-143.8, (double)eval, 0); } @Test @@ -81,7 +81,7 @@ public class ExpressionUtilTest { .set("b", 45) .set("c", -199.100); final Object eval = engine.eval("#a-(#b-#c)", dict); - Assert.assertEquals(-143.8, (double)eval, 0); + Assertions.assertEquals(-143.8, (double)eval, 0); } @Test @@ -93,7 +93,7 @@ public class ExpressionUtilTest { .set("b", 45) .set("c", -199.100); final Object eval = engine.eval("a-(b-c)", dict); - Assert.assertEquals(-143.8, (double)eval, 0); + Assertions.assertEquals(-143.8, (double)eval, 0); } @Test @@ -105,7 +105,7 @@ public class ExpressionUtilTest { .set("b", 45) .set("c", -199.100); final Object eval = engine.eval("a-(b-c)", dict); - Assert.assertEquals(-143.8, (double)eval, 0); + Assertions.assertEquals(-143.8, (double)eval, 0); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java b/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java index ddc5b3fe0..d5e75cdc3 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/ftp/FtpTest.java @@ -1,18 +1,18 @@ package cn.hutool.extra.ftp; -import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; import cn.hutool.extra.ssh.Sftp; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.List; public class FtpTest { @Test - @Ignore + @Disabled public void cdTest() { final Ftp ftp = new Ftp("looly.centos"); @@ -23,7 +23,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void uploadTest() { final Ftp ftp = new Ftp("localhost"); @@ -34,7 +34,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void reconnectIfTimeoutTest() throws InterruptedException { final Ftp ftp = new Ftp("looly.centos"); @@ -58,7 +58,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void recursiveDownloadFolder() { final Ftp ftp = new Ftp("looly.centos"); ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download")); @@ -67,7 +67,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void recursiveDownloadFolderSftp() { final Sftp ftp = new Sftp("127.0.0.1", 22, "test", "test"); @@ -79,7 +79,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void downloadTest() { final Ftp ftp = new Ftp("localhost"); @@ -94,7 +94,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void isDirTest() throws Exception { try (final Ftp ftp = new Ftp("127.0.0.1", 21)) { Console.log(ftp.pwd()); @@ -104,7 +104,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void existSftpTest() { try (final Sftp ftp = new Sftp("127.0.0.1", 22, "test", "test")) { Console.log(ftp.pwd()); @@ -127,7 +127,7 @@ public class FtpTest { } @Test - @Ignore + @Disabled public void existFtpTest() throws Exception { try (final Ftp ftp = new Ftp("127.0.0.1", 21)) { Console.log(ftp.pwd()); diff --git a/hutool-extra/src/test/java/cn/hutool/extra/mail/MailAccountTest.java b/hutool-extra/src/test/java/cn/hutool/extra/mail/MailAccountTest.java index 81c71a24c..7465965ff 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/mail/MailAccountTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/mail/MailAccountTest.java @@ -1,9 +1,9 @@ package cn.hutool.extra.mail; import com.sun.mail.util.MailSSLSocketFactory; -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.security.GeneralSecurityException; @@ -19,8 +19,8 @@ public class MailAccountTest { final MailAccount account = GlobalMailAccount.INSTANCE.getAccount(); account.getSmtpProps(); - Assert.assertNotNull(account.getCharset()); - Assert.assertTrue(account.isSslEnable()); + Assertions.assertNotNull(account.getCharset()); + Assertions.assertTrue(account.isSslEnable()); } /** @@ -31,7 +31,7 @@ public class MailAccountTest { * 已经测试通过 */ @Test - @Ignore + @Disabled public void customPropertyTest() throws GeneralSecurityException { final MailAccount mailAccount = new MailAccount(); mailAccount.setFrom("xxx@xxx.com"); diff --git a/hutool-extra/src/test/java/cn/hutool/extra/mail/MailTest.java b/hutool-extra/src/test/java/cn/hutool/extra/mail/MailTest.java index bf84e765d..306c2d2cb 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/mail/MailTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/mail/MailTest.java @@ -1,9 +1,9 @@ package cn.hutool.extra.mail; import cn.hutool.core.io.file.FileUtil; -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.InputStream; import java.util.HashMap; @@ -18,20 +18,20 @@ import java.util.Properties; public class MailTest { @Test - @Ignore + @Disabled public void sendWithFileTest() { MailUtil.send("hutool@foxmail.com", "测试", "

邮件来自Hutool测试

", true, FileUtil.file("d:/测试附件文本.txt")); } @Test - @Ignore + @Disabled public void sendWithLongNameFileTest() { //附件名长度大于60时的测试 MailUtil.send("hutool@foxmail.com", "测试", "

邮件来自Hutool测试

", true, FileUtil.file("d:/6-LongLong一阶段平台建设周报2018.3.12-3.16.xlsx")); } @Test - @Ignore + @Disabled public void sendWithImageTest() { final Map map = new HashMap<>(); map.put("testImage", FileUtil.getInputStream("f:/test/me.png")); @@ -39,13 +39,13 @@ public class MailTest { } @Test - @Ignore + @Disabled public void sendHtmlTest() { MailUtil.send("hutool@foxmail.com", "测试", "

邮件来自Hutool测试

", true); } @Test - @Ignore + @Disabled public void sendByAccountTest() { final MailAccount account = new MailAccount(); account.setHost("smtp.yeah.net"); @@ -64,11 +64,11 @@ public class MailTest { account.setDebug(true); account.defaultIfEmpty(); final Properties props = account.getSmtpProps(); - Assert.assertEquals("true", props.getProperty("mail.debug")); + Assertions.assertEquals("true", props.getProperty("mail.debug")); } @Test - @Ignore + @Disabled public void sendHtmlWithPicsTest() { HashMap map = new HashMap<>(); map.put("abc", FileUtil.getInputStream("D:/test/abc.png")); diff --git a/hutool-extra/src/test/java/cn/hutool/extra/management/JavaInfoTest.java b/hutool-extra/src/test/java/cn/hutool/extra/management/JavaInfoTest.java index 30aff77b6..b6c3f4bd3 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/management/JavaInfoTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/management/JavaInfoTest.java @@ -1,7 +1,7 @@ package cn.hutool.extra.management; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @see JavaInfo @@ -11,8 +11,8 @@ public class JavaInfoTest { @Test public void isJavaVersionAtLeastTest() { final int versionInt = ManagementUtil.getJavaInfo().getVersionIntSimple(); - Assert.assertTrue(versionInt >= 8); + Assertions.assertTrue(versionInt >= 8); final boolean javaVersionAtLeast1 = ManagementUtil.getJavaInfo().isJavaVersionAtLeast(1.8f); - Assert.assertTrue(javaVersionAtLeast1); + Assertions.assertTrue(javaVersionAtLeast1); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/management/OshiPrintTest.java b/hutool-extra/src/test/java/cn/hutool/extra/management/OshiPrintTest.java index 6c8744ebd..775c570e4 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/management/OshiPrintTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/management/OshiPrintTest.java @@ -2,14 +2,14 @@ package cn.hutool.extra.management; import cn.hutool.core.lang.Console; import cn.hutool.extra.management.oshi.OshiUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -@Ignore +@Disabled public class OshiPrintTest { @Test - @Ignore + @Disabled public void printCpuInfo(){ Console.log(OshiUtil.getCpuInfo()); } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/management/OshiTest.java b/hutool-extra/src/test/java/cn/hutool/extra/management/OshiTest.java index ce1fec97b..bcd9f4565 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/management/OshiTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/management/OshiTest.java @@ -3,9 +3,9 @@ package cn.hutool.extra.management; import cn.hutool.core.lang.Console; import cn.hutool.extra.management.oshi.CpuInfo; import cn.hutool.extra.management.oshi.OshiUtil; -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 oshi.software.os.OSProcess; /** @@ -16,23 +16,23 @@ public class OshiTest { @Test public void getMemoryTest() { final long total = OshiUtil.getMemory().getTotal(); - Assert.assertTrue(total > 0); + Assertions.assertTrue(total > 0); } @Test public void getCupInfo() { final CpuInfo cpuInfo = OshiUtil.getCpuInfo(); - Assert.assertNotNull(cpuInfo); + Assertions.assertNotNull(cpuInfo); } @Test public void getCurrentProcessTest() { final OSProcess currentProcess = OshiUtil.getCurrentProcess(); - Assert.assertEquals("java", currentProcess.getName()); + Assertions.assertEquals("java", currentProcess.getName()); } @Test - @Ignore + @Disabled public void getUsedTest() { int i = 0; while (i < 1000) { diff --git a/hutool-extra/src/test/java/cn/hutool/extra/management/SystemUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/management/SystemUtilTest.java index 6032b5ac9..1be7321fb 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/management/SystemUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/management/SystemUtilTest.java @@ -1,16 +1,16 @@ package cn.hutool.extra.management; import cn.hutool.core.util.SystemUtil; -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; public class SystemUtilTest { @Test - @Ignore + @Disabled public void dumpTest() { ManagementUtil.dumpSystemInfo(); } @@ -18,45 +18,45 @@ public class SystemUtilTest { @Test public void getCurrentPidTest() { final long pid = ManagementUtil.getCurrentPID(); - Assert.assertTrue(pid > 0); + Assertions.assertTrue(pid > 0); } @Test public void getJavaInfoTest() { final JavaInfo javaInfo = ManagementUtil.getJavaInfo(); - Assert.assertNotNull(javaInfo); + Assertions.assertNotNull(javaInfo); } @Test public void getJavaRuntimeInfoTest() { final JavaRuntimeInfo info = ManagementUtil.getJavaRuntimeInfo(); - Assert.assertNotNull(info); + Assertions.assertNotNull(info); } @Test public void getOsInfoTest() { final OsInfo osInfo = ManagementUtil.getOsInfo(); - Assert.assertNotNull(osInfo); + Assertions.assertNotNull(osInfo); } @Test public void getHostInfo() { final HostInfo hostInfo = ManagementUtil.getHostInfo(); - Assert.assertNotNull(hostInfo); + Assertions.assertNotNull(hostInfo); } @Test public void getUserInfoTest(){ // https://gitee.com/dromara/hutool/issues/I3NM39 final UserInfo userInfo = ManagementUtil.getUserInfo(); - Assert.assertTrue(userInfo.getTempDir().endsWith(File.separator)); + Assertions.assertTrue(userInfo.getTempDir().endsWith(File.separator)); } @Test public void getOsVersionTest(){ String s = SystemUtil.get("os.name"); - Assert.assertNotNull(s); + Assertions.assertNotNull(s); s = SystemUtil.get("os.version"); - Assert.assertNotNull(s); + Assertions.assertNotNull(s); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Bopomofo4jTest.java b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Bopomofo4jTest.java index 86e97cd6d..60d0ed112 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Bopomofo4jTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Bopomofo4jTest.java @@ -1,8 +1,8 @@ package cn.hutool.extra.pinyin; import cn.hutool.extra.pinyin.engine.bopomofo4j.Bopomofo4jEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Bopomofo4jTest { @@ -11,13 +11,13 @@ public class Bopomofo4jTest { @Test public void getFirstLetterByBopomofo4jTest(){ final String result = engine.getFirstLetter("林海", ""); - Assert.assertEquals("lh", result); + Assertions.assertEquals("lh", result); } @Test public void getPinyinByBopomofo4jTest() { final String pinyin = engine.getPinyin("你好h", " "); - Assert.assertEquals("ni haoh", pinyin); + Assertions.assertEquals("ni haoh", pinyin); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/HoubbPinyinTest.java b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/HoubbPinyinTest.java index 624c8b133..06dc79131 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/HoubbPinyinTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/HoubbPinyinTest.java @@ -1,8 +1,8 @@ package cn.hutool.extra.pinyin; import cn.hutool.extra.pinyin.engine.houbbpinyin.HoubbPinyinEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class HoubbPinyinTest { @@ -11,12 +11,12 @@ public class HoubbPinyinTest { @Test public void getFirstLetterTest(){ final String result = engine.getFirstLetter("林海", ""); - Assert.assertEquals("lh", result); + Assertions.assertEquals("lh", result); } @Test public void getPinyinTest() { final String pinyin = engine.getPinyin("你好h", " "); - Assert.assertEquals("ni hao h", pinyin); + Assertions.assertEquals("ni hao h", pinyin); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/JpinyinTest.java b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/JpinyinTest.java index e8a2c41c0..32891d9da 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/JpinyinTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/JpinyinTest.java @@ -1,8 +1,8 @@ package cn.hutool.extra.pinyin; import cn.hutool.extra.pinyin.engine.jpinyin.JPinyinEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JpinyinTest { @@ -11,13 +11,13 @@ public class JpinyinTest { @Test public void getFirstLetterByPinyin4jTest(){ final String result = engine.getFirstLetter("林海", ""); - Assert.assertEquals("lh", result); + Assertions.assertEquals("lh", result); } @Test public void getPinyinByPinyin4jTest() { final String pinyin = engine.getPinyin("你好h", " "); - Assert.assertEquals("ni hao h", pinyin); + Assertions.assertEquals("ni hao h", pinyin); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Pinyin4jTest.java b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Pinyin4jTest.java index 3af1d8ed3..f69ea714a 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Pinyin4jTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/Pinyin4jTest.java @@ -1,8 +1,8 @@ package cn.hutool.extra.pinyin; import cn.hutool.extra.pinyin.engine.pinyin4j.Pinyin4jEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Pinyin4jTest { @@ -11,12 +11,12 @@ public class Pinyin4jTest { @Test public void getFirstLetterByPinyin4jTest(){ final String result = engine.getFirstLetter("林海", ""); - Assert.assertEquals("lh", result); + Assertions.assertEquals("lh", result); } @Test public void getPinyinByPinyin4jTest() { final String pinyin = engine.getPinyin("你好h", " "); - Assert.assertEquals("ni hao h", pinyin); + Assertions.assertEquals("ni hao h", pinyin); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/PinyinUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/PinyinUtilTest.java index dfe17edf8..e56791393 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/PinyinUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/PinyinUtilTest.java @@ -1,25 +1,25 @@ package cn.hutool.extra.pinyin; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PinyinUtilTest { @Test public void getPinyinTest(){ final String pinyin = PinyinUtil.getPinyin("你好怡", " "); - Assert.assertEquals("ni hao yi", pinyin); + Assertions.assertEquals("ni hao yi", pinyin); } @Test public void getFirstLetterTest(){ final String result = PinyinUtil.getFirstLetter("H是第一个", ", "); - Assert.assertEquals("h, s, d, y, g", result); + Assertions.assertEquals("h, s, d, y, g", result); } @Test public void getFirstLetterTest2(){ final String result = PinyinUtil.getFirstLetter("崞阳", ", "); - Assert.assertEquals("g, y", result); + Assertions.assertEquals("g, y", result); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/TinyPinyinTest.java b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/TinyPinyinTest.java index 87e7b14ff..280ad2c7f 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/pinyin/TinyPinyinTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/pinyin/TinyPinyinTest.java @@ -1,8 +1,8 @@ package cn.hutool.extra.pinyin; import cn.hutool.extra.pinyin.engine.tinypinyin.TinyPinyinEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TinyPinyinTest { @@ -11,12 +11,12 @@ public class TinyPinyinTest { @Test public void getFirstLetterByPinyin4jTest(){ final String result = engine.getFirstLetter("林海", ""); - Assert.assertEquals("lh", result); + Assertions.assertEquals("lh", result); } @Test public void getPinyinByPinyin4jTest() { final String pinyin = engine.getPinyin("你好h", " "); - Assert.assertEquals("ni hao h", pinyin); + Assertions.assertEquals("ni hao h", pinyin); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/qrcode/Discussions3030Test.java b/hutool-extra/src/test/java/cn/hutool/extra/qrcode/Discussions3030Test.java new file mode 100644 index 000000000..3224589a0 --- /dev/null +++ b/hutool-extra/src/test/java/cn/hutool/extra/qrcode/Discussions3030Test.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 looly(loolly@aliyun.com) + * Hutool is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package cn.hutool.extra.qrcode; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static cn.hutool.core.io.file.FileUtil.file; + +public class Discussions3030Test { + @Test + @Disabled + public void name() { + //扫描二维码后 对应的链接正常 + String path = "https://juejin.cn/backend?name=%E5%BC%A0%E7%8F%8A&school=%E5%8E%A6%E9%97%A8%E5%A4%A7%E5%AD%A6"; + QrCodeUtil.generate(path, QrConfig.of(), file("d:/test/3030.png")); + } +} diff --git a/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java index 02d3b42f0..9b776e43d 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/qrcode/QrCodeUtilTest.java @@ -1,17 +1,17 @@ package cn.hutool.extra.qrcode; import cn.hutool.core.codec.binary.Base64; -import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.text.StrUtil; import cn.hutool.swing.img.ImgUtil; import com.google.zxing.BarcodeFormat; import com.google.zxing.datamatrix.encoder.SymbolShapeHint; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; -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.awt.Color; import java.awt.image.BufferedImage; @@ -28,11 +28,11 @@ public class QrCodeUtilTest { @Test public void generateTest() { final BufferedImage image = QrCodeUtil.generate("https://hutool.cn/", 300, 300); - Assert.assertNotNull(image); + Assertions.assertNotNull(image); } @Test - @Ignore + @Disabled public void generateCustomTest() { final QrConfig config = QrConfig.of(); config.setMargin(0); @@ -45,25 +45,25 @@ public class QrCodeUtilTest { } @Test - @Ignore + @Disabled public void generateWithLogoTest() { final String icon = FileUtil.isWindows() ? "d:/test/pic/logo.jpg" : "~/Desktop/hutool/pic/logo.jpg"; final String targetPath = FileUtil.isWindows() ? "d:/test/qrcodeWithLogo.jpg" : "~/Desktop/hutool/qrcodeWithLogo.jpg"; QrCodeUtil.generate(// - "https://hutool.cn/", // - QrConfig.of().setImg(icon), // - FileUtil.touch(targetPath)); + "https://hutool.cn/", // + QrConfig.of().setImg(icon), // + FileUtil.touch(targetPath)); } @Test - @Ignore + @Disabled public void decodeTest() { final String decode = QrCodeUtil.decode(FileUtil.file("d:/test/pic/qr.png")); Console.log(decode); } @Test - @Ignore + @Disabled public void decodeTest2() { // 条形码 final String decode = QrCodeUtil.decode(FileUtil.file("d:/test/90.png")); @@ -74,24 +74,27 @@ public class QrCodeUtilTest { public void generateAsBase64AndDecodeTest() { final String url = "https://hutool.cn/"; String base64 = QrCodeUtil.generateAsBase64DataUri(url, new QrConfig(400, 400), "png"); - Assert.assertNotNull(base64); + Assertions.assertNotNull(base64); base64 = StrUtil.removePrefix(base64, "data:image/png;base64,"); final String decode = QrCodeUtil.decode(IoUtil.toStream(Base64.decode(base64))); - Assert.assertEquals(url, decode); + Assertions.assertEquals(url, decode); } @Test - @Ignore + @Disabled public void generateAsBase64Test2() { final byte[] bytes = FileUtil.readBytes(new File("d:/test/qr.png")); - final String base641 = QrCodeUtil.generateAsBase64DataUri("https://hutool.cn/", - new QrConfig(400, 400), "png", bytes); - Assert.assertNotNull(base641); + final String base641 = QrCodeUtil.generateAsBase64DataUri( + "https://hutool.cn/", + QrConfig.of(400, 400).setImg(bytes), + "png" + ); + Assertions.assertNotNull(base641); } @Test - @Ignore + @Disabled public void decodeTest3() { final String decode = QrCodeUtil.decode(ImgUtil.read("d:/test/qr_a.png"), false, true); Console.log(decode); @@ -100,7 +103,7 @@ public class QrCodeUtilTest { @Test public void pdf417Test() { final BufferedImage image = QrCodeUtil.generate("content111", QrConfig.of().setFormat(BarcodeFormat.PDF_417)); - Assert.assertNotNull(image); + Assertions.assertNotNull(image); } @Test @@ -108,49 +111,49 @@ public class QrCodeUtilTest { final QrConfig qrConfig = QrConfig.of(); qrConfig.setShapeHint(SymbolShapeHint.FORCE_RECTANGLE); final BufferedImage image = QrCodeUtil.generate("content111", qrConfig.setFormat(BarcodeFormat.DATA_MATRIX)); - Assert.assertNotNull(image); + Assertions.assertNotNull(image); final QrConfig config = QrConfig.of(); config.setShapeHint(SymbolShapeHint.FORCE_SQUARE); final BufferedImage imageSquare = QrCodeUtil.generate("content111", qrConfig.setFormat(BarcodeFormat.DATA_MATRIX)); - Assert.assertNotNull(imageSquare); + Assertions.assertNotNull(imageSquare); } @Test - @Ignore + @Disabled public void generateSvgTest() { final QrConfig qrConfig = QrConfig.of() - .setImg("d:/test/pic/logo.jpg") - .setForeColor(Color.blue) - .setBackColor(Color.pink) - .setRatio(8) - .setErrorCorrection(ErrorCorrectionLevel.M) - .setMargin(1); + .setImg("d:/test/pic/logo.jpg") + .setForeColor(Color.blue) + .setBackColor(Color.pink) + .setRatio(8) + .setErrorCorrection(ErrorCorrectionLevel.M) + .setMargin(1); final String svg = QrCodeUtil.generateAsSvg("https://hutool.cn/", qrConfig); - Assert.assertNotNull(svg); + Assertions.assertNotNull(svg); FileUtil.writeString(svg, FileUtil.touch("d:/test/hutool_qr.svg"), StandardCharsets.UTF_8); } @Test public void generateAsciiArtTest() { final QrConfig qrConfig = QrConfig.of() - .setForeColor(Color.BLUE) - .setBackColor(Color.MAGENTA) - .setWidth(0) - .setHeight(0).setMargin(1); - final String asciiArt = QrCodeUtil.generateAsAsciiArt("https://hutool.cn/",qrConfig); - Assert.assertNotNull(asciiArt); + .setForeColor(Color.BLUE) + .setBackColor(Color.MAGENTA) + .setWidth(0) + .setHeight(0).setMargin(1); + final String asciiArt = QrCodeUtil.generateAsAsciiArt("https://hutool.cn/", qrConfig); + Assertions.assertNotNull(asciiArt); //Console.log(asciiArt); } @Test public void generateAsciiArtNoCustomColorTest() { final QrConfig qrConfig = QrConfig.of() - .setForeColor(null) - .setBackColor(null) - .setWidth(0) - .setHeight(0).setMargin(1); - final String asciiArt = QrCodeUtil.generateAsAsciiArt("https://hutool.cn/",qrConfig); - Assert.assertNotNull(asciiArt); + .setForeColor(null) + .setBackColor(null) + .setWidth(0) + .setHeight(0).setMargin(1); + final String asciiArt = QrCodeUtil.generateAsAsciiArt("https://hutool.cn/", qrConfig); + Assertions.assertNotNull(asciiArt); //Console.log(asciiArt); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/script/ScriptUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/script/ScriptUtilTest.java index b5d37de20..3a632c0f9 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/script/ScriptUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/script/ScriptUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.extra.script; import cn.hutool.core.exceptions.UtilException; import cn.hutool.core.io.resource.ResourceUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.script.CompiledScript; import javax.script.ScriptException; @@ -34,6 +34,6 @@ public class ScriptUtilTest { @Test public void invokeTest() { final Object result = ScriptUtil.invoke(ResourceUtil.readUtf8Str("filter1.js"), "filter1", 2, 1); - Assert.assertTrue((Boolean) result); + Assertions.assertTrue((Boolean) result); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/servlet/ServletUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/servlet/ServletUtilTest.java index 61451d12b..c311dbbcf 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/servlet/ServletUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/servlet/ServletUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.extra.servlet; import cn.hutool.core.util.ByteUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayInputStream; @@ -18,7 +18,7 @@ import java.nio.charset.StandardCharsets; public class ServletUtilTest { @Test - @Ignore + @Disabled public void writeTest() { final HttpServletResponse response = null; final byte[] bytes = ByteUtil.toUtf8Bytes("地球是我们共同的家园,需要大家珍惜."); @@ -35,7 +35,7 @@ public class ServletUtilTest { } @Test - @Ignore + @Disabled public void jakartaWriteTest() { final jakarta.servlet.http.HttpServletResponse response = null; final byte[] bytes = ByteUtil.toUtf8Bytes("地球是我们共同的家园,需要大家珍惜."); diff --git a/hutool-extra/src/test/java/cn/hutool/extra/spring/EnableSpringUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/spring/EnableSpringUtilTest.java index 5d48569c0..dc97700cb 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/spring/EnableSpringUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/spring/EnableSpringUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.extra.spring; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -17,8 +17,8 @@ public class EnableSpringUtilTest { @Test public void test() { // 使用@EnableSpringUtil注解后, 能获取上下文 - Assert.assertNotNull(SpringUtil.getApplicationContext()); + Assertions.assertNotNull(SpringUtil.getApplicationContext()); // 不使用时, 为null -// Assert.assertNull(SpringUtil.getApplicationContext()); +// Assertions.assertNull(SpringUtil.getApplicationContext()); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilTest.java index 3c88ea126..5b6ac582b 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilTest.java @@ -1,22 +1,22 @@ package cn.hutool.extra.spring; -import cn.hutool.core.reflect.TypeReference; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.reflect.TypeReference; import lombok.Data; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = {SpringUtil.class, SpringUtilTest.Demo2.class}) //@Import(cn.hutool.extra.spring.SpringUtil.class) public class SpringUtilTest { @@ -32,8 +32,8 @@ public class SpringUtilTest { SpringUtil.registerBean("registerBean", registerBean); final Demo2 registerBean2 = SpringUtil.getBean("registerBean"); - Assert.assertEquals(123, registerBean2.getId()); - Assert.assertEquals("222", registerBean2.getName()); + Assertions.assertEquals(123, registerBean2.getId()); + Assertions.assertEquals("222", registerBean2.getName()); } @@ -44,12 +44,12 @@ public class SpringUtilTest { @Test public void unregisterBeanTest() { registerTestAutoWired(); - Assert.assertNotNull(SpringUtil.getBean("testAutoWired")); + Assertions.assertNotNull(SpringUtil.getBean("testAutoWired")); SpringUtil.unregisterBean("testAutoWired1"); try { SpringUtil.getBean("testAutoWired"); } catch (final NoSuchBeanDefinitionException e) { - Assert.assertEquals(e.getClass(), NoSuchBeanDefinitionException.class); + Assertions.assertEquals(e.getClass(), NoSuchBeanDefinitionException.class); } } @@ -64,26 +64,26 @@ public class SpringUtilTest { SpringUtil.registerBean("testAutoWired", testAutoWired); testAutoWired = SpringUtil.getBean("testAutoWired"); - Assert.assertNotNull(testAutoWired); - Assert.assertNotNull(testAutoWired.getAutowiredBean()); - Assert.assertNotNull(testAutoWired.getResourceBean()); - Assert.assertEquals("123", testAutoWired.getAutowiredBean().getId()); + Assertions.assertNotNull(testAutoWired); + Assertions.assertNotNull(testAutoWired.getAutowiredBean()); + Assertions.assertNotNull(testAutoWired.getResourceBean()); + Assertions.assertEquals("123", testAutoWired.getAutowiredBean().getId()); } @Test public void getBeanTest(){ final Demo2 testDemo = SpringUtil.getBean("testDemo"); - Assert.assertEquals(12345, testDemo.getId()); - Assert.assertEquals("test", testDemo.getName()); + Assertions.assertEquals(12345, testDemo.getId()); + Assertions.assertEquals("test", testDemo.getName()); } @Test public void getBeanWithTypeReferenceTest() { final Map mapBean = SpringUtil.getBean(new TypeReference>() {}); - Assert.assertNotNull(mapBean); - Assert.assertEquals("value1", mapBean.get("key1")); - Assert.assertEquals("value2", mapBean.get("key2")); + Assertions.assertNotNull(mapBean); + Assertions.assertEquals("value1", mapBean.get("key1")); + Assertions.assertEquals("value2", mapBean.get("key2")); } @Data diff --git a/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilWithAutoConfigTest.java b/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilWithAutoConfigTest.java index f35b5ae76..3c21320fe 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilWithAutoConfigTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/spring/SpringUtilWithAutoConfigTest.java @@ -1,20 +1,20 @@ package cn.hutool.extra.spring; -import cn.hutool.core.reflect.TypeReference; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.reflect.TypeReference; import lombok.Data; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.HashMap; import java.util.Map; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(classes = {SpringUtilWithAutoConfigTest.Demo2.class}) //@Import(cn.hutool.extra.spring.SpringUtil.class) @EnableAutoConfiguration @@ -31,23 +31,23 @@ public class SpringUtilWithAutoConfigTest { SpringUtil.registerBean("registerBean", registerBean); final Demo2 registerBean2 = SpringUtil.getBean("registerBean"); - Assert.assertEquals(123, registerBean2.getId()); - Assert.assertEquals("222", registerBean2.getName()); + Assertions.assertEquals(123, registerBean2.getId()); + Assertions.assertEquals("222", registerBean2.getName()); } @Test public void getBeanTest(){ final Demo2 testDemo = SpringUtil.getBean("testDemo"); - Assert.assertEquals(12345, testDemo.getId()); - Assert.assertEquals("test", testDemo.getName()); + Assertions.assertEquals(12345, testDemo.getId()); + Assertions.assertEquals("test", testDemo.getName()); } @Test public void getBeanWithTypeReferenceTest() { final Map mapBean = SpringUtil.getBean(new TypeReference>() {}); - Assert.assertNotNull(mapBean); - Assert.assertEquals("value1", mapBean.get("key1")); - Assert.assertEquals("value2", mapBean.get("key2")); + Assertions.assertNotNull(mapBean); + Assertions.assertEquals("value1", mapBean.get("key1")); + Assertions.assertEquals("value2", mapBean.get("key2")); } @Data diff --git a/hutool-extra/src/test/java/cn/hutool/extra/ssh/JschUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/ssh/JschUtilTest.java index b03927c55..218456363 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/ssh/JschUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/ssh/JschUtilTest.java @@ -3,9 +3,9 @@ package cn.hutool.extra.ssh; import cn.hutool.core.io.IoUtil; import cn.hutool.core.lang.Console; import com.jcraft.jsch.Session; -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; /** * Jsch工具类单元测试 @@ -16,7 +16,7 @@ import org.junit.Test; public class JschUtilTest { @Test - @Ignore + @Disabled public void bindPortTest() { //新建会话,此会话用于ssh连接到跳板机(堡垒机),此处为10.1.1.1:22 final Session session = JschUtil.getSession("looly.centos", 22, "test", "123456"); @@ -26,19 +26,19 @@ public class JschUtilTest { @Test - @Ignore + @Disabled public void bindRemotePort() { // 建立会话 final Session session = JschUtil.getSession("looly.centos", 22, "test", "123456"); // 绑定ssh服务端8089端口到本机的8000端口上 final boolean b = JschUtil.bindRemotePort(session, 8089, "localhost", 8000); - Assert.assertTrue(b); + Assertions.assertTrue(b); // 保证一直运行 } @SuppressWarnings("resource") @Test - @Ignore + @Disabled public void sftpTest() { final Session session = JschUtil.getSession("looly.centos", 22, "root", "123456"); final Sftp sftp = JschUtil.createSftp(session); @@ -47,7 +47,7 @@ public class JschUtilTest { } @Test - @Ignore + @Disabled public void reconnectIfTimeoutTest() throws InterruptedException { final Session session = JschUtil.getSession("sunnyserver", 22,"mysftp","liuyang1234"); final Sftp sftp = JschUtil.createSftp(session); @@ -75,7 +75,7 @@ public class JschUtilTest { } @Test - @Ignore + @Disabled public void getSessionTest(){ JschUtil.getSession("192.168.1.134", 22, "root", "aaa", null); } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java b/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java index 42e6e7d68..681d3ca66 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/ssh/SftpTest.java @@ -2,8 +2,8 @@ package cn.hutool.extra.ssh; import cn.hutool.core.util.CharsetUtil; import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.List; @@ -19,13 +19,13 @@ public class SftpTest { private SshjSftp sshjSftp; @Before - @Ignore + @Disabled public void init() { sshjSftp = new SshjSftp("ip", 22, "test", "test", CharsetUtil.UTF_8); } @Test - @Ignore + @Disabled public void lsTest() { final List files = sshjSftp.ls("/"); if (files != null && !files.isEmpty()) { @@ -34,33 +34,33 @@ public class SftpTest { } @Test - @Ignore + @Disabled public void downloadTest() { sshjSftp.recursiveDownloadFolder("/home/test/temp", new File("C:\\Users\\akwangl\\Downloads\\temp")); } @Test - @Ignore + @Disabled public void uploadTest() { sshjSftp.uploadFile("/home/test/temp/", new File("C:\\Users\\akwangl\\Downloads\\temp\\辽宁_20190718_104324.CIME")); } @Test - @Ignore + @Disabled public void mkDirTest() { final boolean flag = sshjSftp.mkdir("/home/test/temp"); System.out.println("是否创建成功: " + flag); } @Test - @Ignore + @Disabled public void mkDirsTest() { // 在当前目录下批量创建目录 sshjSftp.mkDirs("/home/test/temp"); } @Test - @Ignore + @Disabled public void delDirTest() { sshjSftp.delDir("/home/test/temp"); } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/template/JetbrickTest.java b/hutool-extra/src/test/java/cn/hutool/extra/template/JetbrickTest.java index 0c6b95f78..5951fa121 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/template/JetbrickTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/template/JetbrickTest.java @@ -3,8 +3,8 @@ package cn.hutool.extra.template; import cn.hutool.core.map.Dict; import cn.hutool.core.text.StrUtil; import cn.hutool.extra.template.engine.jetbrick.JetbrickEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JetbrickTest { @@ -16,7 +16,7 @@ public class JetbrickTest { final TemplateEngine engine = TemplateUtil.createEngine(config); final Template template = engine.getTemplate("jetbrick_test.jetx"); final String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("你好,hutool", StrUtil.trim(result)); + Assertions.assertEquals("你好,hutool", StrUtil.trim(result)); } @Test @@ -27,6 +27,6 @@ public class JetbrickTest { final TemplateEngine engine = TemplateUtil.createEngine(config); final Template template = engine.getTemplate("hello,${name}"); final String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", StrUtil.trim(result)); + Assertions.assertEquals("hello,hutool", StrUtil.trim(result)); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/template/TemplateUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/template/TemplateUtilTest.java index 16fdf6ac7..44a334e07 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/template/TemplateUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/template/TemplateUtilTest.java @@ -10,9 +10,9 @@ import cn.hutool.extra.template.engine.rythm.RythmEngine; import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine; import cn.hutool.extra.template.engine.velocity.VelocityEngine; import cn.hutool.extra.template.engine.wit.WitEngine; -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.util.HashMap; @@ -32,13 +32,13 @@ public class TemplateUtilTest { TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig()); final Template template = engine.getTemplate("hello,${name}"); final String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result); + Assertions.assertEquals("hello,hutool", result); // classpath中获取模板 engine = TemplateUtil.createEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH)); final Template template2 = engine.getTemplate("beetl_test.btl"); final String result2 = template2.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result2); + Assertions.assertEquals("hello,hutool", result2); } @Test @@ -47,13 +47,13 @@ public class TemplateUtilTest { TemplateEngine engine = new BeetlEngine(new TemplateConfig("templates")); final Template template = engine.getTemplate("hello,${name}"); final String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result); + Assertions.assertEquals("hello,hutool", result); // classpath中获取模板 engine = new BeetlEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH)); final Template template2 = engine.getTemplate("beetl_test.btl"); final String result2 = template2.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result2); + Assertions.assertEquals("hello,hutool", result2); } @Test @@ -63,12 +63,12 @@ public class TemplateUtilTest { new TemplateConfig("templates").setCustomEngine(RythmEngine.class)); final Template template = engine.getTemplate("hello,@name"); final String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result); + Assertions.assertEquals("hello,hutool", result); // classpath中获取模板 final Template template2 = engine.getTemplate("rythm_test.tmpl"); final String result2 = template2.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result2); + Assertions.assertEquals("hello,hutool", result2); } @Test @@ -78,14 +78,14 @@ public class TemplateUtilTest { new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(FreemarkerEngine.class)); Template template = engine.getTemplate("hello,${name}"); String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result); + Assertions.assertEquals("hello,hutool", result); //ClassPath模板 engine = TemplateUtil.createEngine( new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(FreemarkerEngine.class)); template = engine.getTemplate("freemarker_test.ftl"); result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", result); + Assertions.assertEquals("hello,hutool", result); } @Test @@ -95,18 +95,18 @@ public class TemplateUtilTest { new TemplateConfig("templates", ResourceMode.STRING).setCustomEngine(VelocityEngine.class)); Template template = engine.getTemplate("你好,$name"); String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("你好,hutool", result); + Assertions.assertEquals("你好,hutool", result); //ClassPath模板 engine = TemplateUtil.createEngine( new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(VelocityEngine.class)); template = engine.getTemplate("velocity_test.vtl"); result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("你好,hutool", result); + Assertions.assertEquals("你好,hutool", result); template = engine.getTemplate("templates/velocity_test.vtl"); result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("你好,hutool", result); + Assertions.assertEquals("你好,hutool", result); } @Test @@ -116,14 +116,14 @@ public class TemplateUtilTest { new TemplateConfig("templates").setCustomEngine(EnjoyEngine.class)); Template template = engine.getTemplate("#(x + 123)"); String result = template.render(Dict.of().set("x", 1)); - Assert.assertEquals("124", result); + Assertions.assertEquals("124", result); //ClassPath模板 engine = new EnjoyEngine( new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(EnjoyEngine.class)); template = engine.getTemplate("enjoy_test.etl"); result = template.render(Dict.of().set("x", 1)); - Assert.assertEquals("124", result); + Assertions.assertEquals("124", result); } @Test @@ -133,18 +133,18 @@ public class TemplateUtilTest { new TemplateConfig("templates").setCustomEngine(ThymeleafEngine.class)); Template template = engine.getTemplate("

"); String result = template.render(Dict.of().set("message", "Hutool")); - Assert.assertEquals("

Hutool

", result); + Assertions.assertEquals("

Hutool

", result); //ClassPath模板 engine = TemplateUtil.createEngine( new TemplateConfig("templates", ResourceMode.CLASSPATH).setCustomEngine(ThymeleafEngine.class)); template = engine.getTemplate("thymeleaf_test.ttl"); result = template.render(Dict.of().set("message", "Hutool")); - Assert.assertEquals("

Hutool

", result); + Assertions.assertEquals("

Hutool

", result); } @Test - @Ignore + @Disabled public void renderToFileTest() { final TemplateEngine engine = new BeetlEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH)); final Template template = engine.getTemplate("freemarker_test.ftl"); @@ -163,7 +163,7 @@ public class TemplateUtilTest { TemplateEngine engine = TemplateUtil.createEngine(config); Template template = engine.getTemplate("/wit_test.wit"); String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", StrUtil.trim(result)); + Assertions.assertEquals("hello,hutool", StrUtil.trim(result)); // 字符串模板 config = new TemplateConfig("templates", ResourceMode.STRING) @@ -171,6 +171,6 @@ public class TemplateUtilTest { engine = TemplateUtil.createEngine(config); template = engine.getTemplate("<%var name;%>hello,${name}"); result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("hello,hutool", StrUtil.trim(result)); + Assertions.assertEquals("hello,hutool", StrUtil.trim(result)); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/template/ThymeleafTest.java b/hutool-extra/src/test/java/cn/hutool/extra/template/ThymeleafTest.java index c88b89a02..92ca42a40 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/template/ThymeleafTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/template/ThymeleafTest.java @@ -3,20 +3,15 @@ package cn.hutool.extra.template; import cn.hutool.core.date.DateUtil; import cn.hutool.core.map.Dict; import cn.hutool.extra.template.engine.thymeleaf.ThymeleafEngine; -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 org.thymeleaf.context.Context; import org.thymeleaf.standard.StandardDialect; import org.thymeleaf.templateresolver.StringTemplateResolver; import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; /** * Thymeleaf单元测试 @@ -31,7 +26,7 @@ public class ThymeleafTest { * 自定义操作原始引擎 */ @Test - @Ignore + @Disabled public void addDialectTest(){ final TemplateEngine engine = TemplateUtil.createEngine(); if(engine instanceof ThymeleafEngine){ @@ -61,7 +56,7 @@ public class ThymeleafTest { final TemplateEngine engine = new ThymeleafEngine(new TemplateConfig()); final Template template = engine.getTemplate("

"); final String render = template.render(Dict.of().set("list", list)); - Assert.assertEquals("

a

b

2019-01-01 00:00:00

", render); + Assertions.assertEquals("

a

b

2019-01-01 00:00:00

", render); } @Test @@ -98,7 +93,7 @@ public class ThymeleafTest { final Context context = new Context(Locale.getDefault(), map); templateEngine.process("

", context, writer); - Assert.assertEquals("

a

b

2019-01-01 00:00:00

", writer.toString()); + Assertions.assertEquals("

a

b

2019-01-01 00:00:00

", writer.toString()); } @SuppressWarnings("rawtypes") @@ -109,6 +104,6 @@ public class ThymeleafTest { final Template template = engine.getTemplate("

"); // "

" final String render = template.render(map); - Assert.assertEquals("

a

b

2019-01-01 00:00:00

", render); + Assertions.assertEquals("

a

b

2019-01-01 00:00:00

", render); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/template/VelocityTest.java b/hutool-extra/src/test/java/cn/hutool/extra/template/VelocityTest.java index da2737ffa..072c22ff0 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/template/VelocityTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/template/VelocityTest.java @@ -3,8 +3,8 @@ package cn.hutool.extra.template; import cn.hutool.core.map.Dict; import cn.hutool.core.util.CharsetUtil; import cn.hutool.extra.template.engine.velocity.VelocityEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class VelocityTest { @@ -16,6 +16,6 @@ public class VelocityTest { final TemplateEngine engine = TemplateUtil.createEngine(config); final Template template = engine.getTemplate("velocity_test_gbk.vtl"); final String result = template.render(Dict.of().set("name", "hutool")); - Assert.assertEquals("你好,hutool", result); + Assertions.assertEquals("你好,hutool", result); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/tokenizer/TokenizerUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/tokenizer/TokenizerUtilTest.java index dc7bead1d..a98f5daf1 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/tokenizer/TokenizerUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/tokenizer/TokenizerUtilTest.java @@ -9,8 +9,8 @@ import cn.hutool.extra.tokenizer.engine.jieba.JiebaEngine; import cn.hutool.extra.tokenizer.engine.mmseg.MmsegEngine; import cn.hutool.extra.tokenizer.engine.mynlp.MynlpEngine; import cn.hutool.extra.tokenizer.engine.word.WordEngine; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 模板引擎单元测试 @@ -35,7 +35,7 @@ public class TokenizerUtilTest { final TokenizerEngine engine = new HanLPEngine(); final Result result = engine.parse(text); final String resultStr = IterUtil.join(result, " "); - Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr); + Assertions.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr); } @Test @@ -43,7 +43,7 @@ public class TokenizerUtilTest { final TokenizerEngine engine = new IKAnalyzerEngine(); final Result result = engine.parse(text); final String resultStr = IterUtil.join(result, " "); - Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr); + Assertions.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr); } @Test @@ -58,7 +58,7 @@ public class TokenizerUtilTest { final TokenizerEngine engine = new JiebaEngine(); final Result result = engine.parse(text); final String resultStr = IterUtil.join(result, " "); - Assert.assertEquals("这 两个 方法 的 区别 在于 返回值", resultStr); + Assertions.assertEquals("这 两个 方法 的 区别 在于 返回值", resultStr); } @Test @@ -73,7 +73,7 @@ public class TokenizerUtilTest { final TokenizerEngine engine = new SmartcnEngine(); final Result result = engine.parse(text); final String resultStr = IterUtil.join(result, " "); - Assert.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr); + Assertions.assertEquals("这 两 个 方法 的 区别 在于 返回 值", resultStr); } @Test @@ -81,7 +81,7 @@ public class TokenizerUtilTest { final TokenizerEngine engine = new WordEngine(); final Result result = engine.parse(text); final String resultStr = IterUtil.join(result, " "); - Assert.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr); + Assertions.assertEquals("这两个 方法 的 区别 在于 返回值", resultStr); } @Test @@ -89,11 +89,11 @@ public class TokenizerUtilTest { final TokenizerEngine engine = new MynlpEngine(); final Result result = engine.parse(text); final String resultStr = IterUtil.join(result, " "); - Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr); + Assertions.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr); } private void checkResult(final Result result) { final String resultStr = IterUtil.join(result, " "); - Assert.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr); + Assertions.assertEquals("这 两个 方法 的 区别 在于 返回 值", resultStr); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/validation/BeanValidatorUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/validation/BeanValidatorUtilTest.java index 039335eea..ac848fe16 100755 --- a/hutool-extra/src/test/java/cn/hutool/extra/validation/BeanValidatorUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/validation/BeanValidatorUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.extra.validation; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import jakarta.validation.constraints.NotBlank; @@ -40,14 +40,14 @@ public class BeanValidatorUtilTest { @Test public void beanValidatorTest() { final BeanValidationResult result = ValidationUtil.warpValidate(new TestClass()); - Assert.assertFalse(result.isSuccess()); - Assert.assertEquals(2, result.getErrorMessages().size()); + Assertions.assertFalse(result.isSuccess()); + Assertions.assertEquals(2, result.getErrorMessages().size()); } @Test public void propertyValidatorTest() { final BeanValidationResult result = ValidationUtil.warpValidateProperty(new TestClass(), "name"); - Assert.assertFalse(result.isSuccess()); - Assert.assertEquals(1, result.getErrorMessages().size()); + Assertions.assertFalse(result.isSuccess()); + Assertions.assertEquals(1, result.getErrorMessages().size()); } } diff --git a/hutool-extra/src/test/java/cn/hutool/extra/xml/JAXBUtilTest.java b/hutool-extra/src/test/java/cn/hutool/extra/xml/JAXBUtilTest.java index f53c93b7e..9b74b6036 100644 --- a/hutool-extra/src/test/java/cn/hutool/extra/xml/JAXBUtilTest.java +++ b/hutool-extra/src/test/java/cn/hutool/extra/xml/JAXBUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.extra.xml; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.xml.bind.annotation.*; @@ -34,18 +34,18 @@ public class JAXBUtilTest { roomVo.setRoomNo("101"); schoolVo.setRoom(roomVo); - Assert.assertEquals(xmlStr, JAXBUtil.beanToXml(schoolVo)); + Assertions.assertEquals(xmlStr, JAXBUtil.beanToXml(schoolVo)); } @Test public void xmlToBeanTest() { final SchoolVo schoolVo = JAXBUtil.xmlToBean(xmlStr, SchoolVo.class); - Assert.assertNotNull(schoolVo); - Assert.assertEquals("西安市第一中学", schoolVo.getSchoolName()); - Assert.assertEquals("西安市雁塔区长安堡一号", schoolVo.getSchoolAddress()); + Assertions.assertNotNull(schoolVo); + Assertions.assertEquals("西安市第一中学", schoolVo.getSchoolName()); + Assertions.assertEquals("西安市雁塔区长安堡一号", schoolVo.getSchoolAddress()); - Assert.assertEquals("101教室", schoolVo.getRoom().getRoomName()); - Assert.assertEquals("101", schoolVo.getRoom().getRoomNo()); + Assertions.assertEquals("101教室", schoolVo.getRoom().getRoomName()); + Assertions.assertEquals("101", schoolVo.getRoom().getRoomNo()); } @XmlRootElement(name = "school") diff --git a/hutool-http/src/test/java/cn/hutool/http/ContentTypeTest.java b/hutool-http/src/test/java/cn/hutool/http/ContentTypeTest.java index fc92ba5bb..5bb77f7d0 100644 --- a/hutool-http/src/test/java/cn/hutool/http/ContentTypeTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/ContentTypeTest.java @@ -2,8 +2,8 @@ package cn.hutool.http; import cn.hutool.core.util.CharsetUtil; import cn.hutool.http.meta.ContentType; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * ContentType 单元测试 @@ -14,6 +14,6 @@ public class ContentTypeTest { @Test public void testBuild() { final String result = ContentType.build(ContentType.JSON, CharsetUtil.UTF_8); - Assert.assertEquals("application/json;charset=UTF-8", result); + Assertions.assertEquals("application/json;charset=UTF-8", result); } } diff --git a/hutool-http/src/test/java/cn/hutool/http/DownloadTest.java b/hutool-http/src/test/java/cn/hutool/http/DownloadTest.java index d30928f7d..5d034a130 100644 --- a/hutool-http/src/test/java/cn/hutool/http/DownloadTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/DownloadTest.java @@ -1,17 +1,17 @@ package cn.hutool.http; import cn.hutool.core.codec.binary.Base64; -import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.io.StreamProgress; +import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.util.CharsetUtil; import cn.hutool.http.client.HttpDownloader; import cn.hutool.http.client.Request; import cn.hutool.http.client.engine.ClientEngineFactory; -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.ByteArrayOutputStream; import java.io.File; @@ -28,7 +28,7 @@ import java.util.UUID; public class DownloadTest { @Test - @Ignore + @Disabled public void downloadPicTest() { final String url = "http://wx.qlogo.cn/mmopen/vKhlFcibVUtNBVDjcIowlg0X8aJfHXrTNCEFBukWVH9ta99pfEN88lU39MKspCUCOP3yrFBH3y2NbV7sYtIIlon8XxLwAEqv2/0"; HttpDownloader.downloadFile(url, new File("e:/pic/t3.jpg")); @@ -36,7 +36,7 @@ public class DownloadTest { } @Test - @Ignore + @Disabled public void downloadSizeTest() { final String url = "https://res.t-io.org/im/upload/img/67/8948/1119501/88097554/74541310922/85/231910/366466 - 副本.jpg"; ClientEngineFactory.get().send(Request.of(url)).body().write("e:/pic/366466.jpg"); @@ -44,14 +44,14 @@ public class DownloadTest { } @Test - @Ignore + @Disabled public void downloadTest1() { final File size = HttpDownloader.downloadFile("http://explorer.bbfriend.com/crossdomain.xml", new File("e:/temp/")); System.out.println("Download size: " + size); } @Test - @Ignore + @Disabled public void downloadTest() { // 带进度显示的文件下载 HttpDownloader.downloadFile("http://mirrors.sohu.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso", FileUtil.file("d:/"), -1, new StreamProgress() { @@ -77,16 +77,16 @@ public class DownloadTest { } @Test - @Ignore + @Disabled public void downloadFileFromUrlTest1() { final File file = HttpDownloader.downloadFile("http://groovy-lang.org/changelogs/changelog-3.0.5.html", new File("d:/download/temp")); - Assert.assertNotNull(file); - Assert.assertTrue(file.isFile()); - Assert.assertTrue(file.length() > 0); + Assertions.assertNotNull(file); + Assertions.assertTrue(file.isFile()); + Assertions.assertTrue(file.length() > 0); } @Test - @Ignore + @Disabled public void downloadFileFromUrlTest2() { File file = null; try { @@ -107,20 +107,20 @@ public class DownloadTest { } }); - Assert.assertNotNull(file); - Assert.assertTrue(file.exists()); - Assert.assertTrue(file.isFile()); - Assert.assertTrue(file.length() > 0); - Assert.assertTrue(file.getName().length() > 0); + Assertions.assertNotNull(file); + Assertions.assertTrue(file.exists()); + Assertions.assertTrue(file.isFile()); + Assertions.assertTrue(file.length() > 0); + Assertions.assertTrue(file.getName().length() > 0); } catch (final Exception e) { - Assert.assertTrue(e instanceof IORuntimeException); + Assertions.assertTrue(e instanceof IORuntimeException); } finally { FileUtil.del(file); } } @Test - @Ignore + @Disabled public void downloadFileFromUrlTest3() { File file = null; try { @@ -141,30 +141,30 @@ public class DownloadTest { } }); - Assert.assertNotNull(file); - Assert.assertTrue(file.exists()); - Assert.assertTrue(file.isFile()); - Assert.assertTrue(file.length() > 0); - Assert.assertTrue(file.getName().length() > 0); + Assertions.assertNotNull(file); + Assertions.assertTrue(file.exists()); + Assertions.assertTrue(file.isFile()); + Assertions.assertTrue(file.length() > 0); + Assertions.assertTrue(file.getName().length() > 0); } finally { FileUtil.del(file); } } @Test - @Ignore + @Disabled public void downloadFileFromUrlTest4() { File file = null; try { file = HttpDownloader.downloadFile("http://groovy-lang.org/changelogs/changelog-3.0.5.html", FileUtil.file("d:/download/temp"), 1); - Assert.assertNotNull(file); - Assert.assertTrue(file.exists()); - Assert.assertTrue(file.isFile()); - Assert.assertTrue(file.length() > 0); - Assert.assertTrue(file.getName().length() > 0); + Assertions.assertNotNull(file); + Assertions.assertTrue(file.exists()); + Assertions.assertTrue(file.isFile()); + Assertions.assertTrue(file.length() > 0); + Assertions.assertTrue(file.getName().length() > 0); } catch (final Exception e) { - Assert.assertTrue(e instanceof IORuntimeException); + Assertions.assertTrue(e instanceof IORuntimeException); } finally { FileUtil.del(file); } @@ -172,16 +172,16 @@ public class DownloadTest { @Test - @Ignore + @Disabled public void downloadFileFromUrlTest5() { File file = null; try { file = HttpDownloader.downloadFile("http://groovy-lang.org/changelogs/changelog-3.0.5.html", FileUtil.file("d:/download/temp", UUID.randomUUID().toString())); - Assert.assertNotNull(file); - Assert.assertTrue(file.exists()); - Assert.assertTrue(file.isFile()); - Assert.assertTrue(file.length() > 0); + Assertions.assertNotNull(file); + Assertions.assertTrue(file.exists()); + Assertions.assertTrue(file.isFile()); + Assertions.assertTrue(file.length() > 0); } finally { FileUtil.del(file); } @@ -190,17 +190,17 @@ public class DownloadTest { try { file1 = HttpDownloader.downloadFile("http://groovy-lang.org/changelogs/changelog-3.0.5.html", FileUtil.file("d:/download/temp")); - Assert.assertNotNull(file1); - Assert.assertTrue(file1.exists()); - Assert.assertTrue(file1.isFile()); - Assert.assertTrue(file1.length() > 0); + Assertions.assertNotNull(file1); + Assertions.assertTrue(file1.exists()); + Assertions.assertTrue(file1.isFile()); + Assertions.assertTrue(file1.length() > 0); } finally { FileUtil.del(file1); } } @Test - @Ignore + @Disabled public void downloadTeamViewerTest() throws IOException { // 此URL有3次重定向, 需要请求4次 final String url = "https://download.teamviewer.com/download/TeamViewer_Setup_x64.exe"; @@ -211,7 +211,7 @@ public class DownloadTest { } @Test - @Ignore + @Disabled public void downloadToStreamTest() { String url2 = "http://storage.chancecloud.com.cn/20200413_%E7%B2%A4B12313_386.pdf"; final ByteArrayOutputStream os2 = new ByteArrayOutputStream(); @@ -222,7 +222,7 @@ public class DownloadTest { } @Test - @Ignore + @Disabled public void downloadStringTest() { final String url = "https://www.baidu.com"; // 从远程直接读取字符串,需要自定义编码,直接调用JDK方法 @@ -231,7 +231,7 @@ public class DownloadTest { } @Test - @Ignore + @Disabled public void gimg2Test(){ final byte[] bytes = HttpDownloader.downloadBytes("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F1114%2F0H320120Z3%2F200H3120Z3-6-1200.jpg&refer=http%3A%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621996490&t=8c384c2823ea453da15a1b9cd5183eea"); Console.log(Base64.encode(bytes)); diff --git a/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java index 7242ba526..694243aba 100644 --- a/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/HtmlUtilTest.java @@ -3,8 +3,8 @@ package cn.hutool.http; import cn.hutool.core.regex.ReUtil; import cn.hutool.http.html.HtmlUtil; import cn.hutool.http.meta.ContentTypeUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Html单元测试 @@ -19,32 +19,32 @@ public class HtmlUtilTest { //非闭合标签 String str = "pre"; String result = HtmlUtil.removeHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.removeHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.removeHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.removeHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //包含内容标签 str = "pre
dfdsfdsfdsf
"; result = HtmlUtil.removeHtmlTag(str, "div"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //带换行 str = "pre
\r\n\t\tdfdsfdsfdsf\r\n
"; result = HtmlUtil.removeHtmlTag(str, "div"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); } @Test @@ -52,32 +52,32 @@ public class HtmlUtilTest { //非闭合标签 String str = "pre"; String result = HtmlUtil.cleanHtmlTag(str); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.cleanHtmlTag(str); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.cleanHtmlTag(str); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.cleanHtmlTag(str); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //包含内容标签 str = "pre
dfdsfdsfdsf
"; result = HtmlUtil.cleanHtmlTag(str); - Assert.assertEquals("predfdsfdsfdsf", result); + Assertions.assertEquals("predfdsfdsfdsf", result); //带换行 str = "pre
\r\n\t\tdfdsfdsfdsf\r\n
BBBB
"; result = HtmlUtil.cleanHtmlTag(str); - Assert.assertEquals("pre\r\n\t\tdfdsfdsfdsf\r\nBBBB", result); + Assertions.assertEquals("pre\r\n\t\tdfdsfdsfdsf\r\nBBBB", result); } @Test @@ -85,37 +85,37 @@ public class HtmlUtilTest { //非闭合标签 String str = "pre"; String result = HtmlUtil.unwrapHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.unwrapHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.unwrapHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.unwrapHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //闭合标签 str = "pre"; result = HtmlUtil.unwrapHtmlTag(str, "img"); - Assert.assertEquals("pre", result); + Assertions.assertEquals("pre", result); //包含内容标签 str = "pre
abc
"; result = HtmlUtil.unwrapHtmlTag(str, "div"); - Assert.assertEquals("preabc", result); + Assertions.assertEquals("preabc", result); //带换行 str = "pre
\r\n\t\tabc\r\n
"; result = HtmlUtil.unwrapHtmlTag(str, "div"); - Assert.assertEquals("pre\r\n\t\tabc\r\n", result); + Assertions.assertEquals("pre\r\n\t\tabc\r\n", result); } @Test @@ -124,34 +124,34 @@ public class HtmlUtilTest { final String htmlString = "测试文本"; final String tagString = "i,br"; final String cleanTxt = HtmlUtil.removeHtmlTag(htmlString, false, tagString.split(",")); - Assert.assertEquals("测试文本", cleanTxt); + Assertions.assertEquals("测试文本", cleanTxt); } @Test public void escapeTest() { final String html = "123'123'"; final String escape = HtmlUtil.escape(html); - Assert.assertEquals("<html><body>123'123'</body></html>", escape); + Assertions.assertEquals("<html><body>123'123'</body></html>", escape); final String restoreEscaped = HtmlUtil.unescape(escape); - Assert.assertEquals(html, restoreEscaped); - Assert.assertEquals("'", HtmlUtil.unescape("'")); + Assertions.assertEquals(html, restoreEscaped); + Assertions.assertEquals("'", HtmlUtil.unescape("'")); } @Test public void escapeTest2() { final char c = ' '; // 不断开空格(non-breaking space,缩写nbsp。) - Assert.assertEquals(c, 160); + Assertions.assertEquals(c, 160); final String html = " "; final String escape = HtmlUtil.escape(html); - Assert.assertEquals("<html><body> </body></html>", escape); - Assert.assertEquals(" ", HtmlUtil.unescape(" ")); + Assertions.assertEquals("<html><body> </body></html>", escape); + Assertions.assertEquals(" ", HtmlUtil.unescape(" ")); } @Test public void filterTest() { final String html = ""; final String filter = HtmlUtil.filter(html); - Assert.assertEquals("", filter); + Assertions.assertEquals("", filter); } @Test @@ -160,43 +160,43 @@ public class HtmlUtilTest { // 去除的属性加双引号测试 String html = "
"; String result = HtmlUtil.removeHtmlAttr(html, "class"); - Assert.assertEquals("
", result); + Assertions.assertEquals("
", result); // 去除的属性后跟空格、加单引号、不加引号测试 html = "
"; result = HtmlUtil.removeHtmlAttr(html, "class"); - Assert.assertEquals("
", result); + Assertions.assertEquals("
", result); // 去除的属性位于标签末尾、其它属性前测试 html = "
"; result = HtmlUtil.removeHtmlAttr(html, "class"); - Assert.assertEquals("
", result); + Assertions.assertEquals("
", result); // 去除的属性名和值之间存在空格 html = "
"; result = HtmlUtil.removeHtmlAttr(html, "class"); - Assert.assertEquals("
", result); + Assertions.assertEquals("
", result); } @Test public void removeAllHtmlAttrTest() { final String html = "
"; final String result = HtmlUtil.removeAllHtmlAttr(html, "div"); - Assert.assertEquals("
", result); + Assertions.assertEquals("
", result); } @Test public void getCharsetTest() { String charsetName = ReUtil.get(ContentTypeUtil.CHARSET_PATTERN, "Charset=UTF-8;fq=0.9", 1); - Assert.assertEquals("UTF-8", charsetName); + Assertions.assertEquals("UTF-8", charsetName); charsetName = ReUtil.get(HtmlUtil.META_CHARSET_PATTERN, "> headers = response.headers(); @@ -65,7 +65,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void asyncGetTest() { final StopWatch timer = DateUtil.createStopWatch(); timer.start(); @@ -80,7 +80,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void syncGetTest() { final StopWatch timer = DateUtil.createStopWatch(); timer.start(); @@ -96,7 +96,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void getDeflateTest() { final Response res = Request.of("https://comment.bilibili.com/67573272.xml") .header(Header.ACCEPT_ENCODING, "deflate") @@ -106,7 +106,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void bodyTest() { final String ddddd1 = Request.of("https://baijiahao.baidu.com/s").body("id=1625528941695652600").send().bodyStr(); Console.log(ddddd1); @@ -116,7 +116,7 @@ public class HttpRequestTest { * 测试GET请求附带body体是否会变更为POST */ @Test - @Ignore + @Disabled public void getLocalTest() { final List list = new ArrayList<>(); list.add("hhhhh"); @@ -135,7 +135,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void getWithoutEncodeTest() { final String url = "https://img-cloud.voc.com.cn/140/2020/09/03/c3d41b93e0d32138574af8e8b50928b376ca5ba61599127028157.png?imageMogr2/auto-orient/thumbnail/500&pid=259848"; final Request get = Request.of(url); @@ -145,7 +145,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void followRedirectsTest() { // 从5.7.19开始关闭JDK的自动重定向功能,改为手动重定向 // 当有多层重定向时,JDK的重定向会失效,或者说只有最后一个重定向有效,因此改为手动更易控制次数 @@ -164,7 +164,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void getWithFormTest(){ final String url = "https://postman-echo.com/get"; final Map map = new HashMap<>(); @@ -174,7 +174,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void urlWithParamIfGetTest(){ final UrlBuilder urlBuilder = new UrlBuilder(); urlBuilder.setScheme("https").setHost("hutool.cn"); @@ -184,7 +184,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void getCookieTest(){ final Response execute = Request.of("http://localhost:8888/getCookier").send(); Console.log(execute.getCookieStr()); @@ -193,25 +193,25 @@ public class HttpRequestTest { @Test public void optionsTest() { final Request options = Request.of("https://hutool.cn").method(Method.OPTIONS); - Assert.notNull(options.toString()); + Assertions.assertNotNull(options.toString()); } @Test public void deleteTest() { final Request options = Request.of("https://hutool.cn").method(Method.DELETE); - Assert.notNull(options.toString()); + Assertions.assertNotNull(options.toString()); } @Test public void traceTest() { final Request options = Request.of("https://hutool.cn").method(Method.TRACE); - Assert.notNull(options.toString()); + Assertions.assertNotNull(options.toString()); } @Test public void getToStringTest() { final Request a = Request.of("https://hutool.cn/").form(MapUtil.of("a", 1)); - Assert.notNull(a.toString()); + Assertions.assertNotNull(a.toString()); } @Test @@ -221,7 +221,7 @@ public class HttpRequestTest { } @Test - @Ignore + @Disabled public void issueI5Y68WTest() { final Response httpResponse = Request.of("http://82.157.17.173:8100/app/getAddress").send(); Console.log(httpResponse.body()); diff --git a/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java index 46205f016..b24772da4 100755 --- a/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java @@ -7,9 +7,9 @@ import cn.hutool.core.util.CharsetUtil; import cn.hutool.http.client.Request; import cn.hutool.http.meta.Header; import cn.hutool.http.meta.Method; -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.LinkedHashMap; import java.util.List; @@ -20,21 +20,21 @@ public class HttpUtilTest { @Test public void isHttpTest(){ - Assert.assertTrue(HttpUtil.isHttp("Http://aaa.bbb")); - Assert.assertTrue(HttpUtil.isHttp("HTTP://aaa.bbb")); - Assert.assertFalse(HttpUtil.isHttp("FTP://aaa.bbb")); + Assertions.assertTrue(HttpUtil.isHttp("Http://aaa.bbb")); + Assertions.assertTrue(HttpUtil.isHttp("HTTP://aaa.bbb")); + Assertions.assertFalse(HttpUtil.isHttp("FTP://aaa.bbb")); } @Test public void isHttpsTest(){ - Assert.assertTrue(HttpUtil.isHttps("Https://aaa.bbb")); - Assert.assertTrue(HttpUtil.isHttps("HTTPS://aaa.bbb")); - Assert.assertTrue(HttpUtil.isHttps("https://aaa.bbb")); - Assert.assertFalse(HttpUtil.isHttps("ftp://aaa.bbb")); + Assertions.assertTrue(HttpUtil.isHttps("Https://aaa.bbb")); + Assertions.assertTrue(HttpUtil.isHttps("HTTPS://aaa.bbb")); + Assertions.assertTrue(HttpUtil.isHttps("https://aaa.bbb")); + Assertions.assertFalse(HttpUtil.isHttps("ftp://aaa.bbb")); } @Test - @Ignore + @Disabled public void postTest2() { // 某些接口对Accept头有特殊要求,此处自定义头 final String result = HttpUtil.send(Request @@ -45,14 +45,14 @@ public class HttpUtilTest { } @Test - @Ignore + @Disabled public void getTest() { final String result1 = HttpUtil.get("http://photo.qzone.qq.com/fcgi-bin/fcg_list_album?uin=88888&outstyle=2", CharsetUtil.GBK); Console.log(result1); } @Test - @Ignore + @Disabled public void getTest2() { // 此链接较为特殊,User-Agent去掉后进入一个JS跳转页面,如果设置了,需要开启302跳转 // 自定义的默认header无效 @@ -63,7 +63,7 @@ public class HttpUtilTest { } @Test - @Ignore + @Disabled public void getTest3() { // 测试url中带有空格的情况 final String result1 = HttpUtil.get("http://hutool.cn:5000/kf?abc= d"); @@ -71,7 +71,7 @@ public class HttpUtilTest { } @Test - @Ignore + @Disabled public void getTest4() { // 测试url中带有空格的情况 final byte[] str = Request.of("http://img01.fs.yiban.cn/mobile/2D0Y71").send().bodyBytes(); @@ -81,14 +81,14 @@ public class HttpUtilTest { } @Test - @Ignore + @Disabled public void get12306Test() { HttpUtil.send(Request.of("https://kyfw.12306.cn/otn/").setMaxRedirectCount(2)) .then(response -> Console.log(response.bodyStr())); } @Test - @Ignore + @Disabled public void oschinaTest() { // 请求列表页 String listContent = HttpUtil.get("https://www.oschina.net/action/ajax/get_more_news_list?newsType=&p=2"); @@ -105,7 +105,7 @@ public class HttpUtilTest { } @Test - //@Ignore + //@Disabled public void patchTest() { // 验证patch请求是否可用 final String body = HttpUtil.send(Request.of("https://hutool.cn").method(Method.PATCH)).bodyStr(); @@ -126,18 +126,18 @@ public class HttpUtilTest { param.put("Version", "1.0"); String urlWithForm = HttpUtil.urlWithForm("http://api.hutool.cn/login?type=aaa", param, CharsetUtil.UTF_8, false); - Assert.assertEquals( + Assertions.assertEquals( "http://api.hutool.cn/login?type=aaa&AccessKeyId=123&Action=DescribeDomainRecords&Format=date&DomainName=lesper.cn&SignatureMethod=POST&SignatureNonce=123&SignatureVersion=4.3.1&Timestamp=123432453&Version=1.0", urlWithForm); urlWithForm = HttpUtil.urlWithForm("http://api.hutool.cn/login?type=aaa", param, CharsetUtil.UTF_8, false); - Assert.assertEquals( + Assertions.assertEquals( "http://api.hutool.cn/login?type=aaa&AccessKeyId=123&Action=DescribeDomainRecords&Format=date&DomainName=lesper.cn&SignatureMethod=POST&SignatureNonce=123&SignatureVersion=4.3.1&Timestamp=123432453&Version=1.0", urlWithForm); } @Test - @Ignore + @Disabled public void getWeixinTest(){ // 测试特殊URL,即URL中有&情况是否请求正常 final String url = "https://mp.weixin.qq.com/s?__biz=MzI5NjkyNTIxMg==&mid=100000465&idx=1&sn=1044c0d19723f74f04f4c1da34eefa35&chksm=6cbda3a25bca2ab4516410db6ce6e125badaac2f8c5548ea6e18eab6dc3c5422cb8cbe1095f7"; @@ -146,7 +146,7 @@ public class HttpUtilTest { } @Test - @Ignore + @Disabled public void getNocovTest(){ final String url = "https://qiniu.nocov.cn/medical-manage%2Ftest%2FBANNER_IMG%2F444004467954556928%2F1595215173047icon.png~imgReduce?e=1597081986&token=V2lJYVgQgAv_sbypfEZ0qpKs6TzD1q5JIDVr0Tw8:89cbBkLLwEc9JsMoCLkAEOu820E="; final String s = HttpUtil.get(url); @@ -154,21 +154,21 @@ public class HttpUtilTest { } @Test - @Ignore + @Disabled public void sinajsTest(){ final String s = HttpUtil.get("http://hq.sinajs.cn/list=sh600519"); Console.log(s); } @Test - @Ignore + @Disabled public void acplayTest(){ final String body = HttpUtil.send(Request.of("https://api.acplay.net/api/v2/bangumi/9541")).bodyStr(); Console.log(body); } @Test - @Ignore + @Disabled public void getPicTest(){ HttpGlobalConfig.setDecodeUrl(false); final String url = "https://p3-sign.douyinpic.com/tos-cn-i-0813/f41afb2e79a94dcf80970affb9a69415~noop.webp?x-expires=1647738000&x-signature=%2Br1ekUCGjXiu50Y%2Bk0MO4ovulK8%3D&from=4257465056&s=PackSourceEnum_DOUYIN_REFLOW&se=false&sh=&sc=&l=2022021809224601020810013524310DD3&biz_tag=aweme_images"; diff --git a/hutool-http/src/test/java/cn/hutool/http/HttpsTest.java b/hutool-http/src/test/java/cn/hutool/http/HttpsTest.java index ece225ed5..f0465c78d 100644 --- a/hutool-http/src/test/java/cn/hutool/http/HttpsTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/HttpsTest.java @@ -2,8 +2,8 @@ package cn.hutool.http; import cn.hutool.core.lang.Console; import cn.hutool.core.thread.ThreadUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicInteger; @@ -13,7 +13,7 @@ public class HttpsTest { * 测试单例的SSLSocketFactory是否有线程安全问题 */ @Test - @Ignore + @Disabled public void getTest() { final AtomicInteger count = new AtomicInteger(); for(int i =0; i < 100; i++){ diff --git a/hutool-http/src/test/java/cn/hutool/http/Issue2531Test.java b/hutool-http/src/test/java/cn/hutool/http/Issue2531Test.java index 90fe889a9..378fa3ea5 100755 --- a/hutool-http/src/test/java/cn/hutool/http/Issue2531Test.java +++ b/hutool-http/src/test/java/cn/hutool/http/Issue2531Test.java @@ -5,9 +5,9 @@ import cn.hutool.core.map.MapUtil; import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.http.client.Request; import cn.hutool.http.client.Response; -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.HashMap; import java.util.Map; @@ -15,7 +15,7 @@ import java.util.Map; public class Issue2531Test { @Test - @Ignore + @Disabled public void getTest(){ final Map map = new HashMap<>(); map.put("str","+123"); @@ -34,14 +34,14 @@ public class Issue2531Test { public void encodePlusTest(){ // 根据RFC3986规范,在URL中,"+"是安全字符,所以不会解码也不会编码 UrlBuilder builder = UrlBuilder.ofHttp("https://hutool.cn/a=+"); - Assert.assertEquals("https://hutool.cn/a=+", builder.toString()); + Assertions.assertEquals("https://hutool.cn/a=+", builder.toString()); // 由于+为安全字符无需编码,ofHttp方法会把%2B解码为+,但是编码的时候不会编码 builder = UrlBuilder.ofHttp("https://hutool.cn/a=%2B"); - Assert.assertEquals("https://hutool.cn/a=+", builder.toString()); + Assertions.assertEquals("https://hutool.cn/a=+", builder.toString()); // 如果你不想解码%2B,则charset传null表示不做解码,编码时候也被忽略 builder = UrlBuilder.ofHttp("https://hutool.cn/a=%2B", null); - Assert.assertEquals("https://hutool.cn/a=%2B", builder.toString()); + Assertions.assertEquals("https://hutool.cn/a=%2B", builder.toString()); } } diff --git a/hutool-http/src/test/java/cn/hutool/http/Issue2901Test.java b/hutool-http/src/test/java/cn/hutool/http/Issue2901Test.java index 6f5ba7e49..9d20a0d55 100644 --- a/hutool-http/src/test/java/cn/hutool/http/Issue2901Test.java +++ b/hutool-http/src/test/java/cn/hutool/http/Issue2901Test.java @@ -9,13 +9,13 @@ import cn.hutool.http.client.Response; import cn.hutool.http.client.body.ResourceBody; import cn.hutool.http.meta.ContentType; import cn.hutool.http.meta.Method; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class Issue2901Test { @Test - @Ignore + @Disabled public void bodyTest() { // 自定义请求体,请求体作为资源读取,解决一次性读取到内存的问题 final Response res = Request.of("http://localhost:8888/restTest") diff --git a/hutool-http/src/test/java/cn/hutool/http/IssueI5TFPUTest.java b/hutool-http/src/test/java/cn/hutool/http/IssueI5TFPUTest.java index ecb75d970..96fdbe284 100644 --- a/hutool-http/src/test/java/cn/hutool/http/IssueI5TFPUTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/IssueI5TFPUTest.java @@ -1,13 +1,13 @@ package cn.hutool.http; import cn.hutool.core.net.url.UrlBuilder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class IssueI5TFPUTest { @Test public void urlBuilderTest() { final UrlBuilder urlBuilder = UrlBuilder.of("https://hutool.cn", null).addQuery("opt", "%"); - Assert.assertEquals("https://hutool.cn?opt=%", urlBuilder.toString()); + Assertions.assertEquals("https://hutool.cn?opt=%", urlBuilder.toString()); } } diff --git a/hutool-http/src/test/java/cn/hutool/http/IssueI5TPSYTest.java b/hutool-http/src/test/java/cn/hutool/http/IssueI5TPSYTest.java index 8bfb5e705..df79b397f 100755 --- a/hutool-http/src/test/java/cn/hutool/http/IssueI5TPSYTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/IssueI5TPSYTest.java @@ -4,13 +4,13 @@ import cn.hutool.core.lang.Console; import cn.hutool.http.client.Request; import cn.hutool.http.client.Response; import cn.hutool.http.meta.Header; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class IssueI5TPSYTest { @Test - @Ignore + @Disabled public void redirectTest() { final String url = "https://bsxt.gdzwfw.gov.cn/UnifiedReporting/auth/newIndex"; final Response res = HttpUtil.send(Request.of(url) diff --git a/hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java b/hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java index dc8687d10..30d75c579 100755 --- a/hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java +++ b/hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java @@ -2,8 +2,8 @@ package cn.hutool.http; import cn.hutool.http.client.Request; import cn.hutool.json.JSONUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; @@ -11,7 +11,7 @@ import java.util.Map; public class IssueI5WAV4Test { @Test - @Ignore + @Disabled public void getTest(){ //测试代码 final Map map = new HashMap<>(); diff --git a/hutool-http/src/test/java/cn/hutool/http/IssueI5XBCFTest.java b/hutool-http/src/test/java/cn/hutool/http/IssueI5XBCFTest.java index 43b0d5e5d..4e64d1a7d 100755 --- a/hutool-http/src/test/java/cn/hutool/http/IssueI5XBCFTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/IssueI5XBCFTest.java @@ -5,13 +5,13 @@ import cn.hutool.http.client.Request; import cn.hutool.http.client.Response; import cn.hutool.http.meta.Header; import org.brotli.dec.BrotliInputStream; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class IssueI5XBCFTest { @Test - @Ignore + @Disabled public void getTest() { GlobalCompressStreamRegister.INSTANCE.register("br", BrotliInputStream.class); diff --git a/hutool-http/src/test/java/cn/hutool/http/RestTest.java b/hutool-http/src/test/java/cn/hutool/http/RestTest.java index 555a36872..f1b9001b6 100644 --- a/hutool-http/src/test/java/cn/hutool/http/RestTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/RestTest.java @@ -5,9 +5,9 @@ import cn.hutool.http.client.Request; import cn.hutool.http.meta.Header; import cn.hutool.http.meta.Method; import cn.hutool.json.JSONUtil; -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; /** * Rest类型请求单元测试 @@ -24,12 +24,12 @@ public class RestTest { .body(JSONUtil.ofObj() .set("aaa", "aaaValue") .set("键2", "值2").toString()); - Assert.assertEquals("application/json;charset=UTF-8", request.header(Header.CONTENT_TYPE)); + Assertions.assertEquals("application/json;charset=UTF-8", request.header(Header.CONTENT_TYPE)); } @SuppressWarnings("resource") @Test - @Ignore + @Disabled public void postTest() { final Request request = Request.of("http://localhost:8090/rest/restTest/") .method(Method.POST) @@ -40,7 +40,7 @@ public class RestTest { } @Test - @Ignore + @Disabled public void postTest2() { final String result = HttpUtil.post("http://localhost:8090/rest/restTest/", JSONUtil.ofObj()// .set("aaa", "aaaValue") @@ -49,7 +49,7 @@ public class RestTest { } @Test - @Ignore + @Disabled public void getWithBodyTest() { final Request request = Request.of("http://localhost:8888/restTest")// .header(Header.CONTENT_TYPE, "application/json") diff --git a/hutool-http/src/test/java/cn/hutool/http/UploadTest.java b/hutool-http/src/test/java/cn/hutool/http/UploadTest.java index 2117b9be7..aff8d1e1b 100644 --- a/hutool-http/src/test/java/cn/hutool/http/UploadTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/UploadTest.java @@ -8,8 +8,8 @@ import cn.hutool.http.client.Request; import cn.hutool.http.client.Response; import cn.hutool.http.meta.Header; import cn.hutool.http.meta.Method; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.HashMap; @@ -26,7 +26,7 @@ public class UploadTest { * 多文件上传测试 */ @Test - @Ignore + @Disabled public void uploadFilesTest() { final File file = FileUtil.file("d:\\图片1.JPG"); final File file2 = FileUtil.file("d:\\图片3.png"); @@ -47,7 +47,7 @@ public class UploadTest { } @Test - @Ignore + @Disabled public void uploadFileTest() { final File file = FileUtil.file("D:\\face.jpg"); @@ -60,7 +60,7 @@ public class UploadTest { } @Test - @Ignore + @Disabled public void smmsTest(){ // https://github.com/dromara/hutool/issues/2079 // hutool的user agent 被封了 diff --git a/hutool-http/src/test/java/cn/hutool/http/client/ClientEngineFactoryTest.java b/hutool-http/src/test/java/cn/hutool/http/client/ClientEngineFactoryTest.java index fa57e9d13..9ac6bea4a 100755 --- a/hutool-http/src/test/java/cn/hutool/http/client/ClientEngineFactoryTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/client/ClientEngineFactoryTest.java @@ -1,13 +1,13 @@ package cn.hutool.http.client; import cn.hutool.http.client.engine.ClientEngineFactory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ClientEngineFactoryTest { @Test public void getTest() { final ClientEngine clientEngineFactory = ClientEngineFactory.get(); - Assert.assertNotNull(clientEngineFactory); + Assertions.assertNotNull(clientEngineFactory); } } diff --git a/hutool-http/src/test/java/cn/hutool/http/client/HttpClient4EngineTest.java b/hutool-http/src/test/java/cn/hutool/http/client/HttpClient4EngineTest.java index 2a5ef4f3e..9066e739e 100755 --- a/hutool-http/src/test/java/cn/hutool/http/client/HttpClient4EngineTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/client/HttpClient4EngineTest.java @@ -3,14 +3,14 @@ package cn.hutool.http.client; import cn.hutool.core.lang.Console; import cn.hutool.http.client.engine.httpclient4.HttpClient4Engine; import cn.hutool.http.meta.Method; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class HttpClient4EngineTest { @SuppressWarnings("resource") @Test - @Ignore + @Disabled public void getTest() { final ClientEngine engine = new HttpClient4Engine(); diff --git a/hutool-http/src/test/java/cn/hutool/http/client/HttpClient5EngineTest.java b/hutool-http/src/test/java/cn/hutool/http/client/HttpClient5EngineTest.java index c1b447ec0..0cd39c6e1 100755 --- a/hutool-http/src/test/java/cn/hutool/http/client/HttpClient5EngineTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/client/HttpClient5EngineTest.java @@ -3,14 +3,14 @@ package cn.hutool.http.client; import cn.hutool.core.lang.Console; import cn.hutool.http.client.engine.httpclient5.HttpClient5Engine; import cn.hutool.http.meta.Method; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class HttpClient5EngineTest { @SuppressWarnings("resource") @Test - @Ignore + @Disabled public void getTest() { final ClientEngine engine = new HttpClient5Engine(); diff --git a/hutool-http/src/test/java/cn/hutool/http/client/HttpUrlConnectionUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/client/HttpUrlConnectionUtilTest.java index 53bdb480f..712d66648 100755 --- a/hutool-http/src/test/java/cn/hutool/http/client/HttpUrlConnectionUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/client/HttpUrlConnectionUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.http.client; import cn.hutool.http.client.engine.jdk.HttpUrlConnectionUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class HttpUrlConnectionUtilTest { @Test diff --git a/hutool-http/src/test/java/cn/hutool/http/client/JdkEngineTest.java b/hutool-http/src/test/java/cn/hutool/http/client/JdkEngineTest.java index 0e69f5155..5022fd171 100755 --- a/hutool-http/src/test/java/cn/hutool/http/client/JdkEngineTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/client/JdkEngineTest.java @@ -3,13 +3,13 @@ package cn.hutool.http.client; import cn.hutool.core.lang.Console; import cn.hutool.http.client.engine.jdk.JdkClientEngine; import cn.hutool.http.meta.Method; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class JdkEngineTest { @Test - @Ignore + @Disabled public void getTest(){ final ClientEngine engine = new JdkClientEngine(); diff --git a/hutool-http/src/test/java/cn/hutool/http/client/OkHttpEngineTest.java b/hutool-http/src/test/java/cn/hutool/http/client/OkHttpEngineTest.java index 83714ffb6..5af6352f4 100755 --- a/hutool-http/src/test/java/cn/hutool/http/client/OkHttpEngineTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/client/OkHttpEngineTest.java @@ -3,14 +3,14 @@ package cn.hutool.http.client; import cn.hutool.core.lang.Console; import cn.hutool.http.client.engine.okhttp.OkHttpEngine; import cn.hutool.http.meta.Method; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class OkHttpEngineTest { @SuppressWarnings("resource") @Test - @Ignore + @Disabled public void getTest(){ final ClientEngine engine = new OkHttpEngine(); diff --git a/hutool-http/src/test/java/cn/hutool/http/client/body/MultipartBodyTest.java b/hutool-http/src/test/java/cn/hutool/http/client/body/MultipartBodyTest.java index 5fd810889..2f3581753 100644 --- a/hutool-http/src/test/java/cn/hutool/http/client/body/MultipartBodyTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/client/body/MultipartBodyTest.java @@ -3,8 +3,8 @@ package cn.hutool.http.client.body; import cn.hutool.core.io.resource.HttpResource; import cn.hutool.core.io.resource.StringResource; 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.HashMap; import java.util.Map; @@ -22,7 +22,7 @@ public class MultipartBodyTest { final MultipartBody body = MultipartBody.of(form, CharsetUtil.UTF_8); - Assert.assertNotNull(body.toString()); + Assertions.assertNotNull(body.toString()); // Console.log(body); } } diff --git a/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java index 21047c802..fb22d8750 100644 --- a/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.http.useragent; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class UserAgentUtilTest { @@ -10,14 +10,14 @@ public class UserAgentUtilTest { final String uaStr = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("Chrome", ua.getBrowser().toString()); - Assert.assertEquals("14.0.835.163", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("535.1", ua.getEngineVersion()); - Assert.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); - Assert.assertEquals("6.1", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("Chrome", ua.getBrowser().toString()); + Assertions.assertEquals("14.0.835.163", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("535.1", ua.getEngineVersion()); + Assertions.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); + Assertions.assertEquals("6.1", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test @@ -25,182 +25,182 @@ public class UserAgentUtilTest { final String uaStr = "User-Agent:Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("Safari", ua.getBrowser().toString()); - Assert.assertEquals("5.0.2", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("533.17.9", ua.getEngineVersion()); - Assert.assertEquals("iPhone", ua.getOs().toString()); - Assert.assertEquals("4_3_3", ua.getOsVersion()); - Assert.assertEquals("iPhone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("Safari", ua.getBrowser().toString()); + Assertions.assertEquals("5.0.2", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("533.17.9", ua.getEngineVersion()); + Assertions.assertEquals("iPhone", ua.getOs().toString()); + Assertions.assertEquals("4_3_3", ua.getOsVersion()); + Assertions.assertEquals("iPhone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseMiui10WithChromeTest() { final String uaStr = "Mozilla/5.0 (Linux; Android 9; MIX 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.80 Mobile Safari/537.36"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("Chrome", ua.getBrowser().toString()); - Assert.assertEquals("70.0.3538.80", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("9", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("Chrome", ua.getBrowser().toString()); + Assertions.assertEquals("70.0.3538.80", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("9", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseHuaweiPhoneWithNativeBrowserTest() { final String uaString = "Mozilla/5.0 (Linux; Android 10; EML-AL00 Build/HUAWEIEML-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("Android Browser", ua.getBrowser().toString()); - Assert.assertEquals("4.0", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("10", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("Android Browser", ua.getBrowser().toString()); + Assertions.assertEquals("4.0", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("10", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseSamsungPhoneWithNativeBrowserTest() { final String uaString = "Dalvik/2.1.0 (Linux; U; Android 9; SM-G950U Build/PPR1.180610.011)"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("Android Browser", ua.getBrowser().toString()); - Assert.assertNull(ua.getVersion()); - Assert.assertEquals("Unknown", ua.getEngine().toString()); - Assert.assertNull(ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("9", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("Android Browser", ua.getBrowser().toString()); + Assertions.assertNull(ua.getVersion()); + Assertions.assertEquals("Unknown", ua.getEngine().toString()); + Assertions.assertNull(ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("9", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseWindows10WithChromeTest() { final String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("Chrome", ua.getBrowser().toString()); - Assert.assertEquals("70.0.3538.102", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("Chrome", ua.getBrowser().toString()); + Assertions.assertEquals("70.0.3538.102", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseWindows10WithIe11Test() { final String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MSIE11", ua.getBrowser().toString()); - Assert.assertEquals("11.0", ua.getVersion()); - Assert.assertEquals("Trident", ua.getEngine().toString()); - Assert.assertEquals("7.0", ua.getEngineVersion()); - Assert.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("MSIE11", ua.getBrowser().toString()); + Assertions.assertEquals("11.0", ua.getVersion()); + Assertions.assertEquals("Trident", ua.getEngine().toString()); + Assertions.assertEquals("7.0", ua.getEngineVersion()); + Assertions.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseWindows10WithIeMobileLumia520Test() { final String uaStr = "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537 "; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("IEMobile", ua.getBrowser().toString()); - Assert.assertEquals("11.0", ua.getVersion()); - Assert.assertEquals("Trident", ua.getEngine().toString()); - Assert.assertEquals("7.0", ua.getEngineVersion()); - Assert.assertEquals("Windows Phone", ua.getOs().toString()); - Assert.assertEquals("8.1", ua.getOsVersion()); - Assert.assertEquals("Windows Phone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("IEMobile", ua.getBrowser().toString()); + Assertions.assertEquals("11.0", ua.getVersion()); + Assertions.assertEquals("Trident", ua.getEngine().toString()); + Assertions.assertEquals("7.0", ua.getEngineVersion()); + Assertions.assertEquals("Windows Phone", ua.getOs().toString()); + Assertions.assertEquals("8.1", ua.getOsVersion()); + Assertions.assertEquals("Windows Phone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseWindows10WithIe8EmulatorTest() { final String uaStr = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MSIE", ua.getBrowser().toString()); - Assert.assertEquals("8.0", ua.getVersion()); - Assert.assertEquals("Trident", ua.getEngine().toString()); - Assert.assertEquals("4.0", ua.getEngineVersion()); - Assert.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); - Assert.assertEquals("6.1", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("MSIE", ua.getBrowser().toString()); + Assertions.assertEquals("8.0", ua.getVersion()); + Assertions.assertEquals("Trident", ua.getEngine().toString()); + Assertions.assertEquals("4.0", ua.getEngineVersion()); + Assertions.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); + Assertions.assertEquals("6.1", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseWindows10WithEdgeTest() { final String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MSEdge", ua.getBrowser().toString()); - Assert.assertEquals("18.17763", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("MSEdge", ua.getBrowser().toString()); + Assertions.assertEquals("18.17763", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseEdgeOnLumia950XLTest() { final String uaStr = "Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; Lumia 950XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36 Edge/15.14900"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MSEdge", ua.getBrowser().toString()); - Assert.assertEquals("15.14900", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows Phone", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows Phone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("MSEdge", ua.getBrowser().toString()); + Assertions.assertEquals("15.14900", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows Phone", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows Phone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseChromeOnWindowsServer2012R2Test() { final String uaStr = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("Chrome", ua.getBrowser().toString()); - Assert.assertEquals("63.0.3239.132", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 8.1 or Windows Server 2012R2", ua.getOs().toString()); - Assert.assertEquals("6.3", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("Chrome", ua.getBrowser().toString()); + Assertions.assertEquals("63.0.3239.132", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 8.1 or Windows Server 2012R2", ua.getOs().toString()); + Assertions.assertEquals("6.3", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseIE11OnWindowsServer2008R2Test() { final String uaStr = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MSIE11", ua.getBrowser().toString()); - Assert.assertEquals("11.0", ua.getVersion()); - Assert.assertEquals("Trident", ua.getEngine().toString()); - Assert.assertEquals("7.0", ua.getEngineVersion()); - Assert.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); - Assert.assertEquals("6.1", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("MSIE11", ua.getBrowser().toString()); + Assertions.assertEquals("11.0", ua.getVersion()); + Assertions.assertEquals("Trident", ua.getEngine().toString()); + Assertions.assertEquals("7.0", ua.getEngineVersion()); + Assertions.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); + Assertions.assertEquals("6.1", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseEdgeTest() { final String uaStr = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.69 Safari/537.36 Edg/81.0.416.34"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MSEdge", ua.getBrowser().toString()); - Assert.assertEquals("81.0.416.34", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("MSEdge", ua.getBrowser().toString()); + Assertions.assertEquals("81.0.416.34", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } /** @@ -210,153 +210,153 @@ public class UserAgentUtilTest { public void parseMicroMessengerTest() { final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Mobile/15A372 MicroMessenger/7.0.17(0x17001127) NetType/WIFI Language/zh_CN"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("MicroMessenger", ua.getBrowser().toString()); - Assert.assertEquals("7.0.17", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("604.1.38", ua.getEngineVersion()); - Assert.assertEquals("iPhone", ua.getOs().toString()); - Assert.assertEquals("11_0", ua.getOsVersion()); - Assert.assertEquals("iPhone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("MicroMessenger", ua.getBrowser().toString()); + Assertions.assertEquals("7.0.17", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("604.1.38", ua.getEngineVersion()); + Assertions.assertEquals("iPhone", ua.getOs().toString()); + Assertions.assertEquals("11_0", ua.getOsVersion()); + Assertions.assertEquals("iPhone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseWorkWxTest() { final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 wxwork/3.0.31 MicroMessenger/7.0.1 Language/zh"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("wxwork", ua.getBrowser().toString()); - Assert.assertEquals("3.0.31", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("605.1.15", ua.getEngineVersion()); - Assert.assertEquals("iPhone", ua.getOs().toString()); - Assert.assertEquals("iPhone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("wxwork", ua.getBrowser().toString()); + Assertions.assertEquals("3.0.31", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("605.1.15", ua.getEngineVersion()); + Assertions.assertEquals("iPhone", ua.getOs().toString()); + Assertions.assertEquals("iPhone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseQQTest() { final String uaString = "User-Agent: MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("QQBrowser", ua.getBrowser().toString()); - Assert.assertEquals("26", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("533.1", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("2.3.7", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("QQBrowser", ua.getBrowser().toString()); + Assertions.assertEquals("26", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("533.1", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("2.3.7", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseDingTalkTest() { final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/18A373 AliApp(DingTalk/5.1.33) com.laiwang.DingTalk/13976299 Channel/201200 language/zh-Hans-CN WK"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("DingTalk", ua.getBrowser().toString()); - Assert.assertEquals("5.1.33", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("605.1.15", ua.getEngineVersion()); - Assert.assertEquals("iPhone", ua.getOs().toString()); - Assert.assertEquals("14_0", ua.getOsVersion()); - Assert.assertEquals("iPhone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("DingTalk", ua.getBrowser().toString()); + Assertions.assertEquals("5.1.33", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("605.1.15", ua.getEngineVersion()); + Assertions.assertEquals("iPhone", ua.getOs().toString()); + Assertions.assertEquals("14_0", ua.getOsVersion()); + Assertions.assertEquals("iPhone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseAlipayTest() { final String uaString = "Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; FRD-AL00 Build/HUAWEIFRD-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.3.8.909 UWS/2.10.2.5 Mobile Safari/537.36 UCBS/2.10.2.5 Nebula AlipayDefined(nt:WIFI,ws:360|0|3.0) AliApp(AP/10.0.18.062203) AlipayClient/10.0.18.062203 Language/zh-Hans useStatusBar/true"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("Alipay", ua.getBrowser().toString()); - Assert.assertEquals("10.0.18.062203", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("7.0", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("Alipay", ua.getBrowser().toString()); + Assertions.assertEquals("10.0.18.062203", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("7.0", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseTaobaoTest() { final String uaString = "Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; MI 2C Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 AliApp(TB/4.9.2) WindVane/5.2.2 TBANDROID/700342@taobao_android_4.9.2 720X1280"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("Taobao", ua.getBrowser().toString()); - Assert.assertEquals("4.9.2", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("4.4.4", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("Taobao", ua.getBrowser().toString()); + Assertions.assertEquals("4.9.2", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("4.4.4", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseUCTest() { final String uaString = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 UBrowser/4.0.3214.0 Safari/537.36"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("UCBrowser", ua.getBrowser().toString()); - Assert.assertEquals("4.0.3214.0", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); - Assert.assertEquals("6.1", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("UCBrowser", ua.getBrowser().toString()); + Assertions.assertEquals("4.0.3214.0", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 7 or Windows Server 2008R2", ua.getOs().toString()); + Assertions.assertEquals("6.1", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseUCTest2() { final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/16G102 UCBrowser/12.7.6.1251 Mobile AliApp(TUnionSDK/0.1.20.3)"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("UCBrowser", ua.getBrowser().toString()); - Assert.assertEquals("12.7.6.1251", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.51.1", ua.getEngineVersion()); - Assert.assertEquals("iPhone", ua.getOs().toString()); - Assert.assertEquals("12_4_1", ua.getOsVersion()); - Assert.assertEquals("iPhone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("UCBrowser", ua.getBrowser().toString()); + Assertions.assertEquals("12.7.6.1251", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.51.1", ua.getEngineVersion()); + Assertions.assertEquals("iPhone", ua.getOs().toString()); + Assertions.assertEquals("12_4_1", ua.getOsVersion()); + Assertions.assertEquals("iPhone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseQuarkTest() { final String uaString = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X; zh-cn) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/16G102 Quark/3.6.2.993 Mobile"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("Quark", ua.getBrowser().toString()); - Assert.assertEquals("3.6.2.993", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("601.1.46", ua.getEngineVersion()); - Assert.assertEquals("iPhone", ua.getOs().toString()); - Assert.assertEquals("12_4_1", ua.getOsVersion()); - Assert.assertEquals("iPhone", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("Quark", ua.getBrowser().toString()); + Assertions.assertEquals("3.6.2.993", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("601.1.46", ua.getEngineVersion()); + Assertions.assertEquals("iPhone", ua.getOs().toString()); + Assertions.assertEquals("12_4_1", ua.getOsVersion()); + Assertions.assertEquals("iPhone", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test public void parseWxworkTest() { final String uaString = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1326.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 wxwork/3.1.10 (MicroMessenger/6.2) WindowsWechat"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("wxwork", ua.getBrowser().toString()); - Assert.assertEquals("3.1.10", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("wxwork", ua.getBrowser().toString()); + Assertions.assertEquals("3.1.10", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test public void parseWxworkMobileTest() { final String uaString = "Mozilla/5.0 (Linux; Android 10; JSN-AL00 Build/HONORJSN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045710 Mobile Safari/537.36 wxwork/3.1.10 ColorScheme/Light MicroMessenger/7.0.1 NetType/WIFI Language/zh Lang/zh"; final UserAgent ua = UserAgentUtil.parse(uaString); - Assert.assertEquals("wxwork", ua.getBrowser().toString()); - Assert.assertEquals("3.1.10", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("10", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("wxwork", ua.getBrowser().toString()); + Assertions.assertEquals("3.1.10", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("10", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test @@ -364,14 +364,14 @@ public class UserAgentUtilTest { // https://gitee.com/dromara/hutool/issues/I4MCBP final String uaStr = "userAgent: Mozilla/5.0 (Linux; Android 11; MI 9 Transparent Edition) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Mobile Safari/537.36 EdgA/96.0.1054.36"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MSEdge", ua.getBrowser().toString()); - Assert.assertEquals("96.0.1054.36", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("11", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("MSEdge", ua.getBrowser().toString()); + Assertions.assertEquals("96.0.1054.36", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("11", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test @@ -380,14 +380,14 @@ public class UserAgentUtilTest { final String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("Lenovo", ua.getBrowser().toString()); - Assert.assertEquals("7.0.0.6241", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("Lenovo", ua.getBrowser().toString()); + Assertions.assertEquals("7.0.0.6241", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } @Test @@ -395,14 +395,14 @@ public class UserAgentUtilTest { final String uaStr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/89.0.4389.116 Safari/534.24 XiaoMi/MiuiBrowser/16.0.18 swan-mibrowser"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("MiuiBrowser", ua.getBrowser().toString()); - Assert.assertEquals("16.0.18", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("534.24", ua.getEngineVersion()); - Assert.assertEquals("Android", ua.getOs().toString()); - Assert.assertEquals("11", ua.getOsVersion()); - Assert.assertEquals("Android", ua.getPlatform().toString()); - Assert.assertTrue(ua.isMobile()); + Assertions.assertEquals("MiuiBrowser", ua.getBrowser().toString()); + Assertions.assertEquals("16.0.18", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("534.24", ua.getEngineVersion()); + Assertions.assertEquals("Android", ua.getOs().toString()); + Assertions.assertEquals("11", ua.getOsVersion()); + Assertions.assertEquals("Android", ua.getPlatform().toString()); + Assertions.assertTrue(ua.isMobile()); } @Test @@ -410,20 +410,20 @@ public class UserAgentUtilTest { // https://gitee.com/dromara/hutool/issues/I50YGY final String uaStr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("Linux", ua.getOs().toString()); + Assertions.assertEquals("Linux", ua.getOs().toString()); } @Test public void issueI60UOPTest() { final String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36 dingtalk-win/1.0.0 nw(0.14.7) DingTalk(6.5.40-Release.9059101) Mojo/1.0.0 Native AppType(release) Channel/201200"; final UserAgent ua = UserAgentUtil.parse(uaStr); - Assert.assertEquals("DingTalk-win", ua.getBrowser().toString()); - Assert.assertEquals("6.5.40-Release.9059101", ua.getVersion()); - Assert.assertEquals("Webkit", ua.getEngine().toString()); - Assert.assertEquals("537.36", ua.getEngineVersion()); - Assert.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); - Assert.assertEquals("10.0", ua.getOsVersion()); - Assert.assertEquals("Windows", ua.getPlatform().toString()); - Assert.assertFalse(ua.isMobile()); + Assertions.assertEquals("DingTalk-win", ua.getBrowser().toString()); + Assertions.assertEquals("6.5.40-Release.9059101", ua.getVersion()); + Assertions.assertEquals("Webkit", ua.getEngine().toString()); + Assertions.assertEquals("537.36", ua.getEngineVersion()); + Assertions.assertEquals("Windows 10 or Windows Server 2016", ua.getOs().toString()); + Assertions.assertEquals("10.0", ua.getOsVersion()); + Assertions.assertEquals("Windows", ua.getPlatform().toString()); + Assertions.assertFalse(ua.isMobile()); } } diff --git a/hutool-http/src/test/java/cn/hutool/http/webservice/SoapClientTest.java b/hutool-http/src/test/java/cn/hutool/http/webservice/SoapClientTest.java index 4e7a28f62..b27a1c51e 100644 --- a/hutool-http/src/test/java/cn/hutool/http/webservice/SoapClientTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/webservice/SoapClientTest.java @@ -2,8 +2,8 @@ package cn.hutool.http.webservice; import cn.hutool.core.lang.Console; 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 javax.xml.soap.SOAPException; import javax.xml.soap.SOAPMessage; @@ -17,7 +17,7 @@ import javax.xml.soap.SOAPMessage; public class SoapClientTest { @Test - @Ignore + @Disabled public void requestTest() { final SoapClient client = SoapClient.of("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx") .setMethod("web:getCountryCityByIp", "http://WebXml.com.cn/") @@ -30,7 +30,7 @@ public class SoapClientTest { } @Test - @Ignore + @Disabled public void requestForMessageTest() throws SOAPException { final SoapClient client = SoapClient.of("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx") .setMethod("web:getCountryCityByIp", "http://WebXml.com.cn/") diff --git a/hutool-json/src/test/java/cn/hutool/json/CustomSerializeTest.java b/hutool-json/src/test/java/cn/hutool/json/CustomSerializeTest.java index e22a07f57..f511c3a36 100644 --- a/hutool-json/src/test/java/cn/hutool/json/CustomSerializeTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/CustomSerializeTest.java @@ -2,15 +2,15 @@ package cn.hutool.json; import cn.hutool.json.serialize.JSONObjectSerializer; import lombok.ToString; -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.Date; public class CustomSerializeTest { - @Before + @BeforeEach public void init(){ JSONUtil.putSerializer(CustomBean.class, (JSONObjectSerializer) (json, bean) -> json.set("customName", bean.name)); } @@ -21,7 +21,7 @@ public class CustomSerializeTest { customBean.name = "testName"; final JSONObject obj = JSONUtil.parseObj(customBean); - Assert.assertEquals("testName", obj.getStr("customName")); + Assertions.assertEquals("testName", obj.getStr("customName")); } @Test @@ -30,7 +30,7 @@ public class CustomSerializeTest { customBean.name = "testName"; final JSONObject obj = JSONUtil.ofObj().set("customBean", customBean); - Assert.assertEquals("testName", obj.getJSONObject("customBean").getStr("customName")); + Assertions.assertEquals("testName", obj.getJSONObject("customBean").getStr("customName")); } @Test @@ -43,7 +43,7 @@ public class CustomSerializeTest { final String jsonStr = "{\"customName\":\"testName\"}"; final CustomBean bean = JSONUtil.parseObj(jsonStr).toBean(CustomBean.class); - Assert.assertEquals("testName", bean.name); + Assertions.assertEquals("testName", bean.name); } @ToString diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue1075Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue1075Test.java index bfd4edd05..f7a8ee737 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue1075Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue1075Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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 Issue1075Test { @@ -12,8 +12,8 @@ public class Issue1075Test { public void testToBean() { // 在不忽略大小写的情况下,f2、fac都不匹配 final ObjA o2 = JSONUtil.toBean(jsonStr, ObjA.class); - Assert.assertNull(o2.getFAC()); - Assert.assertNull(o2.getF2()); + Assertions.assertNull(o2.getFAC()); + Assertions.assertNull(o2.getF2()); } @Test @@ -21,8 +21,8 @@ public class Issue1075Test { // 在忽略大小写的情况下,f2、fac都匹配 final ObjA o2 = JSONUtil.parseObj(jsonStr, JSONConfig.of().setIgnoreCase(true)).toBean(ObjA.class); - Assert.assertEquals("fac", o2.getFAC()); - Assert.assertEquals("f2", o2.getF2()); + Assertions.assertEquals("fac", o2.getFAC()); + Assertions.assertEquals("f2", o2.getF2()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue1101Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue1101Test.java index 688af266a..183182196 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue1101Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue1101Test.java @@ -4,8 +4,8 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.reflect.TypeReference; 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.Comparator; import java.util.TreeSet; @@ -21,7 +21,7 @@ public class Issue1101Test { final JSONArray objects = JSONUtil.parseArray(json); final TreeSet convert = Convert.convert(new TypeReference>() { }, objects); - Assert.assertEquals(2, convert.size()); + Assertions.assertEquals(2, convert.size()); } @Test @@ -58,11 +58,11 @@ public class Issue1101Test { final JSONObject jsonObject = JSONUtil.parseObj(json); final TreeNode treeNode = JSONUtil.toBean(jsonObject, TreeNode.class); - Assert.assertEquals(2, treeNode.getChildren().size()); + Assertions.assertEquals(2, treeNode.getChildren().size()); final TreeNodeDto dto = new TreeNodeDto(); BeanUtil.copyProperties(treeNode, dto, true); - Assert.assertEquals(2, dto.getChildren().size()); + Assertions.assertEquals(2, dto.getChildren().size()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue1200Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue1200Test.java index b3fa0e8dc..117cfec97 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue1200Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue1200Test.java @@ -3,8 +3,8 @@ package cn.hutool.json; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.lang.Console; import cn.hutool.json.test.bean.ResultBean; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * 测试在bean转换时使用BeanConverter,默认忽略转换失败的字段。 @@ -16,7 +16,7 @@ import org.junit.Test; public class Issue1200Test { @Test - @Ignore + @Disabled public void toBeanTest(){ final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issue1200.json")); Console.log(jsonObject); diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2090Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2090Test.java index d6ff166d7..906bc6612 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2090Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2090Test.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.lang.Console; 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.time.LocalDate; import java.time.LocalDateTime; @@ -23,14 +23,14 @@ public class Issue2090Test { final JSONObject json = JSONUtil.parseObj(test); Console.log(json); final TestBean test1 = json.toBean(TestBean.class); - Assert.assertEquals(test, test1); + Assertions.assertEquals(test, test1); } @Test public void parseLocalDateTest(){ final LocalDate localDate = LocalDate.now(); final JSONObject jsonObject = JSONUtil.parseObj(localDate); - Assert.assertNotNull(jsonObject.toString()); + Assertions.assertNotNull(jsonObject.toString()); } @Test @@ -38,7 +38,7 @@ public class Issue2090Test { final LocalDate d = LocalDate.now(); final JSONObject obj = JSONUtil.parseObj(d); final LocalDate d2 = obj.toBean(LocalDate.class); - Assert.assertEquals(d, d2); + Assertions.assertEquals(d, d2); } @Test @@ -46,7 +46,7 @@ public class Issue2090Test { final LocalDateTime d = LocalDateTime.now(); final JSONObject obj = JSONUtil.parseObj(d); final LocalDateTime d2 = obj.toBean(LocalDateTime.class); - Assert.assertEquals(d, d2); + Assertions.assertEquals(d, d2); } @Test @@ -54,14 +54,14 @@ public class Issue2090Test { final LocalTime d = LocalTime.now(); final JSONObject obj = JSONUtil.parseObj(d); final LocalTime d2 = obj.toBean(LocalTime.class); - Assert.assertEquals(d, d2); + Assertions.assertEquals(d, d2); } @Test public void monthTest(){ final JSONObject jsonObject = new JSONObject(); jsonObject.set("month", Month.JANUARY); - Assert.assertEquals("{\"month\":1}", jsonObject.toString()); + Assertions.assertEquals("{\"month\":1}", jsonObject.toString()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2131Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2131Test.java index 437621b7c..26f2715db 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2131Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2131Test.java @@ -4,8 +4,8 @@ import cn.hutool.core.collection.ListUtil; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.beans.Transient; import java.util.List; @@ -29,7 +29,7 @@ public class Issue2131Test { final JSONObject jsonObject = JSONUtil.parseObj(jsonStr); final GoodsResponse result = jsonObject.toBean(GoodsResponse.class); - Assert.assertEquals(0, result.getCollections().size()); + Assertions.assertEquals(0, result.getCollections().size()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2223Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2223Test.java index 327c81015..dbc8eae63 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2223Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2223Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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.LinkedHashMap; @@ -17,17 +17,17 @@ public class Issue2223Test { m1.put("2022/" + i, i); } - Assert.assertEquals("{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}", JSONUtil.toJsonStr(m1)); + Assertions.assertEquals("{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}", JSONUtil.toJsonStr(m1)); final Map> map1 = new HashMap<>(); map1.put("m1", m1); - Assert.assertEquals("{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}", + Assertions.assertEquals("{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}", JSONUtil.toJsonStr(map1, JSONConfig.of())); final BeanDemo beanDemo = new BeanDemo(); beanDemo.setMap1(map1); - Assert.assertEquals("{\"map1\":{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}}", + Assertions.assertEquals("{\"map1\":{\"m1\":{\"2022/0\":0,\"2022/1\":1,\"2022/2\":2,\"2022/3\":3,\"2022/4\":4}}}", JSONUtil.toJsonStr(beanDemo, JSONConfig.of())); } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2377Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2377Test.java index dc7c84a78..7bd32357a 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2377Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2377Test.java @@ -1,7 +1,7 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; @@ -10,14 +10,14 @@ public class Issue2377Test { public void bytesTest() { final Object[] paramArray = new Object[]{1, new byte[]{10, 11}, "报表.xlsx"}; final String paramsStr = JSONUtil.toJsonStr(paramArray); - Assert.assertEquals("[1,[10,11],\"报表.xlsx\"]", paramsStr); + Assertions.assertEquals("[1,[10,11],\"报表.xlsx\"]", paramsStr); final List paramList = JSONUtil.toList(paramsStr, Object.class); final String paramBytesStr = JSONUtil.toJsonStr(paramList.get(1)); - Assert.assertEquals("[10,11]", paramBytesStr); + Assertions.assertEquals("[10,11]", paramBytesStr); final byte[] paramBytes = JSONUtil.toBean(paramBytesStr, byte[].class); - Assert.assertArrayEquals((byte[]) paramArray[1], paramBytes); + Assertions.assertArrayEquals((byte[]) paramArray[1], paramBytes); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2447Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2447Test.java index d9ccb17e8..2818ee68c 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2447Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2447Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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.time.LocalDateTime; @@ -13,8 +13,8 @@ public class Issue2447Test { Time time = new Time(); time.setTime(LocalDateTime.of(1970, 1, 2, 10, 0, 1, 0)); String timeStr = JSONUtil.toJsonStr(time); - Assert.assertEquals(timeStr, "{\"time\":93601000}"); - Assert.assertEquals(JSONUtil.toBean(timeStr, Time.class).getTime(), time.getTime()); + Assertions.assertEquals(timeStr, "{\"time\":93601000}"); + Assertions.assertEquals(JSONUtil.toBean(timeStr, Time.class).getTime(), time.getTime()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2507Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2507Test.java index 5101aec1b..5012f00bb 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2507Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2507Test.java @@ -1,13 +1,13 @@ package cn.hutool.json; 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; public class Issue2507Test { @Test - @Ignore + @Disabled public void xmlToJsonTest(){ String xml = " 低盐饮食[嘱托]]>]]> 流质饮食]]> "; JSONObject jsonObject = JSONUtil.xmlToJson(xml); diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2555Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2555Test.java index 9d1cdc6f2..3cba6285e 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2555Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2555Test.java @@ -3,8 +3,8 @@ package cn.hutool.json; import cn.hutool.json.serialize.JSONDeserializer; import cn.hutool.json.serialize.JSONObjectSerializer; 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 Issue2555Test { @Test @@ -18,11 +18,11 @@ public class Issue2555Test { simpleObj.setMyType(child); final String json = JSONUtil.toJsonStr(simpleObj); - Assert.assertEquals("{\"myType\":{\"addr\":\"addrValue1\"}}", json); + Assertions.assertEquals("{\"myType\":{\"addr\":\"addrValue1\"}}", json); //MyDeserializer不会被调用 final SimpleObj simpleObj2 = JSONUtil.toBean(json, SimpleObj.class); - Assert.assertEquals("addrValue1", simpleObj2.getMyType().getAddress()); + Assertions.assertEquals("addrValue1", simpleObj2.getMyType().getAddress()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2564Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2564Test.java index a70ec745d..1c8a9ae7d 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2564Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2564Test.java @@ -2,8 +2,8 @@ package cn.hutool.json; import lombok.Getter; import lombok.Setter; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Issue2564Test { @@ -14,7 +14,7 @@ public class Issue2564Test { public void emptyToBeanTest(){ final String x = "{}"; final A a = JSONUtil.toBean(x, JSONConfig.of().setIgnoreError(true), A.class); - Assert.assertNull(a); + Assertions.assertNull(a); } @Getter diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2572Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2572Test.java index f6be2e764..d90776a66 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2572Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2572Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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.time.DayOfWeek; import java.time.Month; @@ -18,11 +18,11 @@ public class Issue2572Test { weeks.add(DayOfWeek.MONDAY); final JSONObject obj = new JSONObject(); obj.set("weeks", weeks); - Assert.assertEquals("{\"weeks\":[1]}", obj.toString()); + Assertions.assertEquals("{\"weeks\":[1]}", obj.toString()); final Map> monthDays1 = obj.toBean(new TypeReference>>() { }); - Assert.assertEquals("{weeks=[MONDAY]}", monthDays1.toString()); + Assertions.assertEquals("{weeks=[MONDAY]}", monthDays1.toString()); } @Test @@ -31,11 +31,11 @@ public class Issue2572Test { months.add(Month.DECEMBER); final JSONObject obj = new JSONObject(); obj.set("months", months); - Assert.assertEquals("{\"months\":[12]}", obj.toString()); + Assertions.assertEquals("{\"months\":[12]}", obj.toString()); final Map> monthDays1 = obj.toBean(new TypeReference>>() { }); - Assert.assertEquals("{months=[DECEMBER]}", monthDays1.toString()); + Assertions.assertEquals("{months=[DECEMBER]}", monthDays1.toString()); } @Test @@ -44,10 +44,10 @@ public class Issue2572Test { monthDays.add(MonthDay.of(Month.DECEMBER, 1)); final JSONObject obj = new JSONObject(); obj.set("monthDays", monthDays); - Assert.assertEquals("{\"monthDays\":[\"--12-01\"]}", obj.toString()); + Assertions.assertEquals("{\"monthDays\":[\"--12-01\"]}", obj.toString()); final Map> monthDays1 = obj.toBean(new TypeReference>>() { }); - Assert.assertEquals("{monthDays=[--12-01]}", monthDays1.toString()); + Assertions.assertEquals("{monthDays=[--12-01]}", monthDays1.toString()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2746Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2746Test.java index f01439f5d..20b3f8958 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2746Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2746Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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; public class Issue2746Test { @@ -12,13 +12,15 @@ public class Issue2746Test { try{ JSONUtil.parseObj(str); } catch (final JSONException e){ - Assert.assertTrue(e.getMessage().startsWith("A JSONObject can not directly nest another JSONObject or JSONArray")); + Assertions.assertTrue(e.getMessage().startsWith("A JSONObject can not directly nest another JSONObject or JSONArray")); } } - @Test(expected = JSONException.class) + @Test public void parseTest() { - final String str = StrUtil.repeat("[", 1500) + StrUtil.repeat("]", 1500); - JSONUtil.parseArray(str); + Assertions.assertThrows(JSONException.class, ()->{ + final String str = StrUtil.repeat("[", 1500) + StrUtil.repeat("]", 1500); + JSONUtil.parseArray(str); + }); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2749Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2749Test.java index 67b461cd4..0e616d7cd 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2749Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2749Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; -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.HashMap; import java.util.Map; @@ -16,7 +16,7 @@ public class Issue2749Test { @SuppressWarnings("unchecked") @Test - @Ignore + @Disabled public void jsonObjectTest() { final Map map = new HashMap<>(1, 1f); Map node = map; @@ -28,7 +28,7 @@ public class Issue2749Test { @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final JSONObject jsonObject = new JSONObject(jsonStr); - Assert.assertNotNull(jsonObject); + Assertions.assertNotNull(jsonObject); // 栈溢出 //noinspection ResultOfMethodCallIgnored diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2801Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2801Test.java index 08e03399c..d0708c865 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2801Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2801Test.java @@ -1,13 +1,13 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Issue2801Test { @Test public void toStringTest() { final JSONObject recordObj = new JSONObject(JSONConfig.of().setIgnoreNullValue(false)); recordObj.put("m_reportId", null); - Assert.assertEquals("{\"m_reportId\":null}", recordObj.toString()); + Assertions.assertEquals("{\"m_reportId\":null}", recordObj.toString()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2924Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2924Test.java index 5f4523b85..557d8b033 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2924Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2924Test.java @@ -1,7 +1,7 @@ package cn.hutool.json; -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,6 +11,6 @@ public class Issue2924Test { public void toListTest(){ final String idsJsonString = "[1174,137,1172,210,1173,627,628]"; final List idList = JSONUtil.toList(idsJsonString,Integer.class); - Assert.assertEquals("[1174, 137, 1172, 210, 1173, 627, 628]", idList.toString()); + Assertions.assertEquals("[1174, 137, 1172, 210, 1173, 627, 628]", idList.toString()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue2953Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue2953Test.java index f997d7eb9..9fa8476ca 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue2953Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue2953Test.java @@ -1,13 +1,13 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class Issue2953Test { @Test public void parseObjWithBigNumberTest() { final String a = "{\"a\": 114793903847679990000000000000000000000}"; final JSONObject jsonObject = JSONUtil.parseObj(a, JSONConfig.of()); - Assert.assertEquals("{\"a\":\"114793903847679990000000000000000000000\"}", jsonObject.toString()); + Assertions.assertEquals("{\"a\":\"114793903847679990000000000000000000000\"}", jsonObject.toString()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue488Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue488Test.java index 826f821cb..dfd6b18bf 100755 --- a/hutool-json/src/test/java/cn/hutool/json/Issue488Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue488Test.java @@ -3,8 +3,8 @@ package cn.hutool.json; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.reflect.TypeReference; 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.List; @@ -17,17 +17,17 @@ public class Issue488Test { final ResultSuccess> result = JSONUtil.toBean(jsonStr, JSONConfig.of(), new TypeReference>>() {}); - Assert.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext()); + Assertions.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext()); final List adds = result.getValue(); - Assert.assertEquals("会议室101", adds.get(0).getName()); - Assert.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress()); - Assert.assertEquals("会议室102", adds.get(1).getName()); - Assert.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress()); - Assert.assertEquals("会议室103", adds.get(2).getName()); - Assert.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress()); - Assert.assertEquals("会议室219", adds.get(3).getName()); - Assert.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress()); + Assertions.assertEquals("会议室101", adds.get(0).getName()); + Assertions.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress()); + Assertions.assertEquals("会议室102", adds.get(1).getName()); + Assertions.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress()); + Assertions.assertEquals("会议室103", adds.get(2).getName()); + Assertions.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress()); + Assertions.assertEquals("会议室219", adds.get(3).getName()); + Assertions.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress()); } @Test @@ -39,17 +39,17 @@ public class Issue488Test { final ResultSuccess> result = resultList.get(0); - Assert.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext()); + Assertions.assertEquals("https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.emailAddress)", result.getContext()); final List adds = result.getValue(); - Assert.assertEquals("会议室101", adds.get(0).getName()); - Assert.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress()); - Assert.assertEquals("会议室102", adds.get(1).getName()); - Assert.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress()); - Assert.assertEquals("会议室103", adds.get(2).getName()); - Assert.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress()); - Assert.assertEquals("会议室219", adds.get(3).getName()); - Assert.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress()); + Assertions.assertEquals("会议室101", adds.get(0).getName()); + Assertions.assertEquals("MeetingRoom101@abc.com", adds.get(0).getAddress()); + Assertions.assertEquals("会议室102", adds.get(1).getName()); + Assertions.assertEquals("MeetingRoom102@abc.com", adds.get(1).getAddress()); + Assertions.assertEquals("会议室103", adds.get(2).getName()); + Assertions.assertEquals("MeetingRoom103@abc.com", adds.get(2).getAddress()); + Assertions.assertEquals("会议室219", adds.get(3).getName()); + Assertions.assertEquals("MeetingRoom219@abc.com", adds.get(3).getAddress()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue644Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue644Test.java index 37644a577..6f6c7450f 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue644Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue644Test.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.date.TimeUtil; 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.time.LocalDateTime; @@ -20,11 +20,11 @@ public class Issue644Test { final JSONObject jsonObject = JSONUtil.parseObj(beanWithDate); BeanWithDate beanWithDate2 = JSONUtil.toBean(jsonObject, BeanWithDate.class); - Assert.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()), + Assertions.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()), TimeUtil.formatNormal(beanWithDate2.getDate())); beanWithDate2 = JSONUtil.toBean(jsonObject.toString(), BeanWithDate.class); - Assert.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()), + Assertions.assertEquals(TimeUtil.formatNormal(beanWithDate.getDate()), TimeUtil.formatNormal(beanWithDate2.getDate())); } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue677Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue677Test.java index b6a041318..6970dfd2a 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue677Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue677Test.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.date.DateUtil; 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.Date; @@ -19,7 +19,7 @@ public class Issue677Test { final String jsonStr = JSONUtil.toJsonStr(dto); final AuditResultDto auditResultDto = JSONUtil.toBean(jsonStr, AuditResultDto.class); - Assert.assertEquals("Mon Dec 15 00:00:00 CST 1969", auditResultDto.getDate().toString().replace("GMT+08:00", "CST")); + Assertions.assertEquals("Mon Dec 15 00:00:00 CST 1969", auditResultDto.getDate().toString().replace("GMT+08:00", "CST")); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/Issue867Test.java b/hutool-json/src/test/java/cn/hutool/json/Issue867Test.java index ecc71ac6a..eb2be6d54 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issue867Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issue867Test.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.annotation.Alias; 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 Issue867Test { @@ -11,9 +11,9 @@ public class Issue867Test { public void toBeanTest(){ final String json = "{\"abc_1d\":\"123\",\"abc_d\":\"456\",\"abc_de\":\"789\"}"; final Test02 bean = JSONUtil.toBean(JSONUtil.parseObj(json),Test02.class); - Assert.assertEquals("123", bean.getAbc1d()); - Assert.assertEquals("456", bean.getAbcD()); - Assert.assertEquals("789", bean.getAbcDe()); + Assertions.assertEquals("123", bean.getAbc1d()); + Assertions.assertEquals("456", bean.getAbcD()); + Assertions.assertEquals("789", bean.getAbcDe()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI1AU86Test.java b/hutool-json/src/test/java/cn/hutool/json/IssueI1AU86Test.java index 922e40b2e..6d6035350 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI1AU86Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI1AU86Test.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.collection.ListUtil; 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; import java.util.Date; @@ -32,7 +32,7 @@ public class IssueI1AU86Test { final List vccs = jsonArray.toList(Vcc.class); for (final Vcc vcc : vccs) { - Assert.assertNotNull(vcc); + Assertions.assertNotNull(vcc); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI1F8M2Test.java b/hutool-json/src/test/java/cn/hutool/json/IssueI1F8M2Test.java index 7e09aedd5..cf41f1cf1 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI1F8M2Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI1F8M2Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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.time.LocalDateTime; @@ -14,8 +14,8 @@ public class IssueI1F8M2Test { public void toBeanTest() { final String jsonStr = "{\"eventType\":\"fee\",\"fwdAlertingTime\":\"2020-04-22 16:34:13\",\"fwdAnswerTime\":\"\"}"; final Param param = JSONUtil.toBean(jsonStr, Param.class); - Assert.assertEquals("2020-04-22T16:34:13", param.getFwdAlertingTime().toString()); - Assert.assertNull(param.getFwdAnswerTime()); + Assertions.assertEquals("2020-04-22T16:34:13", param.getFwdAlertingTime().toString()); + Assertions.assertNull(param.getFwdAnswerTime()); } // Param类的字段 diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI1H2VNTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI1H2VNTest.java index 423bab1e2..27f18d7e1 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI1H2VNTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI1H2VNTest.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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.List; @@ -18,11 +18,11 @@ public class IssueI1H2VNTest { final String jsonStr = "{'conditionsVo':[{'column':'StockNo','value':'abc','type':'='},{'column':'CheckIncoming','value':'1','type':'='}]," + "'queryVo':{'conditionsVo':[{'column':'StockNo','value':'abc','type':'='},{'column':'CheckIncoming','value':'1','type':'='}],'queryVo':null}}"; final QueryVo vo = JSONUtil.toBean(jsonStr, QueryVo.class); - Assert.assertEquals(2, vo.getConditionsVo().size()); + Assertions.assertEquals(2, vo.getConditionsVo().size()); final QueryVo subVo = vo.getQueryVo(); - Assert.assertNotNull(subVo); - Assert.assertEquals(2, subVo.getConditionsVo().size()); - Assert.assertNull(subVo.getQueryVo()); + Assertions.assertNotNull(subVo); + Assertions.assertEquals(2, subVo.getConditionsVo().size()); + Assertions.assertNull(subVo.getQueryVo()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI3BS4STest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI3BS4STest.java index da320e45f..af50230ec 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI3BS4STest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI3BS4STest.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.bean.BeanUtil; 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.time.LocalDateTime; @@ -17,7 +17,7 @@ public class IssueI3BS4STest { final String jsonStr = "{date: '2021-03-17T06:31:33.99'}"; final Bean1 bean1 = new Bean1(); BeanUtil.copyProperties(JSONUtil.parseObj(jsonStr), bean1); - Assert.assertEquals("2021-03-17T06:31:33.099", bean1.getDate().toString()); + Assertions.assertEquals("2021-03-17T06:31:33.099", bean1.getDate().toString()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI3EGJPTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI3EGJPTest.java index 9d65c78af..536765f66 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI3EGJPTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI3EGJPTest.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.bean.BeanUtil; 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 IssueI3EGJPTest { @@ -14,8 +14,8 @@ public class IssueI3EGJPTest { paramJson.set("is_booleanb", true); final ConvertDO convertDO = BeanUtil.toBean(paramJson, ConvertDO.class); - Assert.assertTrue(convertDO.isBooleana()); - Assert.assertTrue(convertDO.getIsBooleanb()); + Assertions.assertTrue(convertDO.isBooleana()); + Assertions.assertTrue(convertDO.getIsBooleanb()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI49VZBTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI49VZBTest.java index 3a480cb70..5e29492c9 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI49VZBTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI49VZBTest.java @@ -3,8 +3,8 @@ package cn.hutool.json; import cn.hutool.core.convert.Convert; import lombok.Data; import lombok.EqualsAndHashCode; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.stream.Stream; @@ -65,12 +65,12 @@ public class IssueI49VZBTest { public void toBeanTest(){ final String str = "{type: \"password\"}"; final UPOpendoor upOpendoor = JSONUtil.toBean(str, UPOpendoor.class); - Assert.assertEquals(NBCloudKeyType.password, upOpendoor.getType()); + Assertions.assertEquals(NBCloudKeyType.password, upOpendoor.getType()); } @Test public void enumConvertTest(){ final NBCloudKeyType type = Convert.toEnum(NBCloudKeyType.class, "snapKey"); - Assert.assertEquals(NBCloudKeyType.snapKey, type); + Assertions.assertEquals(NBCloudKeyType.snapKey, type); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI4RBZ4Test.java b/hutool-json/src/test/java/cn/hutool/json/IssueI4RBZ4Test.java index 7fa39184a..3287c5223 100755 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI4RBZ4Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI4RBZ4Test.java @@ -1,7 +1,7 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * https://gitee.com/dromara/hutool/issues/I4RBZ4 @@ -13,6 +13,6 @@ public class IssueI4RBZ4Test { final String jsonStr = "{\"id\":\"123\",\"array\":[1,2,3],\"outNum\":356,\"body\":{\"ava1\":\"20220108\",\"use\":1,\"ava2\":\"20230108\"},\"name\":\"John\"}"; final JSONObject jsonObject = JSONUtil.parseObj(jsonStr, JSONConfig.of().setNatureKeyComparator()); - Assert.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString()); + Assertions.assertEquals("{\"array\":[1,2,3],\"body\":{\"ava1\":\"20220108\",\"ava2\":\"20230108\",\"use\":1},\"id\":\"123\",\"name\":\"John\",\"outNum\":356}", jsonObject.toString()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI4XFMWTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI4XFMWTest.java index c88c02f34..d3078b472 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI4XFMWTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI4XFMWTest.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.annotation.Alias; 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; @@ -27,10 +27,10 @@ public class IssueI4XFMWTest { entityList.add(entityB); final String jsonStr = JSONUtil.toJsonStr(entityList); - Assert.assertEquals("[{\"uid\":\"123\",\"password\":\"456\"},{\"uid\":\"789\",\"password\":\"098\"}]", jsonStr); + Assertions.assertEquals("[{\"uid\":\"123\",\"password\":\"456\"},{\"uid\":\"789\",\"password\":\"098\"}]", jsonStr); final List testEntities = JSONUtil.toList(jsonStr, TestEntity.class); - Assert.assertEquals("123", testEntities.get(0).getId()); - Assert.assertEquals("789", testEntities.get(1).getId()); + Assertions.assertEquals("123", testEntities.get(0).getId()); + Assertions.assertEquals("789", testEntities.get(1).getId()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI50EGGTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI50EGGTest.java index 699f48383..9e2a73a09 100755 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI50EGGTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI50EGGTest.java @@ -2,8 +2,8 @@ package cn.hutool.json; 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; public class IssueI50EGGTest { @@ -11,7 +11,7 @@ public class IssueI50EGGTest { public void toBeanTest(){ final String data = "{\"return_code\": 1, \"return_msg\": \"成功\", \"return_data\" : null}"; final ApiResult apiResult = JSONUtil.toBean(data, JSONConfig.of().setIgnoreCase(true), ApiResult.class); - Assert.assertEquals(1, apiResult.getReturn_code()); + Assertions.assertEquals(1, apiResult.getReturn_code()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI59LW4Test.java b/hutool-json/src/test/java/cn/hutool/json/IssueI59LW4Test.java index f63094ab3..9c7214240 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI59LW4Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI59LW4Test.java @@ -1,24 +1,24 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class IssueI59LW4Test { @Test public void bytesTest(){ final JSONObject jsonObject = JSONUtil.ofObj().set("bytes", new byte[]{1}); - Assert.assertEquals("{\"bytes\":[1]}", jsonObject.toString()); + Assertions.assertEquals("{\"bytes\":[1]}", jsonObject.toString()); final byte[] bytes = jsonObject.getBytes("bytes"); - Assert.assertArrayEquals(new byte[]{1}, bytes); + Assertions.assertArrayEquals(new byte[]{1}, bytes); } @Test public void bytesInJSONArrayTest(){ final JSONArray jsonArray = JSONUtil.ofArray().set(new byte[]{1}); - Assert.assertEquals("[[1]]", jsonArray.toString()); + Assertions.assertEquals("[[1]]", jsonArray.toString()); final byte[] bytes = jsonArray.getBytes(0); - Assert.assertArrayEquals(new byte[]{1}, bytes); + Assertions.assertArrayEquals(new byte[]{1}, bytes); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI5DHK2Test.java b/hutool-json/src/test/java/cn/hutool/json/IssueI5DHK2Test.java index bc086fda0..a11c47616 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI5DHK2Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI5DHK2Test.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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 IssueI5DHK2Test { @@ -25,11 +25,11 @@ public class IssueI5DHK2Test { .getJSONObject("properties") .getJSONArray("employment_informations") .getJSONObject(0).getStr("employer_name"); - Assert.assertEquals("张三皮包公司", exployerName); + Assertions.assertEquals("张三皮包公司", exployerName); final Punished punished = JSONUtil.toBean(json, Punished.class); - Assert.assertEquals("张三皮包公司", punished.getPunished_parties()[0].getProperties().getEmployment_informations()[0].getEmployer_name()); + Assertions.assertEquals("张三皮包公司", punished.getPunished_parties()[0].getProperties().getEmployment_informations()[0].getEmployer_name()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI5OMSCTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI5OMSCTest.java index 3679e1d5b..02fa28fb0 100755 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI5OMSCTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI5OMSCTest.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.resource.ResourceUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Predicate多层过滤 @@ -21,6 +21,6 @@ public class IssueI5OMSCTest { } return true; }); - Assert.assertEquals("{\"store\":{\"bicycle\":{\"color\":\"red\"},\"book\":[{\"author\":\"Evelyn Waugh\"},{\"author\":\"Evelyn Waugh02\"}]}}", s); + Assertions.assertEquals("{\"store\":{\"bicycle\":{\"color\":\"red\"},\"book\":[{\"author\":\"Evelyn Waugh\"},{\"author\":\"Evelyn Waugh02\"}]}}", s); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI676ITTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI676ITTest.java index 71b20d5e0..fa9355797 100755 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI676ITTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI676ITTest.java @@ -3,8 +3,8 @@ package cn.hutool.json; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.util.XmlUtil; import cn.hutool.json.xml.JSONXMLSerializer; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import javax.xml.xpath.XPathConstants; @@ -14,6 +14,6 @@ public class IssueI676ITTest { final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.readUtf8Str("issueI676IT.json")); final String xmlStr = JSONXMLSerializer.toXml(jsonObject, null, (String) null); final String content = String.valueOf(XmlUtil.getByXPath("/page/orderItems[1]/content", XmlUtil.readXML(xmlStr), XPathConstants.STRING)); - Assert.assertEquals(content, "bar1"); + Assertions.assertEquals(content, "bar1"); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI6H0XFTest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI6H0XFTest.java index a77e680b6..ec840c1a1 100644 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI6H0XFTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI6H0XFTest.java @@ -1,16 +1,16 @@ package cn.hutool.json; 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 IssueI6H0XFTest { @Test public void toBeanTest(){ final Demo demo = JSONUtil.toBean("{\"biz\":\"A\",\"isBiz\":true}", Demo.class); - Assert.assertEquals("A", demo.getBiz()); - Assert.assertEquals("{\"biz\":\"A\"}", JSONUtil.toJsonStr(demo)); + Assertions.assertEquals("A", demo.getBiz()); + Assertions.assertEquals("{\"biz\":\"A\"}", JSONUtil.toJsonStr(demo)); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/IssueI6LBZATest.java b/hutool-json/src/test/java/cn/hutool/json/IssueI6LBZATest.java index ae343a13b..cc8bd4b37 100755 --- a/hutool-json/src/test/java/cn/hutool/json/IssueI6LBZATest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssueI6LBZATest.java @@ -1,34 +1,36 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class IssueI6LBZATest { @Test public void parseJSONStringTest() { final String a = "\"a\""; final Object parse = JSONUtil.parse(a); - Assert.assertEquals(String.class, parse.getClass()); + Assertions.assertEquals(String.class, parse.getClass()); } @Test public void parseJSONStringTest2() { final String a = "'a'"; final Object parse = JSONUtil.parse(a); - Assert.assertEquals(String.class, parse.getClass()); + Assertions.assertEquals(String.class, parse.getClass()); } - @Test(expected = JSONException.class) + @Test public void parseJSONErrorTest() { - final String a = "a"; - final Object parse = JSONUtil.parse(a); - Assert.assertEquals(String.class, parse.getClass()); + Assertions.assertThrows(JSONException.class, ()->{ + final String a = "a"; + final Object parse = JSONUtil.parse(a); + Assertions.assertEquals(String.class, parse.getClass()); + }); } @Test public void parseJSONNumberTest() { final String a = "123"; final Object parse = JSONUtil.parse(a); - Assert.assertEquals(Integer.class, parse.getClass()); + Assertions.assertEquals(Integer.class, parse.getClass()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Issues1881Test.java b/hutool-json/src/test/java/cn/hutool/json/Issues1881Test.java index 416db75c7..4b180b384 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Issues1881Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Issues1881Test.java @@ -2,8 +2,8 @@ package cn.hutool.json; import lombok.Data; import lombok.experimental.Accessors; -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.ArrayList; @@ -31,6 +31,6 @@ public class Issues1881Test { holderContactVOList.add(new ThingsHolderContactVO().setId(1L).setName("1")); holderContactVOList.add(new ThingsHolderContactVO().setId(2L).setName("2")); - Assert.assertEquals("[{\"id\":1,\"name\":\"1\"},{\"id\":2,\"name\":\"2\"}]", JSONUtil.parseArray(holderContactVOList).toString()); + Assertions.assertEquals("[{\"id\":1,\"name\":\"1\"},{\"id\":2,\"name\":\"2\"}]", JSONUtil.parseArray(holderContactVOList).toString()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/IssuesI44E4HTest.java b/hutool-json/src/test/java/cn/hutool/json/IssuesI44E4HTest.java index 101215859..52fa42028 100755 --- a/hutool-json/src/test/java/cn/hutool/json/IssuesI44E4HTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssuesI44E4HTest.java @@ -5,8 +5,8 @@ import cn.hutool.json.serialize.JSONDeserializer; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 测试自定义反序列化 @@ -23,7 +23,7 @@ public class IssuesI44E4HTest { final String jsonStr = "{\"md\":\"value1\"}"; final TestDto testDto = JSONUtil.toBean(jsonStr, TestDto.class); - Assert.assertEquals("value1", testDto.getMd().getValue()); + Assertions.assertEquals("value1", testDto.getMd().getValue()); } @Getter diff --git a/hutool-json/src/test/java/cn/hutool/json/IssuesI4V14NTest.java b/hutool-json/src/test/java/cn/hutool/json/IssuesI4V14NTest.java index 72261ab8f..aed4fd34b 100755 --- a/hutool-json/src/test/java/cn/hutool/json/IssuesI4V14NTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/IssuesI4V14NTest.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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.Map; @@ -12,9 +12,9 @@ public class IssuesI4V14NTest { public void parseTest(){ final String str = "{\"A\" : \"A\\nb\"}"; final JSONObject jsonObject = JSONUtil.parseObj(str); - Assert.assertEquals("A\nb", jsonObject.getStr("A")); + Assertions.assertEquals("A\nb", jsonObject.getStr("A")); final Map map = jsonObject.toBean(new TypeReference>() {}); - Assert.assertEquals("A\nb", map.get("A")); + Assertions.assertEquals("A\nb", map.get("A")); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONArrayTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONArrayTest.java index a47014556..f360c82d0 100755 --- a/hutool-json/src/test/java/cn/hutool/json/JSONArrayTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONArrayTest.java @@ -10,8 +10,8 @@ import cn.hutool.json.test.bean.Exam; import cn.hutool.json.test.bean.JsonNode; import cn.hutool.json.test.bean.KeyBean; 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.HashMap; @@ -31,19 +31,19 @@ public class JSONArrayTest { final JSONObject jsonObject = new JSONObject(); JSONArray jsonArray = new JSONArray(jsonObject, JSONConfig.of()); - Assert.assertEquals(new JSONArray(), jsonArray); + Assertions.assertEquals(new JSONArray(), jsonArray); jsonObject.set("key1", "value1"); jsonArray = new JSONArray(jsonObject, JSONConfig.of()); - Assert.assertEquals(1, jsonArray.size()); - Assert.assertEquals("[{\"key1\":\"value1\"}]", jsonArray.toString()); + Assertions.assertEquals(1, jsonArray.size()); + Assertions.assertEquals("[{\"key1\":\"value1\"}]", jsonArray.toString()); } @Test public void addNullTest() { final List aaa = ListUtil.view("aaa", null); final String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa, JSONConfig.of().setIgnoreNullValue(false))); - Assert.assertEquals("[\"aaa\",null]", jsonStr); + Assertions.assertEquals("[\"aaa\",null]", jsonStr); } @Test @@ -56,25 +56,25 @@ public class JSONArrayTest { array.add("value2"); array.add("value3"); - Assert.assertEquals(array.get(0), "value1"); + Assertions.assertEquals(array.get(0), "value1"); } @Test public void parseTest() { final String jsonStr = "[\"value1\", \"value2\", \"value3\"]"; final JSONArray array = JSONUtil.parseArray(jsonStr); - Assert.assertEquals(array.get(0), "value1"); + Assertions.assertEquals(array.get(0), "value1"); } @Test public void parseWithNullTest() { final String jsonStr = "[{\"grep\":\"4.8\",\"result\":\"右\"},{\"grep\":\"4.8\",\"result\":null}]"; JSONArray jsonArray = JSONUtil.parseArray(jsonStr); - Assert.assertFalse(jsonArray.getJSONObject(1).containsKey("result")); + Assertions.assertFalse(jsonArray.getJSONObject(1).containsKey("result")); // 不忽略null,则null的键值对被保留 jsonArray = JSONUtil.parseArray(jsonStr, JSONConfig.of().setIgnoreNullValue(false)); - Assert.assertTrue(jsonArray.getJSONObject(1).containsKey("result")); + Assertions.assertTrue(jsonArray.getJSONObject(1).containsKey("result")); } @Test @@ -83,7 +83,7 @@ public class JSONArrayTest { final JSONObject obj0 = array.getJSONObject(0); final Exam exam = JSONUtil.toBean(obj0, Exam.class); - Assert.assertEquals("0", exam.getAnswerArray()[0].getSeq()); + Assertions.assertEquals("0", exam.getAnswerArray()[0].getSeq()); } @Test @@ -98,8 +98,8 @@ public class JSONArrayTest { final ArrayList list = ListUtil.of(b1, b2); final JSONArray jsonArray = JSONUtil.parseArray(list); - Assert.assertEquals("aValue1", jsonArray.getJSONObject(0).getStr("akey")); - Assert.assertEquals("bValue2", jsonArray.getJSONObject(1).getStr("bkey")); + Assertions.assertEquals("aValue1", jsonArray.getJSONObject(0).getStr("akey")); + Assertions.assertEquals("bValue2", jsonArray.getJSONObject(1).getStr("bkey")); } @Test @@ -108,8 +108,8 @@ public class JSONArrayTest { final JSONArray array = JSONUtil.parseArray(jsonStr); final List list = array.toList(Exam.class); - Assert.assertFalse(list.isEmpty()); - Assert.assertSame(Exam.class, list.get(0).getClass()); + Assertions.assertFalse(list.isEmpty()); + Assertions.assertSame(Exam.class, list.get(0).getClass()); } @Test @@ -119,14 +119,14 @@ public class JSONArrayTest { final JSONArray array = JSONUtil.parseArray(jsonArr); final List userList = JSONUtil.toList(array, User.class); - Assert.assertFalse(userList.isEmpty()); - Assert.assertSame(User.class, userList.get(0).getClass()); + Assertions.assertFalse(userList.isEmpty()); + Assertions.assertSame(User.class, userList.get(0).getClass()); - Assert.assertEquals(Integer.valueOf(111), userList.get(0).getId()); - Assert.assertEquals(Integer.valueOf(112), userList.get(1).getId()); + Assertions.assertEquals(Integer.valueOf(111), userList.get(0).getId()); + Assertions.assertEquals(Integer.valueOf(112), userList.get(1).getId()); - Assert.assertEquals("test1", userList.get(0).getName()); - Assert.assertEquals("test2", userList.get(1).getName()); + Assertions.assertEquals("test1", userList.get(0).getName()); + Assertions.assertEquals("test2", userList.get(1).getName()); } @Test @@ -137,14 +137,14 @@ public class JSONArrayTest { final List list = JSONUtil.toList(array, Dict.class); - Assert.assertFalse(list.isEmpty()); - Assert.assertSame(Dict.class, list.get(0).getClass()); + Assertions.assertFalse(list.isEmpty()); + Assertions.assertSame(Dict.class, list.get(0).getClass()); - Assert.assertEquals(Integer.valueOf(111), list.get(0).getInt("id")); - Assert.assertEquals(Integer.valueOf(112), list.get(1).getInt("id")); + Assertions.assertEquals(Integer.valueOf(111), list.get(0).getInt("id")); + Assertions.assertEquals(Integer.valueOf(112), list.get(1).getInt("id")); - Assert.assertEquals("test1", list.get(0).getStr("name")); - Assert.assertEquals("test2", list.get(1).getStr("name")); + Assertions.assertEquals("test1", list.get(0).getStr("name")); + Assertions.assertEquals("test2", list.get(1).getStr("name")); } @Test @@ -154,8 +154,8 @@ public class JSONArrayTest { //noinspection SuspiciousToArrayCall final Exam[] list = array.toArray(new Exam[0]); - Assert.assertNotEquals(0, list.length); - Assert.assertSame(Exam.class, list[0].getClass()); + Assertions.assertNotEquals(0, list.length); + Assertions.assertSame(Exam.class, list[0].getClass()); } /** @@ -167,17 +167,19 @@ public class JSONArrayTest { final JSONArray ja = JSONUtil.parseArray(json, JSONConfig.of().setIgnoreNullValue(false)); final List list = ja.toList(KeyBean.class); - Assert.assertNull(list.get(0)); - Assert.assertEquals("avalue", list.get(1).getAkey()); - Assert.assertEquals("bvalue", list.get(1).getBkey()); + Assertions.assertNull(list.get(0)); + Assertions.assertEquals("avalue", list.get(1).getAkey()); + Assertions.assertEquals("bvalue", list.get(1).getBkey()); } - @Test(expected = ConvertException.class) + @Test public void toListWithErrorTest() { - final String json = "[['aaa',{'akey':'avalue','bkey':'bvalue'}]]"; - final JSONArray ja = JSONUtil.parseArray(json); + Assertions.assertThrows(ConvertException.class, ()->{ + final String json = "[['aaa',{'akey':'avalue','bkey':'bvalue'}]]"; + final JSONArray ja = JSONUtil.parseArray(json); - ja.toBean(new TypeReference>>() { + ja.toBean(new TypeReference>>() { + }); }); } @@ -191,28 +193,28 @@ public class JSONArrayTest { final JSONArray jsonArray = JSONUtil.parseArray(mapList); final List nodeList = jsonArray.toList(JsonNode.class); - Assert.assertEquals(Long.valueOf(0L), nodeList.get(0).getId()); - Assert.assertEquals(Long.valueOf(1L), nodeList.get(1).getId()); - Assert.assertEquals(Long.valueOf(0L), nodeList.get(2).getId()); - Assert.assertEquals(Long.valueOf(0L), nodeList.get(3).getId()); + Assertions.assertEquals(Long.valueOf(0L), nodeList.get(0).getId()); + Assertions.assertEquals(Long.valueOf(1L), nodeList.get(1).getId()); + Assertions.assertEquals(Long.valueOf(0L), nodeList.get(2).getId()); + Assertions.assertEquals(Long.valueOf(0L), nodeList.get(3).getId()); - Assert.assertEquals(Integer.valueOf(0), nodeList.get(0).getParentId()); - Assert.assertEquals(Integer.valueOf(1), nodeList.get(1).getParentId()); - Assert.assertEquals(Integer.valueOf(0), nodeList.get(2).getParentId()); - Assert.assertEquals(Integer.valueOf(0), nodeList.get(3).getParentId()); + Assertions.assertEquals(Integer.valueOf(0), nodeList.get(0).getParentId()); + Assertions.assertEquals(Integer.valueOf(1), nodeList.get(1).getParentId()); + Assertions.assertEquals(Integer.valueOf(0), nodeList.get(2).getParentId()); + Assertions.assertEquals(Integer.valueOf(0), nodeList.get(3).getParentId()); - Assert.assertEquals("0", nodeList.get(0).getName()); - Assert.assertEquals("1", nodeList.get(1).getName()); - Assert.assertEquals("+0", nodeList.get(2).getName()); - Assert.assertEquals("-0", nodeList.get(3).getName()); + Assertions.assertEquals("0", nodeList.get(0).getName()); + Assertions.assertEquals("1", nodeList.get(1).getName()); + Assertions.assertEquals("+0", nodeList.get(2).getName()); + Assertions.assertEquals("-0", nodeList.get(3).getName()); } @Test public void getByPathTest() { final String jsonStr = "[{\"id\": \"1\",\"name\": \"a\"},{\"id\": \"2\",\"name\": \"b\"}]"; final JSONArray jsonArray = JSONUtil.parseArray(jsonStr); - Assert.assertEquals("b", jsonArray.getByPath("[1].name")); - Assert.assertEquals("b", JSONUtil.getByPath(jsonArray, "[1].name")); + Assertions.assertEquals("b", jsonArray.getByPath("[1].name")); + Assertions.assertEquals("b", JSONUtil.getByPath(jsonArray, "[1].name")); } @Test @@ -220,12 +222,12 @@ public class JSONArrayTest { JSONArray jsonArray = new JSONArray(); jsonArray.set(3, "test"); // 默认忽略null值,因此空位无值,只有一个值 - Assert.assertEquals(1, jsonArray.size()); + Assertions.assertEquals(1, jsonArray.size()); jsonArray = new JSONArray(JSONConfig.of().setIgnoreNullValue(false)); jsonArray.set(3, "test"); // 第三个位置插入值,0~2都是null - Assert.assertEquals(4, jsonArray.size()); + Assertions.assertEquals(4, jsonArray.size()); } // https://github.com/dromara/hutool/issues/1858 @@ -233,8 +235,8 @@ public class JSONArrayTest { public void putTest2() { final JSONArray jsonArray = new JSONArray(); jsonArray.put(0, 1); - Assert.assertEquals(1, jsonArray.size()); - Assert.assertEquals(1, jsonArray.get(0)); + Assertions.assertEquals(1, jsonArray.size()); + Assertions.assertEquals(1, jsonArray.get(0)); } private static Map buildMap(final String id, final String parentId, final String name) { @@ -260,7 +262,7 @@ public class JSONArrayTest { .set(true); final String s = json1.toJSONString(0, (pair) -> pair.getValue().equals("value2")); - Assert.assertEquals("[\"value2\"]", s); + Assertions.assertEquals("[\"value2\"]", s); } @Test @@ -272,7 +274,7 @@ public class JSONArrayTest { .set(true); final String s = json1.toJSONString(0, (pair) -> false == pair.getValue().equals("value2")); - Assert.assertEquals("[\"value1\",\"value3\",true]", s); + Assertions.assertEquals("[\"value1\",\"value3\",true]", s); } @Test @@ -280,7 +282,7 @@ public class JSONArrayTest { final JSONArray array = JSONUtil.ofArray(JSONConfig.of().setIgnoreNullValue(false)); array.set(null); - Assert.assertEquals("[null]", array.toString()); + Assertions.assertEquals("[null]", array.toString()); } @Test @@ -288,8 +290,8 @@ public class JSONArrayTest { final String jsonArr = "[{\"id\":111,\"name\":\"test1\"},{\"id\":112,\"name\":\"test2\"}]"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONArray array = new JSONArray(jsonArr, null, (mutable) -> mutable.get().toString().contains("111")); - Assert.assertEquals(1, array.size()); - Assert.assertTrue(array.getJSONObject(0).containsKey("id")); + Assertions.assertEquals(1, array.size()); + Assertions.assertTrue(array.getJSONObject(0).containsKey("id")); } @Test @@ -304,8 +306,8 @@ public class JSONArrayTest { mutable.set(o); return true; }); - Assert.assertEquals(2, array.size()); - Assert.assertTrue(array.getJSONObject(0).containsKey("id")); - Assert.assertEquals("test1_edit", array.getJSONObject(0).get("name")); + Assertions.assertEquals(2, array.size()); + Assertions.assertTrue(array.getJSONObject(0).containsKey("id")); + Assertions.assertEquals("test1_edit", array.getJSONObject(0).get("name")); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONConvertTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONConvertTest.java index f1d69663c..f101d3306 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONConvertTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONConvertTest.java @@ -4,8 +4,8 @@ import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.json.test.bean.ExamInfoDict; import cn.hutool.json.test.bean.PerfectEvaluationProductResVo; import cn.hutool.json.test.bean.UserInfoDict; -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.HashMap; @@ -55,14 +55,14 @@ public class JSONConvertTest { tempMap.put("toSendManIdCard", 1); final JSONObject obj = JSONUtil.parseObj(tempMap); - Assert.assertEquals(new Integer(1), obj.getInt("toSendManIdCard")); + Assertions.assertEquals(new Integer(1), obj.getInt("toSendManIdCard")); final JSONObject examInfoDictsJson = obj.getJSONObject("userInfoDict"); - Assert.assertEquals(new Integer(1), examInfoDictsJson.getInt("id")); - Assert.assertEquals("质量过关", examInfoDictsJson.getStr("realName")); + Assertions.assertEquals(new Integer(1), examInfoDictsJson.getInt("id")); + Assertions.assertEquals("质量过关", examInfoDictsJson.getStr("realName")); final Object id = JSONUtil.getByPath(obj, "userInfoDict.examInfoDict[0].id"); - Assert.assertEquals(1, id); + Assertions.assertEquals(1, id); } @Test @@ -77,15 +77,15 @@ public class JSONConvertTest { final JSONObject jsonObject = JSONUtil.parseObj(examJson).getJSONObject("examInfoDicts"); final UserInfoDict userInfoDict = jsonObject.toBean(UserInfoDict.class); - Assert.assertEquals(userInfoDict.getId(), new Integer(1)); - Assert.assertEquals(userInfoDict.getRealName(), "质量过关"); + Assertions.assertEquals(userInfoDict.getId(), new Integer(1)); + Assertions.assertEquals(userInfoDict.getRealName(), "质量过关"); //============ final String jsonStr = "{\"id\":null,\"examInfoDict\":[{\"answerIs\":1, \"id\":null}]}";//JSONUtil.toJsonStr(userInfoDict1); final JSONObject jsonObject2 = JSONUtil.parseObj(jsonStr);//.getJSONObject("examInfoDicts"); final UserInfoDict userInfoDict2 = jsonObject2.toBean(UserInfoDict.class); - Assert.assertNull(userInfoDict2.getId()); + Assertions.assertNull(userInfoDict2.getId()); } /** @@ -97,7 +97,7 @@ public class JSONConvertTest { final JSONObject obj = JSONUtil.parseObj(jsonStr); final PerfectEvaluationProductResVo vo = obj.toBean(PerfectEvaluationProductResVo.class); - Assert.assertEquals(obj.getStr("HA001"), vo.getHA001()); - Assert.assertEquals(obj.getInt("costTotal"), vo.getCostTotal()); + Assertions.assertEquals(obj.getStr("HA001"), vo.getHA001()); + Assertions.assertEquals(obj.getInt("costTotal"), vo.getCostTotal()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONDeserializerTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONDeserializerTest.java index 2e675f65a..d20b1514b 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONDeserializerTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONDeserializerTest.java @@ -2,8 +2,8 @@ package cn.hutool.json; import cn.hutool.json.serialize.JSONDeserializer; 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 JSONDeserializerTest { @@ -11,9 +11,9 @@ public class JSONDeserializerTest { public void parseTest(){ final String jsonStr = "{\"customName\": \"customValue\", \"customAddress\": \"customAddressValue\"}"; final TestBean testBean = JSONUtil.toBean(jsonStr, TestBean.class); - Assert.assertNotNull(testBean); - Assert.assertEquals("customValue", testBean.getName()); - Assert.assertEquals("customAddressValue", testBean.getAddress()); + Assertions.assertNotNull(testBean); + Assertions.assertEquals("customValue", testBean.getName()); + Assertions.assertEquals("customAddressValue", testBean.getAddress()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONNullTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONNullTest.java index d14eb7d5e..bac188b20 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONNullTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONNullTest.java @@ -1,7 +1,7 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JSONNullTest { @@ -12,12 +12,12 @@ public class JSONNullTest { " \"device_status_date\": null,\n" + " \"imsi\": null,\n" + " \"act_date\": \"2021-07-23T06:23:26.000+00:00\"}"); - Assert.assertNull(bodyjson.get("device_model")); - Assert.assertNull(bodyjson.get("device_status_date")); - Assert.assertNull(bodyjson.get("imsi")); + Assertions.assertNull(bodyjson.get("device_model")); + Assertions.assertNull(bodyjson.get("device_status_date")); + Assertions.assertNull(bodyjson.get("imsi")); bodyjson.getConfig().setIgnoreNullValue(true); - Assert.assertEquals("{\"act_date\":\"2021-07-23T06:23:26.000+00:00\"}", bodyjson.toString()); + Assertions.assertEquals("{\"act_date\":\"2021-07-23T06:23:26.000+00:00\"}", bodyjson.toString()); } @Test @@ -27,30 +27,30 @@ public class JSONNullTest { " \"device_status_date\": null,\n" + " \"imsi\": null,\n" + " \"act_date\": \"2021-07-23T06:23:26.000+00:00\"}", true); - Assert.assertFalse(bodyjson.containsKey("device_model")); - Assert.assertFalse(bodyjson.containsKey("device_status_date")); - Assert.assertFalse(bodyjson.containsKey("imsi")); + Assertions.assertFalse(bodyjson.containsKey("device_model")); + Assertions.assertFalse(bodyjson.containsKey("device_status_date")); + Assertions.assertFalse(bodyjson.containsKey("imsi")); } @Test public void setNullTest(){ // 忽略null String json1 = JSONUtil.ofObj().set("key1", null).toString(); - Assert.assertEquals("{}", json1); + Assertions.assertEquals("{}", json1); // 不忽略null json1 = JSONUtil.ofObj(JSONConfig.of().setIgnoreNullValue(false)).set("key1", null).toString(); - Assert.assertEquals("{\"key1\":null}", json1); + Assertions.assertEquals("{\"key1\":null}", json1); } @Test public void setNullOfJSONArrayTest(){ // 忽略null String json1 = JSONUtil.ofArray().set(null).toString(); - Assert.assertEquals("[]", json1); + Assertions.assertEquals("[]", json1); // 不忽略null json1 = JSONUtil.ofArray(JSONConfig.of().setIgnoreNullValue(false)).set(null).toString(); - Assert.assertEquals("[null]", json1); + Assertions.assertEquals("[null]", json1); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONObjectTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONObjectTest.java index 283e05303..bcbf3bf4e 100755 --- a/hutool-json/src/test/java/cn/hutool/json/JSONObjectTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONObjectTest.java @@ -21,8 +21,8 @@ import cn.hutool.json.test.bean.report.CaseReport; import cn.hutool.json.test.bean.report.StepReport; import cn.hutool.json.test.bean.report.SuiteReport; 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.ByteArrayInputStream; import java.io.StringReader; @@ -48,9 +48,9 @@ public class JSONObjectTest { final String str = "{\"code\": 500, \"data\":null}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject jsonObject = new JSONObject(str); - Assert.assertEquals("{\"code\":500,\"data\":null}", jsonObject.toString()); + Assertions.assertEquals("{\"code\":500,\"data\":null}", jsonObject.toString()); jsonObject.getConfig().setIgnoreNullValue(true); - Assert.assertEquals("{\"code\":500}", jsonObject.toString()); + Assertions.assertEquals("{\"code\":500}", jsonObject.toString()); } @Test @@ -58,7 +58,7 @@ public class JSONObjectTest { final String str = "{\"test\":\"关于开展2018年度“文明集体”、“文明职工”评选表彰活动的通知\"}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(str); - Assert.assertEquals(str, json.toString()); + Assertions.assertEquals(str, json.toString()); } /** @@ -69,17 +69,17 @@ public class JSONObjectTest { final JSONObject json = Objects.requireNonNull(JSONUtil.ofObj()// .set("dateTime", DateUtil.parse("2019-05-02 22:12:01")))// .setDateFormat(DatePattern.NORM_DATE_PATTERN); - Assert.assertEquals("{\"dateTime\":\"2019-05-02\"}", json.toString()); + Assertions.assertEquals("{\"dateTime\":\"2019-05-02\"}", json.toString()); } @Test public void toStringWithDateTest() { JSONObject json = JSONUtil.ofObj().set("date", DateUtil.parse("2019-05-08 19:18:21")); assert json != null; - Assert.assertEquals("{\"date\":1557314301000}", json.toString()); + Assertions.assertEquals("{\"date\":1557314301000}", json.toString()); json = Objects.requireNonNull(JSONUtil.ofObj().set("date", DateUtil.parse("2019-05-08 19:18:21"))).setDateFormat(DatePattern.NORM_DATE_PATTERN); - Assert.assertEquals("{\"date\":\"2019-05-08\"}", json.toString()); + Assertions.assertEquals("{\"date\":\"2019-05-08\"}", json.toString()); } @@ -98,22 +98,22 @@ public class JSONObjectTest { // putAll操作会覆盖相同key的值,因此a,b两个key的值改变,c的值不变 json1.putAll(json2); - Assert.assertEquals(json1.get("a"), "value21"); - Assert.assertEquals(json1.get("b"), "value22"); - Assert.assertEquals(json1.get("c"), "value3"); + Assertions.assertEquals(json1.get("a"), "value21"); + Assertions.assertEquals(json1.get("b"), "value22"); + Assertions.assertEquals(json1.get("c"), "value3"); } @Test public void parseStringTest() { final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}"; final JSONObject jsonObject = JSONUtil.parseObj(jsonStr); - Assert.assertEquals(jsonObject.get("a"), "value1"); - Assert.assertEquals(jsonObject.get("b"), "value2"); - Assert.assertEquals(jsonObject.get("c"), "value3"); - Assert.assertEquals(jsonObject.get("d"), true); + Assertions.assertEquals(jsonObject.get("a"), "value1"); + Assertions.assertEquals(jsonObject.get("b"), "value2"); + Assertions.assertEquals(jsonObject.get("c"), "value3"); + Assertions.assertEquals(jsonObject.get("d"), true); - Assert.assertTrue(jsonObject.containsKey("e")); - Assert.assertNull(jsonObject.get("e")); + Assertions.assertTrue(jsonObject.containsKey("e")); + Assertions.assertNull(jsonObject.get("e")); } @Test @@ -121,8 +121,8 @@ public class JSONObjectTest { final String jsonStr = "{\"file_name\":\"RMM20180127009_731.000\",\"error_data\":\"201121151350701001252500000032 18973908335 18973908335 13601893517 201711211700152017112115135420171121 6594000000010100000000000000000000000043190101701001910072 100001100 \",\"error_code\":\"F140\",\"error_info\":\"最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”\",\"app_name\":\"inter-pre-check\"}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(jsonStr); - Assert.assertEquals("F140", json.getStr("error_code")); - Assert.assertEquals("最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”", json.getStr("error_info")); + Assertions.assertEquals("F140", json.getStr("error_code")); + Assertions.assertEquals("最早发送时间格式错误,该字段可以为空,当不为空时正确填写格式为“YYYYMMDDHHMISS”", json.getStr("error_info")); } @Test @@ -130,7 +130,7 @@ public class JSONObjectTest { final String jsonStr = "{\"test\":\"体”、“文\"}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(jsonStr); - Assert.assertEquals("体”、“文", json.getStr("test")); + Assertions.assertEquals("体”、“文", json.getStr("test")); } @Test @@ -138,8 +138,8 @@ public class JSONObjectTest { final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(jsonStr); - Assert.assertEquals(new Integer(0), json.getInt("ok")); - Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); + Assertions.assertEquals(new Integer(0), json.getInt("ok")); + Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); } @Test @@ -147,8 +147,8 @@ public class JSONObjectTest { final String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(jsonStr.getBytes(StandardCharsets.UTF_8)); - Assert.assertEquals(new Integer(0), json.getInt("ok")); - Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); + Assertions.assertEquals(new Integer(0), json.getInt("ok")); + Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); } @Test @@ -158,8 +158,8 @@ public class JSONObjectTest { //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(stringReader); - Assert.assertEquals(new Integer(0), json.getInt("ok")); - Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); + Assertions.assertEquals(new Integer(0), json.getInt("ok")); + Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); } @Test @@ -169,8 +169,8 @@ public class JSONObjectTest { //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(in); - Assert.assertEquals(new Integer(0), json.getInt("ok")); - Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); + Assertions.assertEquals(new Integer(0), json.getInt("ok")); + Assertions.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards")); } @Test @@ -179,8 +179,8 @@ public class JSONObjectTest { final String jsonStr = "{\"a\":\"
aaa
\"}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject json = new JSONObject(jsonStr); - Assert.assertEquals("
aaa
", json.get("a")); - Assert.assertEquals(jsonStr, json.toString()); + Assertions.assertEquals("
aaa
", json.get("a")); + Assertions.assertEquals(jsonStr, json.toString()); } @Test @@ -193,14 +193,14 @@ public class JSONObjectTest { .set("list", JSONUtil.ofArray().set("a").set("b")).set("testEnum", "TYPE_A"); final TestBean bean = json.toBean(TestBean.class); - Assert.assertEquals("a", bean.getList().get(0)); - Assert.assertEquals("b", bean.getList().get(1)); + Assertions.assertEquals("a", bean.getList().get(0)); + Assertions.assertEquals("b", bean.getList().get(1)); - Assert.assertEquals("strValue1", bean.getBeanValue().getValue1()); + Assertions.assertEquals("strValue1", bean.getBeanValue().getValue1()); // BigDecimal转换检查 - Assert.assertEquals(new BigDecimal("234"), bean.getBeanValue().getValue2()); + Assertions.assertEquals(new BigDecimal("234"), bean.getBeanValue().getValue2()); // 枚举转换检查 - Assert.assertEquals(TestEnum.TYPE_A, bean.getTestEnum()); + Assertions.assertEquals(TestEnum.TYPE_A, bean.getTestEnum()); } @Test @@ -214,9 +214,9 @@ public class JSONObjectTest { final TestBean bean = json.toBean(TestBean.class); // 当JSON中为字符串"null"时应被当作字符串处理 - Assert.assertEquals("null", bean.getStrValue()); + Assertions.assertEquals("null", bean.getStrValue()); // 当JSON中为字符串"null"时Bean中的字段类型不匹配应在ignoreError模式下忽略注入 - Assert.assertNull(bean.getBeanValue()); + Assertions.assertNull(bean.getBeanValue()); } @Test @@ -230,16 +230,16 @@ public class JSONObjectTest { final JSONObject json = JSONUtil.parseObj(userA); final UserA userA2 = json.toBean(UserA.class); // 测试数组 - Assert.assertEquals("seq1", userA2.getSqs().get(0).getSeq()); + Assertions.assertEquals("seq1", userA2.getSqs().get(0).getSeq()); // 测试带换行符等特殊字符转换是否成功 - Assert.assertTrue(StrUtil.isNotBlank(userA2.getName())); + Assertions.assertTrue(StrUtil.isNotBlank(userA2.getName())); } @Test public void toBeanWithNullTest() { final String jsonStr = "{'data':{'userName':'ak','password': null}}"; final UserWithMap user = JSONUtil.toBean(JSONUtil.parseObj(jsonStr), UserWithMap.class); - Assert.assertTrue(user.getData().containsKey("password")); + Assertions.assertTrue(user.getData().containsKey("password")); } @Test @@ -247,7 +247,7 @@ public class JSONObjectTest { final String json = "{\"data\":{\"b\": \"c\"}}"; final UserWithMap map = JSONUtil.toBean(json, UserWithMap.class); - Assert.assertEquals("c", map.getData().get("b")); + Assertions.assertEquals("c", map.getData().get("b")); } @Test @@ -259,12 +259,12 @@ public class JSONObjectTest { // 第一层 final List caseReports = bean.getCaseReports(); final CaseReport caseReport = caseReports.get(0); - Assert.assertNotNull(caseReport); + Assertions.assertNotNull(caseReport); // 第二层 final List stepReports = caseReports.get(0).getStepReports(); final StepReport stepReport = stepReports.get(0); - Assert.assertNotNull(stepReport); + Assertions.assertNotNull(stepReport); } /** @@ -280,13 +280,13 @@ public class JSONObjectTest { .set("userId", "测试用户1")); final TokenAuthWarp2 bean = json.toBean(TokenAuthWarp2.class); - Assert.assertEquals("http://test.com", bean.getTargetUrl()); - Assert.assertEquals("true", bean.getSuccess()); + Assertions.assertEquals("http://test.com", bean.getTargetUrl()); + Assertions.assertEquals("true", bean.getSuccess()); final TokenAuthResponse result = bean.getResult(); - Assert.assertNotNull(result); - Assert.assertEquals("tokenTest", result.getToken()); - Assert.assertEquals("测试用户1", result.getUserId()); + Assertions.assertNotNull(result); + Assertions.assertEquals("tokenTest", result.getToken()); + Assertions.assertEquals("测试用户1", result.getUserId()); } /** @@ -299,7 +299,7 @@ public class JSONObjectTest { "\"secret\":\"dsadadqwdqs121d1e2\",\"message\":\"hello world\"},\"code\":100,\"" + "message\":\"validate message\"}"; final ResultDto dto = JSONUtil.toBean(jsonStr, ResultDto.class); - Assert.assertEquals("validate message", dto.getMessage()); + Assertions.assertEquals("validate message", dto.getMessage()); } @Test @@ -311,8 +311,8 @@ public class JSONObjectTest { final JSONObject json = JSONUtil.parseObj(userA, false); - Assert.assertTrue(json.containsKey("a")); - Assert.assertTrue(json.getJSONArray("sqs").getJSONObject(0).containsKey("seq")); + Assertions.assertTrue(json.containsKey("a")); + Assertions.assertTrue(json.getJSONArray("sqs").getJSONObject(0).containsKey("seq")); } @Test @@ -326,10 +326,10 @@ public class JSONObjectTest { final JSONObject json = JSONUtil.parseObj(bean, false); // 枚举转换检查 - Assert.assertEquals("TYPE_B", json.get("testEnum")); + Assertions.assertEquals("TYPE_B", json.get("testEnum")); final TestBean bean2 = json.toBean(TestBean.class); - Assert.assertEquals(bean.toString(), bean2.toString()); + Assertions.assertEquals(bean.toString(), bean2.toString()); } @Test @@ -339,9 +339,9 @@ public class JSONObjectTest { .set("data", "{\"jobId\": \"abc\", \"videoUrl\": \"http://a.com/a.mp4\"}"); final JSONBean bean = json.toBean(JSONBean.class); - Assert.assertEquals(22, bean.getCode()); - Assert.assertEquals("abc", bean.getData().getObj("jobId")); - Assert.assertEquals("http://a.com/a.mp4", bean.getData().getObj("videoUrl")); + Assertions.assertEquals(22, bean.getCode()); + Assertions.assertEquals("abc", bean.getData().getObj("jobId")); + Assertions.assertEquals("http://a.com/a.mp4", bean.getData().getObj("videoUrl")); } @Test @@ -354,8 +354,8 @@ public class JSONObjectTest { final JSONObject userAJson = JSONUtil.parseObj(userA); final UserB userB = JSONUtil.toBean(userAJson, UserB.class); - Assert.assertEquals(userA.getName(), userB.getName()); - Assert.assertEquals(userA.getDate(), userB.getDate()); + Assertions.assertEquals(userA.getName(), userB.getName()); + Assertions.assertEquals(userA.getDate(), userB.getDate()); } @Test @@ -370,7 +370,7 @@ public class JSONObjectTest { userAJson.setDateFormat("yyyy-MM-dd"); final UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class); - Assert.assertEquals(DateUtil.parse("2018-10-25"), bean.getDate()); + Assertions.assertEquals(DateUtil.parse("2018-10-25"), bean.getDate()); } @Test @@ -380,7 +380,7 @@ public class JSONObjectTest { .set("name", "nameValue") .set("date", "08:00:00"); final UserA bean = JSONUtil.toBean(userAJson.toString(), UserA.class); - Assert.assertEquals(DateUtil.formatToday() + " 08:00:00", DateUtil.date(bean.getDate()).toString()); + Assertions.assertEquals(DateUtil.formatToday() + " 08:00:00", DateUtil.date(bean.getDate()).toString()); } @Test @@ -391,19 +391,19 @@ public class JSONObjectTest { userA.setDate(new Date()); final JSONObject userAJson = JSONUtil.parseObj(userA); - Assert.assertFalse(userAJson.containsKey("a")); + Assertions.assertFalse(userAJson.containsKey("a")); final JSONObject userAJsonWithNullValue = JSONUtil.parseObj(userA, false); - Assert.assertTrue(userAJsonWithNullValue.containsKey("a")); - Assert.assertTrue(userAJsonWithNullValue.containsKey("sqs")); + Assertions.assertTrue(userAJsonWithNullValue.containsKey("a")); + Assertions.assertTrue(userAJsonWithNullValue.containsKey("sqs")); } @Test public void specialCharTest() { final String json = "{\"pattern\": \"[abc]\b\u2001\", \"pattern2Json\": {\"patternText\": \"[ab]\\b\"}}"; final JSONObject obj = JSONUtil.parseObj(json); - Assert.assertEquals("[abc]\\b\\u2001", obj.getStrEscaped("pattern")); - Assert.assertEquals("{\"patternText\":\"[ab]\\b\"}", obj.getStrEscaped("pattern2Json")); + Assertions.assertEquals("[abc]\\b\\u2001", obj.getStrEscaped("pattern")); + Assertions.assertEquals("{\"patternText\":\"[ab]\\b\"}", obj.getStrEscaped("pattern2Json")); } @Test @@ -412,12 +412,12 @@ public class JSONObjectTest { final JSONObject jsonObject = JSONUtil.parseObj(json); // 没有转义按照默认规则显示 - Assert.assertEquals("yyb\nbbb", jsonObject.getStr("name")); + Assertions.assertEquals("yyb\nbbb", jsonObject.getStr("name")); // 转义按照字符串显示 - Assert.assertEquals("yyb\\nbbb", jsonObject.getStrEscaped("name")); + Assertions.assertEquals("yyb\\nbbb", jsonObject.getStrEscaped("name")); final String bbb = jsonObject.getStr("bbb", "defaultBBB"); - Assert.assertEquals("defaultBBB", bbb); + Assertions.assertEquals("defaultBBB", bbb); } @Test @@ -427,15 +427,15 @@ public class JSONObjectTest { beanWithAlias.setValue2(35); final JSONObject jsonObject = JSONUtil.parseObj(beanWithAlias); - Assert.assertEquals("张三", jsonObject.getStr("name")); - Assert.assertEquals(new Integer(35), jsonObject.getInt("age")); + Assertions.assertEquals("张三", jsonObject.getStr("name")); + Assertions.assertEquals(new Integer(35), jsonObject.getInt("age")); final JSONObject json = JSONUtil.ofObj() .set("name", "张三") .set("age", 35); final BeanWithAlias bean = JSONUtil.toBean(Objects.requireNonNull(json).toString(), BeanWithAlias.class); - Assert.assertEquals("张三", bean.getValue1()); - Assert.assertEquals(new Integer(35), bean.getValue2()); + Assertions.assertEquals("张三", bean.getValue1()); + Assertions.assertEquals(new Integer(35), bean.getValue2()); } @Test @@ -447,7 +447,7 @@ public class JSONObjectTest { json.append("date", DateUtil.parse("2020-06-05 11:16:11")); json.append("bbb", "222"); json.append("aaa", "123"); - Assert.assertEquals("{\"date\":\"2020-06-05 11:16:11\",\"bbb\":\"222\",\"aaa\":\"123\"}", json.toString()); + Assertions.assertEquals("{\"date\":\"2020-06-05 11:16:11\",\"bbb\":\"222\",\"aaa\":\"123\"}", json.toString()); } @Test @@ -463,11 +463,11 @@ public class JSONObjectTest { final String jsonStr = "{\"date\":\"2020#06#05\",\"bbb\":\"222\",\"aaa\":\"123\"}"; - Assert.assertEquals(jsonStr, json.toString()); + Assertions.assertEquals(jsonStr, json.toString()); // 解析测试 final JSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig); - Assert.assertEquals(DateUtil.beginOfDay(date), parse.getDate("date")); + Assertions.assertEquals(DateUtil.beginOfDay(date), parse.getDate("date")); } @Test @@ -479,11 +479,11 @@ public class JSONObjectTest { final JSONObject json = new JSONObject(jsonConfig); json.set("date", date); - Assert.assertEquals("{\"date\":1591326971}", json.toString()); + Assertions.assertEquals("{\"date\":1591326971}", json.toString()); // 解析测试 final JSONObject parse = JSONUtil.parseObj(json.toString(), jsonConfig); - Assert.assertEquals(date, DateUtil.date(parse.getDate("date"))); + Assertions.assertEquals(date, DateUtil.date(parse.getDate("date"))); } @Test @@ -499,11 +499,11 @@ public class JSONObjectTest { final String jsonStr = "{\"date\":1591326971,\"bbb\":\"222\",\"aaa\":\"123\"}"; - Assert.assertEquals(jsonStr, json.toString()); + Assertions.assertEquals(jsonStr, json.toString()); // 解析测试 final JSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig); - Assert.assertEquals(date, parse.getDate("date")); + Assertions.assertEquals(date, parse.getDate("date")); } @Test @@ -511,7 +511,7 @@ public class JSONObjectTest { final String timeStr = "1970-01-01 00:00:00"; final JSONObject jsonObject = JSONUtil.ofObj().set("time", timeStr); final Timestamp time = jsonObject.get("time", Timestamp.class); - Assert.assertEquals("1970-01-01 00:00:00.0", time.toString()); + Assertions.assertEquals("1970-01-01 00:00:00.0", time.toString()); } public enum TestEnum { @@ -556,11 +556,11 @@ public class JSONObjectTest { public void parseBeanSameNameTest() { final SameNameBean sameNameBean = new SameNameBean(); final JSONObject parse = JSONUtil.parseObj(sameNameBean); - Assert.assertEquals("123", parse.getStr("username")); - Assert.assertEquals("abc", parse.getStr("userName")); + Assertions.assertEquals("123", parse.getStr("username")); + Assertions.assertEquals("abc", parse.getStr("userName")); // 测试ignore注解是否有效 - Assert.assertNull(parse.getStr("fieldToIgnore")); + Assertions.assertNull(parse.getStr("fieldToIgnore")); } /** @@ -596,13 +596,15 @@ public class JSONObjectTest { final Map.Entry next = entries.iterator().next(); final JSONObject jsonObject = JSONUtil.parseObj(next); - Assert.assertEquals("{\"test\":\"testValue\"}", jsonObject.toString()); + Assertions.assertEquals("{\"test\":\"testValue\"}", jsonObject.toString()); } - @Test(expected = JSONException.class) + @Test public void createJSONObjectTest() { - // 集合类不支持转为JSONObject - new JSONObject(new JSONArray(), JSONConfig.of()); + Assertions.assertThrows(JSONException.class, ()->{ + // 集合类不支持转为JSONObject + new JSONObject(new JSONArray(), JSONConfig.of()); + }); } @Test @@ -611,26 +613,26 @@ public class JSONObjectTest { map.put("c", 2.0F); final String s = JSONUtil.toJsonStr(map); - Assert.assertEquals("{\"c\":2}", s); + Assertions.assertEquals("{\"c\":2}", s); } @Test public void appendTest() { final JSONObject jsonObject = JSONUtil.ofObj().append("key1", "value1"); - Assert.assertEquals("{\"key1\":\"value1\"}", jsonObject.toString()); + Assertions.assertEquals("{\"key1\":\"value1\"}", jsonObject.toString()); jsonObject.append("key1", "value2"); - Assert.assertEquals("{\"key1\":[\"value1\",\"value2\"]}", jsonObject.toString()); + Assertions.assertEquals("{\"key1\":[\"value1\",\"value2\"]}", jsonObject.toString()); jsonObject.append("key1", "value3"); - Assert.assertEquals("{\"key1\":[\"value1\",\"value2\",\"value3\"]}", jsonObject.toString()); + Assertions.assertEquals("{\"key1\":[\"value1\",\"value2\",\"value3\"]}", jsonObject.toString()); } @Test public void putByPathTest() { final JSONObject json = new JSONObject(); json.putByPath("aa.bb", "BB"); - Assert.assertEquals("{\"aa\":{\"bb\":\"BB\"}}", json.toString()); + Assertions.assertEquals("{\"aa\":{\"bb\":\"BB\"}}", json.toString()); } @@ -638,7 +640,7 @@ public class JSONObjectTest { public void bigDecimalTest() { final String jsonStr = "{\"orderId\":\"1704747698891333662002277\"}"; final BigDecimalBean bigDecimalBean = JSONUtil.toBean(jsonStr, BigDecimalBean.class); - Assert.assertEquals("{\"orderId\":1704747698891333662002277}", JSONUtil.toJsonStr(bigDecimalBean)); + Assertions.assertEquals("{\"orderId\":1704747698891333662002277}", JSONUtil.toJsonStr(bigDecimalBean)); } @Data @@ -656,7 +658,7 @@ public class JSONObjectTest { .set("d", true); final String s = json1.toJSONString(0, (pair) -> pair.getKey().equals("b")); - Assert.assertEquals("{\"b\":\"value2\"}", s); + Assertions.assertEquals("{\"b\":\"value2\"}", s); } @Test @@ -668,7 +670,7 @@ public class JSONObjectTest { .set("d", true); final String s = json1.toJSONString(0, (pair) -> false == pair.getKey().equals("b")); - Assert.assertEquals("{\"a\":\"value1\",\"c\":\"value3\",\"d\":true}", s); + Assertions.assertEquals("{\"a\":\"value1\",\"c\":\"value3\",\"d\":true}", s); } @Test @@ -688,7 +690,7 @@ public class JSONObjectTest { // 除了"b",其他都去掉 return false; }); - Assert.assertEquals("{\"b\":\"value2_edit\"}", s); + Assertions.assertEquals("{\"b\":\"value2_edit\"}", s); } @Test @@ -703,7 +705,7 @@ public class JSONObjectTest { pair.setKey(StrUtil.toUnderlineCase((String)pair.getKey())); return true; }); - Assert.assertEquals("{\"a_key\":\"value1\",\"b_job\":\"value2\",\"c_good\":\"value3\",\"d\":true}", s); + Assertions.assertEquals("{\"a_key\":\"value1\",\"b_job\":\"value2\",\"c_good\":\"value3\",\"d\":true}", s); } @Test @@ -716,7 +718,7 @@ public class JSONObjectTest { pair.setValue(ObjUtil.defaultIfNull(pair.getValue(), StrUtil.EMPTY)); return true; }); - Assert.assertEquals("{\"a\":\"\",\"b\":\"value2\"}", s); + Assertions.assertEquals("{\"a\":\"\",\"b\":\"value2\"}", s); } @Test @@ -724,8 +726,8 @@ public class JSONObjectTest { final String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\", \"d\": true, \"e\": null}"; //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject jsonObject = new JSONObject(jsonStr, null, (pair)-> "b".equals(pair.getKey())); - Assert.assertEquals(1, jsonObject.size()); - Assert.assertEquals("value2", jsonObject.get("b")); + Assertions.assertEquals(1, jsonObject.size()); + Assertions.assertEquals("value2", jsonObject.get("b")); } @Test @@ -738,6 +740,6 @@ public class JSONObjectTest { } return true; }); - Assert.assertEquals("value2_edit", jsonObject.get("b")); + Assertions.assertEquals("value2_edit", jsonObject.get("b")); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONPathTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONPathTest.java index 9765ca509..196b09420 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONPathTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONPathTest.java @@ -1,7 +1,7 @@ package cn.hutool.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * JSON路径单元测试 @@ -15,9 +15,9 @@ public class JSONPathTest { public void getByPathTest() { final String json = "[{\"id\":\"1\",\"name\":\"xingming\"},{\"id\":\"2\",\"name\":\"mingzi\"}]"; Object value = JSONUtil.parseArray(json).getByPath("[0].name"); - Assert.assertEquals("xingming", value); + Assertions.assertEquals("xingming", value); value = JSONUtil.parseArray(json).getByPath("[1].name"); - Assert.assertEquals("mingzi", value); + Assertions.assertEquals("mingzi", value); } @Test @@ -25,6 +25,6 @@ public class JSONPathTest { final String str = "{'accountId':111}"; final JSON json = (JSON) JSONUtil.parse(str); final Long accountId = JSONUtil.getByPath(json, "$.accountId", 0L); - Assert.assertEquals(111L, accountId.longValue()); + Assertions.assertEquals(111L, accountId.longValue()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONStrFormatterTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONStrFormatterTest.java index eb5f719d0..71fa2cbb3 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONStrFormatterTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONStrFormatterTest.java @@ -1,9 +1,9 @@ package cn.hutool.json; 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; /** * JSON字符串格式化单元测试 @@ -16,25 +16,25 @@ public class JSONStrFormatterTest { public void formatTest() { final String json = "{'age':23,'aihao':['pashan','movies'],'name':{'firstName':'zhang','lastName':'san','aihao':['pashan','movies','name':{'firstName':'zhang','lastName':'san','aihao':['pashan','movies']}]}}"; final String result = JSONStrFormatter.format(json); - Assert.assertNotNull(result); + Assertions.assertNotNull(result); } @Test public void formatTest2() { final String json = "{\"abc\":{\"def\":\"\\\"[ghi]\"}}"; final String result = JSONStrFormatter.format(json); - Assert.assertNotNull(result); + Assertions.assertNotNull(result); } @Test public void formatTest3() { final String json = "{\"id\":13,\"title\":\"《标题》\",\"subtitle\":\"副标题z'c'z'xv'c'xv\",\"user_id\":6,\"type\":0}"; final String result = JSONStrFormatter.format(json); - Assert.assertNotNull(result); + Assertions.assertNotNull(result); } @Test - @Ignore + @Disabled public void formatTest4(){ final String jsonStr = "{\"employees\":[{\"firstName\":\"Bill\",\"lastName\":\"Gates\"},{\"firstName\":\"George\",\"lastName\":\"Bush\"},{\"firstName\":\"Thomas\",\"lastName\":\"Carter\"}]}"; Console.log(JSONUtil.formatJsonStr(jsonStr)); diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONSupportTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONSupportTest.java index 72c529b20..fc9064d1a 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONSupportTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONSupportTest.java @@ -2,8 +2,8 @@ package cn.hutool.json; import lombok.Data; import lombok.EqualsAndHashCode; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JSONSupportTest { @@ -23,10 +23,10 @@ public class JSONSupportTest { final TestBean testBean = JSONUtil.toBean(jsonstr, TestBean.class); - Assert.assertEquals("https://hutool.cn", testBean.getLocation()); - Assert.assertEquals("这是一条测试消息", testBean.getMessage()); - Assert.assertEquals("123456789", testBean.getRequestId()); - Assert.assertEquals("987654321", testBean.getTraceId()); + Assertions.assertEquals("https://hutool.cn", testBean.getLocation()); + Assertions.assertEquals("这是一条测试消息", testBean.getMessage()); + Assertions.assertEquals("123456789", testBean.getRequestId()); + Assertions.assertEquals("987654321", testBean.getTraceId()); } @EqualsAndHashCode(callSuper = true) diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONTokenerTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONTokenerTest.java index e543a11ad..b541c9b9a 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONTokenerTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONTokenerTest.java @@ -1,13 +1,13 @@ package cn.hutool.json; import cn.hutool.core.io.resource.ResourceUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JSONTokenerTest { @Test public void parseTest() { final JSONObject jsonObject = JSONUtil.parseObj(ResourceUtil.getUtf8Reader("issue1200.json")); - Assert.assertNotNull(jsonObject); + Assertions.assertNotNull(jsonObject); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONUtilTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONUtilTest.java index 758a82a2a..b30b70390 100644 --- a/hutool-json/src/test/java/cn/hutool/json/JSONUtilTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONUtilTest.java @@ -9,65 +9,75 @@ import cn.hutool.json.test.bean.Price; import cn.hutool.json.test.bean.UserA; import cn.hutool.json.test.bean.UserC; 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.sql.SQLException; import java.util.*; public class JSONUtilTest { - @Test(expected = JSONException.class) + @Test public void parseInvalid() { - JSONUtil.parse("abc"); + Assertions.assertThrows(JSONException.class, ()->{ + JSONUtil.parse("abc"); + }); } - @Test(expected = JSONException.class) + @Test public void parseInvalid2() { - JSONUtil.parse("'abc"); + Assertions.assertThrows(JSONException.class, ()->{ + JSONUtil.parse("'abc"); + }); } - @Test(expected = JSONException.class) + @Test public void parseInvalid3() { - JSONUtil.parse("\"abc"); + Assertions.assertThrows(JSONException.class, ()->{ + JSONUtil.parse("\"abc"); + }); } @Test public void parseValueTest() { Object parse = JSONUtil.parse(123); - Assert.assertEquals(123, parse); + Assertions.assertEquals(123, parse); parse = JSONUtil.parse("\"abc\""); - Assert.assertEquals("abc", parse); + Assertions.assertEquals("abc", parse); parse = JSONUtil.parse("true"); - Assert.assertEquals(true, parse); + Assertions.assertEquals(true, parse); parse = JSONUtil.parse("False"); - Assert.assertEquals(false, parse); + Assertions.assertEquals(false, parse); parse = JSONUtil.parse("null"); - Assert.assertNull(parse); + Assertions.assertNull(parse); parse = JSONUtil.parse(""); - Assert.assertNull(parse); + Assertions.assertNull(parse); } /** * 出现语法错误时报错,检查解析\x字符时是否会导致死循环异常 */ - @Test(expected = JSONException.class) + @Test public void parseTest() { - JSONUtil.parseArray("[{\"a\":\"a\\x]"); + Assertions.assertThrows(JSONException.class, ()->{ + JSONUtil.parseArray("[{\"a\":\"a\\x]"); + }); } /** * 数字解析为JSONArray报错 */ - @Test(expected = JSONException.class) + @Test public void parseNumberToJSONArrayTest() { - final JSONArray json = JSONUtil.parseArray(123L); - Assert.assertNotNull(json); + Assertions.assertThrows(JSONException.class, ()->{ + final JSONArray json = JSONUtil.parseArray(123L); + Assertions.assertNotNull(json); + }); } /** @@ -77,16 +87,18 @@ public class JSONUtilTest { public void parseNumberToJSONArrayTest2() { final JSONArray json = JSONUtil.parseArray(123L, JSONConfig.of().setIgnoreError(true)); - Assert.assertNotNull(json); + Assertions.assertNotNull(json); } /** * 数字解析为JSONArray报错 */ - @Test(expected = JSONException.class) + @Test public void parseNumberToJSONObjectTest() { - final JSONObject json = JSONUtil.parseObj(123L); - Assert.assertNotNull(json); + Assertions.assertThrows(JSONException.class, ()->{ + final JSONObject json = JSONUtil.parseObj(123L); + Assertions.assertNotNull(json); + }); } /** @@ -95,7 +107,7 @@ public class JSONUtilTest { @Test public void parseNumberToJSONObjectTest2() { final JSONObject json = JSONUtil.parseObj(123L, JSONConfig.of().setIgnoreError(true)); - Assert.assertEquals(new JSONObject(), json); + Assertions.assertEquals(new JSONObject(), json); } @Test @@ -116,7 +128,7 @@ public class JSONUtilTest { final String str = JSONUtil.toJsonPrettyStr(map); JSONUtil.parse(str); - Assert.assertNotNull(str); + Assertions.assertNotNull(str); } @Test @@ -131,10 +143,10 @@ public class JSONUtilTest { final JSONObject jsonObject = JSONUtil.parseObj(data); - Assert.assertTrue(jsonObject.containsKey("model")); - Assert.assertEquals(1, jsonObject.getJSONObject("model").getInt("type").intValue()); - Assert.assertEquals("17610836523", jsonObject.getJSONObject("model").getStr("mobile")); - // Assert.assertEquals("{\"model\":{\"type\":1,\"mobile\":\"17610836523\"}}", jsonObject.toString()); + Assertions.assertTrue(jsonObject.containsKey("model")); + Assertions.assertEquals(1, jsonObject.getJSONObject("model").getInt("type").intValue()); + Assertions.assertEquals("17610836523", jsonObject.getJSONObject("model").getStr("mobile")); + // Assertions.assertEquals("{\"model\":{\"type\":1,\"mobile\":\"17610836523\"}}", jsonObject.toString()); } @Test @@ -149,11 +161,11 @@ public class JSONUtilTest { map.put("user", object.toString()); final JSONObject json = JSONUtil.parseObj(map); - Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"640102197312070614640102197312070614Xaa1"; final JSONObject json = JSONUtil.parseFromXml(s); - Assert.assertEquals(640102197312070614L, json.get("sfzh")); - Assert.assertEquals("640102197312070614X", json.get("sfz")); - Assert.assertEquals("aa", json.get("name")); - Assert.assertEquals(1, json.get("gender")); + Assertions.assertEquals(640102197312070614L, json.get("sfzh")); + Assertions.assertEquals("640102197312070614X", json.get("sfz")); + Assertions.assertEquals("aa", json.get("name")); + Assertions.assertEquals(1, json.get("gender")); } @Test @@ -224,7 +236,7 @@ public class JSONUtilTest { final String json = "{\"test\": 12.00}"; final JSONObject jsonObject = JSONUtil.parseObj(json); //noinspection BigDecimalMethodWithoutRoundingCalled - Assert.assertEquals("12.00", jsonObject.getBigDecimal("test").setScale(2).toString()); + Assertions.assertEquals("12.00", jsonObject.getBigDecimal("test").setScale(2).toString()); } @Test @@ -232,7 +244,7 @@ public class JSONUtilTest { final JSONObject jsonObject = JSONUtil.ofObj() .set("test2", (JSONStringer) () -> NumberUtil.format("#.0", 12.00D)); - Assert.assertEquals("{\"test2\":12.0}", jsonObject.toString()); + Assertions.assertEquals("{\"test2\":12.0}", jsonObject.toString()); } @Test @@ -240,16 +252,16 @@ public class JSONUtilTest { // 默认去除多余的0 final JSONObject jsonObjectDefault = JSONUtil.ofObj() .set("test2", 12.00D); - Assert.assertEquals("{\"test2\":12}", jsonObjectDefault.toString()); + Assertions.assertEquals("{\"test2\":12}", jsonObjectDefault.toString()); // 不去除多余的0 final JSONObject jsonObject = JSONUtil.ofObj(JSONConfig.of().setStripTrailingZeros(false)) .set("test2", 12.00D); - Assert.assertEquals("{\"test2\":12.0}", jsonObject.toString()); + Assertions.assertEquals("{\"test2\":12.0}", jsonObject.toString()); // 去除多余的0 jsonObject.getConfig().setStripTrailingZeros(true); - Assert.assertEquals("{\"test2\":12}", jsonObject.toString()); + Assertions.assertEquals("{\"test2\":12}", jsonObject.toString()); } @Test @@ -259,7 +271,7 @@ public class JSONUtilTest { " \"test\": \"\\\\地库地库\",\n" + "}"); - Assert.assertEquals("\\地库地库", jsonObject.getObj("test")); + Assertions.assertEquals("\\地库地库", jsonObject.getObj("test")); } @Test @@ -267,14 +279,14 @@ public class JSONUtilTest { //https://github.com/dromara/hutool/issues/1399 // SQLException实现了Iterable接口,默认是遍历之,会栈溢出,修正后只返回string final JSONObject set = JSONUtil.ofObj().set("test", new SQLException("test")); - Assert.assertEquals("{\"test\":\"java.sql.SQLException: test\"}", set.toString()); + Assertions.assertEquals("{\"test\":\"java.sql.SQLException: test\"}", set.toString()); } @Test public void parseBigNumberTest(){ // 科学计数法使用BigDecimal处理,默认输出非科学计数形式 final String str = "{\"test\":100000054128897953e4}"; - Assert.assertEquals("{\"test\":1000000541288979530000}", JSONUtil.parseObj(str).toString()); + Assertions.assertEquals("{\"test\":1000000541288979530000}", JSONUtil.parseObj(str).toString()); } @Test @@ -283,23 +295,25 @@ public class JSONUtilTest { obj.set("key1", "v1") .set("key2", ListUtil.view("a", "b", "c")); final String xmlStr = JSONUtil.toXmlStr(obj); - Assert.assertEquals("v1abc", xmlStr); + Assertions.assertEquals("v1abc", xmlStr); } - @Test(expected = JSONException.class) + @Test public void toJsonStrOfStringTest(){ - final String a = "a"; + Assertions.assertThrows(JSONException.class, ()->{ + final String a = "a"; - // 普通字符串不能解析为JSON字符串,必须由双引号或者单引号包裹 - final String s = JSONUtil.toJsonStr(a); - Assert.assertEquals(a, s); + // 普通字符串不能解析为JSON字符串,必须由双引号或者单引号包裹 + final String s = JSONUtil.toJsonStr(a); + Assertions.assertEquals(a, s); + }); } @Test public void toJsonStrOfNumberTest(){ final int a = 1; final String s = JSONUtil.toJsonStr(a); - Assert.assertEquals("1", s); + Assertions.assertEquals("1", s); } /** @@ -309,7 +323,7 @@ public class JSONUtilTest { public void testArrayEntity() { final String jsonStr = JSONUtil.toJsonStr(new ArrayEntity()); // a为空的bytes数组,按照空的流对待 - Assert.assertEquals("{\"b\":[0],\"c\":[],\"d\":[],\"e\":[]}", jsonStr); + Assertions.assertEquals("{\"b\":[0],\"c\":[],\"d\":[],\"e\":[]}", jsonStr); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/JSONWriterTest.java b/hutool-json/src/test/java/cn/hutool/json/JSONWriterTest.java index 3c9d4425b..5f1af3689 100755 --- a/hutool-json/src/test/java/cn/hutool/json/JSONWriterTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/JSONWriterTest.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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.util.Date; @@ -15,13 +15,13 @@ public class JSONWriterTest { // 日期原样写入 final Date date = jsonObject.getDate("date"); - Assert.assertEquals("2022-09-30 00:00:00", date.toString()); + Assertions.assertEquals("2022-09-30 00:00:00", date.toString()); // 自定义日期格式生效 - Assert.assertEquals("{\"date\":\"2022-09-30\"}", jsonObject.toString()); + Assertions.assertEquals("{\"date\":\"2022-09-30\"}", jsonObject.toString()); // 自定义日期格式解析生效 final JSONObject parse = JSONUtil.parseObj(jsonObject.toString(), JSONConfig.of().setDateFormat("yyyy-MM-dd")); - Assert.assertEquals(String.class, parse.get("date").getClass()); + Assertions.assertEquals(String.class, parse.get("date").getClass()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/ParseBeanTest.java b/hutool-json/src/test/java/cn/hutool/json/ParseBeanTest.java index f9c3cd578..f97504229 100644 --- a/hutool-json/src/test/java/cn/hutool/json/ParseBeanTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/ParseBeanTest.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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; @@ -33,7 +33,7 @@ public class ParseBeanTest { final JSONObject json = JSONUtil.parseObj(a); final A a1 = JSONUtil.toBean(json, A.class); - Assert.assertEquals(json.toString(), JSONUtil.toJsonStr(a1)); + Assertions.assertEquals(json.toString(), JSONUtil.toJsonStr(a1)); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/Pr192Test.java b/hutool-json/src/test/java/cn/hutool/json/Pr192Test.java index 3a71e2cb9..fcfada612 100644 --- a/hutool-json/src/test/java/cn/hutool/json/Pr192Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/Pr192Test.java @@ -1,7 +1,7 @@ package cn.hutool.json; -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.List; @@ -14,7 +14,7 @@ public class Pr192Test { final String number = "1234.123456789123456"; final String jsonString = "{\"create\":{\"details\":[{\"price\":" + number + "}]}}"; final WebCreate create = JSONUtil.toBean(jsonString, WebCreate.class); - Assert.assertEquals(number,create.getCreate().getDetails().get(0).getPrice().toString()); + Assertions.assertEquals(number,create.getCreate().getDetails().get(0).getPrice().toString()); } static class WebCreate { diff --git a/hutool-json/src/test/java/cn/hutool/json/TransientTest.java b/hutool-json/src/test/java/cn/hutool/json/TransientTest.java index ee3f5ad5b..d2910096d 100644 --- a/hutool-json/src/test/java/cn/hutool/json/TransientTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/TransientTest.java @@ -1,8 +1,8 @@ package cn.hutool.json; 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 TransientTest { @@ -21,7 +21,7 @@ public class TransientTest { //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject jsonObject = new JSONObject(detailBill, JSONConfig.of().setTransientSupport(false)); - Assert.assertEquals("{\"id\":\"3243\",\"bizNo\":\"bizNo\"}", jsonObject.toString()); + Assertions.assertEquals("{\"id\":\"3243\",\"bizNo\":\"bizNo\"}", jsonObject.toString()); } @Test @@ -33,7 +33,7 @@ public class TransientTest { //noinspection MismatchedQueryAndUpdateOfCollection final JSONObject jsonObject = new JSONObject(detailBill, JSONConfig.of().setTransientSupport(true)); - Assert.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString()); + Assertions.assertEquals("{\"bizNo\":\"bizNo\"}", jsonObject.toString()); } @Test @@ -46,8 +46,8 @@ public class TransientTest { JSONConfig.of().setTransientSupport(false)); final Bill bill = jsonObject.toBean(Bill.class); - Assert.assertEquals("3243", bill.getId()); - Assert.assertEquals("bizNo", bill.getBizNo()); + Assertions.assertEquals("3243", bill.getId()); + Assertions.assertEquals("bizNo", bill.getBizNo()); } @Test @@ -60,7 +60,7 @@ public class TransientTest { JSONConfig.of().setTransientSupport(true)); final Bill bill = jsonObject.toBean(Bill.class); - Assert.assertNull(bill.getId()); - Assert.assertEquals("bizNo", bill.getBizNo()); + Assertions.assertNull(bill.getId()); + Assertions.assertEquals("bizNo", bill.getBizNo()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/issueIVMD5/IssueIVMD5Test.java b/hutool-json/src/test/java/cn/hutool/json/issueIVMD5/IssueIVMD5Test.java index 59c312495..35491c63c 100755 --- a/hutool-json/src/test/java/cn/hutool/json/issueIVMD5/IssueIVMD5Test.java +++ b/hutool-json/src/test/java/cn/hutool/json/issueIVMD5/IssueIVMD5Test.java @@ -4,8 +4,8 @@ import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.reflect.TypeReference; import cn.hutool.json.JSONConfig; import cn.hutool.json.JSONUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; @@ -22,7 +22,7 @@ public class IssueIVMD5Test { final BaseResult bean = JSONUtil.toBean(jsonStr, JSONConfig.of(), typeReference.getType()); final StudentInfo data2 = bean.getData2(); - Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", data2.getAccountId()); + Assertions.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", data2.getAccountId()); } /** @@ -37,6 +37,6 @@ public class IssueIVMD5Test { final List data = bean.getData(); final StudentInfo studentInfo = data.get(0); - Assert.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", studentInfo.getAccountId()); + Assertions.assertEquals("B4DDF491FDF34074AE7A819E1341CB6C", studentInfo.getAccountId()); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI5QRUOTest.java b/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI5QRUOTest.java index cf68ffadd..99a90d34c 100644 --- a/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI5QRUOTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI5QRUOTest.java @@ -1,7 +1,7 @@ package cn.hutool.json.jwt; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.LinkedHashMap; import java.util.Map; @@ -31,11 +31,11 @@ public class IssueI5QRUOTest { }; final String token = JWTUtil.createToken(header, payload, "123456".getBytes()); - Assert.assertEquals("eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9." + + Assertions.assertEquals("eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9." + "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." + "3Ywq9NlR3cBST4nfcdbR-fcZ8374RHzU50X6flKvG-tnWFMalMaHRm3cMpXs1NrZ", token); final boolean verify = JWT.of(token).setKey("123456".getBytes()).verify(); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI6IS5BTest.java b/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI6IS5BTest.java index e2de93d70..030717b48 100644 --- a/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI6IS5BTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/jwt/IssueI6IS5BTest.java @@ -5,8 +5,8 @@ import cn.hutool.core.date.TimeUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; 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.nio.charset.StandardCharsets; import java.time.LocalDateTime; @@ -23,11 +23,11 @@ public class IssueI6IS5BTest { final JwtToken jwtToken = new JwtToken(); jwtToken.setIat(iat); final String token = JWTUtil.createToken(JSONUtil.parseObj(jwtToken), "123".getBytes(StandardCharsets.UTF_8)); - Assert.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token); + Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token); final JSONObject payloads = JWTUtil.parseToken(token).getPayloads(); - Assert.assertEquals("{\"iat\":1677772800}", payloads.toString()); + Assertions.assertEquals("{\"iat\":1677772800}", payloads.toString()); final JwtToken o = payloads.toBean(JwtToken.class); - Assert.assertEquals(iat, o.getIat()); + Assertions.assertEquals(iat, o.getIat()); } @Data @@ -41,11 +41,11 @@ public class IssueI6IS5BTest { final JwtToken2 jwtToken = new JwtToken2(); jwtToken.setIat(iat); final String token = JWTUtil.createToken(JSONUtil.parseObj(jwtToken), "123".getBytes(StandardCharsets.UTF_8)); - Assert.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token); + Assertions.assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzc3NzI4MDB9.SXU_mm1wT5lNoK-Dq5Y8f3BItv_44zuAlyeWLqajpXg", token); final JSONObject payloads = JWTUtil.parseToken(token).getPayloads(); - Assert.assertEquals("{\"iat\":1677772800}", payloads.toString()); + Assertions.assertEquals("{\"iat\":1677772800}", payloads.toString()); final JwtToken2 o = payloads.toBean(JwtToken2.class); - Assert.assertEquals(iat, o.getIat()); + Assertions.assertEquals(iat, o.getIat()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTSignerTest.java b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTSignerTest.java index 6c9a27c81..0261ba0a3 100755 --- a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTSignerTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTSignerTest.java @@ -5,8 +5,8 @@ import cn.hutool.crypto.KeyUtil; import cn.hutool.json.jwt.signers.AlgorithmUtil; import cn.hutool.json.jwt.signers.JWTSigner; import cn.hutool.json.jwt.signers.JWTSignerUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class JWTSignerTest { @@ -14,7 +14,7 @@ public class JWTSignerTest { public void hs256Test(){ final String id = "hs256"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -30,7 +30,7 @@ public class JWTSignerTest { public void hs384Test(){ final String id = "hs384"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -39,7 +39,7 @@ public class JWTSignerTest { public void hs512Test(){ final String id = "hs512"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -48,7 +48,7 @@ public class JWTSignerTest { public void rs256Test(){ final String id = "rs256"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -57,7 +57,7 @@ public class JWTSignerTest { public void rs384Test(){ final String id = "rs384"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -66,7 +66,7 @@ public class JWTSignerTest { public void rs512Test(){ final String id = "rs512"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -75,7 +75,7 @@ public class JWTSignerTest { public void es256Test(){ final String id = "es256"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -84,7 +84,7 @@ public class JWTSignerTest { public void es384Test(){ final String id = "es384"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -93,7 +93,7 @@ public class JWTSignerTest { public void es512Test(){ final String id = "es512"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -102,7 +102,7 @@ public class JWTSignerTest { public void ps256Test(){ final String id = "ps256"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -111,7 +111,7 @@ public class JWTSignerTest { public void ps384Test(){ final String id = "ps384"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -120,7 +120,7 @@ public class JWTSignerTest { public void hmd5Test(){ final String id = "hmd5"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -129,7 +129,7 @@ public class JWTSignerTest { public void hsha1Test(){ final String id = "hsha1"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -138,7 +138,7 @@ public class JWTSignerTest { public void sm4cmacTest(){ final String id = "sm4cmac"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKey(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -147,7 +147,7 @@ public class JWTSignerTest { public void rmd2Test(){ final String id = "rmd2"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -156,7 +156,7 @@ public class JWTSignerTest { public void rmd5Test(){ final String id = "rmd5"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -165,7 +165,7 @@ public class JWTSignerTest { public void rsha1Test(){ final String id = "rsha1"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -174,7 +174,7 @@ public class JWTSignerTest { public void dnoneTest(){ final String id = "dnone"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -183,7 +183,7 @@ public class JWTSignerTest { public void dsha1Test(){ final String id = "dsha1"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -192,7 +192,7 @@ public class JWTSignerTest { public void enoneTest(){ final String id = "enone"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -201,7 +201,7 @@ public class JWTSignerTest { public void esha1Test(){ final String id = "esha1"; final JWTSigner signer = JWTSignerUtil.createSigner(id, KeyUtil.generateKeyPair(AlgorithmUtil.getAlgorithm(id))); - Assert.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); + Assertions.assertEquals(AlgorithmUtil.getAlgorithm(id), signer.getAlgorithm()); signAndVerify(signer); } @@ -215,6 +215,6 @@ public class JWTSignerTest { .setSigner(signer); final String token = jwt.sign(); - Assert.assertTrue(JWT.of(token).verify(signer)); + Assertions.assertTrue(JWT.of(token).verify(signer)); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTTest.java b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTTest.java index e45c0040a..ac2d11850 100755 --- a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTTest.java @@ -7,8 +7,8 @@ import cn.hutool.json.jwt.signers.AlgorithmUtil; import cn.hutool.json.jwt.signers.JWTSigner; import cn.hutool.json.jwt.signers.JWTSignerUtil; 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.*; @@ -29,9 +29,9 @@ public class JWTTest { "bXlSnqVeJXWqUIt7HyEhgKNVlIPjkumHlAwFY-5YCtk"; final String token = jwt.sign(); - Assert.assertEquals(rightToken, token); + Assertions.assertEquals(rightToken, token); - Assert.assertTrue(JWT.of(rightToken).setKey(key).verify()); + Assertions.assertTrue(JWT.of(rightToken).setKey(key).verify()); } @Test @@ -42,17 +42,17 @@ public class JWTTest { final JWT jwt = JWT.of(rightToken); - Assert.assertTrue(jwt.setKey("1234567890".getBytes()).verify()); + Assertions.assertTrue(jwt.setKey("1234567890".getBytes()).verify()); //header - Assert.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE)); - Assert.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM)); - Assert.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE)); + Assertions.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE)); + Assertions.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM)); + Assertions.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE)); //payload - Assert.assertEquals("1234567890", jwt.getPayload("sub")); - Assert.assertEquals("looly", jwt.getPayload("name")); - Assert.assertEquals(true, jwt.getPayload("admin")); + Assertions.assertEquals("1234567890", jwt.getPayload("sub")); + Assertions.assertEquals("looly", jwt.getPayload("name")); + Assertions.assertEquals(true, jwt.getPayload("admin")); } @Test @@ -63,26 +63,28 @@ public class JWTTest { .setPayload("admin", true) .setSigner(JWTSignerUtil.none()); - final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." + - "eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9."; + final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0." + + "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Imxvb2x5IiwiYWRtaW4iOnRydWV9."; final String token = jwt.sign(); - Assert.assertEquals(token, token); + Assertions.assertEquals(rightToken, token); - Assert.assertTrue(JWT.of(rightToken).setSigner(JWTSignerUtil.none()).verify()); + Assertions.assertTrue(JWT.of(rightToken).setSigner(JWTSignerUtil.none()).verify()); } /** * 必须定义签名器 */ - @Test(expected = JWTException.class) + @Test public void needSignerTest(){ - final JWT jwt = JWT.of() + Assertions.assertThrows(JWTException.class, ()->{ + final JWT jwt = JWT.of() .setPayload("sub", "1234567890") .setPayload("name", "looly") .setPayload("admin", true); - jwt.sign(); + jwt.sign(); + }); } @Test @@ -92,7 +94,7 @@ public class JWTTest { "aixF1eKlAKS_k3ynFnStE7-IRGiD5YaqznvK2xEjBew"; final boolean verify = JWT.of(token).setKey(ByteUtil.toUtf8Bytes("123456")).verify(); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } @Data @@ -135,15 +137,15 @@ public class JWTTest { final Integer numRes = jwt.getPayload("number", Integer.class); final HashMap mapRes = jwt.getPayload("map", HashMap.class); - Assert.assertEquals(bean, beanRes); - Assert.assertEquals(numRes, num); - Assert.assertEquals(username, strRes); - Assert.assertEquals(list, listRes); + Assertions.assertEquals(bean, beanRes); + Assertions.assertEquals(numRes, num); + Assertions.assertEquals(username, strRes); + Assertions.assertEquals(list, listRes); final String formattedDate = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss"); final String formattedRes = DateUtil.format(dateRes, "yyyy-MM-dd HH:mm:ss"); - Assert.assertEquals(formattedDate, formattedRes); - Assert.assertEquals(map, mapRes); + Assertions.assertEquals(formattedDate, formattedRes); + Assertions.assertEquals(map, mapRes); } @Test() @@ -155,7 +157,7 @@ public class JWTTest { // 签发时间早于被检查的时间 final Date date = JWT.of(token).getPayload().getClaimsJson().getDate(JWTPayload.ISSUED_AT); - Assert.assertEquals("2022-02-02", DateUtil.format(date, DatePattern.NORM_DATE_PATTERN)); + Assertions.assertEquals("2022-02-02", DateUtil.format(date, DatePattern.NORM_DATE_PATTERN)); } @Test @@ -165,22 +167,21 @@ public class JWTTest { final JWTSigner jwtSigner = JWTSignerUtil.createSigner(AlgorithmUtil.getAlgorithm("HS256"), Base64.getDecoder().decode("abcdefghijklmn")); final String sign = JWT.of().addPayloads(map).sign(jwtSigner); final Object test2 = JWT.of(sign).getPayload().getClaim("test2"); - Assert.assertEquals(Long.class, test2.getClass()); + Assertions.assertEquals(Long.class, test2.getClass()); } @Test public void getLongTest(){ final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" + ".eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiJhZG1pbiIsImRldmljZSI6ImRlZmF1bHQtZGV2aWNlIiwiZWZmIjoxNjc4Mjg1NzEzOTM1LCJyblN0ciI6IkVuMTczWFhvWUNaaVZUWFNGOTNsN1pabGtOalNTd0pmIn0" - + ".wRe2soTaWYPhwcjxdzesDi1BgEm9D61K-mMT3fPc4YM" - + ""; + + ".wRe2soTaWYPhwcjxdzesDi1BgEm9D61K-mMT3fPc4YM"; final JWT jwt = JWTUtil.parseToken(rightToken); - Assert.assertEquals( + Assertions.assertEquals( "{\"loginType\":\"login\",\"loginId\":\"admin\",\"device\":\"default-device\"," + "\"eff\":1678285713935,\"rnStr\":\"En173XXoYCZiVTXSF93l7ZZlkNjSSwJf\"}", jwt.getPayloads().toString()); - Assert.assertEquals(Long.valueOf(1678285713935L), jwt.getPayloads().getLong("eff")); + Assertions.assertEquals(Long.valueOf(1678285713935L), jwt.getPayloads().getLong("eff")); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTUtilTest.java b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTUtilTest.java index fe7b8fdf5..bb2265945 100755 --- a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTUtilTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.json.jwt; -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; @@ -30,35 +30,41 @@ public class JWTUtilTest { "U2aQkC2THYV9L0fTN-yBBI7gmo5xhmvMhATtu8v0zEA"; final JWT jwt = JWTUtil.parseToken(rightToken); - Assert.assertTrue(jwt.setKey("1234567890".getBytes()).verify()); + Assertions.assertTrue(jwt.setKey("1234567890".getBytes()).verify()); //header - Assert.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE)); - Assert.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM)); - Assert.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE)); + Assertions.assertEquals("JWT", jwt.getHeader(JWTHeader.TYPE)); + Assertions.assertEquals("HS256", jwt.getHeader(JWTHeader.ALGORITHM)); + Assertions.assertNull(jwt.getHeader(JWTHeader.CONTENT_TYPE)); //payload - Assert.assertEquals("1234567890", jwt.getPayload("sub")); - Assert.assertEquals("looly", jwt.getPayload("name")); - Assert.assertEquals(true, jwt.getPayload("admin")); + Assertions.assertEquals("1234567890", jwt.getPayload("sub")); + Assertions.assertEquals("looly", jwt.getPayload("name")); + Assertions.assertEquals(true, jwt.getPayload("admin")); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseNullTest(){ - // https://gitee.com/dromara/hutool/issues/I5OCQB - JWTUtil.parseToken(null); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + // https://gitee.com/dromara/hutool/issues/I5OCQB + JWTUtil.parseToken(null); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseEmptyTest(){ - // https://gitee.com/dromara/hutool/issues/I5OCQB - JWTUtil.parseToken(""); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + // https://gitee.com/dromara/hutool/issues/I5OCQB + JWTUtil.parseToken(""); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseBlankTest(){ - // https://gitee.com/dromara/hutool/issues/I5OCQB - JWTUtil.parseToken(" "); + Assertions.assertThrows(IllegalArgumentException.class, ()->{ + // https://gitee.com/dromara/hutool/issues/I5OCQB + JWTUtil.parseToken(" "); + }); } @Test @@ -68,6 +74,6 @@ public class JWTUtilTest { "aixF1eKlAKS_k3ynFnStE7-IRGiD5YaqznvK2xEjBew"; final boolean verify = JWTUtil.verify(token, "123456".getBytes()); - Assert.assertTrue(verify); + Assertions.assertTrue(verify); } } diff --git a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTValidatorTest.java b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTValidatorTest.java index 263782325..86bf3974f 100755 --- a/hutool-json/src/test/java/cn/hutool/json/jwt/JWTValidatorTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/jwt/JWTValidatorTest.java @@ -3,28 +3,32 @@ package cn.hutool.json.jwt; import cn.hutool.core.date.DateUtil; import cn.hutool.core.exceptions.ValidateException; import cn.hutool.json.jwt.signers.JWTSignerUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Date; public class JWTValidatorTest { - @Test(expected = ValidateException.class) + @Test public void expiredAtTest(){ - final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo"; - JWTValidator.of(token).validateDate(DateUtil.now()); + Assertions.assertThrows(ValidateException.class, ()->{ + final String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo"; + JWTValidator.of(token).validateDate(DateUtil.now()); + }); } - @Test(expected = ValidateException.class) + @Test public void issueAtTest(){ - final String token = JWT.of() + Assertions.assertThrows(ValidateException.class, ()->{ + final String token = JWT.of() .setIssuedAt(DateUtil.now()) .setKey("123456".getBytes()) .sign(); - // 签发时间早于被检查的时间 - JWTValidator.of(token).validateDate(DateUtil.yesterday()); + // 签发时间早于被检查的时间 + JWTValidator.of(token).validateDate(DateUtil.yesterday()); + }); } @Test @@ -38,12 +42,14 @@ public class JWTValidatorTest { JWTValidator.of(token).validateDate(DateUtil.now()); } - @Test(expected = ValidateException.class) + @Test public void notBeforeTest(){ - final JWT jwt = JWT.of() + Assertions.assertThrows(ValidateException.class, ()->{ + final JWT jwt = JWT.of() .setNotBefore(DateUtil.now()); - JWTValidator.of(jwt).validateDate(DateUtil.yesterday()); + JWTValidator.of(jwt).validateDate(DateUtil.yesterday()); + }); } @Test @@ -69,17 +75,19 @@ public class JWTValidatorTest { final String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNb0xpIiwiZXhwIjoxNjI0OTU4MDk0NTI4LCJpYXQiOjE2MjQ5NTgwMzQ1MjAsInVzZXIiOiJ1c2VyIn0.L0uB38p9sZrivbmP0VlDe--j_11YUXTu3TfHhfQhRKc"; final byte[] key = "1234567890".getBytes(); final boolean validate = JWT.of(token).setKey(key).validate(0); - Assert.assertFalse(validate); + Assertions.assertFalse(validate); } - @Test(expected = ValidateException.class) + @Test public void validateDateTest(){ - final JWT jwt = JWT.of() + Assertions.assertThrows(ValidateException.class, ()->{ + final JWT jwt = JWT.of() .setPayload("id", 123) .setPayload("username", "hutool") .setExpiresAt(DateUtil.parse("2021-10-13 09:59:00")); - JWTValidator.of(jwt).validateDate(DateUtil.now()); + JWTValidator.of(jwt).validateDate(DateUtil.now()); + }); } @Test diff --git a/hutool-json/src/test/java/cn/hutool/json/writer/GlobalValueWriterMappingTest.java b/hutool-json/src/test/java/cn/hutool/json/writer/GlobalValueWriterMappingTest.java index bccee300e..2a3e1c06c 100644 --- a/hutool-json/src/test/java/cn/hutool/json/writer/GlobalValueWriterMappingTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/writer/GlobalValueWriterMappingTest.java @@ -4,13 +4,13 @@ import cn.hutool.core.convert.Converter; import cn.hutool.json.JSONConfig; import cn.hutool.json.JSONUtil; 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; public class GlobalValueWriterMappingTest { - @Before + @BeforeEach public void init(){ GlobalValueWriterMapping.put(CustomSubBean.class, (JSONValueWriter) (writer, value) -> writer.writeRaw(String.valueOf(value.getId()))); @@ -22,7 +22,7 @@ public class GlobalValueWriterMappingTest { customBean.setId(12); customBean.setName("aaa"); final String s = JSONUtil.toJsonStr(customBean); - Assert.assertEquals("12", s); + Assertions.assertEquals("12", s); } @Test @@ -35,7 +35,7 @@ public class GlobalValueWriterMappingTest { customBean.setSub(customSubBean); final String s = JSONUtil.toJsonStr(customBean); - Assert.assertEquals("{\"id\":1,\"sub\":12}", s); + Assertions.assertEquals("{\"id\":1,\"sub\":12}", s); // 自定义转换 final JSONConfig jsonConfig = JSONConfig.of(); @@ -49,7 +49,7 @@ public class GlobalValueWriterMappingTest { return converter.convert(targetType, value); }); final CustomBean customBean1 = JSONUtil.parseObj(s, jsonConfig).toBean(CustomBean.class); - Assert.assertEquals(12, customBean1.getSub().getId()); + Assertions.assertEquals(12, customBean1.getSub().getId()); } @Data diff --git a/hutool-json/src/test/java/cn/hutool/json/xml/XMLTest.java b/hutool-json/src/test/java/cn/hutool/json/xml/XMLTest.java index 6fcc29bf0..01a447fb8 100644 --- a/hutool-json/src/test/java/cn/hutool/json/xml/XMLTest.java +++ b/hutool-json/src/test/java/cn/hutool/json/xml/XMLTest.java @@ -2,10 +2,8 @@ package cn.hutool.json.xml; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class XMLTest { @@ -15,7 +13,7 @@ public class XMLTest { .set("aaa", "你好") .set("键2", "test"); final String s = JSONUtil.toXmlStr(put); - MatcherAssert.assertThat(s, CoreMatchers.anyOf(CoreMatchers.is("你好<键2>test"), CoreMatchers.is("<键2>test你好"))); + Assertions.assertEquals("你好<键2>test", s); } @Test @@ -23,10 +21,10 @@ public class XMLTest { final String xml = ""; final JSONObject jsonObject = JSONXMLUtil.toJSONObject(xml); - Assert.assertEquals("{\"a\":\"•\"}", jsonObject.toString()); + Assertions.assertEquals("{\"a\":\"•\"}", jsonObject.toString()); final String xml2 = JSONXMLUtil.toXml(JSONUtil.parseObj(jsonObject)); - Assert.assertEquals(xml, xml2); + Assertions.assertEquals(xml, xml2); } @Test @@ -34,9 +32,9 @@ public class XMLTest { final JSONObject jsonObject = JSONUtil.ofObj().set("content","123456"); String xml = JSONXMLUtil.toXml(jsonObject); - Assert.assertEquals("123456", xml); + Assertions.assertEquals("123456", xml); xml = JSONXMLUtil.toXml(jsonObject, null, new String[0]); - Assert.assertEquals("123456", xml); + Assertions.assertEquals("123456", xml); } } diff --git a/hutool-log/src/test/java/cn/hutool/log/CustomLogTest.java b/hutool-log/src/test/java/cn/hutool/log/CustomLogTest.java index 398581a52..f3b5b8770 100644 --- a/hutool-log/src/test/java/cn/hutool/log/CustomLogTest.java +++ b/hutool-log/src/test/java/cn/hutool/log/CustomLogTest.java @@ -9,7 +9,7 @@ import cn.hutool.log.dialect.log4j2.Log4j2LogFactory; import cn.hutool.log.dialect.slf4j.Slf4jLogFactory; import cn.hutool.log.dialect.tinylog.TinyLog2Factory; import cn.hutool.log.dialect.tinylog.TinyLogFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * 日志门面单元测试 diff --git a/hutool-log/src/test/java/cn/hutool/log/LogTest.java b/hutool-log/src/test/java/cn/hutool/log/LogTest.java index abb30c59c..05551ff83 100644 --- a/hutool-log/src/test/java/cn/hutool/log/LogTest.java +++ b/hutool-log/src/test/java/cn/hutool/log/LogTest.java @@ -1,8 +1,8 @@ package cn.hutool.log; import cn.hutool.log.level.Level; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * 日志门面单元测试 @@ -25,7 +25,7 @@ public class LogTest { * 兼容slf4j日志消息格式测试,即第二个参数是异常对象时正常输出异常信息 */ @Test - @Ignore + @Disabled public void logWithExceptionTest() { final Log log = LogFactory.get(); final Exception e = new Exception("test Exception"); diff --git a/hutool-log/src/test/java/cn/hutool/log/LogTubeTest.java b/hutool-log/src/test/java/cn/hutool/log/LogTubeTest.java index 3fbf51d4b..3af1335c6 100644 --- a/hutool-log/src/test/java/cn/hutool/log/LogTubeTest.java +++ b/hutool-log/src/test/java/cn/hutool/log/LogTubeTest.java @@ -1,7 +1,7 @@ package cn.hutool.log; import cn.hutool.log.dialect.logtube.LogTubeLogFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class LogTubeTest { diff --git a/hutool-log/src/test/java/cn/hutool/log/StaticLogTest.java b/hutool-log/src/test/java/cn/hutool/log/StaticLogTest.java index 7256f9af2..290c422f6 100755 --- a/hutool-log/src/test/java/cn/hutool/log/StaticLogTest.java +++ b/hutool-log/src/test/java/cn/hutool/log/StaticLogTest.java @@ -2,7 +2,7 @@ package cn.hutool.log; import cn.hutool.log.dialect.console.ConsoleColorLogFactory; import cn.hutool.log.dialect.console.ConsoleLogFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StaticLogTest { @Test diff --git a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvParserTest.java b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvParserTest.java index 5ef6f1d75..fb00a5f60 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvParserTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvParserTest.java @@ -2,8 +2,8 @@ package cn.hutool.poi.csv; import cn.hutool.core.io.IoUtil; 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.io.StringReader; @@ -15,7 +15,7 @@ public class CsvParserTest { final CsvParser parser = new CsvParser(reader, null); final CsvRow row = parser.nextRow(); //noinspection ConstantConditions - Assert.assertEquals("b\"bba\"", row.getRawList().get(1)); + Assertions.assertEquals("b\"bba\"", row.getRawList().get(1)); IoUtil.closeQuietly(parser); } @@ -25,7 +25,7 @@ public class CsvParserTest { final CsvParser parser = new CsvParser(reader, null); final CsvRow row = parser.nextRow(); //noinspection ConstantConditions - Assert.assertEquals("\"bba\"bbb", row.getRawList().get(1)); + Assertions.assertEquals("\"bba\"bbb", row.getRawList().get(1)); IoUtil.closeQuietly(parser); } @@ -35,7 +35,7 @@ public class CsvParserTest { final CsvParser parser = new CsvParser(reader, null); final CsvRow row = parser.nextRow(); //noinspection ConstantConditions - Assert.assertEquals("bba", row.getRawList().get(1)); + Assertions.assertEquals("bba", row.getRawList().get(1)); IoUtil.closeQuietly(parser); } @@ -45,7 +45,7 @@ public class CsvParserTest { final CsvParser parser = new CsvParser(reader, null); final CsvRow row = parser.nextRow(); //noinspection ConstantConditions - Assert.assertEquals("", row.getRawList().get(1)); + Assertions.assertEquals("", row.getRawList().get(1)); IoUtil.closeQuietly(parser); } @@ -56,8 +56,8 @@ public class CsvParserTest { final StringReader reader = StrUtil.getReader("\"b\"\"bb\""); final CsvParser parser = new CsvParser(reader, null); final CsvRow row = parser.nextRow(); - Assert.assertNotNull(row); - Assert.assertEquals(1, row.size()); - Assert.assertEquals("b\"bb", row.get(0)); + Assertions.assertNotNull(row); + Assertions.assertEquals(1, row.size()); + Assertions.assertEquals("b\"bb", row.get(0)); } } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvReaderTest.java b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvReaderTest.java index 9e1dd52ca..3b3ab0d10 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvReaderTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvReaderTest.java @@ -7,23 +7,24 @@ import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.util.CharsetUtil; import lombok.Data; -import org.junit.Assert; -import org.junit.Test; -import org.junit.Ignore; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; +@SuppressWarnings("resource") public class CsvReaderTest { @Test public void readTest() { final CsvReader reader = new CsvReader(); final CsvData data = reader.read(ResourceUtil.getReader("test.csv", CharsetUtil.UTF_8)); - Assert.assertEquals("sss,sss", data.getRow(0).get(0)); - Assert.assertEquals(1, data.getRow(0).getOriginalLineNumber()); - Assert.assertEquals("性别", data.getRow(0).get(2)); - Assert.assertEquals("关注\"对象\"", data.getRow(0).get(3)); + Assertions.assertEquals("sss,sss", data.getRow(0).get(0)); + Assertions.assertEquals(1, data.getRow(0).getOriginalLineNumber()); + Assertions.assertEquals("性别", data.getRow(0).get(2)); + Assertions.assertEquals("关注\"对象\"", data.getRow(0).get(3)); } @Test @@ -32,20 +33,20 @@ public class CsvReaderTest { final List> result = reader.readMapList( ResourceUtil.getUtf8Reader("test_bean.csv")); - Assert.assertEquals("张三", result.get(0).get("姓名")); - Assert.assertEquals("男", result.get(0).get("gender")); - Assert.assertEquals("无", result.get(0).get("focus")); - Assert.assertEquals("33", result.get(0).get("age")); + Assertions.assertEquals("张三", result.get(0).get("姓名")); + Assertions.assertEquals("男", result.get(0).get("gender")); + Assertions.assertEquals("无", result.get(0).get("focus")); + Assertions.assertEquals("33", result.get(0).get("age")); - Assert.assertEquals("李四", result.get(1).get("姓名")); - Assert.assertEquals("男", result.get(1).get("gender")); - Assert.assertEquals("好对象", result.get(1).get("focus")); - Assert.assertEquals("23", result.get(1).get("age")); + Assertions.assertEquals("李四", result.get(1).get("姓名")); + Assertions.assertEquals("男", result.get(1).get("gender")); + Assertions.assertEquals("好对象", result.get(1).get("focus")); + Assertions.assertEquals("23", result.get(1).get("age")); - Assert.assertEquals("王妹妹", result.get(2).get("姓名")); - Assert.assertEquals("女", result.get(2).get("gender")); - Assert.assertEquals("特别关注", result.get(2).get("focus")); - Assert.assertEquals("22", result.get(2).get("age")); + Assertions.assertEquals("王妹妹", result.get(2).get("姓名")); + Assertions.assertEquals("女", result.get(2).get("gender")); + Assertions.assertEquals("特别关注", result.get(2).get("focus")); + Assertions.assertEquals("22", result.get(2).get("age")); } @Test @@ -57,20 +58,20 @@ public class CsvReaderTest { final List> result = reader.readMapList( ResourceUtil.getUtf8Reader("test_bean.csv")); - Assert.assertEquals("张三", result.get(0).get("name")); - Assert.assertEquals("男", result.get(0).get("gender")); - Assert.assertEquals("无", result.get(0).get("focus")); - Assert.assertEquals("33", result.get(0).get("age")); + Assertions.assertEquals("张三", result.get(0).get("name")); + Assertions.assertEquals("男", result.get(0).get("gender")); + Assertions.assertEquals("无", result.get(0).get("focus")); + Assertions.assertEquals("33", result.get(0).get("age")); - Assert.assertEquals("李四", result.get(1).get("name")); - Assert.assertEquals("男", result.get(1).get("gender")); - Assert.assertEquals("好对象", result.get(1).get("focus")); - Assert.assertEquals("23", result.get(1).get("age")); + Assertions.assertEquals("李四", result.get(1).get("name")); + Assertions.assertEquals("男", result.get(1).get("gender")); + Assertions.assertEquals("好对象", result.get(1).get("focus")); + Assertions.assertEquals("23", result.get(1).get("age")); - Assert.assertEquals("王妹妹", result.get(2).get("name")); - Assert.assertEquals("女", result.get(2).get("gender")); - Assert.assertEquals("特别关注", result.get(2).get("focus")); - Assert.assertEquals("22", result.get(2).get("age")); + Assertions.assertEquals("王妹妹", result.get(2).get("name")); + Assertions.assertEquals("女", result.get(2).get("gender")); + Assertions.assertEquals("特别关注", result.get(2).get("focus")); + Assertions.assertEquals("22", result.get(2).get("age")); } @Test @@ -79,20 +80,20 @@ public class CsvReaderTest { final List result = reader.read( ResourceUtil.getUtf8Reader("test_bean.csv"), TestBean.class); - Assert.assertEquals("张三", result.get(0).getName()); - Assert.assertEquals("男", result.get(0).getGender()); - Assert.assertEquals("无", result.get(0).getFocus()); - Assert.assertEquals(Integer.valueOf(33), result.get(0).getAge()); + Assertions.assertEquals("张三", result.get(0).getName()); + Assertions.assertEquals("男", result.get(0).getGender()); + Assertions.assertEquals("无", result.get(0).getFocus()); + Assertions.assertEquals(Integer.valueOf(33), result.get(0).getAge()); - Assert.assertEquals("李四", result.get(1).getName()); - Assert.assertEquals("男", result.get(1).getGender()); - Assert.assertEquals("好对象", result.get(1).getFocus()); - Assert.assertEquals(Integer.valueOf(23), result.get(1).getAge()); + Assertions.assertEquals("李四", result.get(1).getName()); + Assertions.assertEquals("男", result.get(1).getGender()); + Assertions.assertEquals("好对象", result.get(1).getFocus()); + Assertions.assertEquals(Integer.valueOf(23), result.get(1).getAge()); - Assert.assertEquals("王妹妹", result.get(2).getName()); - Assert.assertEquals("女", result.get(2).getGender()); - Assert.assertEquals("特别关注", result.get(2).getFocus()); - Assert.assertEquals(Integer.valueOf(22), result.get(2).getAge()); + Assertions.assertEquals("王妹妹", result.get(2).getName()); + Assertions.assertEquals("女", result.get(2).getGender()); + Assertions.assertEquals("特别关注", result.get(2).getFocus()); + Assertions.assertEquals(Integer.valueOf(22), result.get(2).getAge()); } @Data @@ -105,7 +106,7 @@ public class CsvReaderTest { } @Test - @Ignore + @Disabled public void readTest2() { final CsvReader reader = CsvUtil.getReader(); final CsvData read = reader.read(FileUtil.file("d:/test/test.csv")); @@ -115,7 +116,7 @@ public class CsvReaderTest { } @Test - @Ignore + @Disabled public void readTest3() { final CsvReadConfig csvReadConfig = CsvReadConfig.defaultConfig(); csvReadConfig.setContainsHeader(true); @@ -130,16 +131,16 @@ public class CsvReaderTest { public void lineNoTest() { final CsvReader reader = new CsvReader(); final CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.UTF_8)); - Assert.assertEquals(1, data.getRow(0).getOriginalLineNumber()); - Assert.assertEquals("a,b,c,d", CollUtil.join(data.getRow(0), ",")); + Assertions.assertEquals(1, data.getRow(0).getOriginalLineNumber()); + Assertions.assertEquals("a,b,c,d", CollUtil.join(data.getRow(0), ",")); - Assert.assertEquals(4, data.getRow(2).getOriginalLineNumber()); - Assert.assertEquals("q,w,e,r,我是一段\n带换行的内容", + Assertions.assertEquals(4, data.getRow(2).getOriginalLineNumber()); + Assertions.assertEquals("q,w,e,r,我是一段\n带换行的内容", CollUtil.join(data.getRow(2), ",").replace("\r", "")); // 文件中第3行数据,对应原始行号是6(从0开始) - Assert.assertEquals(6, data.getRow(3).getOriginalLineNumber()); - Assert.assertEquals("a,s,d,f", CollUtil.join(data.getRow(3), ",")); + Assertions.assertEquals(6, data.getRow(3).getOriginalLineNumber()); + Assertions.assertEquals("a,s,d,f", CollUtil.join(data.getRow(3), ",")); } @Test @@ -148,16 +149,16 @@ public class CsvReaderTest { final CsvReader reader = new CsvReader(CsvReadConfig.defaultConfig().setBeginLineNo(2)); final CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.UTF_8)); - Assert.assertEquals(2, data.getRow(0).getOriginalLineNumber()); - Assert.assertEquals("1,2,3,4", CollUtil.join(data.getRow(0), ",")); + Assertions.assertEquals(2, data.getRow(0).getOriginalLineNumber()); + Assertions.assertEquals("1,2,3,4", CollUtil.join(data.getRow(0), ",")); - Assert.assertEquals(4, data.getRow(1).getOriginalLineNumber()); - Assert.assertEquals("q,w,e,r,我是一段\n带换行的内容", + Assertions.assertEquals(4, data.getRow(1).getOriginalLineNumber()); + Assertions.assertEquals("q,w,e,r,我是一段\n带换行的内容", CollUtil.join(data.getRow(1), ",").replace("\r", "")); // 文件中第3行数据,对应原始行号是6(从0开始) - Assert.assertEquals(6, data.getRow(2).getOriginalLineNumber()); - Assert.assertEquals("a,s,d,f", CollUtil.join(data.getRow(2), ",")); + Assertions.assertEquals(6, data.getRow(2).getOriginalLineNumber()); + Assertions.assertEquals("a,s,d,f", CollUtil.join(data.getRow(2), ",")); } @Test @@ -166,13 +167,13 @@ public class CsvReaderTest { final CsvReader reader = new CsvReader(CsvReadConfig.defaultConfig().setBeginLineNo(2).setContainsHeader(true)); final CsvData data = reader.read(ResourceUtil.getReader("test_lines.csv", CharsetUtil.UTF_8)); - Assert.assertEquals(4, data.getRow(0).getOriginalLineNumber()); - Assert.assertEquals("q,w,e,r,我是一段\n带换行的内容", + Assertions.assertEquals(4, data.getRow(0).getOriginalLineNumber()); + Assertions.assertEquals("q,w,e,r,我是一段\n带换行的内容", CollUtil.join(data.getRow(0), ",").replace("\r", "")); // 文件中第3行数据,对应原始行号是6(从0开始) - Assert.assertEquals(6, data.getRow(1).getOriginalLineNumber()); - Assert.assertEquals("a,s,d,f", CollUtil.join(data.getRow(1), ",")); + Assertions.assertEquals(6, data.getRow(1).getOriginalLineNumber()); + Assertions.assertEquals("a,s,d,f", CollUtil.join(data.getRow(1), ",")); } @Test @@ -183,9 +184,9 @@ public class CsvReaderTest { .setFieldSeparator(';')); final CsvData csvRows = reader.readFromStr("123;456;'789;0'abc;"); final CsvRow row = csvRows.getRow(0); - Assert.assertEquals("123", row.get(0)); - Assert.assertEquals("456", row.get(1)); - Assert.assertEquals("'789;0'abc", row.get(2)); + Assertions.assertEquals("123", row.get(0)); + Assertions.assertEquals("456", row.get(1)); + Assertions.assertEquals("'789;0'abc", row.get(2)); } @Test @@ -193,18 +194,18 @@ public class CsvReaderTest { final CsvReader reader = CsvUtil.getReader(CsvReadConfig.defaultConfig().disableComment()); final CsvData read = reader.read(ResourceUtil.getUtf8Reader("test.csv")); final CsvRow row = read.getRow(0); - Assert.assertEquals("# 这是一行注释,读取时应忽略", row.get(0)); + Assertions.assertEquals("# 这是一行注释,读取时应忽略", row.get(0)); } @Test - @Ignore + @Disabled public void streamTest() { final CsvReader reader = CsvUtil.getReader(ResourceUtil.getUtf8Reader("test_bean.csv")); reader.stream().limit(2).forEach(Console::log); } @Test - @Ignore + @Disabled public void issue2306Test(){ final CsvReader reader = CsvUtil.getReader(ResourceUtil.getUtf8Reader("d:/test/issue2306.csv")); final CsvData csvData = reader.read(); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvUtilTest.java b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvUtilTest.java index 689065c1f..36146332b 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvUtilTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvUtilTest.java @@ -7,9 +7,9 @@ import cn.hutool.core.lang.Console; import cn.hutool.core.util.CharsetUtil; 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.ArrayList; import java.util.HashMap; @@ -26,13 +26,13 @@ public class CsvUtilTest { final CsvData data = reader.read(FileUtil.file("test.csv")); final List rows = data.getRows(); final CsvRow row0 = rows.get(0); - Assert.assertEquals("sss,sss", row0.get(0)); - Assert.assertEquals("姓名", row0.get(1)); - Assert.assertEquals("性别", row0.get(2)); - Assert.assertEquals("关注\"对象\"", row0.get(3)); - Assert.assertEquals("年龄", row0.get(4)); - Assert.assertEquals("", row0.get(5)); - Assert.assertEquals("\"", row0.get(6)); + Assertions.assertEquals("sss,sss", row0.get(0)); + Assertions.assertEquals("姓名", row0.get(1)); + Assertions.assertEquals("性别", row0.get(2)); + Assertions.assertEquals("关注\"对象\"", row0.get(3)); + Assertions.assertEquals("年龄", row0.get(4)); + Assertions.assertEquals("", row0.get(5)); + Assertions.assertEquals("\"", row0.get(6)); } @Test @@ -40,18 +40,18 @@ public class CsvUtilTest { final CsvReader reader = CsvUtil.getReader(); reader.read(FileUtil.getUtf8Reader("test.csv"), (csvRow)-> { // 只有一行,所以直接判断 - Assert.assertEquals("sss,sss", csvRow.get(0)); - Assert.assertEquals("姓名", csvRow.get(1)); - Assert.assertEquals("性别", csvRow.get(2)); - Assert.assertEquals("关注\"对象\"", csvRow.get(3)); - Assert.assertEquals("年龄", csvRow.get(4)); - Assert.assertEquals("", csvRow.get(5)); - Assert.assertEquals("\"", csvRow.get(6)); + Assertions.assertEquals("sss,sss", csvRow.get(0)); + Assertions.assertEquals("姓名", csvRow.get(1)); + Assertions.assertEquals("性别", csvRow.get(2)); + Assertions.assertEquals("关注\"对象\"", csvRow.get(3)); + Assertions.assertEquals("年龄", csvRow.get(4)); + Assertions.assertEquals("", csvRow.get(5)); + Assertions.assertEquals("\"", csvRow.get(6)); }); } @Test - @Ignore + @Disabled public void readTest3() { final CsvReader reader = CsvUtil.getReader(); final String path = FileUtil.isWindows() ? "d:/test/test.csv" : "~/test/test.csv"; @@ -64,13 +64,13 @@ public class CsvUtilTest { "\"sss,sss\",姓名,\"性别\",关注\"对象\",年龄,\"\",\"\"\"\n"); final List rows = data.getRows(); final CsvRow row0 = rows.get(0); - Assert.assertEquals("sss,sss", row0.get(0)); - Assert.assertEquals("姓名", row0.get(1)); - Assert.assertEquals("性别", row0.get(2)); - Assert.assertEquals("关注\"对象\"", row0.get(3)); - Assert.assertEquals("年龄", row0.get(4)); - Assert.assertEquals("", row0.get(5)); - Assert.assertEquals("\"", row0.get(6)); + Assertions.assertEquals("sss,sss", row0.get(0)); + Assertions.assertEquals("姓名", row0.get(1)); + Assertions.assertEquals("性别", row0.get(2)); + Assertions.assertEquals("关注\"对象\"", row0.get(3)); + Assertions.assertEquals("年龄", row0.get(4)); + Assertions.assertEquals("", row0.get(5)); + Assertions.assertEquals("\"", row0.get(6)); } @Test @@ -78,18 +78,18 @@ public class CsvUtilTest { CsvUtil.getReader().readFromStr("# 这是一行注释,读取时应忽略\n" + "\"sss,sss\",姓名,\"性别\",关注\"对象\",年龄,\"\",\"\"\"\n",(csvRow)-> { // 只有一行,所以直接判断 - Assert.assertEquals("sss,sss", csvRow.get(0)); - Assert.assertEquals("姓名", csvRow.get(1)); - Assert.assertEquals("性别", csvRow.get(2)); - Assert.assertEquals("关注\"对象\"", csvRow.get(3)); - Assert.assertEquals("年龄", csvRow.get(4)); - Assert.assertEquals("", csvRow.get(5)); - Assert.assertEquals("\"", csvRow.get(6)); + Assertions.assertEquals("sss,sss", csvRow.get(0)); + Assertions.assertEquals("姓名", csvRow.get(1)); + Assertions.assertEquals("性别", csvRow.get(2)); + Assertions.assertEquals("关注\"对象\"", csvRow.get(3)); + Assertions.assertEquals("年龄", csvRow.get(4)); + Assertions.assertEquals("", csvRow.get(5)); + Assertions.assertEquals("\"", csvRow.get(6)); }); } @Test - @Ignore + @Disabled public void writeTest() { final String path = FileUtil.isWindows() ? "d:/test/testWrite.csv" : "~/test/testWrite.csv"; final CsvWriter writer = CsvUtil.getWriter(path, CharsetUtil.UTF_8); @@ -101,7 +101,7 @@ public class CsvUtilTest { } @Test - @Ignore + @Disabled public void writeBeansTest() { @Data @@ -137,7 +137,7 @@ public class CsvUtilTest { } @Test - @Ignore + @Disabled public void readLfTest(){ final CsvReader reader = CsvUtil.getReader(); final String path = FileUtil.isWindows() ? "d:/test/rw_test.csv" : "~/test/rw_test.csv"; @@ -148,7 +148,7 @@ public class CsvUtilTest { } @Test - @Ignore + @Disabled public void writeWrapTest(){ final List> resultList=new ArrayList<>(); List list =new ArrayList<>(); @@ -167,7 +167,7 @@ public class CsvUtilTest { } @Test - @Ignore + @Disabled public void writeDataTest(){ @Data @AllArgsConstructor diff --git a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvWriterTest.java b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvWriterTest.java index 7af2f302f..273c63253 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvWriterTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/csv/CsvWriterTest.java @@ -3,8 +3,8 @@ package cn.hutool.poi.csv; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; 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; import java.util.ArrayList; @@ -14,7 +14,7 @@ import java.util.Random; public class CsvWriterTest { @Test - @Ignore + @Disabled public void writeWithAliasTest(){ final CsvWriteConfig csvWriteConfig = CsvWriteConfig.defaultConfig() .addHeaderAlias("name", "姓名") @@ -31,7 +31,7 @@ public class CsvWriterTest { } @Test - @Ignore + @Disabled public void issue2255Test(){ final String fileName = "D:/test/" + new Random().nextInt(100) + "-a.csv"; final CsvWriter writer = CsvUtil.getWriter(fileName, CharsetUtil.UTF_8); @@ -47,7 +47,7 @@ public class CsvWriterTest { } @Test - @Ignore + @Disabled public void issue3014Test(){ // https://blog.csdn.net/weixin_42522167/article/details/112241143 final File tmp = new File("d:/test/dde_safe.csv"); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/csv/Issue2783Test.java b/hutool-poi/src/test/java/cn/hutool/poi/csv/Issue2783Test.java index 59d5dad01..5884a26e2 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/csv/Issue2783Test.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/csv/Issue2783Test.java @@ -3,13 +3,13 @@ package cn.hutool.poi.csv; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.func.SerConsumer; 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; public class Issue2783Test { @Test - @Ignore + @Disabled public void readTest() { // 测试数据 final CsvWriter writer = CsvUtil.getWriter("d:/test/big.csv", CharsetUtil.UTF_8); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/BigExcelWriteTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/BigExcelWriteTest.java index 4c2c5e461..fba44c135 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/BigExcelWriteTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/BigExcelWriteTest.java @@ -10,15 +10,10 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.IndexedColors; -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.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 写出Excel单元测试 @@ -28,7 +23,7 @@ import java.util.Map; public class BigExcelWriteTest { @Test - @Ignore + @Disabled public void writeTest2() { final List row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计"); final BigExcelWriter overtimeWriter = ExcelUtil.getBigWriter("e:/excel/single_line.xlsx"); @@ -37,7 +32,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void writeTest() { final List row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765); final List row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676); @@ -68,7 +63,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void mergeTest() { final List row1 = ListUtil.of("aa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765); final List row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676); @@ -98,7 +93,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapTest() { final Map row1 = new LinkedHashMap<>(); row1.put("姓名", "张三"); @@ -137,7 +132,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapTest2() { final Map row1 = MapUtil.newHashMap(true); row1.put("姓名", "张三"); @@ -158,7 +153,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void writeBeanTest() { final cn.hutool.poi.excel.TestBean bean1 = new cn.hutool.poi.excel.TestBean(); bean1.setName("张三"); @@ -194,7 +189,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void writeCellValueTest() { final String path = "d:/test/cellValueTest.xlsx"; FileUtil.del(FileUtil.file(path)); @@ -204,7 +199,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void closeTest() { final Map map1 = MapUtil.of("id", "123456"); final Map map2 = MapUtil.of("id", "123457"); @@ -217,7 +212,7 @@ public class BigExcelWriteTest { } @Test - @Ignore + @Disabled public void issue1210() { // 通过工具类创建writer final String path = "d:/test/issue1210.xlsx"; diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/CellEditorTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/CellEditorTest.java index 41550ac26..34aeb0579 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/CellEditorTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/CellEditorTest.java @@ -4,25 +4,25 @@ import cn.hutool.poi.excel.cell.CellEditor; import lombok.AllArgsConstructor; import lombok.Data; import org.apache.poi.ss.usermodel.Cell; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.io.Serializable; import java.util.List; public class CellEditorTest { - @org.junit.Test + @org.junit.jupiter.api.Test public void readTest(){ final ExcelReader excelReader= ExcelUtil.getReader("cell_editor_test.xlsx"); excelReader.setCellEditor(new ExcelHandler()); final List excelReaderObjects=excelReader.readAll(Test.class); - Assert.assertEquals("0", excelReaderObjects.get(0).getTest1()); - Assert.assertEquals("b", excelReaderObjects.get(0).getTest2()); - Assert.assertEquals("0", excelReaderObjects.get(1).getTest1()); - Assert.assertEquals("b1", excelReaderObjects.get(1).getTest2()); - Assert.assertEquals("0", excelReaderObjects.get(2).getTest1()); - Assert.assertEquals("c2", excelReaderObjects.get(2).getTest2()); + Assertions.assertEquals("0", excelReaderObjects.get(0).getTest1()); + Assertions.assertEquals("b", excelReaderObjects.get(0).getTest2()); + Assertions.assertEquals("0", excelReaderObjects.get(1).getTest1()); + Assertions.assertEquals("b1", excelReaderObjects.get(1).getTest2()); + Assertions.assertEquals("0", excelReaderObjects.get(2).getTest1()); + Assertions.assertEquals("c2", excelReaderObjects.get(2).getTest2()); } @AllArgsConstructor diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/CellUtilTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/CellUtilTest.java index 086d3befe..725595826 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/CellUtilTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/CellUtilTest.java @@ -1,15 +1,14 @@ package cn.hutool.poi.excel; -import org.apache.poi.ss.usermodel.BuiltinFormats; -import org.junit.Ignore; -import org.junit.Test; - import cn.hutool.core.lang.Console; +import org.apache.poi.ss.usermodel.BuiltinFormats; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class CellUtilTest { @Test - @Ignore + @Disabled public void isDateTest() { final String[] all = BuiltinFormats.getAll(); for(int i = 0 ; i < all.length; i++) { diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelFileUtilTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelFileUtilTest.java index d1054ba63..ca82d0483 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelFileUtilTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelFileUtilTest.java @@ -2,8 +2,8 @@ package cn.hutool.poi.excel; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.IoUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.InputStream; @@ -13,8 +13,8 @@ public class ExcelFileUtilTest { public void xlsTest(){ final InputStream in = FileUtil.getInputStream("aaa.xls"); try{ - Assert.assertTrue(ExcelFileUtil.isXls(in)); - Assert.assertFalse(ExcelFileUtil.isXlsx(in)); + Assertions.assertTrue(ExcelFileUtil.isXls(in)); + Assertions.assertFalse(ExcelFileUtil.isXlsx(in)); } finally { IoUtil.closeQuietly(in); } @@ -24,8 +24,8 @@ public class ExcelFileUtilTest { public void xlsxTest(){ final InputStream in = FileUtil.getInputStream("aaa.xlsx"); try{ - Assert.assertFalse(ExcelFileUtil.isXls(in)); - Assert.assertTrue(ExcelFileUtil.isXlsx(in)); + Assertions.assertFalse(ExcelFileUtil.isXls(in)); + Assertions.assertTrue(ExcelFileUtil.isXlsx(in)); } finally { IoUtil.closeQuietly(in); } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java index 436040430..1ed59afca 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java @@ -7,9 +7,9 @@ import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjUtil; import lombok.Data; import org.apache.poi.ss.usermodel.Cell; -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.math.BigDecimal; import java.util.List; @@ -28,7 +28,7 @@ public class ExcelReadTest { //读取单个单元格内容测试 final Object value = reader.readCellValue(1, 2); - Assert.assertEquals("仓库", value); + Assertions.assertEquals("仓库", value); final Map headerAlias = MapUtil.newHashMap(); headerAlias.put("用户姓名", "userName"); @@ -39,17 +39,17 @@ public class ExcelReadTest { // 读取list时默认首个非空行为标题 final List> read = reader.read(); - Assert.assertEquals("userName", read.get(0).get(0)); - Assert.assertEquals("storageName", read.get(0).get(1)); - Assert.assertEquals("checkPerm", read.get(0).get(2)); - Assert.assertEquals("allotAuditPerm", read.get(0).get(3)); + Assertions.assertEquals("userName", read.get(0).get(0)); + Assertions.assertEquals("storageName", read.get(0).get(1)); + Assertions.assertEquals("checkPerm", read.get(0).get(2)); + Assertions.assertEquals("allotAuditPerm", read.get(0).get(3)); final List> readAll = reader.readAll(); for (final Map map : readAll) { - Assert.assertTrue(map.containsKey("userName")); - Assert.assertTrue(map.containsKey("storageName")); - Assert.assertTrue(map.containsKey("checkPerm")); - Assert.assertTrue(map.containsKey("allotAuditPerm")); + Assertions.assertTrue(map.containsKey("userName")); + Assertions.assertTrue(map.containsKey("storageName")); + Assertions.assertTrue(map.containsKey("checkPerm")); + Assertions.assertTrue(map.containsKey("allotAuditPerm")); } } @@ -58,7 +58,7 @@ public class ExcelReadTest { final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("priceIndex.xls")); final List> readAll = reader.readAll(); - Assert.assertEquals(4, readAll.size()); + Assertions.assertEquals(4, readAll.size()); } @Test @@ -67,22 +67,22 @@ public class ExcelReadTest { final List> readAll = reader.read(); // 标题 - Assert.assertEquals("姓名", readAll.get(0).get(0)); - Assert.assertEquals("性别", readAll.get(0).get(1)); - Assert.assertEquals("年龄", readAll.get(0).get(2)); - Assert.assertEquals("鞋码", readAll.get(0).get(3)); + Assertions.assertEquals("姓名", readAll.get(0).get(0)); + Assertions.assertEquals("性别", readAll.get(0).get(1)); + Assertions.assertEquals("年龄", readAll.get(0).get(2)); + Assertions.assertEquals("鞋码", readAll.get(0).get(3)); // 第一行 - Assert.assertEquals("张三", readAll.get(1).get(0)); - Assert.assertEquals("男", readAll.get(1).get(1)); - Assert.assertEquals(11L, readAll.get(1).get(2)); - Assert.assertEquals(41.5D, readAll.get(1).get(3)); + Assertions.assertEquals("张三", readAll.get(1).get(0)); + Assertions.assertEquals("男", readAll.get(1).get(1)); + Assertions.assertEquals(11L, readAll.get(1).get(2)); + Assertions.assertEquals(41.5D, readAll.get(1).get(3)); } @Test public void excelReadAsTextTest() { final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("aaa.xlsx")); - Assert.assertNotNull(reader.readAsText(false)); + Assertions.assertNotNull(reader.readAsText(false)); } @Test @@ -95,16 +95,16 @@ public class ExcelReadTest { // } // 标题 - Assert.assertEquals("姓名", readAll.get(0).get(0)); - Assert.assertEquals("性别", readAll.get(0).get(1)); - Assert.assertEquals("年龄", readAll.get(0).get(2)); - Assert.assertEquals("分数", readAll.get(0).get(3)); + Assertions.assertEquals("姓名", readAll.get(0).get(0)); + Assertions.assertEquals("性别", readAll.get(0).get(1)); + Assertions.assertEquals("年龄", readAll.get(0).get(2)); + Assertions.assertEquals("分数", readAll.get(0).get(3)); // 第一行 - Assert.assertEquals("张三", readAll.get(1).get(0)); - Assert.assertEquals("男", readAll.get(1).get(1)); - Assert.assertEquals(11L, readAll.get(1).get(2)); - Assert.assertEquals(33.2D, readAll.get(1).get(3)); + Assertions.assertEquals("张三", readAll.get(1).get(0)); + Assertions.assertEquals("男", readAll.get(1).get(1)); + Assertions.assertEquals(11L, readAll.get(1).get(2)); + Assertions.assertEquals(33.2D, readAll.get(1).get(3)); } @Test @@ -113,11 +113,11 @@ public class ExcelReadTest { final List> readAll = reader.read(); // 标题 - Assert.assertEquals("班级", readAll.get(0).get(0)); - Assert.assertEquals("年级", readAll.get(0).get(1)); - Assert.assertEquals("学校", readAll.get(0).get(2)); - Assert.assertEquals("入学时间", readAll.get(0).get(3)); - Assert.assertEquals("更新时间", readAll.get(0).get(4)); + Assertions.assertEquals("班级", readAll.get(0).get(0)); + Assertions.assertEquals("年级", readAll.get(0).get(1)); + Assertions.assertEquals("学校", readAll.get(0).get(2)); + Assertions.assertEquals("入学时间", readAll.get(0).get(3)); + Assertions.assertEquals("更新时间", readAll.get(0).get(4)); } @Test @@ -125,9 +125,9 @@ public class ExcelReadTest { final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("aaa.xlsx")); final List> readAll = reader.readAll(); - Assert.assertEquals("张三", readAll.get(0).get("姓名")); - Assert.assertEquals("男", readAll.get(0).get("性别")); - Assert.assertEquals(11L, readAll.get(0).get("年龄")); + Assertions.assertEquals("张三", readAll.get(0).get("姓名")); + Assertions.assertEquals("男", readAll.get(0).get("性别")); + Assertions.assertEquals(11L, readAll.get(0).get("年龄")); } @Test @@ -139,14 +139,14 @@ public class ExcelReadTest { reader.addHeaderAlias("鞋码", "shoeSize"); final List all = reader.readAll(Person.class); - Assert.assertEquals("张三", all.get(0).getName()); - Assert.assertEquals("男", all.get(0).getGender()); - Assert.assertEquals(Integer.valueOf(11), all.get(0).getAge()); - Assert.assertEquals(new BigDecimal("41.5"), all.get(0).getShoeSize()); + Assertions.assertEquals("张三", all.get(0).getName()); + Assertions.assertEquals("男", all.get(0).getGender()); + Assertions.assertEquals(Integer.valueOf(11), all.get(0).getAge()); + Assertions.assertEquals(new BigDecimal("41.5"), all.get(0).getShoeSize()); } @Test - @Ignore + @Disabled public void excelReadToBeanListTest2() { final ExcelReader reader = ExcelUtil.getReader("f:/test/toBean.xlsx"); reader.addHeaderAlias("姓名", "name"); @@ -168,7 +168,7 @@ public class ExcelReadTest { } @Test - @Ignore + @Disabled public void readDoubleTest() { final ExcelReader reader = ExcelUtil.getReader("f:/test/doubleTest.xls"); final List> read = reader.read(); @@ -182,19 +182,19 @@ public class ExcelReadTest { final ExcelReader reader = ExcelUtil.getReader("merge_test.xlsx"); final List> read = reader.read(); // 验证合并单元格在两行中都可以取到值 - Assert.assertEquals(11L, read.get(1).get(2)); - Assert.assertEquals(11L, read.get(2).get(2)); + Assertions.assertEquals(11L, read.get(1).get(2)); + Assertions.assertEquals(11L, read.get(2).get(2)); } @Test - @Ignore + @Disabled public void readCellsTest() { final ExcelReader reader = ExcelUtil.getReader("merge_test.xlsx"); reader.read((cell, value)-> Console.log("{}, {} {}", cell.getRowIndex(), cell.getColumnIndex(), value)); } @Test - @Ignore + @Disabled public void readTest() { // 测试合并单元格是否可以正常读到第一个单元格的值 final ExcelReader reader = ExcelUtil.getReader("d:/test/人员体检信息表.xlsx"); @@ -211,17 +211,17 @@ public class ExcelReadTest { final List> read = reader.read(); // 对于任意一个单元格有值的情况下,之前的单元格值按照null处理 - Assert.assertEquals(1, read.get(1).size()); - Assert.assertEquals(2, read.get(2).size()); - Assert.assertEquals(3, read.get(3).size()); + Assertions.assertEquals(1, read.get(1).size()); + Assertions.assertEquals(2, read.get(2).size()); + Assertions.assertEquals(3, read.get(3).size()); - Assert.assertEquals("#", read.get(2).get(0)); - Assert.assertEquals("#", read.get(3).get(0)); - Assert.assertEquals("#", read.get(3).get(1)); + Assertions.assertEquals("#", read.get(2).get(0)); + Assertions.assertEquals("#", read.get(3).get(0)); + Assertions.assertEquals("#", read.get(3).get(1)); } @Test - @Ignore + @Disabled public void readEmptyTest(){ final ExcelReader reader = ExcelUtil.getReader("d:/test/issue.xlsx"); final List> maps = reader.readAll(); @@ -229,7 +229,7 @@ public class ExcelReadTest { } @Test - @Ignore + @Disabled public void readNullRowTest(){ final ExcelReader reader = ExcelUtil.getReader("d:/test/1.-.xls"); reader.read((SerBiConsumer) Console::log); @@ -240,10 +240,10 @@ public class ExcelReadTest { final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("aaa.xlsx")); final List objects = reader.readColumn(0, 1); - Assert.assertEquals(3, objects.size()); - Assert.assertEquals("张三", objects.get(0)); - Assert.assertEquals("李四", objects.get(1)); - Assert.assertEquals("", objects.get(2)); + Assertions.assertEquals(3, objects.size()); + Assertions.assertEquals("张三", objects.get(0)); + Assertions.assertEquals("李四", objects.get(1)); + Assertions.assertEquals("", objects.get(2)); } @Test diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelSaxReadTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelSaxReadTest.java index bafdfa8b3..fccd769cb 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelSaxReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelSaxReadTest.java @@ -2,8 +2,8 @@ package cn.hutool.poi.excel; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; -import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.IoUtil; +import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.text.StrUtil; import cn.hutool.poi.excel.cell.values.FormulaCellValue; @@ -11,9 +11,9 @@ import cn.hutool.poi.excel.sax.Excel03SaxReader; import cn.hutool.poi.excel.sax.handler.RowHandler; import cn.hutool.poi.exceptions.POIException; import org.apache.poi.ss.usermodel.CellStyle; -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.util.ArrayList; @@ -66,15 +66,17 @@ public class ExcelSaxReadTest { reader.read("aaa.xls", "sheetName:校园入学"); } - @Test(expected = POIException.class) + @Test public void excel03ByNameErrorTest() { - // sheet名称不存在则报错 - final Excel03SaxReader reader = new Excel03SaxReader(createRowHandler()); - reader.read("aaa.xls", "校园入学1"); + Assertions.assertThrows(POIException.class, ()->{ + // sheet名称不存在则报错 + final Excel03SaxReader reader = new Excel03SaxReader(createRowHandler()); + reader.read("aaa.xls", "校园入学1"); + }); } @Test - @Ignore + @Disabled public void readBlankLineTest() { ExcelUtil.readBySax("e:/ExcelBlankLine.xlsx", 0, (sheetIndex, rowIndex, rowList) -> { if (StrUtil.isAllEmpty(Convert.toStrArray(rowList))) { @@ -100,7 +102,7 @@ public class ExcelSaxReadTest { } @Test - @Ignore + @Disabled public void readBySaxTest2() { ExcelUtil.readBySax("d:/test/456789.xlsx", "0", (sheetIndex, rowIndex, rowList) -> Console.log(rowList)); } @@ -110,13 +112,13 @@ public class ExcelSaxReadTest { // Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist); if (5 != rowIndex && 6 != rowIndex) { // 测试样例中除第五行、第六行都为非空行 - Assert.assertTrue(CollUtil.isNotEmpty(rowlist)); + Assertions.assertTrue(CollUtil.isNotEmpty(rowlist)); } }; } @Test - @Ignore + @Disabled public void handle07CellTest() { ExcelUtil.readBySax("d:/test/test.xlsx", -1, new RowHandler() { @@ -159,7 +161,7 @@ public class ExcelSaxReadTest { rows.add(""); } }); - Assert.assertEquals(50L, rows.get(3)); + Assertions.assertEquals(50L, rows.get(3)); } @Test @@ -169,7 +171,7 @@ public class ExcelSaxReadTest { rows.add(list.get(1))); final FormulaCellValue value = (FormulaCellValue) rows.get(3); - Assert.assertEquals(50L, value.getResult()); + Assertions.assertEquals(50L, value.getResult()); } @Test @@ -179,11 +181,11 @@ public class ExcelSaxReadTest { (i, i1, list) -> rows.add(StrUtil.toString(list.get(0))) ); - Assert.assertEquals("2020-10-09 00:00:00", rows.get(1)); + Assertions.assertEquals("2020-10-09 00:00:00", rows.get(1)); // 非日期格式不做转换 - Assert.assertEquals("112233", rows.get(2)); - Assert.assertEquals("1000.0", rows.get(3)); - Assert.assertEquals("2012-12-21 00:00:00", rows.get(4)); + Assertions.assertEquals("112233", rows.get(2)); + Assertions.assertEquals("1000.0", rows.get(3)); + Assertions.assertEquals("2012-12-21 00:00:00", rows.get(4)); } @Test @@ -193,15 +195,15 @@ public class ExcelSaxReadTest { (i, i1, list) -> rows.add(StrUtil.toString(list.get(0))) ); - Assert.assertEquals("2020-10-09 00:00:00", rows.get(1)); + Assertions.assertEquals("2020-10-09 00:00:00", rows.get(1)); // 非日期格式不做转换 - Assert.assertEquals("112233", rows.get(2)); - Assert.assertEquals("1000.0", rows.get(3)); - Assert.assertEquals("2012-12-21 00:00:00", rows.get(4)); + Assertions.assertEquals("112233", rows.get(2)); + Assertions.assertEquals("1000.0", rows.get(3)); + Assertions.assertEquals("2012-12-21 00:00:00", rows.get(4)); } @Test - @Ignore + @Disabled public void dateReadXlsxTest2() { ExcelUtil.readBySax("d:/test/custom_date_format2.xlsx", 0, (i, i1, list) -> Console.log(list) @@ -209,7 +211,7 @@ public class ExcelSaxReadTest { } @Test - @Ignore + @Disabled public void readBlankTest() { final File file = new File("D:/test/b.xlsx"); @@ -219,7 +221,7 @@ public class ExcelSaxReadTest { } @Test - @Ignore + @Disabled public void readXlsmTest() { ExcelUtil.readBySax("d:/test/WhiteListTemplate.xlsm", -1, (sheetIndex, rowIndex, rowlist) -> Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist)); @@ -241,6 +243,6 @@ public class ExcelSaxReadTest { } }); //总共2个sheet页,读取所有sheet时,一共执行doAfterAllAnalysed2次。 - Assert.assertEquals(2, doAfterAllAnalysedTime.intValue()); + Assertions.assertEquals(2, doAfterAllAnalysedTime.intValue()); } } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java index 4eae2abd4..555b3508c 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.poi.excel; import cn.hutool.poi.excel.cell.CellLocation; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; @@ -11,39 +11,39 @@ public class ExcelUtilTest { @Test public void indexToColNameTest() { - Assert.assertEquals("A", ExcelUtil.indexToColName(0)); - Assert.assertEquals("B", ExcelUtil.indexToColName(1)); - Assert.assertEquals("C", ExcelUtil.indexToColName(2)); + Assertions.assertEquals("A", ExcelUtil.indexToColName(0)); + Assertions.assertEquals("B", ExcelUtil.indexToColName(1)); + Assertions.assertEquals("C", ExcelUtil.indexToColName(2)); - Assert.assertEquals("AA", ExcelUtil.indexToColName(26)); - Assert.assertEquals("AB", ExcelUtil.indexToColName(27)); - Assert.assertEquals("AC", ExcelUtil.indexToColName(28)); + Assertions.assertEquals("AA", ExcelUtil.indexToColName(26)); + Assertions.assertEquals("AB", ExcelUtil.indexToColName(27)); + Assertions.assertEquals("AC", ExcelUtil.indexToColName(28)); - Assert.assertEquals("AAA", ExcelUtil.indexToColName(702)); - Assert.assertEquals("AAB", ExcelUtil.indexToColName(703)); - Assert.assertEquals("AAC", ExcelUtil.indexToColName(704)); + Assertions.assertEquals("AAA", ExcelUtil.indexToColName(702)); + Assertions.assertEquals("AAB", ExcelUtil.indexToColName(703)); + Assertions.assertEquals("AAC", ExcelUtil.indexToColName(704)); } @Test public void colNameToIndexTest() { - Assert.assertEquals(704, ExcelUtil.colNameToIndex("AAC")); - Assert.assertEquals(703, ExcelUtil.colNameToIndex("AAB")); - Assert.assertEquals(702, ExcelUtil.colNameToIndex("AAA")); + Assertions.assertEquals(704, ExcelUtil.colNameToIndex("AAC")); + Assertions.assertEquals(703, ExcelUtil.colNameToIndex("AAB")); + Assertions.assertEquals(702, ExcelUtil.colNameToIndex("AAA")); - Assert.assertEquals(28, ExcelUtil.colNameToIndex("AC")); - Assert.assertEquals(27, ExcelUtil.colNameToIndex("AB")); - Assert.assertEquals(26, ExcelUtil.colNameToIndex("AA")); + Assertions.assertEquals(28, ExcelUtil.colNameToIndex("AC")); + Assertions.assertEquals(27, ExcelUtil.colNameToIndex("AB")); + Assertions.assertEquals(26, ExcelUtil.colNameToIndex("AA")); - Assert.assertEquals(2, ExcelUtil.colNameToIndex("C")); - Assert.assertEquals(1, ExcelUtil.colNameToIndex("B")); - Assert.assertEquals(0, ExcelUtil.colNameToIndex("A")); + Assertions.assertEquals(2, ExcelUtil.colNameToIndex("C")); + Assertions.assertEquals(1, ExcelUtil.colNameToIndex("B")); + Assertions.assertEquals(0, ExcelUtil.colNameToIndex("A")); } @Test public void toLocationTest() { final CellLocation a11 = ExcelUtil.toLocation("A11"); - Assert.assertEquals(0, a11.getX()); - Assert.assertEquals(10, a11.getY()); + Assertions.assertEquals(0, a11.getX()); + Assertions.assertEquals(10, a11.getY()); } @Test @@ -59,6 +59,6 @@ public class ExcelUtilTest { final ExcelReader reader = ExcelUtil.getReader("aaa.xlsx", "12"); final List> list = reader.readAll(); reader.close(); - Assert.assertEquals(1L, list.get(1).get("鞋码")); + Assertions.assertEquals(1L, list.get(1).get("鞋码")); } } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelWriteTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelWriteTest.java index cc9a69430..f2add1ad3 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelWriteTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelWriteTest.java @@ -11,31 +11,15 @@ import cn.hutool.core.util.ObjUtil; import cn.hutool.poi.excel.cell.setters.EscapeStrCellSetter; import cn.hutool.poi.excel.style.StyleUtil; import org.apache.poi.common.usermodel.HyperlinkType; -import org.apache.poi.ss.usermodel.BorderStyle; -import org.apache.poi.ss.usermodel.BuiltinFormats; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.FillPatternType; -import org.apache.poi.ss.usermodel.Font; -import org.apache.poi.ss.usermodel.HorizontalAlignment; -import org.apache.poi.ss.usermodel.Hyperlink; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.xssf.usermodel.XSSFRichTextString; -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.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; /** * 写出Excel单元测试 @@ -59,7 +43,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void testRowOrColumnCellStyle() { final List row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765); final List row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676); @@ -103,7 +87,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeTest2() { final List row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计"); final ExcelWriter overtimeWriter = ExcelUtil.getWriter("d:/test/excel/single_line.xlsx"); @@ -112,7 +96,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeWithSheetTest() { final ExcelWriter writer = ExcelUtil.getWriterWithSheet("表格1"); @@ -132,7 +116,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeTest() { final List row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765); final List row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676); @@ -167,7 +151,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void mergeTest() { final List row1 = ListUtil.of("aa", "bb", "cc", "dd", DateUtil.now(), 3.22676575765); final List row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.now(), 250.7676); @@ -197,7 +181,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void mergeTest2() { final Map row1 = new LinkedHashMap<>(); row1.put("姓名", "张三"); @@ -227,7 +211,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapTest() { final Map row1 = new LinkedHashMap<>(); row1.put("姓名", "张三"); @@ -264,7 +248,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapTest2() { final Map row1 = MapUtil.newHashMap(true); row1.put("姓名", "张三"); @@ -283,7 +267,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapWithStyleTest() { final Map row1 = MapUtil.newHashMap(true); row1.put("姓名", "张三"); @@ -310,7 +294,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapAliasTest() { final Map row1 = new LinkedHashMap<>(); row1.put("name", "张三"); @@ -345,7 +329,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapOnlyAliasTest() { final Map row1 = new LinkedHashMap<>(); row1.put("name", "张三"); @@ -378,7 +362,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapOnlyAliasTest2() { final Map row1 = new LinkedHashMap<>(); row1.put("name", "张三"); @@ -408,7 +392,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapOnlyAliasTest3() { final Map row1 = new LinkedHashMap<>(); row1.put("name", "张三"); @@ -442,7 +426,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeBeanTest() { final cn.hutool.poi.excel.TestBean bean1 = new cn.hutool.poi.excel.TestBean(); bean1.setName("张三"); @@ -478,7 +462,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeBeanTest2() { final cn.hutool.poi.excel.OrderExcel order1 = new cn.hutool.poi.excel.OrderExcel(); order1.setId("1"); @@ -506,7 +490,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeCellValueTest() { final ExcelWriter writer = new ExcelWriter("d:/cellValueTest.xls"); writer.writeCellValue(3, 5, "aaa"); @@ -515,7 +499,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void addSelectTest() { final List row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计"); final ExcelWriter overtimeWriter = ExcelUtil.getWriter("d:/test/single_line.xlsx"); @@ -525,7 +509,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void addSelectTest2() { final ExcelWriter writer = ExcelUtil.getWriter("d:/test/select.xls"); writer.writeCellValue(0, 0, "请选择科目"); @@ -543,13 +527,13 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMultiSheetTest() { final List> rows = new LinkedList<>(); for (int i = 0; i < 10; i++) { final Map tempList = new TreeMap<>(); for (int j = 0; j < 10; j++) { - tempList.put(j + "", IdUtil.randomUUID()); + tempList.put(String.valueOf(j), IdUtil.randomUUID()); } rows.add(tempList); } @@ -578,7 +562,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMultiSheetTest2() { final List> rows = new LinkedList<>(); final HashMap map = MapUtil.newHashMap(); @@ -602,7 +586,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMultiSheetWithStyleTest() { final ExcelWriter writer = ExcelUtil.getWriter("D:\\test\\multiSheetWithStyle.xlsx", "表格1"); @@ -633,7 +617,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeMapsTest() { final List> rows = new ArrayList<>(); @@ -661,7 +645,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void formatTest() { final ExcelWriter writer = ExcelUtil.getWriter("d:/test/formatTest.xlsx"); final CellStyle cellStyle = writer.createCellStyle(0, 0); @@ -670,7 +654,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeNumberFormatTest() { final ExcelWriter writer = ExcelUtil.getWriter("d:/test/formatTest.xlsx"); writer.disableDefaultStyle(); @@ -681,7 +665,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeSecHeadRowTest() { final List row1 = ListUtil.of(1, "aa", "bb", "cc", "dd", "ee"); final List row2 = ListUtil.of(2, "aa1", "bb1", "cc1", "dd1", "ee1"); @@ -731,7 +715,7 @@ public class ExcelWriteTest { * 测试使用BigWriter写出,ExcelWriter修改失败 */ @Test - @Ignore + @Disabled public void editTest() { // 生成文件 final File file = new File("d:/test/100_.xlsx"); @@ -754,7 +738,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void mergeTest3() { // https://github.com/dromara/hutool/issues/1696 @@ -784,7 +768,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void mergeForDateTest() { // https://github.com/dromara/hutool/issues/1911 @@ -797,7 +781,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void changeHeaderStyleTest() { final ExcelWriter writer = ExcelUtil.getWriter("d:/test/headerStyle.xlsx"); writer.writeHeadRow(ListUtil.view("姓名", "性别", "年龄")); @@ -809,7 +793,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeFloatTest() { //issue https://gitee.com/dromara/hutool/issues/I43U9G final String path = "d:/test/floatTest.xlsx"; @@ -821,7 +805,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeDoubleTest() { // https://gitee.com/dromara/hutool/issues/I5PI5C final String path = "d:/test/doubleTest.xlsx"; @@ -834,7 +818,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void issueI466ZZTest() { // https://gitee.com/dromara/hutool/issues/I466ZZ // 需要输出S_20000314_x5116_0004 @@ -847,7 +831,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeLongTest() { //https://gitee.com/dromara/hutool/issues/I49R6U final ExcelWriter writer = ExcelUtil.getWriter("d:/test/long.xlsx"); @@ -856,7 +840,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeHyperlinkTest() { final ExcelWriter writer = ExcelUtil.getWriter("d:/test/hyperlink.xlsx"); @@ -867,7 +851,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void mergeNumberTest() { final File tempFile = new File("d:/test/mergeNumber.xlsx"); FileUtil.del(tempFile); @@ -878,7 +862,7 @@ public class ExcelWriteTest { } @Test - @Ignore + @Disabled public void writeImgTest() { final ExcelWriter writer = ExcelUtil.getWriter(true); @@ -895,6 +879,6 @@ public class ExcelWriteTest { public void getDispositionTest() { final ExcelWriter writer = ExcelUtil.getWriter(true); final String disposition = writer.getDisposition("测试A12.xlsx", CharsetUtil.UTF_8); - Assert.assertEquals("attachment; filename=\"%E6%B5%8B%E8%AF%95A12.xlsx\"", disposition); + Assertions.assertEquals("attachment; filename=\"%E6%B5%8B%E8%AF%95A12.xlsx\"", disposition); } } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue1729Test.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue1729Test.java index e693237ab..88b26ac98 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue1729Test.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue1729Test.java @@ -1,8 +1,8 @@ package cn.hutool.poi.excel; 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.List; @@ -16,9 +16,9 @@ public class Issue1729Test { public void readTest() { final ExcelReader reader = ExcelUtil.getReader("UserProjectDO.xlsx"); final List read = reader.read(0, 1, UserProjectDO.class); - Assert.assertEquals("aa", read.get(0).getProjectName()); - Assert.assertNull(read.get(0).getEndTrainTime()); - Assert.assertEquals("2020-02-02", read.get(0).getEndTestTime().toString()); + Assertions.assertEquals("aa", read.get(0).getProjectName()); + Assertions.assertNull(read.get(0).getEndTrainTime()); + Assertions.assertEquals("2020-02-02", read.get(0).getEndTestTime().toString()); } @Data diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2221Test.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2221Test.java index 696b5a12d..985725bb5 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2221Test.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2221Test.java @@ -6,8 +6,8 @@ import cn.hutool.poi.excel.style.StyleUtil; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.IndexedColors; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; @@ -18,7 +18,7 @@ public class Issue2221Test { * 设置重复别名的时候,通过原key获取写出位置 */ @Test - @Ignore + @Disabled public void writeDuplicateHeaderAliasTest() { final ExcelWriter writer = ExcelUtil.getWriter("d:/test/duplicateAlias.xlsx"); // 设置别名 @@ -37,7 +37,7 @@ public class Issue2221Test { } @Test - @Ignore + @Disabled public void writeDuplicateHeaderAliasTest2(){ // 获取写Excel的流 final ExcelWriter writer = ExcelUtil.getBigWriter("d:/test/duplicateAlias2.xlsx"); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2307Test.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2307Test.java index 58312bde4..a52cd733a 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2307Test.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/Issue2307Test.java @@ -5,15 +5,15 @@ import cn.hutool.core.io.file.FileUtil; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.List; public class Issue2307Test { @Test - @Ignore + @Disabled public void writeTest(){ final String filePath = "d:/test/issue2307.xlsx"; FileUtil.del(FileUtil.file(filePath)); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI53OSTTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI53OSTTest.java index ded9648dc..9d8987241 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI53OSTTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI53OSTTest.java @@ -1,8 +1,8 @@ package cn.hutool.poi.excel; 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.util.ArrayList; import java.util.HashMap; @@ -15,7 +15,7 @@ import java.util.Map; public class IssueI53OSTTest { @Test - @Ignore + @Disabled public void readTest(){ final Map result = new HashMap<>(); final List header = new ArrayList<>(); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5Q1TWTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5Q1TWTest.java index ced81e931..09e4dd91e 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5Q1TWTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5Q1TWTest.java @@ -1,7 +1,7 @@ package cn.hutool.poi.excel; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class IssueI5Q1TWTest { @@ -10,9 +10,9 @@ public class IssueI5Q1TWTest { final ExcelReader reader = ExcelUtil.getReader("I5Q1TW.xlsx"); // 自定义时间格式1 - Assert.assertEquals("18:56", reader.readCellValue(0, 0).toString()); + Assertions.assertEquals("18:56", reader.readCellValue(0, 0).toString()); // 自定义时间格式2 - Assert.assertEquals("18:56", reader.readCellValue(1, 0).toString()); + Assertions.assertEquals("18:56", reader.readCellValue(1, 0).toString()); } } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5U1JATest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5U1JATest.java index a8946997b..6606aad11 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5U1JATest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI5U1JATest.java @@ -1,11 +1,11 @@ package cn.hutool.poi.excel; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class IssueI5U1JATest { @Test - @Ignore + @Disabled public void readAllTest() { final ExcelReader reader = ExcelUtil.getReader("d:/test/issueI5U1JA.xlsx"); reader.readAll(); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI66Z6BTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI66Z6BTest.java index e160fed80..c9cbdd382 100755 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI66Z6BTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI66Z6BTest.java @@ -2,8 +2,8 @@ package cn.hutool.poi.excel; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.file.FileUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.ArrayList; @@ -17,7 +17,7 @@ public class IssueI66Z6BTest { * 部分字段定义别名后,由于IndexedComparator比较器的问题,会造成字段丢失,已修复 */ @Test - @Ignore + @Disabled public void test() { final File destFile = new File("D:/test/0001test.xlsx"); FileUtil.del(destFile); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI6MBS5Test.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI6MBS5Test.java index 0527f01f9..3327b1187 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI6MBS5Test.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/IssueI6MBS5Test.java @@ -5,8 +5,8 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; @@ -20,7 +20,7 @@ import java.nio.file.Files; public class IssueI6MBS5Test { @Test - @Ignore + @Disabled public void setCommentTest() { final ExcelWriter writer = ExcelUtil.getBigWriter("d:/test/setCommentTest.xlsx"); final Cell cell = writer.getOrCreateCell(0, 0); @@ -31,7 +31,7 @@ public class IssueI6MBS5Test { } @Test - @Ignore + @Disabled public void setCommentTest2() { final File file = new File("D:\\test\\CellUtilTest.xlsx"); try (final Workbook workbook = WorkbookUtil.createBook(true)) { diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/NumericCellValueTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/NumericCellValueTest.java index 7161faf81..691f1ade0 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/NumericCellValueTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/NumericCellValueTest.java @@ -3,7 +3,7 @@ package cn.hutool.poi.excel; import cn.hutool.poi.excel.cell.values.NumericCellValue; import java.util.Date; import org.apache.poi.ss.usermodel.Cell; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NumericCellValueTest { diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/WorkbookUtilTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/WorkbookUtilTest.java index 81917162a..3be3c5873 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/WorkbookUtilTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/WorkbookUtilTest.java @@ -1,17 +1,17 @@ package cn.hutool.poi.excel; import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class WorkbookUtilTest { @Test public void createBookTest(){ Workbook book = WorkbookUtil.createBook(true); - Assert.assertNotNull(book); + Assertions.assertNotNull(book); book = WorkbookUtil.createBook(false); - Assert.assertNotNull(book); + Assertions.assertNotNull(book); } } diff --git a/hutool-poi/src/test/java/cn/hutool/poi/ofd/OfdWriterTest.java b/hutool-poi/src/test/java/cn/hutool/poi/ofd/OfdWriterTest.java index 292db1ef9..7bd686857 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/ofd/OfdWriterTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/ofd/OfdWriterTest.java @@ -1,13 +1,13 @@ package cn.hutool.poi.ofd; import cn.hutool.core.io.file.FileUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class OfdWriterTest { @Test - @Ignore + @Disabled public void writeTest(){ final OfdWriter ofdWriter = new OfdWriter(FileUtil.file("d:/test/test.ofd")); ofdWriter.addText(null, "测试文本"); diff --git a/hutool-poi/src/test/java/cn/hutool/poi/word/WordWriterTest.java b/hutool-poi/src/test/java/cn/hutool/poi/word/WordWriterTest.java index 510eaf870..25f4b2281 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/word/WordWriterTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/word/WordWriterTest.java @@ -6,8 +6,8 @@ import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; import lombok.AllArgsConstructor; 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.awt.Font; import java.io.File; @@ -17,10 +17,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +@SuppressWarnings("resource") public class WordWriterTest { @Test - @Ignore + @Disabled public void writeTest() { final Word07Writer writer = new Word07Writer(); writer.addText(new Font("方正小标宋简体", Font.PLAIN, 22), "我是第一部分", "我是第二部分"); @@ -31,7 +32,7 @@ public class WordWriterTest { } @Test - @Ignore + @Disabled public void writePicTest() { final Word07Writer writer = new Word07Writer(); writer.addPicture(new File("d:\\test\\qrcodeCustom.jpg"), 100, 200); @@ -42,7 +43,7 @@ public class WordWriterTest { } @Test - @Ignore + @Disabled public void writeTableTest(){ final Word07Writer writer = new Word07Writer(); final Map map = new LinkedHashMap<>(); @@ -56,7 +57,7 @@ public class WordWriterTest { } @Test - @Ignore + @Disabled public void writeMapAsTableTest() { final Word07Writer writer = new Word07Writer(); @@ -99,7 +100,7 @@ public class WordWriterTest { } @Test - @Ignore + @Disabled public void writeBeanAsTableTest(){ final List of = ListUtil.of( new Vo("测试1", new BigDecimal(12), new BigDecimal(2)), diff --git a/hutool-setting/src/test/java/cn/hutool/setting/Issue3008Test.java b/hutool-setting/src/test/java/cn/hutool/setting/Issue3008Test.java index 37645ef20..f3c50947e 100644 --- a/hutool-setting/src/test/java/cn/hutool/setting/Issue3008Test.java +++ b/hutool-setting/src/test/java/cn/hutool/setting/Issue3008Test.java @@ -4,8 +4,8 @@ import cn.hutool.core.array.ArrayUtil; import cn.hutool.setting.dialect.Props; import cn.hutool.setting.dialect.PropsUtil; 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 Issue3008Test { /** @@ -16,7 +16,7 @@ public class Issue3008Test { public void toBeanTest() { final Props props = PropsUtil.get("issue3008"); final MyUser user = props.toBean(MyUser.class, "person"); - Assert.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(user.getHobby())); + Assertions.assertEquals("[LOL, KFC, COFFE]", ArrayUtil.toString(user.getHobby())); } @Data diff --git a/hutool-setting/src/test/java/cn/hutool/setting/PropsTest.java b/hutool-setting/src/test/java/cn/hutool/setting/PropsTest.java index 7cade096c..4992dde20 100644 --- a/hutool-setting/src/test/java/cn/hutool/setting/PropsTest.java +++ b/hutool-setting/src/test/java/cn/hutool/setting/PropsTest.java @@ -3,9 +3,9 @@ package cn.hutool.setting; import cn.hutool.core.date.DateUtil; import cn.hutool.setting.dialect.Props; 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.Date; import java.util.List; @@ -25,22 +25,22 @@ public class PropsTest { //noinspection MismatchedQueryAndUpdateOfCollection final Props props = new Props("test.properties"); final String user = props.getProperty("user"); - Assert.assertEquals(user, "root"); + Assertions.assertEquals(user, "root"); final String driver = props.getStr("driver"); - Assert.assertEquals(driver, "com.mysql.jdbc.Driver"); + Assertions.assertEquals(driver, "com.mysql.jdbc.Driver"); } @Test - @Ignore + @Disabled public void propTestForAbsPAth() { //noinspection MismatchedQueryAndUpdateOfCollection final Props props = new Props("d:/test.properties"); final String user = props.getProperty("user"); - Assert.assertEquals(user, "root"); + Assertions.assertEquals(user, "root"); final String driver = props.getStr("driver"); - Assert.assertEquals(driver, "com.mysql.jdbc.Driver"); + Assertions.assertEquals(driver, "com.mysql.jdbc.Driver"); } @Test @@ -48,19 +48,19 @@ public class PropsTest { final Props props = Props.of("to_bean_test.properties"); final ConfigProperties cfg = props.toBean(ConfigProperties.class, "mail"); - Assert.assertEquals("mailer@mail.com", cfg.getHost()); - Assert.assertEquals(9000, cfg.getPort()); - Assert.assertEquals("mailer@mail.com", cfg.getFrom()); + Assertions.assertEquals("mailer@mail.com", cfg.getHost()); + Assertions.assertEquals(9000, cfg.getPort()); + Assertions.assertEquals("mailer@mail.com", cfg.getFrom()); - Assert.assertEquals("john", cfg.getCredentials().getUsername()); - Assert.assertEquals("password", cfg.getCredentials().getPassword()); - Assert.assertEquals("SHA1", cfg.getCredentials().getAuthMethod()); + Assertions.assertEquals("john", cfg.getCredentials().getUsername()); + Assertions.assertEquals("password", cfg.getCredentials().getPassword()); + Assertions.assertEquals("SHA1", cfg.getCredentials().getAuthMethod()); - Assert.assertEquals("true", cfg.getAdditionalHeaders().get("redelivery")); - Assert.assertEquals("true", cfg.getAdditionalHeaders().get("secure")); + Assertions.assertEquals("true", cfg.getAdditionalHeaders().get("redelivery")); + Assertions.assertEquals("true", cfg.getAdditionalHeaders().get("secure")); - Assert.assertEquals("admin@mail.com", cfg.getDefaultRecipients().get(0)); - Assert.assertEquals("owner@mail.com", cfg.getDefaultRecipients().get(1)); + Assertions.assertEquals("admin@mail.com", cfg.getDefaultRecipients().get(0)); + Assertions.assertEquals("owner@mail.com", cfg.getDefaultRecipients().get(1)); } @Test @@ -74,11 +74,11 @@ public class PropsTest { configProp.set("version", 3); final SystemConfig systemConfig = configProp.toBean(SystemConfig.class); - Assert.assertEquals(DateUtil.parse("2020-01-01"), systemConfig.getCreateTime()); - Assert.assertEquals(true, systemConfig.getIsInit()); - Assert.assertEquals("1", systemConfig.getStairPlan()); - Assert.assertEquals(new Integer(2), systemConfig.getStageNum()); - Assert.assertEquals("3", systemConfig.getVersion()); + Assertions.assertEquals(DateUtil.parse("2020-01-01"), systemConfig.getCreateTime()); + Assertions.assertEquals(true, systemConfig.getIsInit()); + Assertions.assertEquals("1", systemConfig.getStairPlan()); + Assertions.assertEquals(new Integer(2), systemConfig.getStageNum()); + Assertions.assertEquals("3", systemConfig.getVersion()); } @Data diff --git a/hutool-setting/src/test/java/cn/hutool/setting/PropsUtilTest.java b/hutool-setting/src/test/java/cn/hutool/setting/PropsUtilTest.java index 08318d161..87fca2ffb 100644 --- a/hutool-setting/src/test/java/cn/hutool/setting/PropsUtilTest.java +++ b/hutool-setting/src/test/java/cn/hutool/setting/PropsUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.setting; import cn.hutool.setting.dialect.PropsUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Objects; @@ -11,12 +11,12 @@ public class PropsUtilTest { @Test public void getTest() { final String driver = PropsUtil.get("test").getStr("driver"); - Assert.assertEquals("com.mysql.jdbc.Driver", driver); + Assertions.assertEquals("com.mysql.jdbc.Driver", driver); } @Test public void getFirstFoundTest() { final String driver = Objects.requireNonNull(PropsUtil.getFirstFound("test2", "test")).getStr("driver"); - Assert.assertEquals("com.mysql.jdbc.Driver", driver); + Assertions.assertEquals("com.mysql.jdbc.Driver", driver); } } diff --git a/hutool-setting/src/test/java/cn/hutool/setting/SettingTest.java b/hutool-setting/src/test/java/cn/hutool/setting/SettingTest.java index 22992393d..a3df16f57 100644 --- a/hutool-setting/src/test/java/cn/hutool/setting/SettingTest.java +++ b/hutool-setting/src/test/java/cn/hutool/setting/SettingTest.java @@ -1,9 +1,9 @@ package cn.hutool.setting; 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; /** * Setting单元测试 @@ -18,23 +18,23 @@ public class SettingTest { final Setting setting = new Setting("test.setting", true); final String driver = setting.getStrByGroup("driver", "demo"); - Assert.assertEquals("com.mysql.jdbc.Driver", driver); + Assertions.assertEquals("com.mysql.jdbc.Driver", driver); //本分组变量替换 final String user = setting.getStrByGroup("user", "demo"); - Assert.assertEquals("rootcom.mysql.jdbc.Driver", user); + Assertions.assertEquals("rootcom.mysql.jdbc.Driver", user); //跨分组变量替换 final String user2 = setting.getStrByGroup("user2", "demo"); - Assert.assertEquals("rootcom.mysql.jdbc.Driver", user2); + Assertions.assertEquals("rootcom.mysql.jdbc.Driver", user2); //默认值测试 final String value = setting.getStr("keyNotExist", "defaultTest"); - Assert.assertEquals("defaultTest", value); + Assertions.assertEquals("defaultTest", value); } @Test - @Ignore + @Disabled public void settingTestForAbsPath() { //noinspection MismatchedQueryAndUpdateOfCollection final Setting setting = new Setting("d:\\excel-plugin\\other.setting", true); @@ -50,10 +50,10 @@ public class SettingTest { setting.setByGroup("user", "group3", "root3"); setting.set("user", "root4"); - Assert.assertEquals("root", setting.getStrByGroup("user", "group1")); - Assert.assertEquals("root2", setting.getStrByGroup("user", "group2")); - Assert.assertEquals("root3", setting.getStrByGroup("user", "group3")); - Assert.assertEquals("root4", setting.get("user")); + Assertions.assertEquals("root", setting.getStrByGroup("user", "group1")); + Assertions.assertEquals("root2", setting.getStrByGroup("user", "group2")); + Assertions.assertEquals("root3", setting.getStrByGroup("user", "group3")); + Assertions.assertEquals("root4", setting.get("user")); } /** diff --git a/hutool-setting/src/test/java/cn/hutool/setting/SettingUtilTest.java b/hutool-setting/src/test/java/cn/hutool/setting/SettingUtilTest.java index b3be1fe6c..60b3f91b4 100644 --- a/hutool-setting/src/test/java/cn/hutool/setting/SettingUtilTest.java +++ b/hutool-setting/src/test/java/cn/hutool/setting/SettingUtilTest.java @@ -1,20 +1,20 @@ package cn.hutool.setting; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SettingUtilTest { @Test public void getTest() { final String driver = SettingUtil.get("test").getStrByGroup("driver", "demo"); - Assert.assertEquals("com.mysql.jdbc.Driver", driver); + Assertions.assertEquals("com.mysql.jdbc.Driver", driver); } @Test public void getTest2() { final String driver = SettingUtil.get("example/example").getStrByGroup("key", "demo"); - Assert.assertEquals("value", driver); + Assertions.assertEquals("value", driver); } @Test @@ -22,6 +22,6 @@ public class SettingUtilTest { //noinspection ConstantConditions final String driver = SettingUtil.getFirstFound("test2", "test") .getStrByGroup("driver", "demo"); - Assert.assertEquals("com.mysql.jdbc.Driver", driver); + Assertions.assertEquals("com.mysql.jdbc.Driver", driver); } } diff --git a/hutool-setting/src/test/java/cn/hutool/setting/toml/TomlTest.java b/hutool-setting/src/test/java/cn/hutool/setting/toml/TomlTest.java index 74c538b06..e7487972f 100644 --- a/hutool-setting/src/test/java/cn/hutool/setting/toml/TomlTest.java +++ b/hutool-setting/src/test/java/cn/hutool/setting/toml/TomlTest.java @@ -13,8 +13,8 @@ package cn.hutool.setting.toml; import cn.hutool.core.io.resource.ResourceUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -22,6 +22,6 @@ public class TomlTest { @Test public void readTest() { final Map read = Toml.read(ResourceUtil.getResource("test.toml")); - Assert.assertEquals(5, read.size()); + Assertions.assertEquals(5, read.size()); } } diff --git a/hutool-setting/src/test/java/cn/hutool/setting/yaml/YamlUtilTest.java b/hutool-setting/src/test/java/cn/hutool/setting/yaml/YamlUtilTest.java index ed409e3a2..443265b5f 100755 --- a/hutool-setting/src/test/java/cn/hutool/setting/yaml/YamlUtilTest.java +++ b/hutool-setting/src/test/java/cn/hutool/setting/yaml/YamlUtilTest.java @@ -3,9 +3,9 @@ package cn.hutool.setting.yaml; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.map.Dict; import cn.hutool.core.util.CharsetUtil; -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.List; @@ -15,15 +15,15 @@ public class YamlUtilTest { public void loadByPathTest() { final Dict result = YamlUtil.loadByPath("test.yaml"); - Assert.assertEquals("John", result.getStr("firstName")); + Assertions.assertEquals("John", result.getStr("firstName")); final List numbers = result.getByPath("contactDetails.number"); - Assert.assertEquals(123456789, (int) numbers.get(0)); - Assert.assertEquals(456786868, (int) numbers.get(1)); + Assertions.assertEquals(123456789, (int) numbers.get(0)); + Assertions.assertEquals(456786868, (int) numbers.get(1)); } @Test - @Ignore + @Disabled public void dumpTest() { final Dict dict = Dict.of() .set("name", "hutool") diff --git a/hutool-swing/src/test/java/cn/hutool/swing/ClipboardMonitorTest.java b/hutool-swing/src/test/java/cn/hutool/swing/ClipboardMonitorTest.java index b099ba5bc..3c7ffccbf 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/ClipboardMonitorTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/ClipboardMonitorTest.java @@ -2,13 +2,13 @@ package cn.hutool.swing; import cn.hutool.core.lang.Console; import cn.hutool.swing.clipboard.ClipboardUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class ClipboardMonitorTest { @Test - @Ignore + @Disabled public void monitorTest() { // 第一个监听 ClipboardUtil.listen((clipboard, contents) -> { diff --git a/hutool-swing/src/test/java/cn/hutool/swing/ClipboardUtilTest.java b/hutool-swing/src/test/java/cn/hutool/swing/ClipboardUtilTest.java index d3692685a..9242babcc 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/ClipboardUtilTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/ClipboardUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.swing; import cn.hutool.swing.clipboard.ClipboardUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * 剪贴板工具类单元测试 @@ -18,7 +18,7 @@ public class ClipboardUtilTest { ClipboardUtil.setStr("test"); final String test = ClipboardUtil.getStr(); - Assert.assertEquals("test", test); + Assertions.assertEquals("test", test); } catch (final java.awt.HeadlessException e) { // 忽略 No X11 DISPLAY variable was set, but this program performed an operation which requires it. // ignore diff --git a/hutool-swing/src/test/java/cn/hutool/swing/DesktopUtilTest.java b/hutool-swing/src/test/java/cn/hutool/swing/DesktopUtilTest.java index 561dc520a..98bc873a7 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/DesktopUtilTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/DesktopUtilTest.java @@ -1,12 +1,12 @@ package cn.hutool.swing; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class DesktopUtilTest { @Test - @Ignore + @Disabled public void browseTest() { DesktopUtil.browse("https://www.hutool.club"); } diff --git a/hutool-swing/src/test/java/cn/hutool/swing/RobotUtilTest.java b/hutool-swing/src/test/java/cn/hutool/swing/RobotUtilTest.java index 17862906d..b275a02f1 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/RobotUtilTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/RobotUtilTest.java @@ -1,13 +1,13 @@ package cn.hutool.swing; import cn.hutool.core.io.file.FileUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class RobotUtilTest { @Test - @Ignore + @Disabled public void captureScreenTest() { RobotUtil.captureScreen(FileUtil.file("e:/screen.jpg")); } diff --git a/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaTest.java b/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaTest.java index 32838f68e..f0137c4f0 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaTest.java @@ -1,12 +1,12 @@ package cn.hutool.swing.captcha; -import cn.hutool.swing.captcha.generator.MathGenerator; import cn.hutool.core.lang.Console; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import cn.hutool.swing.captcha.generator.MathGenerator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import java.awt.*; +import java.awt.Color; /** * 直线干扰验证码单元测试 @@ -19,12 +19,12 @@ public class CaptchaTest { public void lineCaptchaTest1() { // 定义图形验证码的长和宽 final LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100); - Assert.assertNotNull(lineCaptcha.getCode()); - Assert.assertTrue(lineCaptcha.verify(lineCaptcha.getCode())); + Assertions.assertNotNull(lineCaptcha.getCode()); + Assertions.assertTrue(lineCaptcha.verify(lineCaptcha.getCode())); } @Test - @Ignore + @Disabled public void lineCaptchaTest3() { // 定义图形验证码的长和宽 final LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 70, 4, 15); @@ -33,7 +33,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void lineCaptchaWithMathTest() { // 定义图形验证码的长和宽 final LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 80); @@ -43,7 +43,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void lineCaptchaTest2() { // 定义图形验证码的长和宽 @@ -63,7 +63,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void circleCaptchaTest() { // 定义图形验证码的长和宽 @@ -76,7 +76,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void shearCaptchaTest() { // 定义图形验证码的长和宽 @@ -89,7 +89,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void shearCaptchaTest2() { // 定义图形验证码的长和宽 @@ -101,7 +101,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void ShearCaptchaWithMathTest() { // 定义图形验证码的长和宽 final ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 45, 4, 4); @@ -114,7 +114,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void GifCaptchaTest() { final GifCaptcha captcha = CaptchaUtil.createGifCaptcha(200, 100, 4); captcha.write("d:/test/gif_captcha.gif"); @@ -122,7 +122,7 @@ public class CaptchaTest { } @Test - @Ignore + @Disabled public void bgTest(){ final LineCaptcha captcha = CaptchaUtil.createLineCaptcha(200, 100, 4, 1); captcha.setBackground(Color.WHITE); diff --git a/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaUtilTest.java b/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaUtilTest.java index 5ae8f314e..37cc7d2b1 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaUtilTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/captcha/CaptchaUtilTest.java @@ -1,12 +1,12 @@ package cn.hutool.swing.captcha; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class CaptchaUtilTest { @Test - @Ignore + @Disabled public void createTest() { for(int i = 0; i < 1; i++) { CaptchaUtil.createShearCaptcha(320, 240); diff --git a/hutool-swing/src/test/java/cn/hutool/swing/captcha/GeneratorTest.java b/hutool-swing/src/test/java/cn/hutool/swing/captcha/GeneratorTest.java index 9314396f1..011ca48bf 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/captcha/GeneratorTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/captcha/GeneratorTest.java @@ -1,7 +1,7 @@ package cn.hutool.swing.captcha; import cn.hutool.swing.captcha.generator.MathGenerator; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GeneratorTest { diff --git a/hutool-swing/src/test/java/cn/hutool/swing/img/ColorUtilTest.java b/hutool-swing/src/test/java/cn/hutool/swing/img/ColorUtilTest.java index a60549fe6..477e908ab 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/img/ColorUtilTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/img/ColorUtilTest.java @@ -1,8 +1,8 @@ package cn.hutool.swing.img; import cn.hutool.swing.img.color.ColorUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.awt.Color; @@ -11,18 +11,18 @@ public class ColorUtilTest { @Test public void getColorTest(){ final Color blue = ColorUtil.getColor("blue"); - Assert.assertEquals(Color.BLUE, blue); + Assertions.assertEquals(Color.BLUE, blue); } @Test public void toCssRgbTest(){ final String s = ColorUtil.toCssRgb(Color.BLUE); - Assert.assertEquals("rgb(0,0,255)", s); + Assertions.assertEquals("rgb(0,0,255)", s); } @Test public void toCssRgbaTest(){ final String s = ColorUtil.toCssRgba(Color.BLUE); - Assert.assertEquals("rgba(0,0,255,1.0)", s); + Assertions.assertEquals("rgba(0,0,255,1.0)", s); } } diff --git a/hutool-swing/src/test/java/cn/hutool/swing/img/FontUtilTest.java b/hutool-swing/src/test/java/cn/hutool/swing/img/FontUtilTest.java index 873fa75ba..dbb481e3b 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/img/FontUtilTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/img/FontUtilTest.java @@ -1,7 +1,7 @@ package cn.hutool.swing.img; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.awt.Font; @@ -10,6 +10,6 @@ public class FontUtilTest { @Test public void createFontTest(){ final Font font = FontUtil.createFont(); - Assert.assertNotNull(font); + Assertions.assertNotNull(font); } } diff --git a/hutool-swing/src/test/java/cn/hutool/swing/img/ImgTest.java b/hutool-swing/src/test/java/cn/hutool/swing/img/ImgTest.java index 16ebc058b..d1113b0b2 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/img/ImgTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/img/ImgTest.java @@ -3,8 +3,8 @@ package cn.hutool.swing.img; import cn.hutool.core.io.file.FileTypeUtil; import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.net.url.URLUtil; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.awt.Color; import java.awt.Font; @@ -15,32 +15,32 @@ import java.io.File; public class ImgTest { @Test - @Ignore + @Disabled public void cutTest1() { Img.from(FileUtil.file("e:/pic/face.jpg")).cut(0, 0, 200).write(FileUtil.file("e:/pic/face_radis.png")); } @Test - @Ignore + @Disabled public void compressTest() { Img.from(FileUtil.file("f:/test/4347273249269e3fb272341acc42d4e.jpg")).setQuality(0.8).write(FileUtil.file("f:/test/test_dest.jpg")); } @Test - @Ignore + @Disabled public void writeTest() { final Img from = Img.from(FileUtil.file("d:/test/81898311-001d6100-95eb-11ea-83c2-a14d7b1010bd.png")); ImgUtil.write(from.getImg(), FileUtil.file("d:/test/dest.jpg")); } @Test - @Ignore + @Disabled public void roundTest() { Img.from(FileUtil.file("e:/pic/face.jpg")).round(0.5).write(FileUtil.file("e:/pic/face_round.png")); } @Test - @Ignore + @Disabled public void pressTextTest() { Img.from(FileUtil.file("d:/test/617180969474805871.jpg")) .setPositionBaseCentre(false) @@ -54,7 +54,7 @@ public class ImgTest { @Test - @Ignore + @Disabled public void pressTextFullScreenTest() { Img.from(FileUtil.file("d:/test/1435859438434136064.jpg")) .setTargetImageType(ImgUtil.IMAGE_TYPE_PNG) @@ -68,7 +68,7 @@ public class ImgTest { } @Test - @Ignore + @Disabled public void pressImgTest() { Img.from(FileUtil.file("d:/test/图片1.JPG")) .pressImage(ImgUtil.read("d:/test/617180969474805871.jpg"), new Rectangle(0, 0, 800, 800), 1f) @@ -76,7 +76,7 @@ public class ImgTest { } @Test - @Ignore + @Disabled public void strokeTest() { Img.from(FileUtil.file("d:/test/公章3.png")) .stroke(null, 2f) @@ -87,7 +87,7 @@ public class ImgTest { * issue#I49FIU */ @Test - @Ignore + @Disabled public void scaleTest() { final String downloadFile = "d:/test/1435859438434136064.JPG"; final File file = FileUtil.file(downloadFile); @@ -98,7 +98,7 @@ public class ImgTest { } @Test - @Ignore + @Disabled public void rotateWithBackgroundTest() { Img.from(FileUtil.file("d:/test/aaa.jpg")) .setBackgroundColor(Color.RED) diff --git a/hutool-swing/src/test/java/cn/hutool/swing/img/ImgUtilTest.java b/hutool-swing/src/test/java/cn/hutool/swing/img/ImgUtilTest.java index 521f0b118..b4b8bf199 100755 --- a/hutool-swing/src/test/java/cn/hutool/swing/img/ImgUtilTest.java +++ b/hutool-swing/src/test/java/cn/hutool/swing/img/ImgUtilTest.java @@ -1,12 +1,12 @@ package cn.hutool.swing.img; -import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.io.IORuntimeException; +import cn.hutool.core.io.file.FileUtil; import cn.hutool.core.lang.Console; import cn.hutool.swing.img.color.ColorUtil; -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 javax.imageio.ImageIO; import java.awt.Color; @@ -22,13 +22,13 @@ import java.net.URL; public class ImgUtilTest { @Test - @Ignore + @Disabled public void scaleTest() { ImgUtil.scale(FileUtil.file("e:/pic/test.jpg"), FileUtil.file("e:/pic/test_result.jpg"), 0.8f); } @Test - @Ignore + @Disabled public void scaleTest2() { ImgUtil.scale( FileUtil.file("d:/test/2.png"), @@ -36,38 +36,38 @@ public class ImgUtilTest { } @Test - @Ignore + @Disabled public void scalePngTest() { ImgUtil.scale(FileUtil.file("f:/test/test.png"), FileUtil.file("f:/test/test_result.png"), 0.5f); } @Test - @Ignore + @Disabled public void scaleByWidthAndHeightTest() { ImgUtil.scale(FileUtil.file("f:/test/aaa.jpg"), FileUtil.file("f:/test/aaa_result.jpg"), 100, 400, Color.BLUE); } @Test - @Ignore + @Disabled public void cutTest() { ImgUtil.cut(FileUtil.file("d:/face.jpg"), FileUtil.file("d:/face_result.jpg"), new Rectangle(200, 200, 100, 100)); } @Test - @Ignore + @Disabled public void rotateTest() throws IOException { final Image image = ImgUtil.rotate(ImageIO.read(FileUtil.file("e:/pic/366466.jpg")), 180); ImgUtil.write(image, FileUtil.file("e:/pic/result.png")); } @Test - @Ignore + @Disabled public void flipTest() { ImgUtil.flip(FileUtil.file("d:/logo.png"), FileUtil.file("d:/result.png")); } @Test - @Ignore + @Disabled public void pressImgTest() { ImgUtil.pressImage( FileUtil.file("d:/test/1435859438434136064.jpg"), @@ -76,7 +76,7 @@ public class ImgUtilTest { } @Test - @Ignore + @Disabled public void pressTextTest() { ImgUtil.pressText(// FileUtil.file("d:/test/2.jpg"), // @@ -89,33 +89,33 @@ public class ImgUtilTest { } @Test - @Ignore + @Disabled public void sliceByRowsAndColsTest() { ImgUtil.sliceByRowsAndCols(FileUtil.file("d:/test/logo.jpg"), FileUtil.file("d:/test/dest"), ImgUtil.IMAGE_TYPE_JPEG, 1, 5); } @Test - @Ignore + @Disabled public void convertTest() { ImgUtil.convert(FileUtil.file("e:/test2.png"), FileUtil.file("e:/test2Convert.jpg")); } @Test - @Ignore + @Disabled public void writeTest() { final byte[] bytes = ImgUtil.toBytes(ImgUtil.read("d:/test/logo_484.png"), "png"); FileUtil.writeBytes(bytes, "d:/test/result.png"); } @Test - @Ignore + @Disabled public void compressTest() { ImgUtil.compress(FileUtil.file("d:/test/dest.png"), FileUtil.file("d:/test/1111_target.jpg"), 0.1f); } @Test - @Ignore + @Disabled public void copyTest() { final BufferedImage image = ImgUtil.copyImage(ImgUtil.read("f:/pic/test.png"), BufferedImage.TYPE_INT_RGB); ImgUtil.write(image, FileUtil.file("f:/pic/test_dest.jpg")); @@ -124,11 +124,11 @@ public class ImgUtilTest { @Test public void toHexTest(){ final String s = ColorUtil.toHex(Color.RED); - Assert.assertEquals("#FF0000", s); + Assertions.assertEquals("#FF0000", s); } @Test - @Ignore + @Disabled public void backgroundRemovalTest() { // 图片 背景 换成 透明的 ImgUtil.backgroundRemoval( @@ -150,7 +150,7 @@ public class ImgUtilTest { } @Test - @Ignore + @Disabled public void createImageTest() throws IORuntimeException, IOException { ImgUtil.createImage( "版权所有", @@ -162,7 +162,7 @@ public class ImgUtilTest { } @Test - @Ignore + @Disabled public void createTransparentImageTest() throws IORuntimeException, IOException { ImgUtil.createTransparentImage( "版权所有", @@ -173,7 +173,7 @@ public class ImgUtilTest { } @Test - @Ignore + @Disabled public void issue2765Test() { // 利用图片元数据工具读取图片旋转角度信息 final File file = FileUtil.file("d:/test/204691690-715c29d9-793a-4b29-ab1d-191a741438bb.jpg"); diff --git a/pom.xml b/pom.xml index d480f5111..43ead1817 100755 --- a/pom.xml +++ b/pom.xml @@ -56,8 +56,8 @@ - org.junit.vintage - junit-vintage-engine + org.junit.jupiter + junit-jupiter-engine ${junit.version} test