diff options
author | Artur Signell <artur@vaadin.com> | 2013-02-22 16:23:49 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-02-22 16:24:06 +0200 |
commit | fbdc52551e258d938db2e230366ca0e21d35c5bc (patch) | |
tree | 640740bcb63c2757facc9f19748a65eb46b50174 /server/tests | |
parent | d9a8a21a62b977e32b65bcf436bbd229c9b798f4 (diff) | |
parent | 7af5b3fceb75b6f505a9a6d0a843b788bb06d9a7 (diff) | |
download | vaadin-framework-fbdc52551e258d938db2e230366ca0e21d35c5bc.tar.gz vaadin-framework-fbdc52551e258d938db2e230366ca0e21d35c5bc.zip |
Merge remote-tracking branch 'origin/7.0'
Change-Id: Id48ccb3c400a78cddb8bb5c7bbcf2d65174e59d0
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java index 16a7091947..c1d7653c01 100644 --- a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java @@ -1,5 +1,8 @@ package com.vaadin.tests.server.component.tree; +import java.lang.reflect.Field; +import java.util.HashSet; + import junit.framework.TestCase; import com.vaadin.data.Container; @@ -71,4 +74,63 @@ public class TreeTest extends TestCase { assertTrue(Container.Hierarchical.class.isAssignableFrom(tree4 .getContainerDataSource().getClass())); } + + public void testRemoveExpandedItems() throws Exception { + tree.expandItem("parent"); + tree.expandItem("child"); + + Field expandedField = tree.getClass() + .getDeclaredField("expanded"); + Field expandedItemIdField = tree.getClass().getDeclaredField( + "expandedItemId"); + + expandedField.setAccessible(true); + expandedItemIdField.setAccessible(true); + + HashSet<Object> expanded = (HashSet<Object>) expandedField.get(tree); + Object expandedItemId = expandedItemIdField.get(tree); + + assertEquals(2, expanded.size()); + assertTrue("Contains parent", expanded.contains("parent")); + assertTrue("Contains child", expanded.contains("child")); + assertEquals("child", expandedItemId); + + tree.removeItem("parent"); + + expanded = (HashSet<Object>) expandedField.get(tree); + expandedItemId = expandedItemIdField.get(tree); + + assertEquals(1, expanded.size()); + assertTrue("Contains child", expanded.contains("child")); + assertEquals("child", expandedItemId); + + tree.removeItem("child"); + + expanded = (HashSet<Object>) expandedField.get(tree); + expandedItemId = expandedItemIdField.get(tree); + + assertEquals(0, expanded.size()); + assertNull(expandedItemId); + } + + public void testRemoveExpandedItemsOnContainerChange() throws Exception { + tree.expandItem("parent"); + tree.expandItem("child"); + + tree.setContainerDataSource(new HierarchicalContainer()); + + Field expandedField = tree.getClass().getDeclaredField("expanded"); + Field expandedItemIdField = tree.getClass().getDeclaredField( + "expandedItemId"); + + expandedField.setAccessible(true); + expandedItemIdField.setAccessible(true); + + HashSet<Object> expanded = (HashSet<Object>) expandedField.get(tree); + assertEquals(0, expanded.size()); + + Object expandedItemId = expandedItemIdField.get(tree); + assertNull(expandedItemId); + } + } |