33
33
import org .springframework .context .annotation .Configuration ;
34
34
import org .springframework .context .annotation .Import ;
35
35
import org .springframework .context .annotation .ImportSelector ;
36
+ import org .springframework .core .annotation .AliasFor ;
36
37
import org .springframework .core .type .AnnotationMetadata ;
37
38
38
39
import static org .assertj .core .api .Assertions .assertThat ;
41
42
* Tests for {@link ImportsContextCustomizer}.
42
43
*
43
44
* @author Andy Wilkinson
45
+ * @author Laurent Martelli
44
46
*/
45
47
class ImportsContextCustomizerTests {
46
48
@@ -80,6 +82,30 @@ void customizersForTestClassesWithDifferentJUnitAnnotationsAreEqual() {
80
82
.isEqualTo (new ImportsContextCustomizer (SecondJUnitAnnotatedTestClass .class ));
81
83
}
82
84
85
+ @ Test
86
+ void customizersForClassesWithDifferentImportsAreNotEqual () {
87
+ assertThat (new ImportsContextCustomizer (FirstAnnotatedTestClass .class ))
88
+ .isNotEqualTo (new ImportsContextCustomizer (SecondAnnotatedTestClass .class ));
89
+ }
90
+
91
+ @ Test
92
+ void customizersForClassesWithDifferentMetaImportsAreNotEqual () {
93
+ assertThat (new ImportsContextCustomizer (FirstMetaAnnotatedTestClass .class ))
94
+ .isNotEqualTo (new ImportsContextCustomizer (SecondMetaAnnotatedTestClass .class ));
95
+ }
96
+
97
+ @ Test
98
+ void customizersForClassesWithDifferentAliasedImportsAreNotEqual () {
99
+ assertThat (new ImportsContextCustomizer (FirstAliasAnnotatedTestClass .class ))
100
+ .isNotEqualTo (new ImportsContextCustomizer (SecondAliasAnnotatedTestClass .class ));
101
+ }
102
+
103
+ @ Test
104
+ void importsCanBeScatteredOnMultipleAnnotations () {
105
+ assertThat (new ImportsContextCustomizer (SingleImportAnnotationTestClass .class ))
106
+ .isEqualTo (new ImportsContextCustomizer (MultipleImportAnnotationTestClass .class ));
107
+ }
108
+
83
109
@ Import (TestImportSelector .class )
84
110
@ Indicator1
85
111
static class FirstImportSelectorAnnotatedClass {
@@ -152,6 +178,17 @@ static class SecondJUnitAnnotatedTestClass {
152
178
153
179
}
154
180
181
+ @ Import ({ FirstImportedClass .class , SecondImportedClass .class })
182
+ static class SingleImportAnnotationTestClass {
183
+
184
+ }
185
+
186
+ @ FirstMetaImport
187
+ @ Import (SecondImportedClass .class )
188
+ static class MultipleImportAnnotationTestClass {
189
+
190
+ }
191
+
155
192
@ Retention (RetentionPolicy .RUNTIME )
156
193
@interface Indicator1 {
157
194
@@ -162,6 +199,65 @@ static class SecondJUnitAnnotatedTestClass {
162
199
163
200
}
164
201
202
+ @ Retention (RetentionPolicy .RUNTIME )
203
+ @ Import (AliasFor .class )
204
+ public @interface AliasedImport {
205
+
206
+ @ AliasFor (annotation = Import .class )
207
+ Class <?>[] value ();
208
+
209
+ }
210
+
211
+ @ Retention (RetentionPolicy .RUNTIME )
212
+ @ Import (FirstImportedClass .class )
213
+ public @interface FirstMetaImport {
214
+
215
+ }
216
+
217
+ @ Retention (RetentionPolicy .RUNTIME )
218
+ @ Import (SecondImportedClass .class )
219
+ public @interface SecondMetaImport {
220
+
221
+ }
222
+
223
+ static class FirstImportedClass {
224
+
225
+ }
226
+
227
+ static class SecondImportedClass {
228
+
229
+ }
230
+
231
+ @ AliasedImport (FirstImportedClass .class )
232
+ static class FirstAliasAnnotatedTestClass {
233
+
234
+ }
235
+
236
+ @ AliasedImport (SecondImportedClass .class )
237
+ static class SecondAliasAnnotatedTestClass {
238
+
239
+ }
240
+
241
+ @ FirstMetaImport
242
+ static class FirstMetaAnnotatedTestClass {
243
+
244
+ }
245
+
246
+ @ SecondMetaImport
247
+ static class SecondMetaAnnotatedTestClass {
248
+
249
+ }
250
+
251
+ @ Import (FirstImportedClass .class )
252
+ static class FirstAnnotatedTestClass {
253
+
254
+ }
255
+
256
+ @ Import (SecondImportedClass .class )
257
+ static class SecondAnnotatedTestClass {
258
+
259
+ }
260
+
165
261
static class TestImportSelector implements ImportSelector {
166
262
167
263
@ Override
0 commit comments