Skip to content

Commit 9baf23c

Browse files
Laurent Martelliphilwebb
authored andcommitted
Test that ImportsContextCustomizer can support @AliasFor
Add test to ensure that `ImportsContextCustomizer` can support `@AliasFor` annotations. See gh-34917
1 parent 1850d19 commit 9baf23c

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/ImportsContextCustomizerTests.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.context.annotation.Configuration;
3434
import org.springframework.context.annotation.Import;
3535
import org.springframework.context.annotation.ImportSelector;
36+
import org.springframework.core.annotation.AliasFor;
3637
import org.springframework.core.type.AnnotationMetadata;
3738

3839
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,6 +42,7 @@
4142
* Tests for {@link ImportsContextCustomizer}.
4243
*
4344
* @author Andy Wilkinson
45+
* @author Laurent Martelli
4446
*/
4547
class ImportsContextCustomizerTests {
4648

@@ -80,6 +82,30 @@ void customizersForTestClassesWithDifferentJUnitAnnotationsAreEqual() {
8082
.isEqualTo(new ImportsContextCustomizer(SecondJUnitAnnotatedTestClass.class));
8183
}
8284

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+
83109
@Import(TestImportSelector.class)
84110
@Indicator1
85111
static class FirstImportSelectorAnnotatedClass {
@@ -152,6 +178,17 @@ static class SecondJUnitAnnotatedTestClass {
152178

153179
}
154180

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+
155192
@Retention(RetentionPolicy.RUNTIME)
156193
@interface Indicator1 {
157194

@@ -162,6 +199,65 @@ static class SecondJUnitAnnotatedTestClass {
162199

163200
}
164201

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+
165261
static class TestImportSelector implements ImportSelector {
166262

167263
@Override

0 commit comments

Comments
 (0)