From 18816c33ab7b50987be756f839118ec93afe27fc Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Thu, 29 Jun 2017 15:52:21 -0700 Subject: [PATCH] Test case to prove binding to collection calls setter Closes gh-9290 --- .../bind/CollectionBinderTests.java | 26 +++++++++++++++++++ 1 file changed, 26 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 17c031aacd..e92a5580aa 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 @@ -305,4 +305,30 @@ public class CollectionBinderTests { assertThat(result).hasSize(3); } + @Test + public void bindToCollectionShouldAlsoCallSetterIfPresent() throws Exception { + MockConfigurationPropertySource source = new MockConfigurationPropertySource(); + source.put("foo.items", "a,b,c"); + this.sources.add(source); + ExampleCollectionBean result = this.binder + .bind("foo", ExampleCollectionBean.class) + .get(); + assertThat(result.getItems()).hasSize(4); + assertThat(result.getItems()).containsExactly("a", "b", "c", "d"); + } + + public static class ExampleCollectionBean { + + private List items = new ArrayList<>(); + + public List getItems() { + return this.items; + } + + public void setItems(List items) { + this.items.add("d"); + } + + } + }