Stop using Constants utility in PropertyPlaceholderConfigurer

See gh-30851
This commit is contained in:
Sam Brannen
2023-07-16 12:55:25 +02:00
parent cebda46469
commit a92bd42236
2 changed files with 42 additions and 4 deletions

View File

@@ -16,7 +16,10 @@
package org.springframework.beans.factory.config;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Properties;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -27,8 +30,10 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.testfixture.beans.TestBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
import static org.springframework.beans.factory.support.BeanDefinitionReaderUtils.registerWithGeneratedName;
@@ -235,4 +240,23 @@ class PropertyPlaceholderConfigurerTests {
System.clearProperty("my.name");
}
/**
* This test effectively verifies that the internal 'constants' map is properly
* configured for all SYSTEM_PROPERTIES_MODE_ constants defined in
* {@link PropertyPlaceholderConfigurer}.
*/
@Test
@SuppressWarnings("deprecation")
void setSystemPropertiesModeNameToAllSupportedValues() {
streamSystemPropertiesModeConstants()
.map(Field::getName)
.forEach(name -> assertThatNoException().as(name).isThrownBy(() -> ppc.setSystemPropertiesModeName(name)));
}
private static Stream<Field> streamSystemPropertiesModeConstants() {
return Arrays.stream(PropertyPlaceholderConfigurer.class.getFields())
.filter(ReflectionUtils::isPublicStaticFinal)
.filter(field -> field.getName().startsWith("SYSTEM_PROPERTIES_MODE_"));
}
}