|
|
|
|
@ -20,6 +20,7 @@ import java.net.InetAddress;
@@ -20,6 +20,7 @@ import java.net.InetAddress;
|
|
|
|
|
import java.util.AbstractMap; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.EnumMap; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
@ -79,6 +80,9 @@ class MapBinderTests {
@@ -79,6 +80,9 @@ class MapBinderTests {
|
|
|
|
|
private static final Bindable<Map<String, String[]>> STRING_ARRAY_MAP = Bindable.mapOf(String.class, |
|
|
|
|
String[].class); |
|
|
|
|
|
|
|
|
|
private static final Bindable<EnumMap<ExampleEnum, String>> EXAMPLE_ENUM_STRING_ENUM_MAP = Bindable |
|
|
|
|
.of(ResolvableType.forClassWithGenerics(EnumMap.class, ExampleEnum.class, String.class)); |
|
|
|
|
|
|
|
|
|
private final List<ConfigurationPropertySource> sources = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
private final Binder binder = new Binder(this.sources); |
|
|
|
|
@ -637,6 +641,17 @@ class MapBinderTests {
@@ -637,6 +641,17 @@ class MapBinderTests {
|
|
|
|
|
assertThat(result.getCustomMap().getSource()).isEqualTo("value"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void bindToEnumMapShouldBind() { |
|
|
|
|
MockConfigurationPropertySource source = new MockConfigurationPropertySource(); |
|
|
|
|
source.put("props.foo-bar", "value"); |
|
|
|
|
this.sources.add(source); |
|
|
|
|
Binder binder = new Binder(this.sources, null, null, null); |
|
|
|
|
EnumMap<ExampleEnum, String> result = binder.bind("props", EXAMPLE_ENUM_STRING_ENUM_MAP).get(); |
|
|
|
|
assertThat(result).hasSize(1).containsEntry(ExampleEnum.FOO_BAR, "value"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) { |
|
|
|
|
ResolvableType keyType = ResolvableType.forClass(keyGeneric); |
|
|
|
|
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType)); |
|
|
|
|
|