1   /*
2    * $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 $
3    * $Revision: 157457 $
4    * $Date: 2005-03-14 15:23:16 -0500 (Mon, 14 Mar 2005) $
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;
30  
31  import junit.framework.*;
32  
33  /***
34   * Simple tests for {@link NameValuePair}.
35   *
36   * @author Rodney Waldhoff
37   * @version $Id: TestNVP.java 157457 2005-03-14 20:23:16Z olegk $
38   */
39  public class TestNVP extends TestCase {
40  
41      // ------------------------------------------------------------ Constructor
42      public TestNVP(String testName) {
43          super(testName);
44      }
45  
46      // ------------------------------------------------------------------- Main
47      public static void main(String args[]) {
48          String[] testCaseName = { TestNVP.class.getName() };
49          junit.textui.TestRunner.main(testCaseName);
50      }
51  
52      // ------------------------------------------------------- TestCase Methods
53  
54      public static Test suite() {
55          return new TestSuite(TestNVP.class);
56      }
57  
58      // ------------------------------------------------------ Protected Methods
59  
60      protected NameValuePair makePair() {
61          return new NameValuePair();
62      }
63  
64      protected NameValuePair makePair(String name, String value) {
65          return new NameValuePair(name,value);
66      }
67  
68  
69      // ----------------------------------------------------------- Test Methods
70  
71      public void testGet() {
72          NameValuePair pair = makePair("name 1","value 1");
73          assertEquals("name 1",pair.getName());
74          assertEquals("value 1",pair.getValue());
75      }
76  
77      public void testSet() {
78          NameValuePair pair = makePair();
79          assertTrue(null == pair.getName());
80          assertTrue(null == pair.getValue());
81          pair.setName("name");
82          assertEquals("name",pair.getName());
83          pair.setValue("value");
84          assertEquals("value",pair.getValue());
85      }
86  
87      public void testHashCode() {
88          NameValuePair param1 = new NameValuePair("name1", "value1");
89          NameValuePair param2 = new NameValuePair("name2", "value2");
90          NameValuePair param3 = new NameValuePair("name1", "value1");
91          assertTrue(param1.hashCode() != param2.hashCode());
92          assertTrue(param1.hashCode() == param3.hashCode());
93      }
94      
95      public void testEquals() {
96          NameValuePair param1 = new NameValuePair("name1", "value1");
97          NameValuePair param2 = new NameValuePair("name2", "value2");
98          NameValuePair param3 = new NameValuePair("name1", "value1");
99          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 }