hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r603563 [1/2] - in /jakarta/httpcomponents/httpclient/trunk/module-client: ./ src/main/java/org/apache/http/client/protocol/ src/main/java/org/apache/http/cookie/ src/main/java/org/apache/http/impl/cookie/ src/test/java/org/apache/http/impl...
Date Wed, 12 Dec 2007 11:17:58 GMT
Author: olegk
Date: Wed Dec 12 03:17:55 2007
New Revision: 603563

URL: http://svn.apache.org/viewvc?rev=603563&view=rev
Log:
HttpCookie converted to use collections with generics

Modified:
    jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2965Spec.java

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/pom.xml Wed Dec 12 03:17:55 2007
@@ -84,8 +84,8 @@
   </dependencies>
 
   <properties>
-    <maven.compile.source>1.4</maven.compile.source>
-    <maven.compile.target>1.4</maven.compile.target>
+    <maven.compile.source>1.5</maven.compile.source>
+    <maven.compile.target>1.5</maven.compile.target>
     <maven.compile.optimize>true</maven.compile.optimize>
     <maven.compile.deprecation>true</maven.compile.deprecation>
   </properties>

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java Wed Dec 12 03:17:55 2007
@@ -159,11 +159,10 @@
             }
         }
         // Generate Cookie request headers
-        cookies = matchedCookies.toArray(new Cookie[matchedCookies.size()]);
         if (cookies.length > 0) {
-            Header[] headers = cookieSpec.formatCookies(cookies);
-            for (int i = 0; i < headers.length; i++) {
-                request.addHeader(headers[i]);
+            List<Header> headers = cookieSpec.formatCookies(matchedCookies);
+            for (int i = 0; i < headers.size(); i++) {
+                request.addHeader(headers.get(i));
             }
         }
         

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java Wed Dec 12 03:17:55 2007
@@ -32,6 +32,7 @@
 package org.apache.http.client.protocol;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -116,9 +117,9 @@
         while (iterator.hasNext()) {
             Header header = iterator.nextHeader();
             try {
-                Cookie[] cookies = cookieSpec.parse(header, cookieOrigin);
-                for (int c = 0; c < cookies.length; c++) {
-                    Cookie cookie = cookies[c];
+                List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin);
+                for (int c = 0; c < cookies.size(); c++) {
+                    Cookie cookie = cookies.get(c);
                     try {
                         cookieSpec.validate(cookie, cookieOrigin);
                         cookieStore.addCookie(cookie);

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java Wed Dec 12 03:17:55 2007
@@ -31,6 +31,8 @@
 
 package org.apache.http.cookie;
 
+import java.util.List;
+
 import org.apache.http.Header;
 
 /**
@@ -71,7 +73,7 @@
       * @return an array of <tt>Cookie</tt>s parsed from the header
       * @throws MalformedCookieException if an exception occurs during parsing
       */
-    Cookie[] parse(Header header, CookieOrigin origin) throws MalformedCookieException;
+    List<Cookie> parse(Header header, CookieOrigin origin) throws MalformedCookieException;
 
     /**
       * Validate the cookie according to validation rules defined by the 
@@ -101,7 +103,7 @@
      * @return a Header for the given Cookies.
      * @throws IllegalArgumentException if an input parameter is illegal
      */
-    Header[] formatCookies(Cookie[] cookies);
+    List<Header> formatCookies(List<Cookie> cookies);
 
     /**
      * Returns a request header identifying what version of the state management 

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java Wed Dec 12 03:17:55 2007
@@ -31,8 +31,8 @@
 
 package org.apache.http.impl.cookie;
 
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.http.cookie.CookieAttributeHandler;
@@ -52,14 +52,14 @@
     /**
     * Stores attribute name -> attribute handler mappings
     */
-    private final Map attribHandlerMap;
+    private final Map<String, CookieAttributeHandler> attribHandlerMap;
 
     /** 
      * Default constructor 
      * */
     public AbstractCookieSpec() {
         super();
-        this.attribHandlerMap = new HashMap(10);        
+        this.attribHandlerMap = new HashMap<String, CookieAttributeHandler>(10);        
     }
 
     public void registerAttribHandler(
@@ -103,8 +103,8 @@
         }
     }
 
-    protected Iterator getAttribHandlerIterator() {
-        return this.attribHandlerMap.values().iterator();
+    protected Collection<CookieAttributeHandler> getAttribHandlers() {
+        return this.attribHandlerMap.values();
     }
     
 }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java Wed Dec 12 03:17:55 2007
@@ -71,7 +71,7 @@
             throw new IllegalArgumentException("Name may not be null");
         }
         this.name = name;
-        this.attribs = new HashMap();
+        this.attribs = new HashMap<String, String>();
         this.value = value;
     }
 
@@ -305,7 +305,7 @@
     }
     
     public String getAttribute(final String name) {
-        return (String) this.attribs.get(name);
+        return this.attribs.get(name);
     }
 
     public boolean containsAttribute(final String name) {
@@ -341,7 +341,7 @@
     private final String name;
 
     /** Cookie attributes as specified by the origin server */
-    private final Map attribs;
+    private final Map<String, String> attribs;
    
     /** Cookie value */
     private String value;

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java Wed Dec 12 03:17:55 2007
@@ -31,6 +31,9 @@
 
 package org.apache.http.impl.cookie;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.http.FormattedHeader;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
@@ -96,7 +99,7 @@
         this(null);
     }
     
-    public Cookie[] parse(final Header header, final CookieOrigin origin) 
+    public List<Cookie> parse(final Header header, final CookieOrigin origin) 
             throws MalformedCookieException {
         if (header == null) {
             throw new IllegalArgumentException("Header may not be null");
@@ -146,18 +149,18 @@
         return parse(elems, origin);
     }
 
-    public Header[] formatCookies(final Cookie[] cookies) {
+    public List<Header> formatCookies(final List<Cookie> cookies) {
         if (cookies == null) {
-            throw new IllegalArgumentException("Cookie array may not be null");
+            throw new IllegalArgumentException("List of cookies may not be null");
         }
-        if (cookies.length == 0) {
-            throw new IllegalArgumentException("Cookie array may not be empty");
+        if (cookies.isEmpty()) {
+            throw new IllegalArgumentException("List of cookies may not be empty");
         }
-        CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.length);
+        CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
         buffer.append(SM.COOKIE);
         buffer.append(": ");
-        for (int i = 0; i < cookies.length; i++) {
-            Cookie cookie = cookies[i];
+        for (int i = 0; i < cookies.size(); i++) {
+            Cookie cookie = cookies.get(i);
             if (i > 0) {
                 buffer.append("; ");
             }
@@ -168,7 +171,9 @@
                 buffer.append(s);
             }
         }
-        return new Header[] { new BufferedHeader(buffer) };
+        List<Header> headers = new ArrayList<Header>(1);
+        headers.add(new BufferedHeader(buffer));
+        return headers;
     }
 
     public int getVersion() {

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java Wed Dec 12 03:17:55 2007
@@ -31,7 +31,8 @@
 
 package org.apache.http.impl.cookie;
 
-import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.http.HeaderElement;
 import org.apache.http.NameValuePair;
@@ -66,9 +67,9 @@
         return origin.getHost();
     }
     
-    protected Cookie[] parse(final HeaderElement[] elems, final CookieOrigin origin)
+    protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin)
                 throws MalformedCookieException {
-        Cookie[] cookies = new Cookie[elems.length];
+        List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
         for (int i = 0; i < elems.length; i++) {
             HeaderElement headerelement = elems[i];
 
@@ -95,7 +96,7 @@
                     handler.parse(cookie, attrib.getValue());
                 }
             }
-            cookies[i] = cookie;
+            cookies.add(cookie);
         }
         return cookies;
     }
@@ -108,8 +109,7 @@
         if (origin == null) {
             throw new IllegalArgumentException("Cookie origin may not be null");
         }
-        for (Iterator i = getAttribHandlerIterator(); i.hasNext();) {
-            CookieAttributeHandler handler = (CookieAttributeHandler) i.next();
+        for (CookieAttributeHandler handler: getAttribHandlers()) {
             handler.validate(cookie, origin);
         }
     }
@@ -121,8 +121,7 @@
         if (origin == null) {
             throw new IllegalArgumentException("Cookie origin may not be null");
         }
-        for (Iterator i = getAttribHandlerIterator(); i.hasNext();) {
-            CookieAttributeHandler handler = (CookieAttributeHandler) i.next();
+        for (CookieAttributeHandler handler: getAttribHandlers()) {
             if (!handler.match(cookie, origin)) {
                 return false;
             }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java Wed Dec 12 03:17:55 2007
@@ -65,14 +65,14 @@
             throw new IllegalArgumentException("Parser cursor may not be null");
         }
         NameValuePair nvp = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
-        List params = new ArrayList(); 
+        List<NameValuePair> params = new ArrayList<NameValuePair>(); 
         while (!cursor.atEnd()) {
             NameValuePair param = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
             params.add(param);
         }
         return new BasicHeaderElement(
                 nvp.getName(), 
-                nvp.getValue(), (NameValuePair[]) params.toArray(new NameValuePair[params.size()]));
+                nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
     }
 
 }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java Wed Dec 12 03:17:55 2007
@@ -31,6 +31,9 @@
 
 package org.apache.http.impl.cookie;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.http.FormattedHeader;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
@@ -98,7 +101,7 @@
       * @return an array of <tt>Cookie</tt>s parsed from the Set-Cookie value
       * @throws MalformedCookieException if an exception occurs during parsing
       */
-    public Cookie[] parse(final Header header, final CookieOrigin origin) 
+    public List<Cookie> parse(final Header header, final CookieOrigin origin) 
             throws MalformedCookieException {
         if (header == null) {
             throw new IllegalArgumentException("Header may not be null");
@@ -126,18 +129,18 @@
         return parse(new HeaderElement[] { parser.parseHeader(buffer, cursor) }, origin);
     }
 
-    public Header[] formatCookies(final Cookie[] cookies) {
+    public List<Header> formatCookies(final List<Cookie> cookies) {
         if (cookies == null) {
-            throw new IllegalArgumentException("Cookie array may not be null");
+            throw new IllegalArgumentException("List of cookies may not be null");
         }
-        if (cookies.length == 0) {
-            throw new IllegalArgumentException("Cookie array may not be empty");
+        if (cookies.isEmpty()) {
+            throw new IllegalArgumentException("List of cookies may not be empty");
         }
-        CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.length);
+        CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
         buffer.append(SM.COOKIE);
         buffer.append(": ");
-        for (int i = 0; i < cookies.length; i++) {
-            Cookie cookie = cookies[i];
+        for (int i = 0; i < cookies.size(); i++) {
+            Cookie cookie = cookies.get(i);
             if (i > 0) {
                 buffer.append("; ");
             }
@@ -148,7 +151,9 @@
                 buffer.append(s);
             }
         }
-        return new Header[] { new BufferedHeader(buffer) };
+        List<Header> headers = new ArrayList<Header>(1);
+        headers.add(new BufferedHeader(buffer));
+        return headers;
     }
 
     public int getVersion() {

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java Wed Dec 12 03:17:55 2007
@@ -31,7 +31,9 @@
 
 package org.apache.http.impl.cookie;
 
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
@@ -98,7 +100,7 @@
         this(null, false);
     }
     
-    public Cookie[] parse(final Header header, final CookieOrigin origin) 
+    public List<Cookie> parse(final Header header, final CookieOrigin origin) 
             throws MalformedCookieException {
         if (header == null) {
             throw new IllegalArgumentException("Header may not be null");
@@ -125,14 +127,14 @@
         super.validate(cookie, origin);
     }
 
-    public Header[] formatCookies(final Cookie[] cookies) {
+    public List<Header> formatCookies(final List<Cookie> cookies) {
         if (cookies == null) {
-            throw new IllegalArgumentException("Cookie array may not be null");
+            throw new IllegalArgumentException("List of cookies may not be null");
         }
-        if (cookies.length == 0) {
-            throw new IllegalArgumentException("Cookie array may not be empty");
+        if (cookies.isEmpty()) {
+            throw new IllegalArgumentException("List of cookies may not be empty");
         }
-        Arrays.sort(cookies, PATH_COMPARATOR);
+        Collections.sort(cookies, PATH_COMPARATOR);
         if (this.oneHeader) {
             return doFormatOneHeader(cookies);
         } else {
@@ -140,40 +142,42 @@
         }
     }
 
-    private Header[] doFormatOneHeader(final Cookie[] cookies) {
+    private List<Header> doFormatOneHeader(final List<Cookie> cookies) {
         int version = Integer.MAX_VALUE;
         // Pick the lowest common denominator
-        for (int i = 0; i < cookies.length; i++) {
-            Cookie cookie = cookies[i];
+        for (int i = 0; i < cookies.size(); i++) {
+            Cookie cookie = cookies.get(i);
             if (cookie.getVersion() < version) {
                 version = cookie.getVersion();
             }
         }
-        CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.length);
+        CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.size());
         buffer.append(SM.COOKIE);
         buffer.append(": ");
         buffer.append("$Version=");
         buffer.append(Integer.toString(version));
-        for (int i = 0; i < cookies.length; i++) {
+        for (int i = 0; i < cookies.size(); i++) {
             buffer.append("; ");
-            Cookie cookie = cookies[i];
+            Cookie cookie = cookies.get(i);
             formatCookieAsVer(buffer, cookie, version);
         }
-        return new Header[] { new BufferedHeader(buffer) };
+        List<Header> headers = new ArrayList<Header>(1);
+        headers.add(new BufferedHeader(buffer));
+        return headers;
     }
 
-    private Header[] doFormatManyHeaders(final Cookie[] cookies) {
-        Header[] headers = new Header[cookies.length]; 
-        for (int i = 0; i < cookies.length; i++) {
-            Cookie cookie = cookies[i];
+    private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
+        List<Header> headers = new ArrayList<Header>(cookies.size()); 
+        for (int i = 0; i < cookies.size(); i++) {
+            Cookie cookie = cookies.get(i);
             int version = cookie.getVersion();
             CharArrayBuffer buffer = new CharArrayBuffer(40);
             buffer.append("Cookie: ");
             buffer.append("$Version=");
             buffer.append(Integer.toString(version));
             buffer.append("; ");
-            formatCookieAsVer(buffer, cookies[i], version);
-            headers[i] = new BufferedHeader(buffer);
+            formatCookieAsVer(buffer, cookie, version);
+            headers.add(new BufferedHeader(buffer));
         }
         return headers;
     }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java Wed Dec 12 03:17:55 2007
@@ -30,8 +30,9 @@
 
 package org.apache.http.impl.cookie;
 
+import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.http.Header;
@@ -90,7 +91,7 @@
         return cookie;
     }
     
-    public Cookie[] parse(
+    public List<Cookie> parse(
             final Header header, 
             CookieOrigin origin) throws MalformedCookieException {
         if (header == null) {
@@ -104,7 +105,7 @@
         
         HeaderElement[] elems = header.getElements();
 
-        Cookie[] cookies = new Cookie[elems.length];
+        List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
         for (int i = 0; i < elems.length; i++) {
             HeaderElement headerelement = elems[i];
 
@@ -126,14 +127,14 @@
             
             // Eliminate duplicate attributes. The first occurrence takes precedence
             // See RFC2965: 3.2  Origin Server Role
-            Map attribmap = new HashMap(attribs.length); 
+            Map<String, NameValuePair> attribmap = 
+                new HashMap<String, NameValuePair>(attribs.length); 
             for (int j = attribs.length - 1; j >= 0; j--) {
                 NameValuePair param = attribs[j];
                 attribmap.put(param.getName().toLowerCase(), param);
             }
-            for (Iterator it = attribmap.entrySet().iterator(); it.hasNext(); ) {
-                Map.Entry entry = (Map.Entry) it.next();
-                NameValuePair attrib = (NameValuePair) entry.getValue();
+            for (Map.Entry<String, NameValuePair> entry: attribmap.entrySet()) {
+                NameValuePair attrib = entry.getValue();
                 String s = attrib.getName().toLowerCase();
                 
                 cookie.setAttribute(s, attrib.getValue());
@@ -143,7 +144,7 @@
                     handler.parse(cookie, attrib.getValue());
                 }
             }
-            cookies[i] = cookie;
+            cookies.add(cookie);
         }
         return cookies;
     }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java Wed Dec 12 03:17:55 2007
@@ -32,6 +32,7 @@
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.List;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -62,7 +63,7 @@
 
     private static class DummyCookieSpec extends AbstractCookieSpec {
 
-        public Header[] formatCookies(Cookie[] cookies) {
+        public List<Header> formatCookies(List<Cookie> cookies) {
             return null;
         }
 
@@ -70,7 +71,7 @@
             return true;
         }
 
-        public Cookie[] parse(Header header, CookieOrigin origin) throws MalformedCookieException {
+        public List<Cookie> parse(Header header, CookieOrigin origin) throws MalformedCookieException {
             return null;
         }
 
@@ -116,7 +117,7 @@
         assertTrue(h1 == cookiespec.getAttribHandler("thistoo"));
         assertTrue(h2 == cookiespec.getAttribHandler("thattoo"));
         
-        Iterator it = cookiespec.getAttribHandlerIterator();
+        Iterator<CookieAttributeHandler> it = cookiespec.getAttribHandlers().iterator();
         assertNotNull(it.next());
         assertNotNull(it.next());
         assertNotNull(it.next());

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java Wed Dec 12 03:17:55 2007
@@ -30,7 +30,9 @@
 
 package org.apache.http.impl.cookie;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -85,13 +87,13 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.WhatEver.com", 80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertNotNull(parsed);
-        assertEquals(1, parsed.length);
-        assertEquals(".whatever.com", parsed[0].getDomain());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertNotNull(cookies);
+        assertEquals(1, cookies.size());
+        assertEquals(".whatever.com", cookies.get(0).getDomain());
     }
     
     /**
@@ -105,27 +107,27 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        for (int i = 0; i < cookies.length; i++) {
-            cookiespec.validate(cookies[i], origin);
-        }
-        assertEquals(2, cookies.length);
-
-        assertEquals("custno", cookies[0].getName());
-        assertEquals("12345", cookies[0].getValue());
-        assertEquals("test", cookies[0].getComment());
-        assertEquals(0, cookies[0].getVersion());
-        assertEquals("www.apache.org", cookies[0].getDomain());
-        assertEquals("/", cookies[0].getPath());
-        assertFalse(cookies[0].isSecure());
-
-        assertEquals("name", cookies[1].getName());
-        assertEquals("John", cookies[1].getValue());
-        assertEquals(null, cookies[1].getComment());
-        assertEquals(0, cookies[1].getVersion());
-        assertEquals(".apache.org", cookies[1].getDomain());
-        assertEquals("/", cookies[1].getPath());
-        assertTrue(cookies[1].isSecure());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals(2, cookies.size());
+
+        assertEquals("custno", cookies.get(0).getName());
+        assertEquals("12345", cookies.get(0).getValue());
+        assertEquals("test", cookies.get(0).getComment());
+        assertEquals(0, cookies.get(0).getVersion());
+        assertEquals("www.apache.org", cookies.get(0).getDomain());
+        assertEquals("/", cookies.get(0).getPath());
+        assertFalse(cookies.get(0).isSecure());
+
+        assertEquals("name", cookies.get(1).getName());
+        assertEquals("John", cookies.get(1).getValue());
+        assertEquals(null, cookies.get(1).getComment());
+        assertEquals(0, cookies.get(1).getVersion());
+        assertEquals(".apache.org", cookies.get(1).getDomain());
+        assertEquals("/", cookies.get(1).getPath());
+        assertTrue(cookies.get(1).isSecure());
     }
 
     /**
@@ -139,28 +141,28 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        for (int i = 0; i < cookies.length; i++) {
-            cookiespec.validate(cookies[i], origin);
-        }
-
-        assertEquals(2, cookies.length);
-
-        assertEquals("custno", cookies[0].getName());
-        assertEquals("12345", cookies[0].getValue());
-        assertEquals("test", cookies[0].getComment());
-        assertEquals(0, cookies[0].getVersion());
-        assertEquals("www.apache.org", cookies[0].getDomain());
-        assertEquals("/", cookies[0].getPath());
-        assertFalse(cookies[0].isSecure());
-
-        assertEquals("name", cookies[1].getName());
-        assertEquals("John", cookies[1].getValue());
-        assertEquals(null, cookies[1].getComment());
-        assertEquals(0, cookies[1].getVersion());
-        assertEquals(".apache.org", cookies[1].getDomain());
-        assertEquals("/", cookies[1].getPath());
-        assertTrue(cookies[1].isSecure());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+
+        assertEquals(2, cookies.size());
+
+        assertEquals("custno", cookies.get(0).getName());
+        assertEquals("12345", cookies.get(0).getValue());
+        assertEquals("test", cookies.get(0).getComment());
+        assertEquals(0, cookies.get(0).getVersion());
+        assertEquals("www.apache.org", cookies.get(0).getDomain());
+        assertEquals("/", cookies.get(0).getPath());
+        assertFalse(cookies.get(0).isSecure());
+
+        assertEquals("name", cookies.get(1).getName());
+        assertEquals("John", cookies.get(1).getValue());
+        assertEquals(null, cookies.get(1).getComment());
+        assertEquals(0, cookies.get(1).getVersion());
+        assertEquals(".apache.org", cookies.get(1).getDomain());
+        assertEquals("/", cookies.get(1).getPath());
+        assertTrue(cookies.get(1).isSecure());
     }
 
 
@@ -174,20 +176,20 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        for (int i = 0; i < cookies.length; i++) {
-            cookiespec.validate(cookies[i], origin);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
         }
 
-        assertEquals(1, cookies.length);
-
-        assertEquals("name", cookies[0].getName());
-        assertEquals("Doe, John", cookies[0].getValue());
-        assertEquals(null, cookies[0].getComment());
-        assertEquals(0, cookies[0].getVersion());
-        assertEquals(".apache.org", cookies[0].getDomain());
-        assertEquals("/", cookies[0].getPath());
-        assertTrue(cookies[0].isSecure());
+        assertEquals(1, cookies.size());
+
+        assertEquals("name", cookies.get(0).getName());
+        assertEquals("Doe, John", cookies.get(0).getValue());
+        assertEquals(null, cookies.get(0).getComment());
+        assertEquals(0, cookies.get(0).getVersion());
+        assertEquals(".apache.org", cookies.get(0).getDomain());
+        assertEquals("/", cookies.get(0).getPath());
+        assertTrue(cookies.get(0).isSecure());
     }
 
 
@@ -199,13 +201,13 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", true);
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        for (int i = 0; i < cookies.length; i++) {
-            cookiespec.validate(cookies[i], origin);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
         }
         assertNotNull("Expected some cookies",cookies);
-        assertEquals("Expected 1 cookie",1,cookies.length);
-        assertNotNull("Expected cookie to have getExpiryDate",cookies[0].getExpiryDate());
+        assertEquals("Expected 1 cookie",1,cookies.size());
+        assertNotNull("Expected cookie to have getExpiryDate",cookies.get(0).getExpiryDate());
     }
 
     public void testSecurityError() throws Exception {
@@ -216,9 +218,9 @@
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", true);
         try {
-            Cookie[] cookies = cookiespec.parse(header, origin);
-            for (int i = 0; i < cookies.length; i++) {
-                cookiespec.validate(cookies[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException exception should have been thrown");
         } catch (MalformedCookieException ex) {
@@ -231,21 +233,21 @@
         
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path/path", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertTrue("Comment",null == parsed[0].getComment());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
-        assertTrue("isPersistent",!parsed[0].isPersistent());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/path",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertEquals("Version",0,parsed[0].getVersion());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertTrue("Comment",null == cookies.get(0).getComment());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        //assertTrue("isToBeDiscarded",cookies.get(0).isToBeDiscarded());
+        assertTrue("isPersistent",!cookies.get(0).isPersistent());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/path",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertEquals("Version",0,cookies.get(0).getVersion());
     }
  
     public void testParseSimple2() throws Exception {
@@ -253,21 +255,21 @@
     
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.", 1, parsed.length);
-        assertEquals("Name", "cookie-name", parsed[0].getName());
-        assertEquals("Value", "cookie-value", parsed[0].getValue());
-        assertTrue("Comment", null == parsed[0].getComment());
-        assertTrue("ExpiryDate", null == parsed[0].getExpiryDate());
-        //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
-        assertTrue("isPersistent", !parsed[0].isPersistent());
-        assertEquals("Domain", "127.0.0.1", parsed[0].getDomain());
-        assertEquals("Path", "/", parsed[0].getPath());
-        assertTrue("Secure", !parsed[0].isSecure());
-        assertEquals("Version", 0, parsed[0].getVersion());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.", 1, cookies.size());
+        assertEquals("Name", "cookie-name", cookies.get(0).getName());
+        assertEquals("Value", "cookie-value", cookies.get(0).getValue());
+        assertTrue("Comment", null == cookies.get(0).getComment());
+        assertTrue("ExpiryDate", null == cookies.get(0).getExpiryDate());
+        //assertTrue("isToBeDiscarded",cookies.get(0).isToBeDiscarded());
+        assertTrue("isPersistent", !cookies.get(0).isPersistent());
+        assertEquals("Domain", "127.0.0.1", cookies.get(0).getDomain());
+        assertEquals("Path", "/", cookies.get(0).getPath());
+        assertTrue("Secure", !cookies.get(0).isSecure());
+        assertEquals("Version", 0, cookies.get(0).getVersion());
     }
  
     public void testParseNoName() throws Exception {
@@ -276,9 +278,9 @@
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
         try {
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException should have been thrown");
         } catch (MalformedCookieException ex) {
@@ -291,21 +293,21 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value", "", parsed[0].getValue());
-        assertTrue("Comment",null == parsed[0].getComment());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
-        assertTrue("isPersistent",!parsed[0].isPersistent());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertEquals("Version",0,parsed[0].getVersion());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value", "", cookies.get(0).getValue());
+        assertTrue("Comment",null == cookies.get(0).getComment());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        //assertTrue("isToBeDiscarded",cookies.get(0).isToBeDiscarded());
+        assertTrue("isPersistent",!cookies.get(0).isPersistent());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertEquals("Version",0,cookies.get(0).getVersion());
     }
 
     public void testParseWithWhiteSpace() throws Exception {
@@ -313,18 +315,18 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        assertTrue("Comment",null == parsed[0].getComment());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        assertTrue("Comment",null == cookies.get(0).getComment());
     }
 
     public void testParseWithQuotes() throws Exception {
@@ -332,18 +334,18 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1",80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value"," cookie-value ",parsed[0].getValue());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        assertTrue("Comment",null == parsed[0].getComment());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value"," cookie-value ",cookies.get(0).getValue());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        assertTrue("Comment",null == cookies.get(0).getComment());
     }
 
     public void testParseWithPath() throws Exception {
@@ -351,18 +353,18 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path/path", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/path/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        assertTrue("Comment",null == parsed[0].getComment());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/path/",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        assertTrue("Comment",null == cookies.get(0).getComment());
     }
 
     public void testParseWithDomain() throws Exception {
@@ -370,18 +372,18 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        assertTrue("Comment",null == parsed[0].getComment());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        assertTrue("Comment",null == cookies.get(0).getComment());
     }
 
     public void testParseWithSecure() throws Exception {
@@ -389,18 +391,18 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",parsed[0].isSecure());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        assertTrue("Comment",null == parsed[0].getComment());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
+        assertTrue("Secure",cookies.get(0).isSecure());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        assertTrue("Comment",null == cookies.get(0).getComment());
     }
 
     public void testParseWithComment() throws Exception {
@@ -409,18 +411,18 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
-        assertEquals("Comment","This is a comment.",parsed[0].getComment());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+        assertEquals("Comment","This is a comment.",cookies.get(0).getComment());
     }
 
     public void testParseWithExpires() throws Exception {
@@ -429,18 +431,18 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].isSecure());
-        assertEquals(new Date(10000L),parsed[0].getExpiryDate());
-        assertTrue("Comment",null == parsed[0].getComment());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
+        assertTrue("Secure",!cookies.get(0).isSecure());
+        assertEquals(new Date(10000L),cookies.get(0).getExpiryDate());
+        assertTrue("Comment",null == cookies.get(0).getComment());
     }
 
     public void testParseWithAll() throws Exception {
@@ -450,19 +452,19 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/commons/httpclient", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookie.",1,parsed.length);
-        assertEquals("Name","cookie-name",parsed[0].getName());
-        assertEquals("Value","cookie-value",parsed[0].getValue());
-        assertEquals("Domain",".apache.org",parsed[0].getDomain());
-        assertEquals("Path","/commons",parsed[0].getPath());
-        assertTrue("Secure",parsed[0].isSecure());
-        assertEquals(new Date(10000L),parsed[0].getExpiryDate());
-        assertEquals("Comment","This is a comment.",parsed[0].getComment());
-        assertEquals("Version",0,parsed[0].getVersion());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookie.",1,cookies.size());
+        assertEquals("Name","cookie-name",cookies.get(0).getName());
+        assertEquals("Value","cookie-value",cookies.get(0).getValue());
+        assertEquals("Domain",".apache.org",cookies.get(0).getDomain());
+        assertEquals("Path","/commons",cookies.get(0).getPath());
+        assertTrue("Secure",cookies.get(0).isSecure());
+        assertEquals(new Date(10000L),cookies.get(0).getExpiryDate());
+        assertEquals("Comment","This is a comment.",cookies.get(0).getComment());
+        assertEquals("Version",0,cookies.get(0).getVersion());
     }
 
     public void testParseMultipleDifferentPaths() throws Exception {
@@ -472,15 +474,15 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/commons/httpclient", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Wrong number of cookies.",2,parsed.length);
-        assertEquals("Name","name1",parsed[0].getName());
-        assertEquals("Value","value1",parsed[0].getValue());
-        assertEquals("Name","name1",parsed[1].getName());
-        assertEquals("Value","value2",parsed[1].getValue());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Wrong number of cookies.",2,cookies.size());
+        assertEquals("Name","name1",cookies.get(0).getName());
+        assertEquals("Value","value1",cookies.get(0).getValue());
+        assertEquals("Name","name1",cookies.get(1).getName());
+        assertEquals("Value","value2",cookies.get(1).getValue());
     }
 
     public void testParseRelativePath() throws Exception {
@@ -488,14 +490,14 @@
 
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "whatever", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookies.",1,parsed.length);
-        assertEquals("Name","name1",parsed[0].getName());
-        assertEquals("Value","value1",parsed[0].getValue());
-        assertEquals("Path","whatever",parsed[0].getPath());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookies.",1,cookies.size());
+        assertEquals("Name","name1",cookies.get(0).getName());
+        assertEquals("Value","value1",cookies.get(0).getValue());
+        assertEquals("Path","whatever",cookies.get(0).getPath());
     }
 
     public void testParseWithWrongDomain() throws Exception {
@@ -505,9 +507,9 @@
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.2", 80, "/", false);
         try {
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException exception should have been thrown");
         } catch (MalformedCookieException ex) {
@@ -522,9 +524,9 @@
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path", false);
         try {
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException should have been thrown.");
         } catch (MalformedCookieException e) {
@@ -539,9 +541,9 @@
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/foo", false);
         try {
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException should have been thrown.");
         } catch (MalformedCookieException e) {
@@ -556,12 +558,12 @@
         Header header = new BasicHeader("Set-Cookie", "invalid name=");
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
         }
-        assertNotNull(parsed);
-        assertEquals(1, parsed.length);
+        assertNotNull(cookies);
+        assertEquals(1, cookies.size());
     }
 
     /**
@@ -572,9 +574,9 @@
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
         try {
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException should have been thrown");
         } catch (MalformedCookieException expected) {
@@ -588,17 +590,17 @@
         Header header = new BasicHeader("Set-Cookie", "$invalid_name=");
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
         }
-        assertNotNull(parsed);
-        assertEquals(1, parsed.length);
+        assertNotNull(cookies);
+        assertEquals(1, cookies.size());
     }
 
 
     /**
-     * Tests if malformatted expires attribute is parsed correctly.
+     * Tests if malformatted expires attribute is cookies correctly.
      */
     public void testCookieWithComma() throws Exception {
         Header header = new BasicHeader("Set-Cookie", "name=value; expires=\"Thu, 01-Jan-1970 00:00:00 GMT");
@@ -606,9 +608,9 @@
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
         try {
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException should have been thrown");
         } catch (MalformedCookieException expected) {
@@ -648,9 +650,9 @@
         Header header = new BasicHeader("Set-Cookie", "custno=12345;Expires='"+date+"';");
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
         }
     }
 
@@ -867,12 +869,12 @@
             "name=value; path=/; domain=.mydomain.com");
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false); 
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        cookiespec.validate(cookies[0], origin);
-        Header[] headers = cookiespec.formatCookies(cookies);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        cookiespec.validate(cookies.get(0), origin);
+        List<Header> headers = cookiespec.formatCookies(cookies);
         assertNotNull(headers);
-        assertEquals(1, headers.length);
-        assertEquals("name=value", headers[0].getValue());
+        assertEquals(1, headers.size());
+        assertEquals("name=value", headers.get(0).getValue());
     }    
 
     /**
@@ -886,10 +888,12 @@
         cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());
 
         CookieSpec cookiespec = new BrowserCompatSpec();
-        Header[] headers = cookiespec.formatCookies(new Cookie[]{ cookie });
+        List<Cookie> cookies = new ArrayList<Cookie>(1);
+        cookies.add(cookie);
+        List<Header> headers = cookiespec.formatCookies(cookies);
         assertNotNull(headers);
-        assertEquals(1, headers.length);
-        assertEquals("name=", headers[0].getValue());
+        assertEquals(1, headers.size());
+        assertEquals("name=", headers.get(0).getValue());
     }
 
     /**
@@ -900,11 +904,11 @@
             "name1=value1; path=/; domain=.mydomain.com, name2 = value2 ; path=/; domain=.mydomain.com");
         CookieSpec cookiespec = new BrowserCompatSpec();
         CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false); 
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        Header[] headers = cookiespec.formatCookies(cookies);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        List<Header> headers = cookiespec.formatCookies(cookies);
         assertNotNull(headers);
-        assertEquals(1, headers.length);
-        assertEquals("name1=value1; name2=value2", headers[0].getValue());
+        assertEquals(1, headers.size());
+        assertEquals("name1=value1; name2=value2", headers.get(0).getValue());
     }    
 
     public void testKeepCloverHappy() throws Exception {
@@ -958,7 +962,8 @@
             // expected
         }
         try {
-            cookiespec.formatCookies(new BasicClientCookie[] {});
+            List<Cookie> cookies = new ArrayList<Cookie>();
+            cookiespec.formatCookies(cookies);
             fail("IllegalArgumentException must have been thrown");
         } catch (IllegalArgumentException ex) {
             // expected

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java?rev=603563&r1=603562&r2=603563&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java Wed Dec 12 03:17:55 2007
@@ -30,6 +30,9 @@
 
 package org.apache.http.impl.cookie;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -68,15 +71,15 @@
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
         CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookies.",1,parsed.length);
-        assertEquals("Name","name1",parsed[0].getName());
-        assertEquals("Value","value1",parsed[0].getValue());
-        assertEquals("Domain","host",parsed[0].getDomain());
-        assertEquals("Path","/path/",parsed[0].getPath());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookies.",1,cookies.size());
+        assertEquals("Name","name1",cookies.get(0).getName());
+        assertEquals("Value","value1",cookies.get(0).getValue());
+        assertEquals("Domain","host",cookies.get(0).getDomain());
+        assertEquals("Path","/path/",cookies.get(0).getPath());
     }
 
     public void testParseAbsPath2() throws Exception {
@@ -84,15 +87,15 @@
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
         CookieOrigin origin = new CookieOrigin("host", 80, "/", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookies.",1,parsed.length);
-        assertEquals("Name","name1",parsed[0].getName());
-        assertEquals("Value","value1",parsed[0].getValue());
-        assertEquals("Domain","host",parsed[0].getDomain());
-        assertEquals("Path","/",parsed[0].getPath());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookies.",1,cookies.size());
+        assertEquals("Name","name1",cookies.get(0).getName());
+        assertEquals("Value","value1",cookies.get(0).getValue());
+        assertEquals("Domain","host",cookies.get(0).getDomain());
+        assertEquals("Path","/",cookies.get(0).getPath());
     }
 
     public void testParseRelativePath() throws Exception {
@@ -100,15 +103,15 @@
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
         CookieOrigin origin = new CookieOrigin("host", 80, "whatever", true);
-        Cookie[] parsed = cookiespec.parse(header, origin);
-        for (int i = 0; i < parsed.length; i++) {
-            cookiespec.validate(parsed[i], origin);
-        }
-        assertEquals("Found 1 cookies.",1,parsed.length);
-        assertEquals("Name","name1",parsed[0].getName());
-        assertEquals("Value","value1",parsed[0].getValue());
-        assertEquals("Domain","host",parsed[0].getDomain());
-        assertEquals("Path","whatever",parsed[0].getPath());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.size(); i++) {
+            cookiespec.validate(cookies.get(i), origin);
+        }
+        assertEquals("Found 1 cookies.",1,cookies.size());
+        assertEquals("Name","name1",cookies.get(0).getName());
+        assertEquals("Value","value1",cookies.get(0).getValue());
+        assertEquals("Domain","host",cookies.get(0).getDomain());
+        assertEquals("Path","whatever",cookies.get(0).getPath());
     }
 
     public void testParseWithIllegalNetscapeDomain1() throws Exception {
@@ -117,9 +120,9 @@
         CookieSpec cookiespec = new NetscapeDraftSpec();
         try {
             CookieOrigin origin = new CookieOrigin("a.com", 80, "/", false);
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException exception should have been thrown");
         } catch (MalformedCookieException e) {
@@ -133,9 +136,9 @@
         CookieSpec cookiespec = new NetscapeDraftSpec();
         try {
             CookieOrigin origin = new CookieOrigin("x.y.z", 80, "/", false);
-            Cookie[] parsed = cookiespec.parse(header, origin);
-            for (int i = 0; i < parsed.length; i++) {
-                cookiespec.validate(parsed[i], origin);
+            List<Cookie> cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.size(); i++) {
+                cookiespec.validate(cookies.get(i), origin);
             }
             fail("MalformedCookieException exception should have been thrown");
         } catch (MalformedCookieException e) {
@@ -151,11 +154,11 @@
           "Set-Cookie", "name=value; path=/; domain=.mydomain.com");
         CookieSpec cookiespec = new NetscapeDraftSpec();
         CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        cookiespec.validate(cookies[0], origin);
-        Header[] headers = cookiespec.formatCookies(cookies);
-        assertEquals(1, headers.length);
-        assertEquals("name=value", headers[0].getValue());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        cookiespec.validate(cookies.get(0), origin);
+        List<Header> headers = cookiespec.formatCookies(cookies);
+        assertEquals(1, headers.size());
+        assertEquals("name=value", headers.get(0).getValue());
     }
     
     /**
@@ -166,13 +169,13 @@
         Header header = new BasicHeader("Set-Cookie", 
             "name=value; path=/; domain=.mydomain.com; expires=Thu, 01-Jan-2070 00:00:10 GMT; comment=no_comment");
         CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        cookiespec.validate(cookies[0], origin);
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        cookiespec.validate(cookies.get(0), origin);
         header = new BasicHeader("Set-Cookie", 
             "name=value; path=/; domain=.mydomain.com; expires=Thu 01-Jan-2070 00:00:10 GMT; comment=no_comment");
         try {
             cookies = cookiespec.parse(header, origin);
-            cookiespec.validate(cookies[0], origin);
+            cookiespec.validate(cookies.get(0), origin);
             fail("MalformedCookieException exception should have been thrown");
         } catch (MalformedCookieException e) {
             // expected
@@ -203,10 +206,10 @@
 
         CookieSpec cookiespec = new NetscapeDraftSpec();
         CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
-        Cookie[] cookies = cookiespec.parse(header, origin);
-        assertEquals("number of cookies", 1, cookies.length);
-        assertEquals("a", cookies[0].getName());
-        assertEquals("b,c", cookies[0].getValue());
+        List<Cookie> cookies = cookiespec.parse(header, origin);
+        assertEquals("number of cookies", 1, cookies.size());
+        assertEquals("a", cookies.get(0).getName());
+        assertEquals("b,c", cookies.get(0).getValue());
     }
  
     public void testFormatCookies() throws Exception {
@@ -220,10 +223,14 @@
         Cookie c3 = new BasicClientCookie("name3", null);
         
         CookieSpec cookiespec = new NetscapeDraftSpec();
-        Header[] headers = cookiespec.formatCookies(new Cookie[] {c1, c2, c3});
+        List<Cookie> cookies = new ArrayList<Cookie>();
+        cookies.add(c1);
+        cookies.add(c2);
+        cookies.add(c3);
+        List<Header> headers = cookiespec.formatCookies(cookies);
         assertNotNull(headers);
-        assertEquals(1, headers.length);
-        assertEquals("name1=value1; name2=value2; name3", headers[0].getValue());
+        assertEquals(1, headers.size());
+        assertEquals("name1=value1; name2=value2; name3", headers.get(0).getValue());
     }    
 
     public void testInvalidInput() throws Exception {
@@ -247,7 +254,8 @@
             // expected
         }
         try {
-            cookiespec.formatCookies(new BasicClientCookie[] {});
+            List<Cookie> cookies = new ArrayList<Cookie>();
+            cookiespec.formatCookies(cookies);
             fail("IllegalArgumentException must have been thrown");
         } catch (IllegalArgumentException ex) {
             // expected



Mime
View raw message