|
|
@ -351,10 +351,10 @@ public class MapBinderTests {
|
|
|
|
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
|
|
|
|
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
|
|
|
|
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP;
|
|
|
|
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP;
|
|
|
|
this.binder.bind("foo", target, handler);
|
|
|
|
this.binder.bind("foo", target, handler);
|
|
|
|
InOrder inOrder = inOrder(handler);
|
|
|
|
InOrder ordered = inOrder(handler);
|
|
|
|
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
|
|
|
|
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
|
|
|
|
eq(Bindable.of(Integer.class)), any(), eq(1));
|
|
|
|
eq(Bindable.of(Integer.class)), any(), eq(1));
|
|
|
|
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")),
|
|
|
|
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")),
|
|
|
|
eq(target), any(), isA(Map.class));
|
|
|
|
eq(target), any(), isA(Map.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -366,27 +366,28 @@ public class MapBinderTests {
|
|
|
|
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
|
|
|
|
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
|
|
|
|
Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP;
|
|
|
|
Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP;
|
|
|
|
this.binder.bind("foo", target, handler);
|
|
|
|
this.binder.bind("foo", target, handler);
|
|
|
|
InOrder inOrder = inOrder(handler);
|
|
|
|
InOrder ordered = inOrder(handler);
|
|
|
|
ArgumentCaptor<String[]> array = ArgumentCaptor.forClass(String[].class);
|
|
|
|
ArgumentCaptor<String[]> array = ArgumentCaptor.forClass(String[].class);
|
|
|
|
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
|
|
|
|
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
|
|
|
|
eq(Bindable.of(String[].class)), any(), array.capture());
|
|
|
|
eq(Bindable.of(String[].class)), any(), array.capture());
|
|
|
|
assertThat(array.getValue()).containsExactly("a", "b", "c");
|
|
|
|
assertThat(array.getValue()).containsExactly("a", "b", "c");
|
|
|
|
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")),
|
|
|
|
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")),
|
|
|
|
eq(target), any(), isA(Map.class));
|
|
|
|
eq(target), any(), isA(Map.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToMapNonScalarCollectionShouldPopulateMap() throws Exception {
|
|
|
|
public void bindToMapNonScalarCollectionShouldPopulateMap() throws Exception {
|
|
|
|
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
|
|
|
|
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
|
|
|
|
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class, valueType.getType());
|
|
|
|
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class,
|
|
|
|
|
|
|
|
valueType.getType());
|
|
|
|
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
|
|
|
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
|
|
|
source.put("foo.bar[0].value", "a");
|
|
|
|
source.put("foo.bar[0].value", "a");
|
|
|
|
source.put("foo.bar[1].value", "b");
|
|
|
|
source.put("foo.bar[1].value", "b");
|
|
|
|
source.put("foo.bar[2].value", "c");
|
|
|
|
source.put("foo.bar[2].value", "c");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(source);
|
|
|
|
.add(source);
|
|
|
|
|
|
|
|
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
|
|
|
|
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
|
|
|
|
List<String> values = map.get("bar").stream().map(JavaBean::getValue).collect(Collectors.toList());
|
|
|
|
List<String> values = map.get("bar").stream().map(JavaBean::getValue)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
assertThat(values).containsExactly("a", "b", "c");
|
|
|
|
assertThat(values).containsExactly("a", "b", "c");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -401,9 +402,10 @@ public class MapBinderTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToMapShouldNotTreatClassWithStringConstructorAsScalar() throws Exception {
|
|
|
|
public void bindToMapShouldNotTreatClassWithStringConstructorAsScalar()
|
|
|
|
this.sources
|
|
|
|
throws Exception {
|
|
|
|
.add(new MockConfigurationPropertySource("foo.bar.pattern", "1", "line1"));
|
|
|
|
this.sources.add(
|
|
|
|
|
|
|
|
new MockConfigurationPropertySource("foo.bar.pattern", "1", "line1"));
|
|
|
|
Bindable<Map<String, Foo>> target = Bindable.mapOf(String.class, Foo.class);
|
|
|
|
Bindable<Map<String, Foo>> target = Bindable.mapOf(String.class, Foo.class);
|
|
|
|
Map<String, Foo> map = this.binder.bind("foo", target).get();
|
|
|
|
Map<String, Foo> map = this.binder.bind("foo", target).get();
|
|
|
|
assertThat(map.get("bar").getPattern()).isEqualTo("1");
|
|
|
|
assertThat(map.get("bar").getPattern()).isEqualTo("1");
|
|
|
@ -415,18 +417,17 @@ public class MapBinderTests {
|
|
|
|
mockSource.put("foo.bar.baz[0]", "a");
|
|
|
|
mockSource.put("foo.bar.baz[0]", "a");
|
|
|
|
mockSource.put("foo.bar.baz[1]", "b");
|
|
|
|
mockSource.put("foo.bar.baz[1]", "b");
|
|
|
|
mockSource.put("foo.bar.baz[2]", "c");
|
|
|
|
mockSource.put("foo.bar.baz[2]", "c");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(mockSource);
|
|
|
|
.add(mockSource);
|
|
|
|
|
|
|
|
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
|
|
|
|
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
|
|
|
|
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
|
|
|
|
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot() throws Exception {
|
|
|
|
public void bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot()
|
|
|
|
|
|
|
|
throws Exception {
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
mockSource.put("foo.bar.baz", "a,b,c");
|
|
|
|
mockSource.put("foo.bar.baz", "a,b,c");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(mockSource);
|
|
|
|
.add(mockSource);
|
|
|
|
|
|
|
|
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
|
|
|
|
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
|
|
|
|
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
|
|
|
|
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -434,13 +435,13 @@ public class MapBinderTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToMapStringCollectionWithDotKeysShouldPreserveDot() throws Exception {
|
|
|
|
public void bindToMapStringCollectionWithDotKeysShouldPreserveDot() throws Exception {
|
|
|
|
Bindable<List<String>> valueType = Bindable.listOf(String.class);
|
|
|
|
Bindable<List<String>> valueType = Bindable.listOf(String.class);
|
|
|
|
Bindable<Map<String, List<String>>> target = getMapBindable(String.class, valueType.getType());
|
|
|
|
Bindable<Map<String, List<String>>> target = getMapBindable(String.class,
|
|
|
|
|
|
|
|
valueType.getType());
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
mockSource.put("foo.bar.baz[0]", "a");
|
|
|
|
mockSource.put("foo.bar.baz[0]", "a");
|
|
|
|
mockSource.put("foo.bar.baz[1]", "b");
|
|
|
|
mockSource.put("foo.bar.baz[1]", "b");
|
|
|
|
mockSource.put("foo.bar.baz[2]", "c");
|
|
|
|
mockSource.put("foo.bar.baz[2]", "c");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(mockSource);
|
|
|
|
.add(mockSource);
|
|
|
|
|
|
|
|
Map<String, List<String>> map = this.binder.bind("foo", target).get();
|
|
|
|
Map<String, List<String>> map = this.binder.bind("foo", target).get();
|
|
|
|
List<String> values = map.get("bar.baz");
|
|
|
|
List<String> values = map.get("bar.baz");
|
|
|
|
assertThat(values).containsExactly("a", "b", "c");
|
|
|
|
assertThat(values).containsExactly("a", "b", "c");
|
|
|
@ -449,28 +450,30 @@ public class MapBinderTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToMapNonScalarCollectionWithDotKeysShouldBind() throws Exception {
|
|
|
|
public void bindToMapNonScalarCollectionWithDotKeysShouldBind() throws Exception {
|
|
|
|
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
|
|
|
|
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
|
|
|
|
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class, valueType.getType());
|
|
|
|
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class,
|
|
|
|
|
|
|
|
valueType.getType());
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
mockSource.put("foo.bar.baz[0].value", "a");
|
|
|
|
mockSource.put("foo.bar.baz[0].value", "a");
|
|
|
|
mockSource.put("foo.bar.baz[1].value", "b");
|
|
|
|
mockSource.put("foo.bar.baz[1].value", "b");
|
|
|
|
mockSource.put("foo.bar.baz[2].value", "c");
|
|
|
|
mockSource.put("foo.bar.baz[2].value", "c");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(mockSource);
|
|
|
|
.add(mockSource);
|
|
|
|
|
|
|
|
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
|
|
|
|
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
|
|
|
|
List<String> values = map.get("bar.baz").stream().map(JavaBean::getValue).collect(Collectors.toList());
|
|
|
|
List<String> values = map.get("bar.baz").stream().map(JavaBean::getValue)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
assertThat(values).containsExactly("a", "b", "c");
|
|
|
|
assertThat(values).containsExactly("a", "b", "c");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToListOfMaps() throws Exception {
|
|
|
|
public void bindToListOfMaps() throws Exception {
|
|
|
|
Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class);
|
|
|
|
Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class);
|
|
|
|
Bindable<Map<String, List<Integer>>> mapBindable = getMapBindable(String.class, listBindable.getType());
|
|
|
|
Bindable<Map<String, List<Integer>>> mapBindable = getMapBindable(String.class,
|
|
|
|
Bindable<List<Map<String, List<Integer>>>> target = getListBindable(mapBindable.getType());
|
|
|
|
listBindable.getType());
|
|
|
|
|
|
|
|
Bindable<List<Map<String, List<Integer>>>> target = getListBindable(
|
|
|
|
|
|
|
|
mapBindable.getType());
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
mockSource.put("foo[0].a", "1,2,3");
|
|
|
|
mockSource.put("foo[0].a", "1,2,3");
|
|
|
|
mockSource.put("foo[1].b", "4,5,6");
|
|
|
|
mockSource.put("foo[1].b", "4,5,6");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(mockSource);
|
|
|
|
.add(mockSource);
|
|
|
|
|
|
|
|
List<Map<String, List<Integer>>> list = this.binder.bind("foo", target).get();
|
|
|
|
List<Map<String, List<Integer>>> list = this.binder.bind("foo", target).get();
|
|
|
|
assertThat(list.get(0).get("a")).containsExactly(1, 2, 3);
|
|
|
|
assertThat(list.get(0).get("a")).containsExactly(1, 2, 3);
|
|
|
|
assertThat(list.get(1).get("b")).containsExactly(4, 5, 6);
|
|
|
|
assertThat(list.get(1).get("b")).containsExactly(4, 5, 6);
|
|
|
@ -479,12 +482,12 @@ public class MapBinderTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToMapWithNumberKeyAndCommaSeparated() throws Exception {
|
|
|
|
public void bindToMapWithNumberKeyAndCommaSeparated() throws Exception {
|
|
|
|
Bindable<List<String>> listBindable = Bindable.listOf(String.class);
|
|
|
|
Bindable<List<String>> listBindable = Bindable.listOf(String.class);
|
|
|
|
Bindable<Map<Integer, List<String>>> target = getMapBindable(Integer.class, listBindable.getType());
|
|
|
|
Bindable<Map<Integer, List<String>>> target = getMapBindable(Integer.class,
|
|
|
|
|
|
|
|
listBindable.getType());
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
mockSource.put("foo[0]", "a,b,c");
|
|
|
|
mockSource.put("foo[0]", "a,b,c");
|
|
|
|
mockSource.put("foo[1]", "e,f,g");
|
|
|
|
mockSource.put("foo[1]", "e,f,g");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(mockSource);
|
|
|
|
.add(mockSource);
|
|
|
|
|
|
|
|
Map<Integer, List<String>> map = this.binder.bind("foo", target).get();
|
|
|
|
Map<Integer, List<String>> map = this.binder.bind("foo", target).get();
|
|
|
|
assertThat(map.get(0)).containsExactly("a", "b", "c");
|
|
|
|
assertThat(map.get(0)).containsExactly("a", "b", "c");
|
|
|
|
assertThat(map.get(1)).containsExactly("e", "f", "g");
|
|
|
|
assertThat(map.get(1)).containsExactly("e", "f", "g");
|
|
|
@ -493,12 +496,12 @@ public class MapBinderTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void bindToMapWithNumberKeyAndIndexed() throws Exception {
|
|
|
|
public void bindToMapWithNumberKeyAndIndexed() throws Exception {
|
|
|
|
Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class);
|
|
|
|
Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class);
|
|
|
|
Bindable<Map<Integer, List<Integer>>> target = getMapBindable(Integer.class, listBindable.getType());
|
|
|
|
Bindable<Map<Integer, List<Integer>>> target = getMapBindable(Integer.class,
|
|
|
|
|
|
|
|
listBindable.getType());
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
|
|
|
|
mockSource.put("foo[0][0]", "8");
|
|
|
|
mockSource.put("foo[0][0]", "8");
|
|
|
|
mockSource.put("foo[0][1]", "9");
|
|
|
|
mockSource.put("foo[0][1]", "9");
|
|
|
|
this.sources
|
|
|
|
this.sources.add(mockSource);
|
|
|
|
.add(mockSource);
|
|
|
|
|
|
|
|
Map<Integer, List<Integer>> map = this.binder.bind("foo", target).get();
|
|
|
|
Map<Integer, List<Integer>> map = this.binder.bind("foo", target).get();
|
|
|
|
assertThat(map.get(0)).containsExactly(8, 9);
|
|
|
|
assertThat(map.get(0)).containsExactly(8, 9);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -512,9 +515,11 @@ public class MapBinderTests {
|
|
|
|
assertThat(map).containsEntry("x [B] y", "[ball]");
|
|
|
|
assertThat(map).containsEntry("x [B] y", "[ball]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) {
|
|
|
|
private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric,
|
|
|
|
|
|
|
|
ResolvableType valueType) {
|
|
|
|
ResolvableType keyType = ResolvableType.forClass(keyGeneric);
|
|
|
|
ResolvableType keyType = ResolvableType.forClass(keyGeneric);
|
|
|
|
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));
|
|
|
|
return Bindable
|
|
|
|
|
|
|
|
.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private <T> Bindable<List<T>> getListBindable(ResolvableType type) {
|
|
|
|
private <T> Bindable<List<T>> getListBindable(ResolvableType type) {
|
|
|
@ -522,6 +527,7 @@ public class MapBinderTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class Foo {
|
|
|
|
public static class Foo {
|
|
|
|
|
|
|
|
|
|
|
|
private String pattern;
|
|
|
|
private String pattern;
|
|
|
|
|
|
|
|
|
|
|
|
public Foo() {
|
|
|
|
public Foo() {
|
|
|
|