25
25
import static org .mockito .Mockito .mock ;
26
26
import static org .mockito .Mockito .times ;
27
27
28
- import java .lang .annotation .ElementType ;
29
28
import java .lang .annotation .Retention ;
30
29
import java .lang .annotation .RetentionPolicy ;
31
- import java .lang .annotation .Target ;
32
30
import java .lang .reflect .Method ;
33
31
import java .util .Collections ;
34
32
@@ -96,10 +94,13 @@ void shouldProvideFromAnnotation() {
96
94
// given
97
95
RetryTopicConfigurationProvider provider = new RetryTopicConfigurationProvider (beanFactory );
98
96
RetryTopicConfiguration configuration = provider .findRetryConfigurationFor (topics , annotatedMethod , bean );
97
+ RetryTopicConfiguration configurationFromClass = provider
98
+ .findRetryConfigurationFor (topics , null , AnnotatedClass .class , bean );
99
99
100
100
// then
101
101
then (this .beanFactory ).should (times (0 )).getBeansOfType (RetryTopicConfiguration .class );
102
-
102
+ assertThat (configuration ).isNotNull ();
103
+ assertThat (configurationFromClass ).isNotNull ();
103
104
}
104
105
105
106
@ Test
@@ -113,10 +114,13 @@ void shouldProvideFromBeanFactory() {
113
114
// given
114
115
RetryTopicConfigurationProvider provider = new RetryTopicConfigurationProvider (beanFactory );
115
116
RetryTopicConfiguration configuration = provider .findRetryConfigurationFor (topics , nonAnnotatedMethod , bean );
117
+ RetryTopicConfiguration configurationFromClass = provider
118
+ .findRetryConfigurationFor (topics , null , NonAnnotatedClass .class , bean );
116
119
117
120
// then
118
- then (this .beanFactory ).should (times (1 )).getBeansOfType (RetryTopicConfiguration .class );
121
+ then (this .beanFactory ).should (times (2 )).getBeansOfType (RetryTopicConfiguration .class );
119
122
assertThat (configuration ).isEqualTo (retryTopicConfiguration );
123
+ assertThat (configurationFromClass ).isEqualTo (retryTopicConfiguration );
120
124
121
125
}
122
126
@@ -131,10 +135,13 @@ void shouldFindNone() {
131
135
// given
132
136
RetryTopicConfigurationProvider provider = new RetryTopicConfigurationProvider (beanFactory );
133
137
RetryTopicConfiguration configuration = provider .findRetryConfigurationFor (topics , nonAnnotatedMethod , bean );
138
+ RetryTopicConfiguration configurationFromClass = provider
139
+ .findRetryConfigurationFor (topics , null , NonAnnotatedClass .class , bean );
134
140
135
141
// then
136
- then (this .beanFactory ).should (times (1 )).getBeansOfType (RetryTopicConfiguration .class );
142
+ then (this .beanFactory ).should (times (2 )).getBeansOfType (RetryTopicConfiguration .class );
137
143
assertThat (configuration ).isNull ();
144
+ assertThat (configurationFromClass ).isNull ();
138
145
139
146
}
140
147
@@ -147,10 +154,15 @@ void shouldProvideFromMetaAnnotation() {
147
154
// given
148
155
RetryTopicConfigurationProvider provider = new RetryTopicConfigurationProvider (beanFactory );
149
156
RetryTopicConfiguration configuration = provider .findRetryConfigurationFor (topics , metaAnnotatedMethod , bean );
157
+ RetryTopicConfiguration configurationFromClass = provider
158
+ .findRetryConfigurationFor (topics , null , MetaAnnotatedClass .class , bean );
150
159
151
160
// then
152
161
then (this .beanFactory ).should (times (0 )).getBeansOfType (RetryTopicConfiguration .class );
162
+ assertThat (configuration ).isNotNull ();
153
163
assertThat (configuration .getConcurrency ()).isEqualTo (3 );
164
+ assertThat (configurationFromClass ).isNotNull ();
165
+ assertThat (configurationFromClass .getConcurrency ()).isEqualTo (3 );
154
166
155
167
}
156
168
@@ -160,9 +172,12 @@ void shouldNotConfigureIfBeanFactoryNull() {
160
172
// given
161
173
RetryTopicConfigurationProvider provider = new RetryTopicConfigurationProvider (null );
162
174
RetryTopicConfiguration configuration = provider .findRetryConfigurationFor (topics , nonAnnotatedMethod , bean );
175
+ RetryTopicConfiguration configurationFromClass
176
+ = provider .findRetryConfigurationFor (topics , null , NonAnnotatedClass .class , bean );
163
177
164
178
// then
165
179
assertThat (configuration ).isNull ();
180
+ assertThat (configurationFromClass ).isNull ();
166
181
167
182
}
168
183
@@ -175,7 +190,6 @@ public void nonAnnotatedMethod() {
175
190
// NoOps
176
191
}
177
192
178
- @ Target ({ElementType .METHOD })
179
193
@ Retention (RetentionPolicy .RUNTIME )
180
194
@ RetryableTopic
181
195
@interface MetaAnnotatedRetryableTopic {
@@ -187,4 +201,19 @@ public void nonAnnotatedMethod() {
187
201
public void metaAnnotatedMethod () {
188
202
// NoOps
189
203
}
204
+
205
+ @ RetryableTopic
206
+ public static class AnnotatedClass {
207
+ // NoOps
208
+ }
209
+
210
+ public static class NonAnnotatedClass {
211
+ // NoOps
212
+ }
213
+
214
+ @ MetaAnnotatedRetryableTopic
215
+ public static class MetaAnnotatedClass {
216
+ // NoOps
217
+ }
218
+
190
219
}
0 commit comments