|
19 | 19 | import java.util.ArrayList;
|
20 | 20 | import java.util.Collections;
|
21 | 21 | import java.util.EnumSet;
|
| 22 | +import java.util.LinkedHashMap; |
22 | 23 | import java.util.LinkedHashSet;
|
23 | 24 | import java.util.LinkedList;
|
24 | 25 | import java.util.List;
|
| 26 | +import java.util.Map; |
25 | 27 | import java.util.Set;
|
26 | 28 |
|
27 | 29 | import org.junit.jupiter.api.Test;
|
|
33 | 35 | import org.springframework.boot.context.properties.source.MockConfigurationPropertySource;
|
34 | 36 | import org.springframework.core.ResolvableType;
|
35 | 37 | import org.springframework.core.env.StandardEnvironment;
|
| 38 | +import org.springframework.core.env.SystemEnvironmentPropertySource; |
36 | 39 | import org.springframework.test.context.support.TestPropertySourceUtils;
|
37 | 40 |
|
38 | 41 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -465,6 +468,36 @@ void bindToBeanWithEnumSetCollection() {
|
465 | 468 | assertThat(result.getValues().get(0)).containsExactly(ExampleEnum.FOO_BAR, ExampleEnum.BAR_BAZ);
|
466 | 469 | }
|
467 | 470 |
|
| 471 | + @Test |
| 472 | + void bindToWellFormedSystemEnvironmentVariableProperty() { |
| 473 | + // gh-46184 |
| 474 | + Map<String, Object> map = new LinkedHashMap<>(); |
| 475 | + map.put("FOO_THENAMES_0_FIRST", "spring"); |
| 476 | + map.put("FOO_THENAMES_0_LAST", "boot"); |
| 477 | + map.put("FOO_THENAMES_1_FIRST", "binding"); |
| 478 | + map.put("FOO_THENAMES_1_LAST", "test"); |
| 479 | + SystemEnvironmentPropertySource propertySource = new SystemEnvironmentPropertySource( |
| 480 | + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, map); |
| 481 | + this.sources.add(ConfigurationPropertySource.from(propertySource)); |
| 482 | + BeanWithCamelCaseNameList result = this.binder.bind("foo", BeanWithCamelCaseNameList.class).get(); |
| 483 | + assertThat(result.theNames()).containsExactly(new Name("spring", "boot"), new Name("binding", "test")); |
| 484 | + } |
| 485 | + |
| 486 | + @Test |
| 487 | + void bindToLegacySystemEnvironmentVariableProperty() { |
| 488 | + // gh-46184 |
| 489 | + Map<String, Object> map = new LinkedHashMap<>(); |
| 490 | + map.put("FOO_THE_NAMES_0_FIRST", "spring"); |
| 491 | + map.put("FOO_THE_NAMES_0_LAST", "boot"); |
| 492 | + map.put("FOO_THE_NAMES_1_FIRST", "binding"); |
| 493 | + map.put("FOO_THE_NAMES_1_LAST", "test"); |
| 494 | + SystemEnvironmentPropertySource propertySource = new SystemEnvironmentPropertySource( |
| 495 | + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, map); |
| 496 | + this.sources.add(ConfigurationPropertySource.from(propertySource)); |
| 497 | + BeanWithCamelCaseNameList result = this.binder.bind("foo", BeanWithCamelCaseNameList.class).get(); |
| 498 | + assertThat(result.theNames()).containsExactly(new Name("spring", "boot"), new Name("binding", "test")); |
| 499 | + } |
| 500 | + |
468 | 501 | static class ExampleCollectionBean {
|
469 | 502 |
|
470 | 503 | private final List<String> items = new ArrayList<>();
|
@@ -607,6 +640,10 @@ List<EnumSet<ExampleEnum>> getValues() {
|
607 | 640 |
|
608 | 641 | }
|
609 | 642 |
|
| 643 | + record BeanWithCamelCaseNameList(List<Name> theNames) { |
| 644 | + |
| 645 | + } |
| 646 | + |
610 | 647 | record Name(String first, String last) {
|
611 | 648 |
|
612 | 649 | }
|
|
0 commit comments