SPR-7239: fix CronTrigger
This commit is contained in:
parent
f0777d130f
commit
b4af04ba9d
|
|
@ -68,7 +68,6 @@ public class CronSequenceGenerator {
|
|||
|
||||
private final TimeZone timeZone;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a {@link CronSequenceGenerator} from the pattern provided.
|
||||
* @param expression a space-separated list of time fields
|
||||
|
|
@ -81,7 +80,6 @@ public class CronSequenceGenerator {
|
|||
parse(expression);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the next {@link Date} in the sequence matching the Cron pattern and
|
||||
* after the value provided. The return value will have a whole number of
|
||||
|
|
@ -314,6 +312,9 @@ public class CronSequenceGenerator {
|
|||
result[0] = Integer.valueOf(split[0]);
|
||||
result[1] = Integer.valueOf(split[1]);
|
||||
}
|
||||
if (result[0] >= max || result[1] >= max) {
|
||||
throw new IllegalArgumentException("Range exceeds maximum (" + max + "): " + field);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,4 +75,9 @@ public class CronTrigger implements Trigger {
|
|||
return this.sequenceGenerator.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sequenceGenerator.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ public class CronTriggerTests {
|
|||
@Parameters
|
||||
public static List<Object[]> getParameters() {
|
||||
List<Object[]> list = new ArrayList<Object[]>();
|
||||
list.add(new Object[] {new Date(), TimeZone.getDefault()});
|
||||
list.add(new Object[] {new Date(), TimeZone.getTimeZone("CET")});
|
||||
list.add(new Object[] { new Date(), TimeZone.getDefault() });
|
||||
list.add(new Object[] { new Date(), TimeZone.getTimeZone("CET") });
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +66,6 @@ public class CronTriggerTests {
|
|||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
calendar.setTimeZone(timeZone);
|
||||
|
|
@ -561,6 +560,51 @@ public class CronTriggerTests {
|
|||
assertEquals(trigger1, trigger2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSecondInvalid() throws Exception {
|
||||
new CronTrigger("77 * * * * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSecondRangeInvalid() throws Exception {
|
||||
new CronTrigger("44-77 * * * * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testMinuteInvalid() throws Exception {
|
||||
new CronTrigger("* 77 * * * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testMinuteRangeInvalid() throws Exception {
|
||||
new CronTrigger("* 44-77 * * * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testHourInvalid() throws Exception {
|
||||
new CronTrigger("* * 27 * * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testHourRangeInvalid() throws Exception {
|
||||
new CronTrigger("* * 23-28 * * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDayInvalid() throws Exception {
|
||||
new CronTrigger("* * * 45 * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDayRangeInvalid() throws Exception {
|
||||
new CronTrigger("* * * 28-45 * *", timeZone);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testMonthInvalid() throws Exception {
|
||||
new CronTrigger("* * * * 11-13 *", timeZone);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhitespace() throws Exception {
|
||||
CronTrigger trigger1 = new CronTrigger("* * * * 1 *", timeZone);
|
||||
|
|
@ -579,7 +623,6 @@ public class CronTriggerTests {
|
|||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
|
||||
}
|
||||
|
||||
|
||||
private static TriggerContext getTriggerContext(Date lastCompletionTime) {
|
||||
SimpleTriggerContext context = new SimpleTriggerContext();
|
||||
context.update(null, null, lastCompletionTime);
|
||||
|
|
|
|||
Loading…
Reference in New Issue