From ac9f380c55b8ed14015a6abdb724e4cde057cad3 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 26 Apr 2017 15:15:31 -0700 Subject: [PATCH] Test binding of Set Add a test to ensure that the new binder can bind correctly to a Set. Closes gh-1415 --- .../properties/bind/CollectionBinderTests.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java index 9fbef4922e0..5fc7f64f7b2 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java @@ -48,6 +48,9 @@ public class CollectionBinderTests { private static final Bindable> STRING_LIST = Bindable .listOf(String.class); + private static final Bindable> STRING_SET = Bindable + .setOf(String.class); + private List sources = new ArrayList<>(); private Binder binder; @@ -68,6 +71,17 @@ public class CollectionBinderTests { assertThat(result).containsExactly(1, 2, 3); } + @Test + public void bindToSetShouldReturnPopulatedCollection() throws Exception { + MockConfigurationPropertySource source = new MockConfigurationPropertySource(); + source.put("foo[0]", "a"); + source.put("foo[1]", "b"); + source.put("foo[2]", "c"); + this.sources.add(source); + Set result = this.binder.bind("foo", STRING_SET).get(); + assertThat(result).containsExactly("a", "b", "c"); + } + @Test public void bindToCollectionWhenNestedShouldReturnPopulatedCollection() throws Exception {