diff options
author | Leif Åstrand <legioth@gmail.com> | 2017-02-07 15:33:20 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-02-07 15:33:20 +0200 |
commit | b57a9cbd6e2d6eeed83e7d9ddd0e61561b3cd557 (patch) | |
tree | a52a38b1b31ce1c2d917890254c0db8c5b855bde /server/src/test | |
parent | 19fdb91d4b8c926431995e157bdf440436209c2d (diff) | |
download | vaadin-framework-b57a9cbd6e2d6eeed83e7d9ddd0e61561b3cd557.tar.gz vaadin-framework-b57a9cbd6e2d6eeed83e7d9ddd0e61561b3cd557.zip |
Add Grid.addColumn(String, Renderer) (#8470)
* Add Grid.addColumn(String, Renderer)
Diffstat (limited to 'server/src/test')
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java index 57c4107a6b..9762b7235e 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -494,6 +495,31 @@ public class GridTest { values.stream().sorted(comparator).toArray()); } + @Test + public void addBeanColumn_validRenderer() { + Grid<Person> grid = new Grid<>(Person.class); + + grid.removeColumn("born"); + grid.addColumn("born", new NumberRenderer(new DecimalFormat("#,###"))); + + Person person = new Person("Name", 2017); + + JsonObject rowData = getRowData(grid, person); + + String formattedValue = Stream.of(rowData.keys()) + .map(rowData::getString).filter(value -> !value.equals("Name")) + .findFirst().orElse(null); + Assert.assertEquals(formattedValue, "2,017"); + } + + @Test(expected = IllegalArgumentException.class) + public void addBeanColumn_invalidRenderer() { + Grid<Person> grid = new Grid<>(Person.class); + + grid.removeColumn("name"); + grid.addColumn("name", new NumberRenderer()); + } + private static <T> JsonObject getRowData(Grid<T> grid, T row) { JsonObject json = Json.createObject(); if (grid.getColumns().isEmpty()) { |