1   /*
2    * $HeaderURL$
3    * $Revision:400312 $
4    * $Date:2006-05-06 14:49:41 +0200 (Sat, 06 May 2006) $
5    * ====================================================================
6    *
7    *  Copyright 1999-2004 The Apache Software Foundation
8    *
9    *  Licensed under the Apache License, Version 2.0 (the "License");
10   *  you may not use this file except in compliance with the License.
11   *  You may obtain a copy of the License at
12   *
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing, software
16   *  distributed under the License is distributed on an "AS IS" BASIS,
17   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   *  See the License for the specific language governing permissions and
19   *  limitations under the License.
20   * ====================================================================
21   *
22   * This software consists of voluntary contributions made by many
23   * individuals on behalf of the Apache Software Foundation.  For more
24   * information on the Apache Software Foundation, please see
25   * <http://www.apache.org/>.
26   *
27   */
28  
29  package org.apache.commons.httpclient.cookie;
30  
31  import java.util.Comparator;
32  
33  import junit.framework.Test;
34  import junit.framework.TestSuite;
35  
36  import org.apache.commons.httpclient.Cookie;
37  
38  /***
39   * Test cases for {@link CookiePathComparator}.
40   */
41  public class TestCookiePathComparator extends TestCookieBase {
42  
43  
44      // ------------------------------------------------------------ Constructor
45  
46      public TestCookiePathComparator(String name) {
47          super(name);
48      }
49  
50      // ------------------------------------------------------- TestCase Methods
51  
52      public static Test suite() {
53          return new TestSuite(TestCookiePathComparator.class);
54      }
55  
56      public void testUnequality1() {
57          Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a/b/", null, false); 
58          Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a/", null, false);
59          Comparator comparator = new CookiePathComparator();
60          assertTrue(comparator.compare(cookie1, cookie2) < 0);
61          assertTrue(comparator.compare(cookie2, cookie1) > 0);
62      }
63  
64      public void testUnequality2() {
65          Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a/b", null, false); 
66          Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a", null, false);
67          Comparator comparator = new CookiePathComparator();
68          assertTrue(comparator.compare(cookie1, cookie2) < 0);
69          assertTrue(comparator.compare(cookie2, cookie1) > 0);
70      }
71  
72      public void testEquality1() {
73          Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a", null, false); 
74          Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a", null, false);
75          Comparator comparator = new CookiePathComparator();
76          assertTrue(comparator.compare(cookie1, cookie2) == 0);
77          assertTrue(comparator.compare(cookie2, cookie1) == 0);
78      }
79  
80      public void testEquality2() {
81          Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/a/", null, false); 
82          Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/a", null, false);
83          Comparator comparator = new CookiePathComparator();
84          assertTrue(comparator.compare(cookie1, cookie2) == 0);
85          assertTrue(comparator.compare(cookie2, cookie1) == 0);
86      }
87  
88      public void testEquality3() {
89          Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", null, null, false); 
90          Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/", null, false);
91          Comparator comparator = new CookiePathComparator();
92          assertTrue(comparator.compare(cookie1, cookie2) == 0);
93          assertTrue(comparator.compare(cookie2, cookie1) == 0);
94      }
95  
96      public void testEquality4() {
97          Cookie cookie1 = new Cookie(".whatever.com", "name1", "value", "/this", null, false); 
98          Cookie cookie2 = new Cookie(".whatever.com", "name1", "value", "/that", null, false);
99          Comparator comparator = new CookiePathComparator();
100         assertTrue(comparator.compare(cookie1, cookie2) == 0);
101         assertTrue(comparator.compare(cookie2, cookie1) == 0);
102     }
103     
104 }
105