summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2012-09-07 16:31:16 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2012-09-07 17:12:24 +0300
commit1fb7d999a09bea25256eef0e9837523c7c81841f (patch)
tree62e239d911bdc064a07621a4b4203c54c7c11349 /server/tests
parent544152d1adc3a098445f7b11b4651fcc3c2f13bc (diff)
downloadvaadin-framework-1fb7d999a09bea25256eef0e9837523c7c81841f.tar.gz
vaadin-framework-1fb7d999a09bea25256eef0e9837523c7c81841f.zip
Commit Pekka's patch for #8030 ((Component...) constructor for layouts) and #5422 (addComponents(Component...) for layouts) with minor formatting/javadoc changes
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java39
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java21
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java108
-rw-r--r--server/tests/src/com/vaadin/tests/server/componentcontainer/FormLayoutTest.java38
4 files changed, 206 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java
index bd67841f33..81c29995f5 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java
@@ -97,6 +97,45 @@ public class AddComponentsTest {
assertOrder(layout, new int[] { 2, 3, 1, 0 });
}
+ @Test
+ public void testConstructorsWithComponents() {
+ AbstractOrderedLayout layout1 = new HorizontalLayout(children);
+ assertOrder(layout1, new int[] { 0, 1, 2, 3 });
+ shuffleChildComponents(layout1);
+
+ AbstractOrderedLayout layout2 = new VerticalLayout(children);
+ assertOrder(layout2, new int[] { 0, 1, 2, 3 });
+ shuffleChildComponents(layout2);
+ }
+
+ @Test
+ public void testAddComponents() {
+ HorizontalLayout layout1 = new HorizontalLayout();
+ layout1.addComponents(children);
+ assertOrder(layout1, new int[] { 0, 1, 2, 3 });
+
+ Label extra = new Label("Extra");
+ layout1.addComponents(extra);
+ assertSame(extra, layout1.getComponent(4));
+
+ layout1.removeAllComponents();
+ layout1.addComponents(children[3], children[2], children[1],
+ children[0]);
+ assertOrder(layout1, new int[] { 3, 2, 1, 0 });
+
+ VerticalLayout layout2 = new VerticalLayout(children);
+ layout2.addComponents(children);
+ assertOrder(layout2, new int[] { 0, 1, 2, 3 });
+
+ layout2.addComponents(extra);
+ assertSame(extra, layout2.getComponent(4));
+
+ layout2.removeAllComponents();
+ layout2.addComponents(children[3], children[2], children[1],
+ children[0]);
+ assertOrder(layout2, new int[] { 3, 2, 1, 0 });
+ }
+
/**
* Asserts that layout has the components in children in the order specified
* by indices.
diff --git a/server/tests/src/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java b/server/tests/src/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java
index ce1357647b..120cf20070 100644
--- a/server/tests/src/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java
@@ -91,6 +91,27 @@ public class AddComponentsTest {
assertOrder(layout, new int[] { 2, 3, 1, 0 });
}
+ @Test
+ public void testConstructorWithComponents() {
+ Layout layout = new CssLayout(children);
+ assertOrder(layout, new int[] { 0, 1, 2, 3 });
+ }
+
+ @Test
+ public void testAddComponents() {
+ CssLayout layout = new CssLayout();
+ layout.addComponents(children);
+ assertOrder(layout, new int[] { 0, 1, 2, 3 });
+
+ Label extra = new Label("Extra");
+ layout.addComponents(extra);
+ assertSame(extra, layout.getComponent(4));
+
+ layout.removeAllComponents();
+ layout.addComponents(children[3], children[2], children[1], children[0]);
+ assertOrder(layout, new int[] { 3, 2, 1, 0 });
+ }
+
/**
* Asserts that layout has the components in children in the order specified
* by indices.
diff --git a/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java b/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java
new file mode 100644
index 0000000000..1eabf2fb62
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java
@@ -0,0 +1,108 @@
+package com.vaadin.tests.server.component.gridlayout;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.junit.Test;
+
+import com.vaadin.ui.Component;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+
+public class GridLayoutTest {
+ Component[] children = new Component[] { new Label("A"), new Label("B"),
+ new Label("C"), new Label("D") };
+
+ @Test
+ public void testConstructorWithComponents() {
+ GridLayout grid = new GridLayout(2, 2, children);
+ assertContentPositions(grid);
+ assertOrder(grid, new int[] { 0, 1, 2, 3 });
+
+ grid = new GridLayout(1, 1, children);
+ assertContentPositions(grid);
+ assertOrder(grid, new int[] { 0, 1, 2, 3 });
+ }
+
+ @Test
+ public void testAddComponents() {
+ GridLayout grid = new GridLayout(2, 2);
+ grid.addComponents(children);
+ assertContentPositions(grid);
+ assertOrder(grid, new int[] { 0, 1, 2, 3 });
+
+ Label extra = new Label("Extra");
+ Label extra2 = new Label("Extra2");
+ grid.addComponents(extra, extra2);
+ assertSame(grid.getComponent(0, 2), extra);
+ assertSame(grid.getComponent(1, 2), extra2);
+
+ grid.removeAllComponents();
+ grid.addComponents(extra, extra2);
+ assertSame(grid.getComponent(0, 0), extra);
+ assertSame(grid.getComponent(1, 0), extra2);
+
+ grid.addComponents(children);
+ assertOrder(grid, new int[] { -1, -1, 0, 1, 2, 3 });
+
+ grid.removeComponent(extra);
+ grid.removeComponent(extra2);
+ assertOrder(grid, new int[] { 0, 1, 2, 3 });
+
+ grid.addComponents(extra2, extra);
+ assertSame(grid.getComponent(0, 3), extra2);
+ assertSame(grid.getComponent(1, 3), extra);
+ assertOrder(grid, new int[] { 0, 1, 2, 3, -1, -1 });
+
+ grid.removeComponent(extra2);
+ grid.removeComponent(extra);
+ grid.setCursorX(0);
+ grid.setCursorY(0);
+ grid.addComponents(extra, extra2);
+ assertSame(grid.getComponent(0, 0), extra);
+ assertSame(grid.getComponent(1, 0), extra2);
+ assertOrder(grid, new int[] { -1, -1, 0, 1, 2, 3 });
+
+ grid = new GridLayout();
+ grid.addComponents(children);
+ assertContentPositions(grid);
+ assertOrder(grid, new int[] { 0, 1, 2, 3 });
+ }
+
+ private void assertContentPositions(GridLayout grid) {
+ assertEquals(grid.getComponentCount(), children.length);
+ int c = 0;
+ for (int i = 0; i < grid.getRows(); i++) {
+ for (int j = 0; j < grid.getColumns(); j++) {
+ assertSame(grid.getComponent(j, i), children[c]);
+ c++;
+ }
+ }
+ }
+
+ /**
+ * Asserts that layout has the components in children in the order specified
+ * by indices.
+ */
+ private void assertOrder(Layout layout, int[] indices) {
+ Iterator<?> i = layout.iterator();
+ try {
+ for (int index : indices) {
+ if (index != -1) {
+ assertSame(children[index], i.next());
+ } else {
+ i.next();
+ }
+ }
+ assertFalse("Too many components in layout", i.hasNext());
+ } catch (NoSuchElementException e) {
+ fail("Too few components in layout");
+ }
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/componentcontainer/FormLayoutTest.java b/server/tests/src/com/vaadin/tests/server/componentcontainer/FormLayoutTest.java
index 71a813d423..50de871106 100644
--- a/server/tests/src/com/vaadin/tests/server/componentcontainer/FormLayoutTest.java
+++ b/server/tests/src/com/vaadin/tests/server/componentcontainer/FormLayoutTest.java
@@ -1,7 +1,13 @@
package com.vaadin.tests.server.componentcontainer;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.junit.Test;
+
import com.vaadin.ui.Component;
import com.vaadin.ui.FormLayout;
+import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
public class FormLayoutTest extends AbstractIndexedLayoutTest {
@@ -31,4 +37,36 @@ public class FormLayoutTest extends AbstractIndexedLayoutTest {
return getLayout().getComponentCount();
}
+ Component[] children = new Component[] { new Label("A"), new Label("B"),
+ new Label("C"), new Label("D") };
+
+ @Test
+ public void testConstructorWithComponents() {
+ FormLayout l = new FormLayout(children);
+ assertOrder(l, new int[] { 0, 1, 2, 3 });
+ }
+
+ @Test
+ public void testAddComponents() {
+ FormLayout l = new FormLayout();
+ l.addComponents(children);
+ assertOrder(l, new int[] { 0, 1, 2, 3 });
+ }
+
+ private void assertOrder(Layout layout, int[] indices) {
+ Iterator<?> i = layout.iterator();
+ try {
+ for (int index : indices) {
+ if (index != -1) {
+ assertSame(children[index], i.next());
+ } else {
+ i.next();
+ }
+ }
+ assertFalse("Too many components in layout", i.hasNext());
+ } catch (NoSuchElementException e) {
+ fail("Too few components in layout");
+ }
+ }
+
}