WICKET-5147 WicketTester MockHttpRequest.getCookies very slow / OutOfMemory

Minor formatting improvements.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/8df9d992
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/8df9d992
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/8df9d992

Branch: refs/heads/master
Commit: 8df9d9920452cef32c1ded2e0d7fc551b730ad0b
Parents: 714f81a
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Fri Apr 26 11:02:20 2013 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Fri Apr 26 11:02:20 2013 +0200

----------------------------------------------------------------------
 .../protocol/http/mock/CookieCollection.java       |   20 +++--------
 .../apache/wicket/protocol/http/mock/Cookies.java  |    3 +-
 .../wicket/util/tester/BaseWicketTester.java       |   12 +++---
 .../wicket/util/tester/WicketTesterCookieTest.java |   26 ++++++++-------
 .../wicket/util/tester/cookies/SetCookiePage.java  |    4 ++-
 5 files changed, 30 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
index d316450..ec89916 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
@@ -32,8 +32,8 @@ import org.apache.wicket.protocol.http.mock.Cookies.Key;
  */
 public class CookieCollection
 {
-       Map<Cookies.Key, Cookie> cookies = new LinkedHashMap<Cookies.Key, 
Cookie>();
-       Map<Cookies.Key, Cookie> expiredCookies = new 
LinkedHashMap<Cookies.Key, Cookie>();
+       private final Map<Cookies.Key, Cookie> cookies = new 
LinkedHashMap<Cookies.Key, Cookie>();
+       private final Map<Cookies.Key, Cookie> expiredCookies = new 
LinkedHashMap<Cookies.Key, Cookie>();
 
        /**
         * add cookie to collection
@@ -45,7 +45,7 @@ public class CookieCollection
        {
                Key key = Cookies.keyOf(cookie);
                Cookie copyOfCookie = Cookies.copyOf(cookie);
-               if (isExpired(cookie))
+               if (Cookies.isExpired(cookie))
                {
                        expiredCookies.put(key, copyOfCookie);
                        cookies.remove(key);
@@ -63,7 +63,9 @@ public class CookieCollection
        public void addAll(Cookie[] cookies)
        {
                if (cookies != null)
+               {
                        addAll(Arrays.asList(cookies));
+               }
        }
 
        /**
@@ -112,16 +114,4 @@ public class CookieCollection
                return ret;
        }
 
-       /**
-        * detect if this cookie is expired
-        * 
-        * @param cookie
-        * @return true, if expired
-        */
-       public static boolean isExpired(Cookie cookie)
-       {
-               return cookie.getMaxAge() == 0;
-       }
-
-
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
index e660772..54ecb97 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
@@ -43,7 +43,7 @@ public final class Cookies
         */
        public static Cookie copyOf(Cookie cookie)
        {
-               return cookie != null ? (Cookie)cookie.clone() : null;
+               return cookie != null ? (Cookie) cookie.clone() : null;
        }
 
        /**
@@ -96,6 +96,7 @@ public final class Cookies
 
                protected Key(Cookie cookie)
                {
+                       Args.notNull(cookie, "cookie");
                        name = cookie.getName();
                        path = cookie.getPath();
                        domain = cookie.getDomain();

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java 
b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index cc28aa5..28dfb2a 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -29,7 +29,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -99,7 +98,6 @@ import 
org.apache.wicket.protocol.http.IMetaDataBufferingWebResponse;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.http.WicketFilter;
 import org.apache.wicket.protocol.http.mock.CookieCollection;
-import org.apache.wicket.protocol.http.mock.Cookies;
 import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
 import org.apache.wicket.protocol.http.mock.MockHttpServletResponse;
 import org.apache.wicket.protocol.http.mock.MockHttpSession;
@@ -382,7 +380,7 @@ public class BaseWicketTester
                        List<Cookie> lastResponseCookies = 
lastResponse.getCookies();
                        if (lastResponse.isRedirect()) 
                        {
-                               CookieCollection responseCookies=new 
CookieCollection();
+                               CookieCollection responseCookies = new 
CookieCollection();
                                
                                // if the last request is a redirect, all 
cookies from last response should appear in current reponse
                                // this call will filter duplicates
@@ -394,7 +392,8 @@ public class BaseWicketTester
                                
                                // copy all request cookies from last request 
to the new request because of redirect handling
                                // this way, the cookie will be send to the 
next requested page
-                               if (lastRequest!=null) {
+                               if (lastRequest != null)
+                               {
                                        CookieCollection requestCookies=new 
CookieCollection();
                                        // this call will filter duplicates
                                        
requestCookies.addAll(lastRequest.getCookies());
@@ -407,8 +406,9 @@ public class BaseWicketTester
                                // - copy last request cookies to collection
                                // - copy last response cookies to collection
                                // - set only the not expired cookies to the 
next request
-                               CookieCollection cookies=new 
CookieCollection();                                
-                               if (lastRequest!=null) {
+                               CookieCollection cookies = new 
CookieCollection();
+                               if (lastRequest != null)
+                               {
                                        // this call will filter duplicates
                                        
cookies.addAll(lastRequest.getCookies());
                                }

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
index 3266604..13facf0 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
+++ 
b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
@@ -248,7 +248,7 @@ public class WicketTesterCookieTest extends WicketTestCase
        }
 
        /**
-        * @see WicketTesterTest#wicketTesterCookieHandlingWithoutRedirect()
+        * @see 
WicketTesterCookieTest#wicketTesterCookieHandlingWithoutRedirect()
         *  
         * https://issues.apache.org/jira/browse/WICKET-5147
         */
@@ -350,7 +350,6 @@ public class WicketTesterCookieTest extends WicketTestCase
 
        /**
         * check cookies in current request
-        * @param page page
         * @param cookies cookies
         */
        private void requestShouldHaveTheseCookies(Cookie...cookies) {
@@ -382,12 +381,12 @@ public class WicketTesterCookieTest extends WicketTestCase
        private static String asString(Map<String, Cookie> cookieMap)
        {
                StringBuilder sb=new StringBuilder();
-               sb.append("{");
+               sb.append('{');
                for (Map.Entry<String, Cookie> e : cookieMap.entrySet()) {
-                       
sb.append(e.getKey()).append("=").append(asString(e.getValue()));
+                       
sb.append(e.getKey()).append('=').append(asString(e.getValue()));
                        sb.append(",");
                }
-               sb.append("}");
+               sb.append('}');
                return sb.toString();
        }
 
@@ -399,11 +398,11 @@ public class WicketTesterCookieTest extends WicketTestCase
        private static String asString(Cookie c)
        {
                StringBuilder sb=new StringBuilder();
-               sb.append("[");
-               sb.append("name=").append(c.getName()).append(",");
-               sb.append("value=").append(c.getValue()).append(",");
+               sb.append('[');
+               sb.append("name=").append(c.getName()).append(',');
+               sb.append("value=").append(c.getValue()).append(',');
                sb.append("maxAge=").append(c.getMaxAge());
-               sb.append("]");
+               sb.append(']');
                return sb.toString();
        }
 
@@ -447,10 +446,13 @@ public class WicketTesterCookieTest extends WicketTestCase
         */
        private static Map<String,Cookie> cookiesFromList(List<Cookie> cookies) 
{
                Map<String, Cookie> ret = new LinkedHashMap<String, Cookie>();
-               for (Cookie cookie : cookies) {
+               for (Cookie cookie : cookies)
+               {
                        Cookie oldValue = ret.put(cookie.getName(), cookie);
-                       if (oldValue!=null) {
-                               throw new RuntimeException("Cookie with name 
"+cookie.getName()+"("+asString(oldValue)+") allready in map "+asString(ret));
+                       if (oldValue != null)
+                       {
+                               throw new 
RuntimeException(String.format("Cookie with name '%s' ('%s') already in map %s",
+                                               cookie.getName(), 
asString(oldValue), asString(ret)));
                        }
                }
                return ret;

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
 
b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
index 0887d02..dd2c49b 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
+++ 
b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
@@ -44,10 +44,12 @@ public class SetCookiePage extends DummyHomePage
        
        protected void onInitialize() {
                super.onInitialize();
+
                WebResponse response = (WebResponse) getResponse();
                response.addCookie(cookie);
                
-               if (redirectToPageClass!=null) {
+               if (redirectToPageClass != null)
+               {
                        setResponsePage(redirectToPageClass);
                }
        };

Reply via email to