click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1053766 - in /click/trunk/click/framework: src/org/apache/click/control/Select.java test/org/apache/click/control/SelectTest.java
Date Wed, 29 Dec 2010 23:15:52 GMT
Author: sabob
Date: Wed Dec 29 23:15:52 2010
New Revision: 1053766

URL: http://svn.apache.org/viewvc?rev=1053766&view=rev
Log:
ensure only Option or OptionGroup is passed through DataProvider. CLK-745

Modified:
    click/trunk/click/framework/src/org/apache/click/control/Select.java
    click/trunk/click/framework/test/org/apache/click/control/SelectTest.java

Modified: click/trunk/click/framework/src/org/apache/click/control/Select.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Select.java?rev=1053766&r1=1053765&r2=1053766&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Select.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Select.java Wed Dec 29 23:15:52
2010
@@ -852,7 +852,13 @@ public class Select extends Field {
 
                         // Populate optionList from options
                         for (Object option : iterableData) {
-                            add(option);
+                            if (option instanceof Option || option instanceof OptionGroup)
{
+                                optionList.add(option);
+                            } else {
+                                String msg = "Select option class not instance of Option"
+                                + " or OptionGroup: " + option.getClass().getName();
+                                throw new IllegalArgumentException(msg);
+                            }
                         }
                     }
                 }

Modified: click/trunk/click/framework/test/org/apache/click/control/SelectTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/SelectTest.java?rev=1053766&r1=1053765&r2=1053766&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/SelectTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/SelectTest.java Wed Dec 29 23:15:52
2010
@@ -20,7 +20,9 @@ package org.apache.click.control;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 import junit.framework.TestCase;
 import org.apache.click.MockContext;
 import org.apache.click.dataprovider.DataProvider;
@@ -183,4 +185,44 @@ public class SelectTest extends TestCase
         // Test initial value
         assertEquals(expectedValue, select.getValue());
     }
+
+    /**
+     * CLK-745
+     */
+    public void testDataProviderValues() {
+        // Setup Select
+        Select select  = new Select("gender");
+
+        select.setDataProvider(new DataProvider() {
+
+            public List getData() {
+                List list = new ArrayList();
+                list.add("male");
+                return list;
+            }
+        });
+
+        try {
+            // Trigger dataProvider
+            select.toString();
+            fail("Cannot pass String to dataProvider");
+        } catch (IllegalArgumentException expected) {
+        }
+
+        select.setDataProvider(new DataProvider() {
+
+            public Set getData() {
+                Set set = new LinkedHashSet();
+                set.add("male");
+                return set;
+            }
+        });
+
+        try {
+            // Trigger dataProvider
+            select.toString();
+            fail("Cannot pass String to dataProvider");
+        } catch (IllegalArgumentException expected) {
+        }
+    }
 }



Mime
View raw message