001: /*
002: * $HeaderURL$
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: * ====================================================================
006: *
007: * Licensed to the Apache Software Foundation (ASF) under one or more
008: * contributor license agreements. See the NOTICE file distributed with
009: * this work for additional information regarding copyright ownership.
010: * The ASF licenses this file to You under the Apache License, Version 2.0
011: * (the "License"); you may not use this file except in compliance with
012: * the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * ====================================================================
022: *
023: * This software consists of voluntary contributions made by many
024: * individuals on behalf of the Apache Software Foundation. For more
025: * information on the Apache Software Foundation, please see
026: * <http://www.apache.org/>.
027: *
028: */
029:
030: package org.apache.commons.httpclient.cookie;
031:
032: import java.util.Comparator;
033:
034: import junit.framework.Test;
035: import junit.framework.TestSuite;
036:
037: import org.apache.commons.httpclient.Cookie;
038:
039: /**
040: * Test cases for {@link CookiePathComparator}.
041: */
042: public class TestCookiePathComparator extends TestCookieBase {
043:
044: // ------------------------------------------------------------ Constructor
045:
046: public TestCookiePathComparator(String name) {
047: super (name);
048: }
049:
050: // ------------------------------------------------------- TestCase Methods
051:
052: public static Test suite() {
053: return new TestSuite(TestCookiePathComparator.class);
054: }
055:
056: public void testUnequality1() {
057: Cookie cookie1 = new Cookie(".whatever.com", "name1", "value",
058: "/a/b/", null, false);
059: Cookie cookie2 = new Cookie(".whatever.com", "name1", "value",
060: "/a/", null, false);
061: Comparator comparator = new CookiePathComparator();
062: assertTrue(comparator.compare(cookie1, cookie2) < 0);
063: assertTrue(comparator.compare(cookie2, cookie1) > 0);
064: }
065:
066: public void testUnequality2() {
067: Cookie cookie1 = new Cookie(".whatever.com", "name1", "value",
068: "/a/b", null, false);
069: Cookie cookie2 = new Cookie(".whatever.com", "name1", "value",
070: "/a", null, false);
071: Comparator comparator = new CookiePathComparator();
072: assertTrue(comparator.compare(cookie1, cookie2) < 0);
073: assertTrue(comparator.compare(cookie2, cookie1) > 0);
074: }
075:
076: public void testEquality1() {
077: Cookie cookie1 = new Cookie(".whatever.com", "name1", "value",
078: "/a", null, false);
079: Cookie cookie2 = new Cookie(".whatever.com", "name1", "value",
080: "/a", null, false);
081: Comparator comparator = new CookiePathComparator();
082: assertTrue(comparator.compare(cookie1, cookie2) == 0);
083: assertTrue(comparator.compare(cookie2, cookie1) == 0);
084: }
085:
086: public void testEquality2() {
087: Cookie cookie1 = new Cookie(".whatever.com", "name1", "value",
088: "/a/", null, false);
089: Cookie cookie2 = new Cookie(".whatever.com", "name1", "value",
090: "/a", null, false);
091: Comparator comparator = new CookiePathComparator();
092: assertTrue(comparator.compare(cookie1, cookie2) == 0);
093: assertTrue(comparator.compare(cookie2, cookie1) == 0);
094: }
095:
096: public void testEquality3() {
097: Cookie cookie1 = new Cookie(".whatever.com", "name1", "value",
098: null, null, false);
099: Cookie cookie2 = new Cookie(".whatever.com", "name1", "value",
100: "/", null, false);
101: Comparator comparator = new CookiePathComparator();
102: assertTrue(comparator.compare(cookie1, cookie2) == 0);
103: assertTrue(comparator.compare(cookie2, cookie1) == 0);
104: }
105:
106: public void testEquality4() {
107: Cookie cookie1 = new Cookie(".whatever.com", "name1", "value",
108: "/this", null, false);
109: Cookie cookie2 = new Cookie(".whatever.com", "name1", "value",
110: "/that", null, false);
111: Comparator comparator = new CookiePathComparator();
112: assertTrue(comparator.compare(cookie1, cookie2) == 0);
113: assertTrue(comparator.compare(cookie2, cookie1) == 0);
114: }
115:
116: }
|