|
19 | 19 |
|
20 | 20 | import org.quartz.impl.triggers.CronTriggerImpl;
|
21 | 21 |
|
| 22 | +import static java.util.Arrays.asList; |
| 23 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | +import static org.hamcrest.Matchers.is; |
| 25 | + |
22 | 26 | /**
|
23 | 27 | * Unit test for CronTrigger.
|
24 | 28 | */
|
@@ -125,6 +129,42 @@ public void testMisfireInstructionValidity() throws ParseException {
|
125 | 129 | }
|
126 | 130 | }
|
127 | 131 |
|
| 132 | + public void testMisfireInstructionInDerivedBuilder() throws ParseException { |
| 133 | + for (int policy : asList( |
| 134 | + Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY, |
| 135 | + Trigger.MISFIRE_INSTRUCTION_SMART_POLICY, |
| 136 | + CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING, |
| 137 | + CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) |
| 138 | + ) { |
| 139 | + CronTriggerImpl trigger = new CronTriggerImpl(); |
| 140 | + trigger.setCronExpression("0 0 12 * * ?"); |
| 141 | + trigger.setMisfireInstruction(policy); |
| 142 | + assertThat(trigger.getMisfireInstruction(), is(policy)); |
| 143 | + |
| 144 | + CronTrigger copy = trigger.getTriggerBuilder().build(); |
| 145 | + assertThat(copy.getMisfireInstruction(), is(policy)); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + public void testUndefinedMisfireInstructionInDerivedBuilder() throws ParseException { |
| 150 | + CronTriggerImpl trigger = new CronTriggerImpl() { |
| 151 | + @Override |
| 152 | + public int getMisfireInstruction() { |
| 153 | + return 12345; |
| 154 | + } |
| 155 | + }; |
| 156 | + trigger.setCronExpression("0 0 12 * * ?"); |
| 157 | + try { |
| 158 | + trigger.setMisfireInstruction(12345); |
| 159 | + fail("Expected IllegalArgumentException"); |
| 160 | + } catch (IllegalArgumentException e) { |
| 161 | + assertThat(e.getMessage(), is("The misfire instruction code is invalid for this type of trigger.")); |
| 162 | + } |
| 163 | + |
| 164 | + CronTrigger copy = trigger.getTriggerBuilder().build(); |
| 165 | + assertThat(copy.getMisfireInstruction(), is(Trigger.MISFIRE_INSTRUCTION_SMART_POLICY)); |
| 166 | + } |
| 167 | + |
128 | 168 | // execute with version number to generate a new version's serialized form
|
129 | 169 | public static void main(String[] args) throws Exception {
|
130 | 170 | new CronTriggerTest().writeJobDataFile("2.0");
|
|
0 commit comments