23
23
import org .junit .Test ;
24
24
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
25
25
import org .springframework .scheduling .support .ScheduledMethodRunnable ;
26
+ import org .springframework .util .StringValueResolver ;
26
27
27
28
import java .time .Duration ;
28
29
import java .time .temporal .ChronoUnit ;
33
34
import static java .time .temporal .ChronoUnit .MILLIS ;
34
35
import static java .time .temporal .ChronoUnit .SECONDS ;
35
36
import static org .assertj .core .api .Assertions .assertThat ;
37
+ import static org .mockito .Mockito .mock ;
38
+ import static org .mockito .Mockito .when ;
36
39
37
40
public class SpringLockConfigurationExtractorTest {
38
41
public static final Duration DEFAULT_LOCK_TIME = Duration .of (30 , ChronoUnit .MINUTES );
39
42
public static final Duration DEFAULT_LOCK_AT_LEAST_FOR = Duration .of (5 , ChronoUnit .MILLIS );
40
- private final SpringLockConfigurationExtractor extractor = new SpringLockConfigurationExtractor (DEFAULT_LOCK_TIME , DEFAULT_LOCK_AT_LEAST_FOR );
43
+ private final StringValueResolver embeddedValueResolver = mock (StringValueResolver .class );
44
+ private final SpringLockConfigurationExtractor extractor = new SpringLockConfigurationExtractor (DEFAULT_LOCK_TIME , DEFAULT_LOCK_AT_LEAST_FOR , embeddedValueResolver );
41
45
42
46
43
47
@ Test
@@ -72,9 +76,10 @@ public void shouldLockTimeFromAnnotation() throws NoSuchMethodException {
72
76
73
77
@ Test
74
78
public void shouldLockTimeFromAnnotationWithString () throws NoSuchMethodException {
79
+ when (embeddedValueResolver .resolveStringValue ("${placeholder}" )).thenReturn ("5" );
75
80
SchedulerLock annotation = getAnnotation ("annotatedMethodWithString" );
76
81
TemporalAmount lockAtMostFor = extractor .getLockAtMostFor (annotation );
77
- assertThat (lockAtMostFor ).isEqualTo (Duration .of (10 , MILLIS ));
82
+ assertThat (lockAtMostFor ).isEqualTo (Duration .of (5 , MILLIS ));
78
83
}
79
84
80
85
@ Test
@@ -93,6 +98,7 @@ public void shouldGetPositiveGracePeriodFromAnnotation() throws NoSuchMethodExce
93
98
94
99
@ Test
95
100
public void shouldGetPositiveGracePeriodFromAnnotationWithString () throws NoSuchMethodException {
101
+ when (embeddedValueResolver .resolveStringValue ("10" )).thenReturn ("10" );
96
102
SchedulerLock annotation = getAnnotation ("annotatedMethodWithPositiveGracePeriodWithString" );
97
103
TemporalAmount gracePeriod = extractor .getLockAtLeastFor (annotation );
98
104
assertThat (gracePeriod ).isEqualTo (Duration .of (10 , MILLIS ));
@@ -128,7 +134,7 @@ public void annotatedMethod() {
128
134
129
135
}
130
136
131
- @ SchedulerLock (name = "lockName" , lockAtMostForString = "10 " )
137
+ @ SchedulerLock (name = "lockName" , lockAtMostForString = "${placeholder} " )
132
138
public void annotatedMethodWithString () {
133
139
134
140
}
0 commit comments