Added cron expression validation method for CronSequenceGenerator

It's handy to know in advance whether or not expression that is
passed to CronSequenceGenerator or CronTrigger constructor would
not results in IllegalArgumentException. The only way to do it
now is to try\catch an instance creation but it's kinda ugly.
This commit is contained in:
Ruslan Sibgatullin
2016-04-23 15:32:11 +03:00
parent 6e4e52b23a
commit 31d634e6bf
2 changed files with 31 additions and 1 deletions

View File

@@ -56,4 +56,18 @@ public class CronSequenceGeneratorTests {
new CronSequenceGenerator("*/-1 * * * * *").next(new Date(2012, 6, 1, 9, 0));
}
@Test
public void testValidExpression() {
assertTrue(CronSequenceGenerator.isValidExpression("0 */2 1-4 * * *"));
}
@Test
public void testNotValidExpression() {
assertFalse(CronSequenceGenerator.isValidExpression("0 */2 1-4 * * * *"));
}
@Test
public void testNullExpression() {
assertFalse(CronSequenceGenerator.isValidExpression(null));
}
}