click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bck...@apache.org
Subject svn commit: r959958 - /click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java
Date Fri, 02 Jul 2010 12:06:07 GMT
Author: bckfnn
Date: Fri Jul  2 12:06:06 2010
New Revision: 959958

URL: http://svn.apache.org/viewvc?rev=959958&view=rev
Log:
support testing of multiple request parameters. part of CLK-558

Modified:
    click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java

Modified: click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java?rev=959958&r1=959957&r2=959958&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java (original)
+++ click/trunk/click/mock/src/org/apache/click/servlet/MockRequest.java Fri Jul  2 12:06:06
2010
@@ -497,6 +497,7 @@ public class MockRequest implements Http
 
             return new ServletInputStream() {
 
+                @Override
                 public int read() {
                     return bais.read();
                 }
@@ -504,6 +505,7 @@ public class MockRequest implements Http
         } else {
             return new ServletInputStream() {
 
+                @Override
                 public int read() {
                     return -1;
                 }
@@ -587,7 +589,12 @@ public class MockRequest implements Http
      * @return The parameter value, or null
      */
     public String getParameter(final String name) {
-        return (String) parameters.get(name);
+        Object value = parameters.get(name);
+        if (value instanceof String[]) {
+            return ((String[])value)[0];
+        } else {
+            return (String) parameters.get(name);
+        }
     }
 
     /**
@@ -669,10 +676,22 @@ public class MockRequest implements Http
             try {
                 for (Iterator iterator = parameters.keySet().iterator(); iterator.hasNext();)
{
                     final String name = (String) iterator.next();
-                    final String value = (String) parameters.get(name);
-                    buf.append(URLEncoder.encode(name, "UTF-8"));
-                    buf.append('=');
-                    buf.append(URLEncoder.encode(value, "UTF-8"));
+                    final Object value = parameters.get(name);
+                    if (value instanceof String[]) {
+                        String[] aValue = (String[]) value; 
+                        for (int i = 0; i < aValue.length; i++) {
+                            buf.append(URLEncoder.encode(name, "UTF-8"));
+                            buf.append('=');
+                            buf.append(URLEncoder.encode(aValue[i], "UTF-8"));
+                            if (i < aValue.length) {
+                                buf.append("&amp;");
+                            }
+                        }
+                    } else {
+                        buf.append(URLEncoder.encode(name, "UTF-8"));
+                        buf.append('=');
+                        buf.append(URLEncoder.encode((String) value, "UTF-8"));
+                    }
                     if (iterator.hasNext()) {
                         buf.append("&amp;");
                     }
@@ -1262,6 +1281,7 @@ public class MockRequest implements Http
      *
      * @return string representation of the mock request
      */
+    @Override
     public String toString() {
         return getRequestURL().toString();
     }



Mime
View raw message