Browse Source

Polishing

pull/32874/head
Sam Brannen 2 years ago
parent
commit
bc291949c2
  1. 23
      spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java
  2. 1
      spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java

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

@ -45,6 +45,8 @@ import org.springframework.util.ReflectionUtils; @@ -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 { @@ -59,20 +61,11 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer {
DynamicPropertiesContextCustomizer(Set<Method> 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 { @@ -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");
}
}

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

@ -41,6 +41,7 @@ class DynamicValuesPropertySource extends MapPropertySource { @@ -41,6 +41,7 @@ class DynamicValuesPropertySource extends MapPropertySource {
super(PROPERTY_SOURCE_NAME, Collections.unmodifiableMap(valueSuppliers));
}
@Override
@Nullable
public Object getProperty(String name) {

Loading…
Cancel
Save