Allow overriding dynamic property from enclosing class in nested test class
Prior to this commit, a dynamic property registered via a @DynamicPropertySource method in a @Nested test class was not able to override a property registered via a @DynamicPropertySource method in the enclosing class. See gh-26091 Closes gh-31083
This commit is contained in:
committed by
Sam Brannen
parent
8a6c0cd221
commit
368036cab4
@@ -39,6 +39,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
|
||||
* {@link SpringExtension} in a JUnit Jupiter environment.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Yanming Zhou
|
||||
* @since 5.3.2
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
@@ -125,6 +126,22 @@ class DynamicPropertySourceNestedTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class DynamicPropertySourceOverrideEnclosingClassTests {
|
||||
|
||||
@DynamicPropertySource
|
||||
static void overrideDynamicPropertyFromEnclosingClass(DynamicPropertyRegistry registry) {
|
||||
registry.add(TEST_CONTAINER_PORT, () -> -999);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("@Service has values injected from @DynamicPropertySource in enclosing class and nested class")
|
||||
void serviceHasInjectedValues(@Autowired Service service) {
|
||||
assertThat(service.getIp()).isEqualTo("127.0.0.1");
|
||||
assertThat(service.getPort()).isEqualTo(-999);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static abstract class DynamicPropertySourceSuperclass {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user