40
40
import org .aspectj .lang .annotation .Aspect ;
41
41
import org .junit .Test ;
42
42
43
- import org .springframework .beans .factory .annotation .AnnotatedGenericBeanDefinition ;
44
43
import org .springframework .beans .factory .config .BeanDefinition ;
45
44
import org .springframework .context .index .CandidateComponentsTestClassLoader ;
46
45
import org .springframework .core .env .ConfigurableEnvironment ;
@@ -80,18 +79,17 @@ public void defaultsWithScan() {
80
79
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (true );
81
80
provider .setResourceLoader (new DefaultResourceLoader (
82
81
CandidateComponentsTestClassLoader .disableIndex (getClass ().getClassLoader ())));
83
- testDefault (provider , ScannedGenericBeanDefinition . class );
82
+ testDefault (provider );
84
83
}
85
84
86
85
@ Test
87
86
public void defaultsWithIndex () {
88
87
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (true );
89
88
provider .setResourceLoader (new DefaultResourceLoader (TEST_BASE_CLASSLOADER ));
90
- testDefault (provider , AnnotatedGenericBeanDefinition . class );
89
+ testDefault (provider );
91
90
}
92
91
93
- private void testDefault (ClassPathScanningCandidateComponentProvider provider ,
94
- Class <? extends BeanDefinition > expectedBeanDefinitionType ) {
92
+ private void testDefault (ClassPathScanningCandidateComponentProvider provider ) {
95
93
Set <BeanDefinition > candidates = provider .findCandidateComponents (TEST_BASE_PACKAGE );
96
94
assertTrue (containsBeanClass (candidates , DefaultNamedComponent .class ));
97
95
assertTrue (containsBeanClass (candidates , NamedComponent .class ));
@@ -101,30 +99,29 @@ private void testDefault(ClassPathScanningCandidateComponentProvider provider,
101
99
assertTrue (containsBeanClass (candidates , ServiceInvocationCounter .class ));
102
100
assertTrue (containsBeanClass (candidates , BarComponent .class ));
103
101
assertEquals (7 , candidates .size ());
104
- assertBeanDefinitionType (candidates , expectedBeanDefinitionType );
102
+ assertBeanDefinitionType (candidates );
105
103
}
106
104
107
105
@ Test
108
106
public void antStylePackageWithScan () {
109
107
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (true );
110
108
provider .setResourceLoader (new DefaultResourceLoader (
111
109
CandidateComponentsTestClassLoader .disableIndex (getClass ().getClassLoader ())));
112
- testAntStyle (provider , ScannedGenericBeanDefinition . class );
110
+ testAntStyle (provider );
113
111
}
114
112
115
113
@ Test
116
114
public void antStylePackageWithIndex () {
117
115
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (true );
118
116
provider .setResourceLoader (new DefaultResourceLoader (TEST_BASE_CLASSLOADER ));
119
- testAntStyle (provider , AnnotatedGenericBeanDefinition . class );
117
+ testAntStyle (provider );
120
118
}
121
119
122
- private void testAntStyle (ClassPathScanningCandidateComponentProvider provider ,
123
- Class <? extends BeanDefinition > expectedBeanDefinitionType ) {
120
+ private void testAntStyle (ClassPathScanningCandidateComponentProvider provider ) {
124
121
Set <BeanDefinition > candidates = provider .findCandidateComponents (TEST_BASE_PACKAGE + ".**.sub" );
125
122
assertTrue (containsBeanClass (candidates , BarComponent .class ));
126
123
assertEquals (1 , candidates .size ());
127
- assertBeanDefinitionType (candidates , expectedBeanDefinitionType );
124
+ assertBeanDefinitionType (candidates );
128
125
}
129
126
130
127
@ Test
@@ -151,74 +148,71 @@ public void customFiltersFollowedByResetUseIndex() {
151
148
provider .addIncludeFilter (new AnnotationTypeFilter (Component .class ));
152
149
provider .resetFilters (true );
153
150
Set <BeanDefinition > candidates = provider .findCandidateComponents (TEST_BASE_PACKAGE );
154
- assertBeanDefinitionType (candidates , AnnotatedGenericBeanDefinition . class );
151
+ assertBeanDefinitionType (candidates );
155
152
}
156
153
157
154
@ Test
158
155
public void customAnnotationTypeIncludeFilterWithScan () {
159
156
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (false );
160
157
provider .setResourceLoader (new DefaultResourceLoader (
161
158
CandidateComponentsTestClassLoader .disableIndex (getClass ().getClassLoader ())));
162
- testCustomAnnotationTypeIncludeFilter (provider , ScannedGenericBeanDefinition . class );
159
+ testCustomAnnotationTypeIncludeFilter (provider );
163
160
}
164
161
165
162
@ Test
166
163
public void customAnnotationTypeIncludeFilterWithIndex () {
167
164
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (false );
168
165
provider .setResourceLoader (new DefaultResourceLoader (TEST_BASE_CLASSLOADER ));
169
- testCustomAnnotationTypeIncludeFilter (provider , AnnotatedGenericBeanDefinition . class );
166
+ testCustomAnnotationTypeIncludeFilter (provider );
170
167
}
171
168
172
- private void testCustomAnnotationTypeIncludeFilter (ClassPathScanningCandidateComponentProvider provider ,
173
- Class <? extends BeanDefinition > expectedBeanDefinitionType ) {
169
+ private void testCustomAnnotationTypeIncludeFilter (ClassPathScanningCandidateComponentProvider provider ) {
174
170
provider .addIncludeFilter (new AnnotationTypeFilter (Component .class ));
175
- testDefault (provider , expectedBeanDefinitionType );
171
+ testDefault (provider );
176
172
}
177
173
178
174
@ Test
179
175
public void customAssignableTypeIncludeFilterWithScan () {
180
176
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (false );
181
177
provider .setResourceLoader (new DefaultResourceLoader (
182
178
CandidateComponentsTestClassLoader .disableIndex (getClass ().getClassLoader ())));
183
- testCustomAssignableTypeIncludeFilter (provider , ScannedGenericBeanDefinition . class );
179
+ testCustomAssignableTypeIncludeFilter (provider );
184
180
}
185
181
186
182
@ Test
187
183
public void customAssignableTypeIncludeFilterWithIndex () {
188
184
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (false );
189
185
provider .setResourceLoader (new DefaultResourceLoader (TEST_BASE_CLASSLOADER ));
190
- testCustomAssignableTypeIncludeFilter (provider , AnnotatedGenericBeanDefinition . class );
186
+ testCustomAssignableTypeIncludeFilter (provider );
191
187
}
192
188
193
- private void testCustomAssignableTypeIncludeFilter (ClassPathScanningCandidateComponentProvider provider ,
194
- Class <? extends BeanDefinition > expectedBeanDefinitionType ) {
189
+ private void testCustomAssignableTypeIncludeFilter (ClassPathScanningCandidateComponentProvider provider ) {
195
190
provider .addIncludeFilter (new AssignableTypeFilter (FooService .class ));
196
191
Set <BeanDefinition > candidates = provider .findCandidateComponents (TEST_BASE_PACKAGE );
197
192
// Interfaces/Abstract class are filtered out automatically.
198
193
assertTrue (containsBeanClass (candidates , AutowiredQualifierFooService .class ));
199
194
assertTrue (containsBeanClass (candidates , FooServiceImpl .class ));
200
195
assertTrue (containsBeanClass (candidates , ScopedProxyTestBean .class ));
201
196
assertEquals (3 , candidates .size ());
202
- assertBeanDefinitionType (candidates , expectedBeanDefinitionType );
197
+ assertBeanDefinitionType (candidates );
203
198
}
204
199
205
200
@ Test
206
201
public void customSupportedIncludeAndExcludedFilterWithScan () {
207
202
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (false );
208
203
provider .setResourceLoader (new DefaultResourceLoader (
209
204
CandidateComponentsTestClassLoader .disableIndex (getClass ().getClassLoader ())));
210
- testCustomSupportedIncludeAndExcludeFilter (provider , ScannedGenericBeanDefinition . class );
205
+ testCustomSupportedIncludeAndExcludeFilter (provider );
211
206
}
212
207
213
208
@ Test
214
209
public void customSupportedIncludeAndExcludeFilterWithIndex () {
215
210
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (false );
216
211
provider .setResourceLoader (new DefaultResourceLoader (TEST_BASE_CLASSLOADER ));
217
- testCustomSupportedIncludeAndExcludeFilter (provider , AnnotatedGenericBeanDefinition . class );
212
+ testCustomSupportedIncludeAndExcludeFilter (provider );
218
213
}
219
214
220
- private void testCustomSupportedIncludeAndExcludeFilter (ClassPathScanningCandidateComponentProvider provider ,
221
- Class <? extends BeanDefinition > expectedBeanDefinitionType ) {
215
+ private void testCustomSupportedIncludeAndExcludeFilter (ClassPathScanningCandidateComponentProvider provider ) {
222
216
provider .addIncludeFilter (new AnnotationTypeFilter (Component .class ));
223
217
provider .addExcludeFilter (new AnnotationTypeFilter (Service .class ));
224
218
provider .addExcludeFilter (new AnnotationTypeFilter (Repository .class ));
@@ -227,7 +221,7 @@ private void testCustomSupportedIncludeAndExcludeFilter(ClassPathScanningCandida
227
221
assertTrue (containsBeanClass (candidates , ServiceInvocationCounter .class ));
228
222
assertTrue (containsBeanClass (candidates , BarComponent .class ));
229
223
assertEquals (3 , candidates .size ());
230
- assertBeanDefinitionType (candidates , expectedBeanDefinitionType );
224
+ assertBeanDefinitionType (candidates );
231
225
}
232
226
233
227
@ Test
@@ -240,7 +234,7 @@ public void customSupportIncludeFilterWithNonIndexedTypeUseScan() {
240
234
Set <BeanDefinition > candidates = provider .findCandidateComponents (TEST_BASE_PACKAGE );
241
235
assertTrue (containsBeanClass (candidates , DefaultNamedComponent .class ));
242
236
assertEquals (1 , candidates .size ());
243
- assertBeanDefinitionType (candidates , ScannedGenericBeanDefinition . class );
237
+ assertBeanDefinitionType (candidates );
244
238
}
245
239
246
240
@ Test
@@ -251,7 +245,7 @@ public void customNotSupportedIncludeFilterUseScan() {
251
245
Set <BeanDefinition > candidates = provider .findCandidateComponents (TEST_BASE_PACKAGE );
252
246
assertTrue (containsBeanClass (candidates , StubFooDao .class ));
253
247
assertEquals (1 , candidates .size ());
254
- assertBeanDefinitionType (candidates , ScannedGenericBeanDefinition . class );
248
+ assertBeanDefinitionType (candidates );
255
249
}
256
250
257
251
@ Test
@@ -260,26 +254,25 @@ public void excludeFilterWithScan() {
260
254
provider .setResourceLoader (new DefaultResourceLoader (
261
255
CandidateComponentsTestClassLoader .disableIndex (getClass ().getClassLoader ())));
262
256
provider .addExcludeFilter (new RegexPatternTypeFilter (Pattern .compile (TEST_BASE_PACKAGE + ".*Named.*" )));
263
- testExclude (provider , ScannedGenericBeanDefinition . class );
257
+ testExclude (provider );
264
258
}
265
259
266
260
@ Test
267
261
public void excludeFilterWithIndex () {
268
262
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider (true );
269
263
provider .setResourceLoader (new DefaultResourceLoader (TEST_BASE_CLASSLOADER ));
270
264
provider .addExcludeFilter (new RegexPatternTypeFilter (Pattern .compile (TEST_BASE_PACKAGE + ".*Named.*" )));
271
- testExclude (provider , AnnotatedGenericBeanDefinition . class );
265
+ testExclude (provider );
272
266
}
273
267
274
- private void testExclude (ClassPathScanningCandidateComponentProvider provider ,
275
- Class <? extends BeanDefinition > expectedBeanDefinitionType ) {
268
+ private void testExclude (ClassPathScanningCandidateComponentProvider provider ) {
276
269
Set <BeanDefinition > candidates = provider .findCandidateComponents (TEST_BASE_PACKAGE );
277
270
assertTrue (containsBeanClass (candidates , FooServiceImpl .class ));
278
271
assertTrue (containsBeanClass (candidates , StubFooDao .class ));
279
272
assertTrue (containsBeanClass (candidates , ServiceInvocationCounter .class ));
280
273
assertTrue (containsBeanClass (candidates , BarComponent .class ));
281
274
assertEquals (4 , candidates .size ());
282
- assertBeanDefinitionType (candidates , expectedBeanDefinitionType );
275
+ assertBeanDefinitionType (candidates );
283
276
}
284
277
285
278
@ Test
@@ -510,10 +503,9 @@ private boolean containsBeanClass(Set<BeanDefinition> candidates, Class<?> beanC
510
503
return false ;
511
504
}
512
505
513
- private void assertBeanDefinitionType (Set <BeanDefinition > candidates ,
514
- Class <? extends BeanDefinition > expectedType ) {
506
+ private void assertBeanDefinitionType (Set <BeanDefinition > candidates ) {
515
507
candidates .forEach (c -> {
516
- assertThat (c , is (instanceOf (expectedType )));
508
+ assertThat (c , is (instanceOf (ScannedGenericBeanDefinition . class )));
517
509
});
518
510
}
519
511
0 commit comments