From bc291949c209643a97a66b361696aee5d44b91ee Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Wed, 22 May 2024 15:09:54 +0200 Subject: [PATCH] Polishing --- .../DynamicPropertiesContextCustomizer.java | 23 +++++++++++-------- .../support/DynamicValuesPropertySource.java | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java index ed6df381b1f..f2ebdd1c23c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java @@ -45,6 +45,8 @@ import org.springframework.util.ReflectionUtils; * @author Sam Brannen * @since 5.2.5 * @see DynamicPropertiesContextCustomizerFactory + * @see DefaultDynamicPropertyRegistry + * @see DynamicPropertySourceBeanInitializer */ class DynamicPropertiesContextCustomizer implements ContextCustomizer { @@ -59,20 +61,11 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer { DynamicPropertiesContextCustomizer(Set methods) { - methods.forEach(this::assertValid); + methods.forEach(DynamicPropertiesContextCustomizer::assertValid); this.methods = methods; } - private void assertValid(Method method) { - Assert.state(Modifier.isStatic(method.getModifiers()), - () -> "@DynamicPropertySource method '" + method.getName() + "' must be static"); - Class[] types = method.getParameterTypes(); - Assert.state(types.length == 1 && types[0] == DynamicPropertyRegistry.class, - () -> "@DynamicPropertySource method '" + method.getName() + - "' must accept a single DynamicPropertyRegistry argument"); - } - @Override public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { ConfigurableEnvironment environment = context.getEnvironment(); @@ -115,4 +108,14 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer { return this.methods.hashCode(); } + + private static void assertValid(Method method) { + Assert.state(Modifier.isStatic(method.getModifiers()), + () -> "@DynamicPropertySource method '" + method.getName() + "' must be static"); + Class[] types = method.getParameterTypes(); + Assert.state(types.length == 1 && types[0] == DynamicPropertyRegistry.class, + () -> "@DynamicPropertySource method '" + method.getName() + + "' must accept a single DynamicPropertyRegistry argument"); + } + } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java index 8d60699e04b..b595e7e2a1e 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java @@ -41,6 +41,7 @@ class DynamicValuesPropertySource extends MapPropertySource { super(PROPERTY_SOURCE_NAME, Collections.unmodifiableMap(valueSuppliers)); } + @Override @Nullable public Object getProperty(String name) {