Revise contribution
Beginning with Java 16, inner classes may contain static members. We therefore need to search for @DynamicPropertySource methods in the current class after searching enclosing classes so that a local @DynamicPropertySource method can override properties registered in an enclosing class. However, since Spring Framework 5.3.x is built using Java 8, this commit removes DynamicPropertySourceOverridesEnclosingClassTests since it declares a static method in a @Nested (inner) test class, which results in a compiler error on Java 8. See https://bugs.openjdk.org/browse/JDK-8254321 See gh-31085
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,6 +55,11 @@ class DynamicPropertiesContextCustomizerFactory implements ContextCustomizerFact
|
||||
}
|
||||
|
||||
private void findMethods(Class<?> testClass, Set<Method> methods) {
|
||||
// Beginning with Java 16, inner classes may contain static members.
|
||||
// We therefore need to search for @DynamicPropertySource methods in the
|
||||
// current class after searching enclosing classes so that a local
|
||||
// @DynamicPropertySource method can override properties registered in
|
||||
// an enclosing class.
|
||||
if (TestContextAnnotationUtils.searchEnclosingClass(testClass)) {
|
||||
findMethods(testClass.getEnclosingClass(), methods);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ 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
|
||||
@@ -126,22 +125,6 @@ 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