Browse Source

Merge branch '6.0.x'

pull/31091/head
Sam Brannen 2 years ago
parent
commit
758dddce3b
  1. 5
      spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java
  2. 19
      spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DynamicPropertySourceNestedTests.java

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

@ -1,5 +1,5 @@ @@ -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.
@ -35,6 +35,7 @@ import org.springframework.test.context.TestContextAnnotationUtils; @@ -35,6 +35,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
*
* @author Phillip Webb
* @author Sam Brannen
* @author Yanming Zhou
* @since 5.2.5
* @see DynamicPropertiesContextCustomizer
*/
@ -54,10 +55,10 @@ class DynamicPropertiesContextCustomizerFactory implements ContextCustomizerFact @@ -54,10 +55,10 @@ class DynamicPropertiesContextCustomizerFactory implements ContextCustomizerFact
}
private void findMethods(Class<?> testClass, Set<Method> methods) {
methods.addAll(MethodIntrospector.selectMethods(testClass, this::isAnnotated));
if (TestContextAnnotationUtils.searchEnclosingClass(testClass)) {
findMethods(testClass.getEnclosingClass(), methods);
}
methods.addAll(MethodIntrospector.selectMethods(testClass, this::isAnnotated));
}
private boolean isAnnotated(Method method) {

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

@ -1,5 +1,5 @@ @@ -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.
@ -39,6 +39,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing @@ -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 { @@ -125,6 +126,22 @@ class DynamicPropertySourceNestedTests {
}
}
@Nested
class DynamicPropertySourceOverridesEnclosingClassTests {
@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 {

Loading…
Cancel
Save