@ -1,5 +1,5 @@
@@ -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,33 @@
@@ -16,21 +16,33 @@
package org.springframework.scheduling.quartz ;
import java.lang.reflect.Field ;
import java.text.ParseException ;
import java.util.Arrays ;
import java.util.stream.Stream ;
import org.junit.jupiter.api.Test ;
import org.quartz.CronTrigger ;
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 CronTriggerFactoryBean } .
*
* @author Stephane Nicoll
* @author Sam Brannen
* /
public class CronTriggerFactoryBeanTests {
class CronTriggerFactoryBeanTests {
private final CronTriggerFactoryBean factory = new CronTriggerFactoryBean ( ) ;
@Test
public void createWithoutJobDetail ( ) throws ParseException {
CronTriggerFactoryBean factory = new CronTriggerFactoryBean ( ) ;
void createWithoutJobDetail ( ) throws ParseException {
factory . setName ( "myTrigger" ) ;
factory . setCronExpression ( "0 15 10 ? * *" ) ;
factory . afterPropertiesSet ( ) ;
@ -38,4 +50,28 @@ public class CronTriggerFactoryBeanTests {
@@ -38,4 +50,28 @@ public class CronTriggerFactoryBeanTests {
assertThat ( trigger . getCronExpression ( ) ) . isEqualTo ( "0 15 10 ? * *" ) ;
}
@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 CronTrigger } .
* /
@Test
void setMisfireInstructionNameToAllSupportedValues ( ) {
streamMisfireInstructionConstants ( )
. map ( Field : : getName )
. forEach ( name - > assertThatNoException ( ) . as ( name ) . isThrownBy ( ( ) - > factory . setMisfireInstructionName ( name ) ) ) ;
}
private static Stream < Field > streamMisfireInstructionConstants ( ) {
return Arrays . stream ( CronTrigger . class . getFields ( ) )
. filter ( ReflectionUtils : : isPublicStaticFinal )
. filter ( field - > field . getName ( ) . startsWith ( "MISFIRE_INSTRUCTION_" ) ) ;
}
}