Skip to content

Commit

Permalink
单元测试由Junit4变更为Junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Aug 9, 2024
1 parent 69e278c commit b427440
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* 定时任务单元测试类
*
Expand Down Expand Up @@ -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");
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions hutool-http/src/test/java/cn/hutool/http/HttpUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,6 +15,8 @@
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

public class HttpUtilTest {


Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions hutool-jwt/src/test/java/cn/hutool/jwt/JWTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions hutool-jwt/src/test/java/cn/hutool/jwt/JWTUtilTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b427440

Please sign in to comment.