From 802b6cbd59186d3a0823b316f7523bb4120cb678 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Tue, 7 Jul 2015 19:39:05 +0300 Subject: Always add "last" item from the string to the collection (#18433). Change-Id: I664fcef77f469c66cd62afb2938db69b7f27e6df --- .../data/util/converter/StringToCollectionConverter.java | 4 +--- .../tests/data/converter/StringToCollectionConverterTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java b/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java index 495bed74f8..b86fec5558 100644 --- a/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java @@ -155,9 +155,7 @@ public class StringToCollectionConverter implements previous = index + delimiter.length(); index = value.indexOf(delimiter, previous); } - if (result.size() > 0) { - collectToken(value.substring(previous), result, converter, locale); - } + collectToken(value.substring(previous), result, converter, locale); return result; } diff --git a/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java b/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java index 977985c6cb..bcd0dc15bd 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java +++ b/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java @@ -141,6 +141,16 @@ public class StringToCollectionConverterTest { Assert.assertEquals("Z,Y", presentation); } + @Test + public void convertToModel_singleItem() { + StringToCollectionConverter converter = new StringToCollectionConverter(); + Collection model = converter.convertToModel("a", List.class, null); + Iterator iterator = model.iterator(); + Assert.assertEquals("Incorrect fist token", "a", iterator.next()); + Assert.assertFalse("More than one item detected after conversation", + iterator.hasNext()); + } + public enum TestEnum { X, Y, Z; } -- cgit v1.2.3