Skip to content

Commit 18816c3

Browse files
committed
Test case to prove binding to collection calls setter
Closes gh-9290
1 parent 915ad47 commit 18816c3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,30 @@ public void bindToImmutableCollectionShouldReturnPopulatedCollection()
305305
assertThat(result).hasSize(3);
306306
}
307307

308+
@Test
309+
public void bindToCollectionShouldAlsoCallSetterIfPresent() throws Exception {
310+
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
311+
source.put("foo.items", "a,b,c");
312+
this.sources.add(source);
313+
ExampleCollectionBean result = this.binder
314+
.bind("foo", ExampleCollectionBean.class)
315+
.get();
316+
assertThat(result.getItems()).hasSize(4);
317+
assertThat(result.getItems()).containsExactly("a", "b", "c", "d");
318+
}
319+
320+
public static class ExampleCollectionBean {
321+
322+
private List<String> items = new ArrayList<>();
323+
324+
public List<String> getItems() {
325+
return this.items;
326+
}
327+
328+
public void setItems(List<String> items) {
329+
this.items.add("d");
330+
}
331+
332+
}
333+
308334
}

0 commit comments

Comments
 (0)