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