|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 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.
|
|
62 | 62 | *
|
63 | 63 | * @author Phillip Webb
|
64 | 64 | * @author Stephane Nicoll
|
| 65 | + * @author Daeho Kwon |
65 | 66 | */
|
66 | 67 | @SuppressWarnings("resource")
|
67 | 68 | public class ImportSelectorTests {
|
@@ -203,6 +204,71 @@ void invokeAwareMethodsInImportGroup() {
|
203 | 204 | assertThat(TestImportGroup.environment).isEqualTo(context.getEnvironment());
|
204 | 205 | }
|
205 | 206 |
|
| 207 | + @Test |
| 208 | + void importAnnotationOnImplementedInterfaceIsRespected() { |
| 209 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( |
| 210 | + InterfaceBasedConfig.class); |
| 211 | + |
| 212 | + assertThat(context.getBean(ImportedConfig.class)).isNotNull(); |
| 213 | + assertThat(context.getBean(ImportedBean.class)).isNotNull(); |
| 214 | + assertThat(context.getBean(ImportedBean.class).name()).isEqualTo("imported"); |
| 215 | + } |
| 216 | + |
| 217 | + @Test |
| 218 | + void localImportShouldOverrideInterfaceImport() { |
| 219 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( |
| 220 | + OverridingConfig.class); |
| 221 | + |
| 222 | + assertThat(context.getBean(ImportedConfig.class)).isNotNull(); |
| 223 | + assertThat(context.getBean(ImportedBean.class)).isNotNull(); |
| 224 | + assertThat(context.getBean(ImportedBean.class).name()).isEqualTo("from class"); |
| 225 | + } |
| 226 | + |
| 227 | + @Import(ImportedConfig.class) |
| 228 | + interface ConfigImportMarker { |
| 229 | + } |
| 230 | + |
| 231 | + @Configuration |
| 232 | + static class InterfaceBasedConfig implements ConfigImportMarker { |
| 233 | + } |
| 234 | + |
| 235 | + @Configuration |
| 236 | + @Import(OverridingImportedConfig.class) |
| 237 | + static class OverridingConfig implements ConfigImportMarker { |
| 238 | + } |
| 239 | + |
| 240 | + @Configuration |
| 241 | + static class OverridingImportedConfig { |
| 242 | + @Bean |
| 243 | + ImportedBean importedBean() { |
| 244 | + return new ImportedBean("from class"); |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + static class ImportedBean { |
| 249 | + |
| 250 | + private final String name; |
| 251 | + |
| 252 | + ImportedBean() { |
| 253 | + this.name = "imported"; |
| 254 | + } |
| 255 | + |
| 256 | + ImportedBean(String name) { |
| 257 | + this.name = name; |
| 258 | + } |
| 259 | + |
| 260 | + String name() { |
| 261 | + return name; |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + @Configuration |
| 266 | + static class ImportedConfig { |
| 267 | + @Bean |
| 268 | + ImportedBean importedBean() { |
| 269 | + return new ImportedBean(); |
| 270 | + } |
| 271 | + } |
206 | 272 |
|
207 | 273 | @Configuration
|
208 | 274 | @Import(SampleImportSelector.class)
|
|
0 commit comments