From 13e3d235e5ce62ad03a2da0046162e10bd5bd94c Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 13 Sep 2016 12:31:08 +0300 Subject: Add multi selection support to CheckBoxGroup This patch adds multi selection support only for CheckBoxGroup without even trying to generalize anything. Adopting the concepts to work with other components will be done separately. Change-Id: Id4ccd2c743b74cb022dc9dfd8cd8dae3bf8f0c54 --- .../test/java/com/vaadin/ui/CheckBoxGroupTest.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java (limited to 'server/src/test/java') diff --git a/server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java b/server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java new file mode 100644 index 0000000000..0ad1801e8b --- /dev/null +++ b/server/src/test/java/com/vaadin/ui/CheckBoxGroupTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.ui; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.server.data.DataSource; +import com.vaadin.shared.data.selection.SelectionModel.Multi; + +public class CheckBoxGroupTest { + @Test + public void stableSelectionOrder() { + CheckBoxGroup checkBoxGroup = new CheckBoxGroup<>(); + // Intentional deviation from upcoming selection order + checkBoxGroup + .setDataSource(DataSource.create("Third", "Second", "First")); + Multi selectionModel = checkBoxGroup.getSelectionModel(); + + selectionModel.select("First"); + selectionModel.select("Second"); + selectionModel.select("Third"); + + assertSelectionOrder(selectionModel, "First", "Second", "Third"); + + selectionModel.deselect("First"); + assertSelectionOrder(selectionModel, "Second", "Third"); + + selectionModel.select("First"); + assertSelectionOrder(selectionModel, "Second", "Third", "First"); + } + + private static void assertSelectionOrder(Multi selectionModel, + String... selectionOrder) { + Assert.assertEquals(Arrays.asList(selectionOrder), + new ArrayList<>(selectionModel.getSelectedItems())); + } +} -- cgit v1.2.3