KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > TestNVP


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNVP.java,v 1.4.2.1 2004/02/22 18:21:16 olegk Exp $
3  * $Revision: 1.4.2.1 $
4  * $Date: 2004/02/22 18:21:16 $
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  * [Additional notices, if required by prior licensing conditions]
28  *
29  */

30
31 package org.apache.commons.httpclient;
32
33 import junit.framework.*;
34
35 /**
36  * Simple tests for {@link NameValuePair}.
37  *
38  * @author Rodney Waldhoff
39  * @version $Id: TestNVP.java,v 1.4.2.1 2004/02/22 18:21:16 olegk Exp $
40  */

41 public class TestNVP extends TestCase {
42
43     // ------------------------------------------------------------ Constructor
44
public TestNVP(String JavaDoc testName) {
45         super(testName);
46     }
47
48     // ------------------------------------------------------------------- Main
49
public static void main(String JavaDoc args[]) {
50         String JavaDoc[] testCaseName = { TestNVP.class.getName() };
51         junit.textui.TestRunner.main(testCaseName);
52     }
53
54     // ------------------------------------------------------- TestCase Methods
55

56     public static Test suite() {
57         return new TestSuite(TestNVP.class);
58     }
59
60     // ------------------------------------------------------ Protected Methods
61

62     protected NameValuePair makePair() {
63         return new NameValuePair();
64     }
65
66     protected NameValuePair makePair(String JavaDoc name, String JavaDoc value) {
67         return new NameValuePair(name,value);
68     }
69
70
71     // ----------------------------------------------------------- Test Methods
72

73     public void testGet() {
74         NameValuePair pair = makePair("name 1","value 1");
75         assertEquals("name 1",pair.getName());
76         assertEquals("value 1",pair.getValue());
77     }
78
79     public void testSet() {
80         NameValuePair pair = makePair();
81         assertTrue(null == pair.getName());
82         assertTrue(null == pair.getValue());
83         pair.setName("name");
84         assertEquals("name",pair.getName());
85         pair.setValue("value");
86         assertEquals("value",pair.getValue());
87     }
88
89     public void testEqualsAndHashCode() {
90         NameValuePair pair1 = makePair();
91         NameValuePair pair2 = makePair();
92
93         assertEquals(pair1,pair1);
94         assertEquals(pair1.hashCode(),pair1.hashCode());
95         assertEquals(pair2,pair2);
96         assertEquals(pair2.hashCode(),pair2.hashCode());
97         assertEquals(pair1,pair2);
98         assertEquals(pair1.hashCode(),pair2.hashCode());
99         assertEquals(pair2,pair1);
100
101         pair1.setName("name");
102         pair1.setValue("value");
103
104         assertEquals(pair1,pair1);
105         assertEquals(pair1.hashCode(),pair1.hashCode());
106         assertTrue(!pair1.equals(pair2));
107         assertTrue(!pair2.equals(pair1));
108
109         pair2.setName("name");
110
111         assertEquals(pair1,pair1);
112         assertEquals(pair1.hashCode(),pair1.hashCode());
113         assertEquals(pair2,pair2);
114         assertEquals(pair2.hashCode(),pair2.hashCode());
115         assertTrue(!pair1.equals(pair2));
116         assertTrue(!pair2.equals(pair1));
117
118
119         pair2.setValue("value");
120
121         assertEquals(pair1,pair1);
122         assertEquals(pair1.hashCode(),pair1.hashCode());
123         assertEquals(pair2,pair2);
124         assertEquals(pair2.hashCode(),pair2.hashCode());
125         assertEquals(pair1,pair2);
126         assertEquals(pair1.hashCode(),pair2.hashCode());
127         assertEquals(pair2,pair1);
128     }
129 }
130
Popular Tags