Skip to content

Commit d7ac89e

Browse files
committed
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
1 parent 9894174 commit d7ac89e

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,6 +55,11 @@ public DynamicPropertiesContextCustomizer createContextCustomizer(Class<?> testC
5555
}
5656

5757
private void findMethods(Class<?> testClass, Set<Method> methods) {
58+
// Beginning with Java 16, inner classes may contain static members.
59+
// We therefore need to search for @DynamicPropertySource methods in the
60+
// current class after searching enclosing classes so that a local
61+
// @DynamicPropertySource method can override properties registered in
62+
// an enclosing class.
5863
if (TestContextAnnotationUtils.searchEnclosingClass(testClass)) {
5964
findMethods(testClass.getEnclosingClass(), methods);
6065
}

spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DynamicPropertySourceNestedTests.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
* {@link SpringExtension} in a JUnit Jupiter environment.
4040
*
4141
* @author Sam Brannen
42-
* @author Yanming Zhou
4342
* @since 5.3.2
4443
*/
4544
@SpringJUnitConfig
@@ -126,22 +125,6 @@ void serviceHasInjectedValues(@Autowired Service service) {
126125
}
127126
}
128127

129-
@Nested
130-
class DynamicPropertySourceOverrideEnclosingClassTests {
131-
132-
@DynamicPropertySource
133-
static void overrideDynamicPropertyFromEnclosingClass(DynamicPropertyRegistry registry) {
134-
registry.add(TEST_CONTAINER_PORT, () -> -999);
135-
}
136-
137-
@Test
138-
@DisplayName("@Service has values injected from @DynamicPropertySource in enclosing class and nested class")
139-
void serviceHasInjectedValues(@Autowired Service service) {
140-
assertThat(service.getIp()).isEqualTo("127.0.0.1");
141-
assertThat(service.getPort()).isEqualTo(-999);
142-
}
143-
144-
}
145128

146129
static abstract class DynamicPropertySourceSuperclass {
147130

0 commit comments

Comments
 (0)