Fix SystemEnvironmentPropertyMapper tests and remove duplicate names
See gh-45741
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.context.properties.source;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.BiPredicate;
|
||||
@@ -40,10 +41,18 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
||||
|
||||
@Override
|
||||
public List<String> map(ConfigurationPropertyName configurationPropertyName) {
|
||||
return List.of(configurationPropertyName.toString(ToStringFormat.SYSTEM_ENVIRONMENT, true),
|
||||
configurationPropertyName.toString(ToStringFormat.LEGACY_SYSTEM_ENVIRONMENT, true),
|
||||
configurationPropertyName.toString(ToStringFormat.SYSTEM_ENVIRONMENT, false),
|
||||
configurationPropertyName.toString(ToStringFormat.LEGACY_SYSTEM_ENVIRONMENT, false));
|
||||
List<String> mapped = new ArrayList<>(4);
|
||||
addIfMissing(mapped, configurationPropertyName.toString(ToStringFormat.SYSTEM_ENVIRONMENT, true));
|
||||
addIfMissing(mapped, configurationPropertyName.toString(ToStringFormat.LEGACY_SYSTEM_ENVIRONMENT, true));
|
||||
addIfMissing(mapped, configurationPropertyName.toString(ToStringFormat.SYSTEM_ENVIRONMENT, false));
|
||||
addIfMissing(mapped, configurationPropertyName.toString(ToStringFormat.LEGACY_SYSTEM_ENVIRONMENT, false));
|
||||
return mapped;
|
||||
}
|
||||
|
||||
private void addIfMissing(List<String> list, String value) {
|
||||
if (!list.contains(value)) {
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -48,13 +48,14 @@ class SystemEnvironmentPropertyMapperTests extends AbstractPropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void mapFromConfigurationShouldReturnBestGuess() {
|
||||
assertThat(mapConfigurationPropertyName("server")).containsExactly("SERVER");
|
||||
assertThat(mapConfigurationPropertyName("server.port")).containsExactly("SERVER_PORT");
|
||||
assertThat(mapConfigurationPropertyName("host[0]")).containsExactly("HOST_0");
|
||||
assertThat(mapConfigurationPropertyName("host[0][1]")).containsExactly("HOST_0_1");
|
||||
assertThat(mapConfigurationPropertyName("host[0].name")).containsExactly("HOST_0_NAME");
|
||||
assertThat(mapConfigurationPropertyName("host.f00.name")).containsExactly("HOST_F00_NAME");
|
||||
assertThat(mapConfigurationPropertyName("foo.the-bar")).containsExactly("FOO_THEBAR", "FOO_THE_BAR");
|
||||
assertThat(mapConfigurationPropertyName("server")).containsExactly("SERVER", "server");
|
||||
assertThat(mapConfigurationPropertyName("server.port")).containsExactly("SERVER_PORT", "server_port");
|
||||
assertThat(mapConfigurationPropertyName("host[0]")).containsExactly("HOST_0", "host_0");
|
||||
assertThat(mapConfigurationPropertyName("host[0][1]")).containsExactly("HOST_0_1", "host_0_1");
|
||||
assertThat(mapConfigurationPropertyName("host[0].name")).containsExactly("HOST_0_NAME", "host_0_name");
|
||||
assertThat(mapConfigurationPropertyName("host.f00.name")).containsExactly("HOST_F00_NAME", "host_f00_name");
|
||||
assertThat(mapConfigurationPropertyName("foo.the-bar")).containsExactly("FOO_THEBAR", "FOO_THE_BAR",
|
||||
"foo_thebar", "foo_the_bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user