Assert SimpleTriggerFactoryBean.setMisfireInstruction() values

See gh-30851
This commit is contained in:
Sam Brannen
2023-07-31 15:51:46 +03:00
parent 1378cce9fb
commit 81181c346a
2 changed files with 23 additions and 0 deletions

View File

@@ -204,6 +204,8 @@ public class SimpleTriggerFactoryBean implements FactoryBean<SimpleTrigger>, Bea
* Specify the misfire instruction for this trigger.
*/
public void setMisfireInstruction(int misfireInstruction) {
Assert.isTrue(constants.containsValue(misfireInstruction),
"Only values of misfire instruction constants allowed");
this.misfireInstruction = misfireInstruction;
}

View File

@@ -28,6 +28,13 @@ import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW;
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT;
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT;
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT;
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT;
import static org.quartz.Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY;
import static org.quartz.Trigger.MISFIRE_INSTRUCTION_SMART_POLICY;
/**
* Tests for {@link SimpleTriggerFactoryBean}.
@@ -69,6 +76,20 @@ class SimpleTriggerFactoryBeanTests {
.forEach(name -> assertThatNoException().as(name).isThrownBy(() -> factory.setMisfireInstructionName(name)));
}
@Test
void setMisfireInstruction() {
assertThatIllegalArgumentException().isThrownBy(() -> factory.setMisfireInstruction(999));
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_SMART_POLICY));
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY));
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_FIRE_NOW));
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT));
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT));
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT));
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT));
}
private static Stream<Field> streamMisfireInstructionConstants() {
return Arrays.stream(SimpleTrigger.class.getFields())
.filter(ReflectionUtils::isPublicStaticFinal)