From 5edb1194f57a3f2f102f4bffa2dc66d4cfa9dbf4 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 26 Apr 2017 12:21:39 -0700 Subject: [PATCH] Test binding of Map Add a test to ensure that the new binder can bind correctly to a Map. Closes gh-3789 --- .../properties/bind/MapBinderTests.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java index 6776686110..971d227446 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java @@ -25,6 +25,7 @@ import java.util.Map; import org.junit.Before; import org.junit.Test; import org.mockito.Answers; +import org.mockito.ArgumentCaptor; import org.mockito.InOrder; import org.springframework.boot.context.properties.bind.BinderTests.ExampleEnum; @@ -64,6 +65,9 @@ public class MapBinderTests { private static final Bindable> STRING_OBJECT_MAP = Bindable .mapOf(String.class, Object.class); + private static final Bindable> STRING_ARRAY_MAP = Bindable + .mapOf(String.class, String[].class); + private List sources = new ArrayList<>(); private Binder binder; @@ -352,4 +356,21 @@ public class MapBinderTests { eq(target), any(), isA(Map.class)); } + @Test + public void bindToMapStringArrayShouldTriggerOnSuccess() throws Exception { + this.sources + .add(new MockConfigurationPropertySource("foo.bar", "a,b,c", "line1")); + BindHandler handler = mock(BindHandler.class, + withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Bindable> target = STRING_ARRAY_MAP; + this.binder.bind("foo", target, handler); + InOrder inOrder = inOrder(handler); + ArgumentCaptor array = ArgumentCaptor.forClass(String[].class); + inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")), + eq(Bindable.of(String[].class)), any(), array.capture()); + assertThat(array.getValue()).containsExactly("a", "b", "c"); + inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")), + eq(target), any(), isA(Map.class)); + } + }