From b4274402744678f4fe74dfefe379bd3d004e159a Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 9 Aug 2024 15:03:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=B1Ju?= =?UTF-8?q?nit4=E5=8F=98=E6=9B=B4=E4=B8=BAJunit5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hutool/cron/pattern/CronPatternBuilderTest.java | 12 ++++++++---- .../java/cn/hutool/cron/pattern/CronPatternTest.java | 12 ++++++++---- .../java/cn/hutool/cron/pattern/Issue3685Test.java | 2 +- .../src/test/java/cn/hutool/http/HttpUtilTest.java | 7 ++++--- hutool-jwt/src/test/java/cn/hutool/jwt/JWTTest.java | 4 ++-- .../src/test/java/cn/hutool/jwt/JWTUtilTest.java | 11 +++++++---- 6 files changed, 30 insertions(+), 18 deletions(-) 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 ee59aee078..781736318c 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,9 +1,11 @@ package cn.hutool.cron.pattern; import cn.hutool.cron.CronException; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class CronPatternBuilderTest { @Test @@ -32,13 +34,15 @@ public void buildRangeTest(){ assertEquals("* * 2-9 * * *", build); } - @Test(expected = CronException.class) + @Test public void buildRangeErrorTest(){ - String build = CronPatternBuilder.of() + assertThrows(CronException.class, () -> { + String build = CronPatternBuilder.of() .set(Part.SECOND, "*") // 55无效值 .setRange(Part.HOUR, 2, 55) .build(); - assertEquals("* * 2-9 * * *", build); + assertEquals("* * 2-9 * * *", build); + }); } } 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 34e6addb7b..8047ffa488 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,9 +2,11 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.cron.CronException; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * 定时任务单元测试类 * @@ -159,10 +161,12 @@ public void lastTest() { 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"); + assertThrows(CronException.class, () -> { + // year的范围是1970~2099年,超出报错 + CronPattern.of("0/1 * * * 1/1 ? 2020-2120"); + }); } /** diff --git a/hutool-cron/src/test/java/cn/hutool/cron/pattern/Issue3685Test.java b/hutool-cron/src/test/java/cn/hutool/cron/pattern/Issue3685Test.java index b1a72760ca..f36f305706 100644 --- a/hutool-cron/src/test/java/cn/hutool/cron/pattern/Issue3685Test.java +++ b/hutool-cron/src/test/java/cn/hutool/cron/pattern/Issue3685Test.java @@ -5,7 +5,7 @@ import java.util.Date; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue3685Test { @Test 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 a1e1f3aec2..8f3e8aa3ca 100755 --- a/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java @@ -7,7 +7,6 @@ import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.ReUtil; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -16,6 +15,8 @@ import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.*; + public class HttpUtilTest { @@ -392,10 +393,10 @@ public void httpParameterDecodeTest () { final String resp = HttpUtil.createPost(String.format("http://localhost:%s/formEncoded", port)) .form("test", test).execute().body(); - assertEquals("Form请求参数解码", test, resp); + assertEquals(test, resp); final String urlGet = UrlBuilder.of(String.format("http://localhost:%s/urlEncoded", port)).addQuery("test", test).build(); final String resp2 = HttpUtil.createGet(urlGet).execute().body(); - assertEquals("QueryString请求参数编码", test, resp2); + assertEquals(test, resp2); } } diff --git a/hutool-jwt/src/test/java/cn/hutool/jwt/JWTTest.java b/hutool-jwt/src/test/java/cn/hutool/jwt/JWTTest.java index bac342554e..4f3450da28 100755 --- a/hutool-jwt/src/test/java/cn/hutool/jwt/JWTTest.java +++ b/hutool-jwt/src/test/java/cn/hutool/jwt/JWTTest.java @@ -58,8 +58,8 @@ public void createNoneTest() { .setPayload("admin", true) .setSigner(JWTSignerUtil.none()); - final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." + - "eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9."; + final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0." + + "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Imxvb2x5IiwiYWRtaW4iOnRydWV9."; final String token = jwt.sign(); assertEquals(rightToken, token); diff --git a/hutool-jwt/src/test/java/cn/hutool/jwt/JWTUtilTest.java b/hutool-jwt/src/test/java/cn/hutool/jwt/JWTUtilTest.java index 451d76fbb7..ac64c32128 100755 --- a/hutool-jwt/src/test/java/cn/hutool/jwt/JWTUtilTest.java +++ b/hutool-jwt/src/test/java/cn/hutool/jwt/JWTUtilTest.java @@ -1,11 +1,12 @@ package cn.hutool.jwt; -import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.*; + public class JWTUtilTest { @Test @@ -43,10 +44,12 @@ public void parseTest(){ assertEquals(true, jwt.getPayload("admin")); } - @Test(expected = IllegalArgumentException.class) + @Test public void parseNullTest(){ - // https://gitee.com/dromara/hutool/issues/I5OCQB - JWTUtil.parseToken(null); + assertThrows(IllegalArgumentException.class, () -> { + // https://gitee.com/dromara/hutool/issues/I5OCQB + JWTUtil.parseToken(null); + }); } @Test