aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2017-02-21 14:26:30 +0200
committerGitHub <noreply@github.com>2017-02-21 14:26:30 +0200
commit948b14bd93064e30481ccb23a6197f557a880d5a (patch)
treeec197e61eea4daeda62a4e79b169089655cae5b3 /server/src/test
parentc53f066d17274b64d0cf91977f9ef68767153d87 (diff)
downloadvaadin-framework-948b14bd93064e30481ccb23a6197f557a880d5a.tar.gz
vaadin-framework-948b14bd93064e30481ccb23a6197f557a880d5a.zip
Fix null caption for NativeSelect and ComboBox (#8633)
* Fix null caption for NativeSelect and ComboBox Unified the null caption converting to empty string, as it was with other selects supporting item caption generator. Fixes #8630
Diffstat (limited to 'server/src/test')
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/ItemCaptionGeneratorTest.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/tests/server/component/ItemCaptionGeneratorTest.java b/server/src/test/java/com/vaadin/tests/server/component/ItemCaptionGeneratorTest.java
new file mode 100644
index 0000000000..1f80e46476
--- /dev/null
+++ b/server/src/test/java/com/vaadin/tests/server/component/ItemCaptionGeneratorTest.java
@@ -0,0 +1,85 @@
+package com.vaadin.tests.server.component;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.data.provider.DataGenerator;
+import com.vaadin.shared.data.DataCommunicatorConstants;
+import com.vaadin.shared.ui.ListingJsonConstants;
+import com.vaadin.ui.AbstractListing;
+import com.vaadin.ui.CheckBoxGroup;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.ListSelect;
+import com.vaadin.ui.NativeSelect;
+import com.vaadin.ui.RadioButtonGroup;
+import com.vaadin.ui.TwinColSelect;
+
+import elemental.json.JsonObject;
+
+public class ItemCaptionGeneratorTest {
+
+ private static class TestDataGenerator implements DataGenerator<Object> {
+ JsonObject generated = null;
+
+ @Override
+ public void generateData(Object item, JsonObject jsonObject) {
+ generated = jsonObject;
+ }
+
+ }
+
+ @Test
+ public void testItemCaptionGenerator_nullCaptionGiven_convertedToEmptyString() {
+ Collection<AbstractListing<Object>> listings = new ArrayList<>();
+
+ ComboBox<Object> comboBox = new ComboBox<>();
+ comboBox.setData(DataCommunicatorConstants.NAME);
+ comboBox.setItemCaptionGenerator(item -> null);
+ listings.add(comboBox);
+
+ CheckBoxGroup<Object> cbg = new CheckBoxGroup<>();
+ cbg.setData(ListingJsonConstants.JSONKEY_ITEM_VALUE);
+ cbg.setItemCaptionGenerator(item -> null);
+ listings.add(cbg);
+
+ ListSelect<Object> listSelect = new ListSelect<>();
+ listSelect.setData(ListingJsonConstants.JSONKEY_ITEM_VALUE);
+ listSelect.setItemCaptionGenerator(item -> null);
+ listings.add(listSelect);
+
+ NativeSelect<Object> nativeSelect = new NativeSelect<>();
+ nativeSelect.setData(DataCommunicatorConstants.DATA);
+ nativeSelect.setItemCaptionGenerator(item -> null);
+ listings.add(nativeSelect);
+
+ RadioButtonGroup<Object> rbg = new RadioButtonGroup<>();
+ rbg.setData(ListingJsonConstants.JSONKEY_ITEM_VALUE);
+ rbg.setItemCaptionGenerator(item -> null);
+ listings.add(rbg);
+
+ TwinColSelect<Object> tc = new TwinColSelect<>();
+ tc.setData(ListingJsonConstants.JSONKEY_ITEM_VALUE);
+ tc.setItemCaptionGenerator(item -> null);
+ listings.add(tc);
+
+ for (AbstractListing<Object> listing : listings) {
+ listing.setItems("Uno");
+ TestDataGenerator dataGenerator = new TestDataGenerator();
+ listing.getDataCommunicator().addDataGenerator(dataGenerator);
+ listing.getDataCommunicator().beforeClientResponse(true);
+
+ Assert.assertEquals(
+ listing.getClass().getName()
+ + " does not convert null caption from generator to empty string",
+ "",
+ dataGenerator.generated.hasKey((String) listing.getData())
+ ? dataGenerator.generated.getString(
+ (String) listing.getData())
+ : null);
+ }
+ }
+
+}