click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1030910 - in /click/trunk/click: extras/test/org/apache/click/extras/control/PickListTest.java framework/src/org/apache/click/util/ClickUtils.java
Date Thu, 04 Nov 2010 12:41:13 GMT
Author: sabob
Date: Thu Nov  4 12:41:13 2010
New Revision: 1030910

URL: http://svn.apache.org/viewvc?rev=1030910&view=rev
Log:
updated javadoc and added encode/decode tests

Modified:
    click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java
    click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java

Modified: click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java?rev=1030910&r1=1030909&r2=1030910&view=diff
==============================================================================
--- click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java (original)
+++ click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java Thu Nov
 4 12:41:13 2010
@@ -18,9 +18,13 @@
  */
 package org.apache.click.extras.control;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import junit.framework.TestCase;
 import org.apache.click.MockContainer;
 import org.apache.click.MockContext;
+import org.apache.click.control.Option;
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -36,7 +40,7 @@ public class PickListTest extends TestCa
      * This could cause concurrent modification exceptions if the PickList is rendered
      * by multiple threads.
      */
-    public void testClassAttributeRenderin() {
+    public void testClassAttributeRendering() {
         // PickList uses Velocity to render its template. In this test we start a
         // MockContainer which also configures Velocity
         MockContainer container = new MockContainer("web");
@@ -68,4 +72,64 @@ public class PickListTest extends TestCa
         assertEquals(1, StringUtils.countMatches(pickListStr, "class="));
         container.stop();
     }
+
+    /**
+     * Test that PickList.getState contains all the selected values.
+     * CLK-715
+     */
+    public void testGetState() {
+        // Setup PickList
+        PickList pickList  = new PickList("languages");
+
+        pickList.add(new Option("002", "C/C++"));
+        pickList.add(new Option("003", "C#"));
+        pickList.add(new Option("004", "Fortran"));
+        pickList.add(new Option("005", "Java"));
+        pickList.add(new Option("006", "Ruby"));
+        pickList.add(new Option("007", "Perl"));
+        pickList.add(new Option("008", "Visual Basic"));
+
+        // Setup PickList selected values
+        pickList.addSelectedValue("004");
+        pickList.addSelectedValue("005");
+
+        String[] state = (String[]) pickList.getState();
+
+        // Perform tests
+        String[] expectedStateArray = new String[] {"004", "005"};
+        assertTrue(Arrays.equals(expectedStateArray, state));
+        assertTrue(Arrays.equals(state, pickList.getSelectedValues().toArray()));
+    }
+
+    /**
+     * Test that PickList.setState set the PickList selected values.
+     *
+     * CLK-715
+     */
+    public void testSetState() {
+        // Setup PickList
+        PickList pickList  = new PickList("languages");
+
+        pickList.add(new Option("002", "C/C++"));
+        pickList.add(new Option("003", "C#"));
+        pickList.add(new Option("004", "Fortran"));
+        pickList.add(new Option("005", "Java"));
+        pickList.add(new Option("006", "Ruby"));
+        pickList.add(new Option("007", "Perl"));
+        pickList.add(new Option("008", "Visual Basic"));
+
+                List expectedSelectedValues = new ArrayList();
+        assertEquals(expectedSelectedValues, pickList.getSelectedValues());
+
+        // Setup PickList selected values
+        String[] expectedState = {"004", "005"};
+
+        // Set state
+        pickList.setState(expectedState);
+
+        // Perform tests
+        assertEquals("", pickList.getValue()); // PickList use value but selectedValues instead
+        assertTrue(Arrays.equals(expectedState, pickList.getSelectedValues().toArray()));
+        assertEquals(pickList.getSelectedValues(), (pickList.getValueObject()));
+    }
 }

Modified: click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java?rev=1030910&r1=1030909&r2=1030910&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java Thu Nov  4 12:41:13
2010
@@ -1936,7 +1936,7 @@ public class ClickUtils {
      * URL encode the specified value using the "UTF-8" encoding scheme.
      * <p/>
      * For example <tt>(http://host?name=value with spaces)</tt> will become
-     * <tt>(http://host?name=value%20with%20spaces)</tt>.
+     * <tt>(http://host?name=value+with+spaces)</tt>.
      * <p/>
      * This method uses {@link URLEncoder#encode(java.lang.String, java.lang.String)}
      * internally.
@@ -1959,7 +1959,7 @@ public class ClickUtils {
     /**
      * URL decode the specified value using the "UTF-8" encoding scheme.
      * <p/>
-     * For example <tt>(http://host?name=value%20with%20spaces)</tt> will become
+     * For example <tt>(http://host?name=value+with+spaces)</tt> will become
      * <tt>(http://host?name=value with spaces)</tt>.
      * <p/>
      * This method uses {@link URLDecoder#decode(java.lang.String, java.lang.String)}
@@ -1986,7 +1986,7 @@ public class ClickUtils {
      * is not specified.
      * <p/>
      * For example <tt>(http://host?name=value with spaces)</tt> will become
-     * <tt>(http://host?name=value%20with%20spaces)</tt>.
+     * <tt>(http://host?name=value+with+spaces)</tt>.
      * <p/>
      * This method uses
      * {@link URLEncoder#encode(java.lang.String, java.lang.String)} internally.



Mime
View raw message