Skip to content

Commit

Permalink
Merge pull request #1254 from konopka/fix_setrepeatinterval_accepts_i…
Browse files Browse the repository at this point in the history
…nvalid_value

Fix setRepeatInterval accepts invalid value
  • Loading branch information
jhouserizer authored Nov 6, 2024
2 parents 94c890f + 5804dc2 commit 33ef506
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public int getRepeatInterval() {
* if repeatInterval is < 1
*/
public void setRepeatInterval( int repeatInterval) {
if (repeatInterval < 0) {
if (repeatInterval < 1) {
throw new IllegalArgumentException(
"Repeat interval must be >= 1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@


import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.quartz.DailyTimeIntervalScheduleBuilder;
import org.quartz.DailyTimeIntervalTrigger;
import org.quartz.DateBuilder;
Expand Down Expand Up @@ -623,7 +625,7 @@ void testExtraConstructors() {
assertEquals("jobName", trigger.getJobName());
assertEquals("jobGroup", trigger.getJobGroup());
assertEquals(dateOf(8, 0, 0, 1, 1, 2012), trigger.getStartTime());
assertNull(trigger.getEndTime());
assertNull(trigger.getEndTime());
assertEquals(new TimeOfDay(8, 0, 0), trigger.getStartTimeOfDay());
assertEquals(new TimeOfDay(17, 0, 0), trigger.getEndTimeOfDay());
assertEquals(IntervalUnit.HOUR, trigger.getRepeatIntervalUnit());
Expand All @@ -637,13 +639,20 @@ void testExtraConstructors() {

assertEquals("triggerName", trigger.getName());
assertEquals("triggerGroup", trigger.getGroup());
assertNull(trigger.getJobName());
assertNull(trigger.getJobName());
assertEquals("DEFAULT", trigger.getJobGroup());
assertEquals(dateOf(8, 0, 0, 1, 1, 2012), trigger.getStartTime());
assertNull(trigger.getEndTime());
assertNull(trigger.getEndTime());
assertEquals(new TimeOfDay(8, 0, 0), trigger.getStartTimeOfDay());
assertEquals(new TimeOfDay(17, 0, 0), trigger.getEndTimeOfDay());
assertEquals(IntervalUnit.HOUR, trigger.getRepeatIntervalUnit());
assertEquals(1, trigger.getRepeatInterval());
}

@ParameterizedTest
@ValueSource(ints = { Integer.MIN_VALUE, 0})
void testSetRepeatIntervalWithInvalidValues(int repeatInterval) {
DailyTimeIntervalTriggerImpl trigger = new DailyTimeIntervalTriggerImpl();
assertThrows(IllegalArgumentException.class, () -> trigger.setRepeatInterval(repeatInterval));
}
}

0 comments on commit 33ef506

Please sign in to comment.