Index: TestCookie.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v
retrieving revision 1.2
diff -c -r1.2 TestCookie.java
*** TestCookie.java	4 Oct 2001 17:49:13 -0000	1.2
--- TestCookie.java	31 Jan 2002 18:34:25 -0000
***************
*** 66,71 ****
--- 66,75 ----
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import java.util.Date;
+ import java.util.Vector;
+ import java.util.SortedSet;
+ import java.util.TreeSet;
+ import java.util.Iterator;
  
  
  /**
***************
*** 376,380 ****
--- 380,445 ----
          } catch (HttpException e) {
              // expected
          }
+     }
+ 
+     public void testComparator() throws Exception {
+         Header setCookie = null;
+ 	Cookie[] parsed = null;
+ 	Vector cookies = new Vector();
+ 	// Cookie 0
+ 	setCookie = new Header("Set-Cookie","cookie-name=cookie-value;Path=/commons;Domain=.apache.org;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
+         parsed = Cookie.parse(".apache.org","/commons/httpclient",true,setCookie);
+ 	cookies.add(parsed[0]);
+ 	// Cookie 1
+         setCookie = new Header("Set-Cookie","cookie-name=cookie-value;Path=/commons/bif;Domain=.apache.org;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
+         parsed = Cookie.parse(".apache.org","/commons/bif/httpclient",true,setCookie);
+ 	cookies.add(parsed[0]);
+ 	// Cookie 2
+         setCookie = new Header("Set-Cookie","cookie-name=cookie-value;Path=/commons;Domain=.baz.org;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
+         parsed = Cookie.parse(".baz.org","/commons/httpclient",true,setCookie);
+ 	cookies.add(parsed[0]);
+ 	// Cookie 3
+         setCookie = new Header("Set-Cookie","cookie-name=cookie-value;Path=/commons/bif;Domain=.baz.org;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
+         parsed = Cookie.parse(".baz.org","/commons/bif/httpclient",true,setCookie);
+ 	cookies.add(parsed[0]);
+ 	// Cookie 4
+         setCookie = new Header("Set-Cookie","cookie-name=cookie-value;Path=/commons;Domain=.baz.com;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
+         parsed = Cookie.parse(".baz.com","/commons/httpclient",true,setCookie);
+ 	cookies.add(parsed[0]);
+ 	// The order should be:
+ 	// 1, 0, 3, 2, 4
+ 	parsed = (Cookie[])cookies.toArray(new Cookie[0]);
+ 	SortedSet set = new TreeSet(parsed[0]);
+ 	int pass = 0;
+ 	for (Iterator itr = set.iterator(); itr.hasNext();) {
+ 	    Cookie cookie = (Cookie)itr.next();
+ 	    switch (pass) {
+ 		case 0:
+ 		    assert("0th cookie should be cookie[1]", cookie == parsed[1]);
+ 		    break;
+ 		case 1:
+ 		    assert("1st cookie should be cookie[0]", cookie == parsed[0]);
+ 		    break;
+ 		case 2:
+ 		    assert("2nd cookie should be cookie[3]", cookie == parsed[3]);
+ 		    break;
+ 		case 3:
+ 		    assert("3rd cookie should be cookie[2]", cookie == parsed[2]);
+ 		    break;
+ 		case 4:
+ 		    assert("4th cookie should be cookie[4]", cookie == parsed[4]);
+ 		    break;
+ 		default:
+ 		    fail("This should never happen.");
+ 	    }
+ 	    pass++;
+ 	}
+ 	try {
+ 	    parsed[0].compare("foo", "bar");
+ 	    fail("Should have thrown an exception trying to compare non-cookies");
+ 	}
+ 	catch (ClassCastException ex) {
+ 	    // expected
+ 	}
      }
  }

