001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/message/TestNameValuePair.java $
003: * $Revision: 604625 $
004: * $Date: 2007-12-16 15:11:11 +0100 (Sun, 16 Dec 2007) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.message;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: import org.apache.http.NameValuePair;
039:
040: /**
041: * Unit tests for {@link NameValuePair}.
042: *
043: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
044: */
045: public class TestNameValuePair extends TestCase {
046:
047: public TestNameValuePair(String testName) {
048: super (testName);
049: }
050:
051: public static void main(String args[]) {
052: String[] testCaseName = { TestNameValuePair.class.getName() };
053: junit.textui.TestRunner.main(testCaseName);
054: }
055:
056: public static Test suite() {
057: return new TestSuite(TestNameValuePair.class);
058: }
059:
060: public void testConstructor() {
061: NameValuePair param = new BasicNameValuePair("name", "value");
062: assertEquals("name", param.getName());
063: assertEquals("value", param.getValue());
064: }
065:
066: public void testInvalidName() {
067: try {
068: new BasicNameValuePair(null, null);
069: fail("IllegalArgumentException should have been thrown");
070: } catch (IllegalArgumentException ex) {
071: //expected
072: }
073: }
074:
075: public void testHashCode() {
076: NameValuePair param1 = new BasicNameValuePair("name1", "value1");
077: NameValuePair param2 = new BasicNameValuePair("name2", "value2");
078: NameValuePair param3 = new BasicNameValuePair("name1", "value1");
079: assertTrue(param1.hashCode() != param2.hashCode());
080: assertTrue(param1.hashCode() == param3.hashCode());
081: }
082:
083: public void testEquals() {
084: NameValuePair param1 = new BasicNameValuePair("name1", "value1");
085: NameValuePair param2 = new BasicNameValuePair("name2", "value2");
086: NameValuePair param3 = new BasicNameValuePair("name1", "value1");
087: assertFalse(param1.equals(param2));
088: assertFalse(param1.equals(null));
089: assertFalse(param1.equals("name1 = value1"));
090: assertTrue(param1.equals(param1));
091: assertTrue(param2.equals(param2));
092: assertTrue(param1.equals(param3));
093: }
094:
095: public void testToString() {
096: NameValuePair param1 = new BasicNameValuePair("name1", "value1");
097: assertEquals("name1=value1", param1.toString());
098: NameValuePair param2 = new BasicNameValuePair("name1", null);
099: assertEquals("name1", param2.toString());
100: }
101:
102: public void testCloning() throws Exception {
103: BasicNameValuePair orig = new BasicNameValuePair("name1",
104: "value1");
105: BasicNameValuePair clone = (BasicNameValuePair) orig.clone();
106: assertEquals(orig, clone);
107: }
108:
109: }
|