001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestNVP.java,v 1.5 2004/02/22 18:08:49 olegk Exp $
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;
031:
032: import junit.framework.*;
033:
034: /**
035: * Simple tests for {@link NameValuePair}.
036: *
037: * @author Rodney Waldhoff
038: * @version $Id: TestNVP.java 480424 2006-11-29 05:56:49Z bayard $
039: */
040: public class TestNVP extends TestCase {
041:
042: // ------------------------------------------------------------ Constructor
043: public TestNVP(String testName) {
044: super (testName);
045: }
046:
047: // ------------------------------------------------------------------- Main
048: public static void main(String args[]) {
049: String[] testCaseName = { TestNVP.class.getName() };
050: junit.textui.TestRunner.main(testCaseName);
051: }
052:
053: // ------------------------------------------------------- TestCase Methods
054:
055: public static Test suite() {
056: return new TestSuite(TestNVP.class);
057: }
058:
059: // ------------------------------------------------------ Protected Methods
060:
061: protected NameValuePair makePair() {
062: return new NameValuePair();
063: }
064:
065: protected NameValuePair makePair(String name, String value) {
066: return new NameValuePair(name, value);
067: }
068:
069: // ----------------------------------------------------------- Test Methods
070:
071: public void testGet() {
072: NameValuePair pair = makePair("name 1", "value 1");
073: assertEquals("name 1", pair.getName());
074: assertEquals("value 1", pair.getValue());
075: }
076:
077: public void testSet() {
078: NameValuePair pair = makePair();
079: assertTrue(null == pair.getName());
080: assertTrue(null == pair.getValue());
081: pair.setName("name");
082: assertEquals("name", pair.getName());
083: pair.setValue("value");
084: assertEquals("value", pair.getValue());
085: }
086:
087: public void testHashCode() {
088: NameValuePair param1 = new NameValuePair("name1", "value1");
089: NameValuePair param2 = new NameValuePair("name2", "value2");
090: NameValuePair param3 = new NameValuePair("name1", "value1");
091: assertTrue(param1.hashCode() != param2.hashCode());
092: assertTrue(param1.hashCode() == param3.hashCode());
093: }
094:
095: public void testEquals() {
096: NameValuePair param1 = new NameValuePair("name1", "value1");
097: NameValuePair param2 = new NameValuePair("name2", "value2");
098: NameValuePair param3 = new NameValuePair("name1", "value1");
099: assertFalse(param1.equals(param2));
100: assertFalse(param1.equals(null));
101: assertFalse(param1.equals("name1 = value1"));
102: assertTrue(param1.equals(param1));
103: assertTrue(param2.equals(param2));
104: assertTrue(param1.equals(param3));
105: }
106:
107: }
|