summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2012-10-16 11:13:35 +0300
committerVaadin Code Review <review@vaadin.com>2012-10-16 09:42:18 +0000
commit39515829548b0ff2097e4562c0d75e8d02074e15 (patch)
treeeccff6ce9764ec8ab334f196cad6e2a96bcca39b /server
parentc3a03b70126931ecab5db93fc12c99ac66677688 (diff)
downloadvaadin-framework-39515829548b0ff2097e4562c0d75e8d02074e15.tar.gz
vaadin-framework-39515829548b0ff2097e4562c0d75e8d02074e15.zip
Delegate UI.replaceComponent() to content instead of throwing UOE (#9967)
* Added a test, also renamed tests/server/component/root to tests/server/component/ui Change-Id: I80d30dd5acb3643cfb3cfc0b972f52ffa4512691
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/UI.java6
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java (renamed from server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java)2
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java65
3 files changed, 71 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java
index 31a7446e96..2878d10fa1 100644
--- a/server/src/com/vaadin/ui/UI.java
+++ b/server/src/com/vaadin/ui/UI.java
@@ -556,9 +556,13 @@ public abstract class UI extends AbstractComponentContainer implements
return this;
}
+ /**
+ * This implementation replaces a component in the content container (
+ * {@link #getContent()}) instead of in the actual UI.
+ */
@Override
public void replaceComponent(Component oldComponent, Component newComponent) {
- throw new UnsupportedOperationException();
+ getContent().replaceComponent(oldComponent, newComponent);
}
/**
diff --git a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java b/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java
index 405d3d1931..82b9944371 100644
--- a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java
+++ b/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java
@@ -1,4 +1,4 @@
-package com.vaadin.tests.server.component.root;
+package com.vaadin.tests.server.component.ui;
import java.util.ArrayList;
import java.util.List;
diff --git a/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java b/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java
new file mode 100644
index 0000000000..1b07321605
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java
@@ -0,0 +1,65 @@
+package com.vaadin.tests.server.component.ui;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.UI;
+
+public class UIAddRemoveComponents {
+
+ private static class TestUI extends UI {
+ @Override
+ protected void init(VaadinRequest request) {
+ }
+ }
+
+ @Test
+ public void addComponent() {
+ UI ui = new TestUI();
+ Component c = new Label("abc");
+
+ ui.addComponent(c);
+
+ assertSame(c, ui.iterator().next());
+ assertSame(c, ui.getContent().iterator().next());
+ assertEquals(1, ui.getComponentCount());
+ assertEquals(1, ui.getContent().getComponentCount());
+ }
+
+ @Test
+ public void removeComponent() {
+ UI ui = new TestUI();
+ Component c = new Label("abc");
+
+ ui.addComponent(c);
+
+ ui.removeComponent(c);
+
+ assertFalse(ui.iterator().hasNext());
+ assertFalse(ui.getContent().iterator().hasNext());
+ assertEquals(0, ui.getComponentCount());
+ assertEquals(0, ui.getContent().getComponentCount());
+ }
+
+ @Test
+ public void replaceComponent() {
+ UI ui = new TestUI();
+ Component c = new Label("abc");
+ Component d = new Label("def");
+
+ ui.addComponent(c);
+
+ ui.replaceComponent(c, d);
+
+ assertSame(d, ui.iterator().next());
+ assertSame(d, ui.getContent().iterator().next());
+ assertEquals(1, ui.getComponentCount());
+ assertEquals(1, ui.getContent().getComponentCount());
+ }
+}