mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-29 13:39:16 +00:00
Merge pull request #50625 from SJvaca30
Closes gh-50625 * gh-50625: Add nested override coverage for @SpringBootTest imports
This commit is contained in:
+34
@@ -24,6 +24,8 @@ import org.springframework.boot.test.context.SpringBootTestImportTests.ImportedB
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.NestedTestConfiguration;
|
||||
import org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -68,6 +70,38 @@ class SpringBootTestImportTests {
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(classes = Config.class)
|
||||
@Import(ImportedByNestedTests.class)
|
||||
@NestedTestConfiguration(EnclosingConfiguration.OVERRIDE)
|
||||
class OverrideNestedTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
private ImportedByContainingTests importedByContainingTests;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ImportedByNestedTests importedByNestedTests;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
void sameClassImportIsHonored() {
|
||||
assertThat(this.importedByNestedTests).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void containingClassImportIsNotInherited() {
|
||||
assertThat(this.importedByContainingTests).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void containingClassTestPropertySourceIsNotInherited() {
|
||||
assertThat(this.environment.getProperty("a")).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class Config {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user