Test binding of Map<String, String[]>
Add a test to ensure that the new binder can bind correctly to a Map<String,String[]>. Closes gh-3789
This commit is contained in:
committed by
Phillip Webb
parent
6184e4154e
commit
5edb1194f5
@@ -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<Map<String, Object>> STRING_OBJECT_MAP = Bindable
|
||||
.mapOf(String.class, Object.class);
|
||||
|
||||
private static final Bindable<Map<String, String[]>> STRING_ARRAY_MAP = Bindable
|
||||
.mapOf(String.class, String[].class);
|
||||
|
||||
private List<ConfigurationPropertySource> 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<Map<String, String[]>> target = STRING_ARRAY_MAP;
|
||||
this.binder.bind("foo", target, handler);
|
||||
InOrder inOrder = inOrder(handler);
|
||||
ArgumentCaptor<String[]> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user