mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add test
This commit is contained in:
parent
f540888a4c
commit
a5c8efd9cc
@ -1,11 +1,10 @@
|
|||||||
package cn.hutool.cron.pattern;
|
package cn.hutool.cron.pattern;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.cron.CronException;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.cron.pattern.CronPattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务单元测试类
|
* 定时任务单元测试类
|
||||||
*
|
*
|
||||||
@ -90,6 +89,7 @@ public class CronPatternTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
@Test
|
@Test
|
||||||
public void CronPatternTest2() {
|
public void CronPatternTest2() {
|
||||||
CronPattern pattern = new CronPattern("0/30 * * * *");
|
CronPattern pattern = new CronPattern("0/30 * * * *");
|
||||||
@ -125,12 +125,19 @@ public class CronPatternTest {
|
|||||||
assertMatch(pattern, "2017-02-19 04:20:33");
|
assertMatch(pattern, "2017-02-19 04:20:33");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = CronException.class)
|
||||||
|
public void rangeYearTest() {
|
||||||
|
// year的范围是1970~2099年,超出报错
|
||||||
|
CronPattern pattern = new CronPattern("0/1 * * * 1/1 ? 2020-2120");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表达式是否匹配日期
|
* 表达式是否匹配日期
|
||||||
*
|
*
|
||||||
* @param pattern 表达式
|
* @param pattern 表达式
|
||||||
* @param date 日期,标准日期时间字符串
|
* @param date 日期,标准日期时间字符串
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
private void assertMatch(CronPattern pattern, String date) {
|
private void assertMatch(CronPattern pattern, String date) {
|
||||||
Assert.assertTrue(pattern.match(DateUtil.parse(date).getTime(), false));
|
Assert.assertTrue(pattern.match(DateUtil.parse(date).getTime(), false));
|
||||||
Assert.assertTrue(pattern.match(DateUtil.parse(date).getTime(), true));
|
Assert.assertTrue(pattern.match(DateUtil.parse(date).getTime(), true));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user