import java.util.Iterator;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import com.vaadin.ui.Component;
public class GridChildrenTest {
- @Test
- public void componentsInMergedHeader() {
- Grid grid = new Grid();
+ private Grid grid;
+
+ @Before
+ public void createGrid() {
+ grid = new Grid();
grid.addColumn("foo");
grid.addColumn("bar");
grid.addColumn("baz");
+
+ }
+
+ @Test
+ public void iteratorFindsComponentsInMergedHeader() {
HeaderCell merged = grid.getDefaultHeaderRow().join("foo", "bar",
"baz");
Label label = new Label();
Assert.assertFalse(i.hasNext());
}
+ @Test
+ public void removeComponentInMergedHeaderCell() {
+ HeaderCell merged = grid.getDefaultHeaderRow().join("foo", "bar",
+ "baz");
+ Label label = new Label();
+ merged.setComponent(label);
+ Assert.assertEquals(grid, label.getParent());
+ merged.setText("foo");
+ Assert.assertNull(label.getParent());
+ }
+
+ @Test
+ public void removeHeaderWithComponentInMergedHeaderCell() {
+ HeaderCell merged = grid.getDefaultHeaderRow().join("foo", "bar",
+ "baz");
+ Label label = new Label();
+ merged.setComponent(label);
+ Assert.assertEquals(grid, label.getParent());
+ grid.removeHeaderRow(0);
+ Assert.assertNull(label.getParent());
+ }
+
+ @Test
+ public void removeComponentInMergedFooterCell() {
+ FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
+ Label label = new Label();
+ merged.setComponent(label);
+ Assert.assertEquals(grid, label.getParent());
+ merged.setText("foo");
+ Assert.assertNull(label.getParent());
+ }
+
+ @Test
+ public void removeFooterWithComponentInMergedFooterCell() {
+ FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
+ Label label = new Label();
+ merged.setComponent(label);
+ Assert.assertEquals(grid, label.getParent());
+ grid.removeFooterRow(0);
+ Assert.assertNull(label.getParent());
+ }
+
@Test
public void componentsInMergedFooter() {
- Grid grid = new Grid();
- grid.addColumn("foo");
- grid.addColumn("bar");
- grid.addColumn("baz");
FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
Label label = new Label();
merged.setComponent(label);
Iterator<Component> i = grid.iterator();
Assert.assertEquals(label, i.next());
Assert.assertFalse(i.hasNext());
+ Assert.assertEquals(grid, label.getParent());
}
}