单元测试由Junit4变更为Junit5

This commit is contained in:
Looly 2024-08-09 15:03:46 +08:00
parent 69e278c787
commit b427440274
6 changed files with 30 additions and 18 deletions

View File

@ -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 class CronPatternBuilderTest {
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);
});
}
}

View File

@ -2,9 +2,11 @@ package cn.hutool.cron.pattern;
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 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");
assertThrows(CronException.class, () -> {
// year的范围是1970~2099年超出报错
CronPattern.of("0/1 * * * 1/1 ? 2020-2120");
});
}
/**

View File

@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue3685Test {
@Test

View File

@ -7,7 +7,6 @@ import cn.hutool.core.net.NetUtil;
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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
public class HttpUtilTest {
@ -392,10 +393,10 @@ public class HttpUtilTest {
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);
}
}

View File

@ -58,8 +58,8 @@ public class JWTTest {
.setPayload("admin", true)
.setSigner(JWTSignerUtil.none());
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
"eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9.";
final String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0." +
"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Imxvb2x5IiwiYWRtaW4iOnRydWV9.";
final String token = jwt.sign();
assertEquals(rightToken, token);

View File

@ -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 class JWTUtilTest {
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