Stop using Constants utility in SimpleTriggerFactoryBean
See gh-30851
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,21 +16,32 @@
|
||||
|
||||
package org.springframework.scheduling.quartz;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.quartz.SimpleTrigger;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests for {@link SimpleTriggerFactoryBean}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class SimpleTriggerFactoryBeanTests {
|
||||
class SimpleTriggerFactoryBeanTests {
|
||||
|
||||
private final SimpleTriggerFactoryBean factory = new SimpleTriggerFactoryBean();
|
||||
|
||||
|
||||
@Test
|
||||
public void createWithoutJobDetail() throws ParseException {
|
||||
SimpleTriggerFactoryBean factory = new SimpleTriggerFactoryBean();
|
||||
void createWithoutJobDetail() {
|
||||
factory.setName("myTrigger");
|
||||
factory.setRepeatCount(5);
|
||||
factory.setRepeatInterval(1000L);
|
||||
@@ -40,4 +51,28 @@ public class SimpleTriggerFactoryBeanTests {
|
||||
assertThat(trigger.getRepeatInterval()).isEqualTo(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setMisfireInstructionNameToUnsupportedValues() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.setMisfireInstructionName(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.setMisfireInstructionName(" "));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factory.setMisfireInstructionName("bogus"));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test effectively verifies that the internal 'constants' map is properly
|
||||
* configured for all MISFIRE_INSTRUCTION_ constants defined in {@link SimpleTrigger}.
|
||||
*/
|
||||
@Test
|
||||
void setMisfireInstructionNameToAllSupportedValues() {
|
||||
streamMisfireInstructionConstants()
|
||||
.map(Field::getName)
|
||||
.forEach(name -> assertThatNoException().as(name).isThrownBy(() -> factory.setMisfireInstructionName(name)));
|
||||
}
|
||||
|
||||
private static Stream<Field> streamMisfireInstructionConstants() {
|
||||
return Arrays.stream(SimpleTrigger.class.getFields())
|
||||
.filter(ReflectionUtils::isPublicStaticFinal)
|
||||
.filter(field -> field.getName().startsWith("MISFIRE_INSTRUCTION_"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user