You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/05/01 17:02:40 UTC

svn commit: r940052 - /click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java

Author: sabob
Date: Sat May  1 15:02:40 2010
New Revision: 940052

URL: http://svn.apache.org/viewvc?rev=940052&view=rev
Log:
fix tests. CLK-666

Modified:
    click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java

Modified: click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java?rev=940052&r1=940051&r2=940052&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/AbstractContainerTest.java Sat May  1 15:02:40 2010
@@ -74,14 +74,6 @@ public class AbstractContainerTest exten
             fail("Field has name defined and is valid");
         }
 
-        // Check that adding TextField with duplicate name fails
-        try {
-            container.add(new TextField("field"));
-            fail("Field with name 'field' already exists on Form");
-        } catch (Exception expected) {
-            // Should fail since field with name 'field' already exist on container
-        }
-
         // Check that adding TextField without name fails
         try {
             container.add(new TextField());
@@ -115,14 +107,6 @@ public class AbstractContainerTest exten
             fail("FieldSet has name defined and is valid");
         }
 
-        // Check that adding FieldSet with duplicate name fails
-        try {
-            container.add(new FieldSet("fieldSet"));
-            fail("FieldSet with name 'fieldSet' already exists on Form");
-        } catch (Exception expected) {
-            // Should fail since fieldSet with name 'fieldSet' already exist on container
-        }
-
         // Check that adding FieldSet without name fails
         try {
             container.add(new FieldSet());
@@ -163,4 +147,35 @@ public class AbstractContainerTest exten
             // Should fail since container cannot be added to itself
         }
     }
+
+    /**
+     * Check that adding controls replace existing controls with the same name.
+     *
+     * CLK-666
+     */
+    public void testReplace() {
+        AbstractContainer container = new AbstractContainer("container") {
+        };
+
+        // Add two fields named child1 and child2
+        Field child1 = new TextField("child1");
+        Field child2 = new TextField("child2");
+        container.add(child1);
+        container.add(child2);
+        assertEquals(2, container.getControlMap().size());
+        assertEquals(2, container.getControls().size());
+        assertSame(child1, container.getControls().get(0));
+        assertSame(child2, container.getControls().get(1));
+
+        // Add another two fields named child1 and child2 and test that these
+        // panels replaces the previous fields
+        child1 = new TextField("child1");
+        child2 = new TextField("child2");
+        container.add(child1);
+        container.add(child2);
+        assertEquals(2, container.getControlMap().size());
+        assertEquals(2, container.getControls().size());
+        assertSame(child1, container.getControls().get(0));
+        assertSame(child2, container.getControls().get(1));
+    }
 }