1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .lang .annotation .Retention ;
21
21
import java .lang .annotation .RetentionPolicy ;
22
22
import java .lang .annotation .Target ;
23
+ import java .util .Arrays ;
23
24
24
25
import org .junit .Test ;
25
26
@@ -81,7 +82,7 @@ public void indirectlyAnnotatedWithImport() {
81
82
}
82
83
83
84
@ Test
84
- public void importRegistrar () throws Exception {
85
+ public void importRegistrar () {
85
86
ImportedRegistrar .called = false ;
86
87
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
87
88
ctx .register (ImportingRegistrarConfig .class );
@@ -91,7 +92,7 @@ public void importRegistrar() throws Exception {
91
92
}
92
93
93
94
@ Test
94
- public void importRegistrarWithImport () throws Exception {
95
+ public void importRegistrarWithImport () {
95
96
ImportedRegistrar .called = false ;
96
97
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
97
98
ctx .register (ImportingRegistrarConfigWithImport .class );
@@ -120,6 +121,11 @@ public void metadataFromImportsTwoThenOne() {
120
121
((StandardAnnotationMetadata ) importMetadata ).getIntrospectedClass ());
121
122
}
122
123
124
+ @ Test
125
+ public void importAwareWithAnnotationAttributes () {
126
+ new AnnotationConfigApplicationContext (ApplicationConfiguration .class );
127
+ }
128
+
123
129
124
130
@ Configuration
125
131
@ Import (ImportedConfig .class )
@@ -290,4 +296,41 @@ public ConfigurationPhase getConfigurationPhase() {
290
296
}
291
297
}
292
298
299
+
300
+ @ Configuration
301
+ @ EnableFeature (policies = {
302
+ @ EnableFeature .FeaturePolicy (name = "one" ),
303
+ @ EnableFeature .FeaturePolicy (name = "two" )
304
+ })
305
+ public static class ApplicationConfiguration {
306
+ }
307
+
308
+
309
+ @ Target (ElementType .TYPE )
310
+ @ Retention (RetentionPolicy .RUNTIME )
311
+ @ Import (FeatureConfiguration .class )
312
+ public @interface EnableFeature {
313
+
314
+ FeaturePolicy [] policies () default {};
315
+
316
+ @interface FeaturePolicy {
317
+
318
+ String name ();
319
+ }
320
+ }
321
+
322
+
323
+ @ Configuration
324
+ public static class FeatureConfiguration implements ImportAware {
325
+
326
+ @ Override
327
+ public void setImportMetadata (AnnotationMetadata annotationMetadata ) {
328
+ AnnotationAttributes enableFeatureAttributes =
329
+ AnnotationAttributes .fromMap (annotationMetadata .getAnnotationAttributes (EnableFeature .class .getName ()));
330
+ assertEquals (EnableFeature .class , enableFeatureAttributes .annotationType ());
331
+ Arrays .stream (enableFeatureAttributes .getAnnotationArray ("policies" )).forEach (featurePolicyAttributes ->
332
+ assertEquals (EnableFeature .FeaturePolicy .class , featurePolicyAttributes .annotationType ()));
333
+ }
334
+ }
335
+
293
336
}
0 commit comments