1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.apache.commons.httpclient;
31
32 import junit.framework.*;
33
34 /***
35 * Simple tests for {@link NameValuePair}.
36 *
37 * @author Rodney Waldhoff
38 * @version $Id: TestNVP.java 608014 2008-01-02 05:48:53Z rolandw $
39 */
40 public class TestNVP extends TestCase {
41
42
43 public TestNVP(String testName) {
44 super(testName);
45 }
46
47
48 public static void main(String args[]) {
49 String[] testCaseName = { TestNVP.class.getName() };
50 junit.textui.TestRunner.main(testCaseName);
51 }
52
53
54
55 public static Test suite() {
56 return new TestSuite(TestNVP.class);
57 }
58
59
60
61 protected NameValuePair makePair() {
62 return new NameValuePair();
63 }
64
65 protected NameValuePair makePair(String name, String value) {
66 return new NameValuePair(name,value);
67 }
68
69
70
71
72 public void testGet() {
73 NameValuePair pair = makePair("name 1","value 1");
74 assertEquals("name 1",pair.getName());
75 assertEquals("value 1",pair.getValue());
76 }
77
78 public void testSet() {
79 NameValuePair pair = makePair();
80 assertTrue(null == pair.getName());
81 assertTrue(null == pair.getValue());
82 pair.setName("name");
83 assertEquals("name",pair.getName());
84 pair.setValue("value");
85 assertEquals("value",pair.getValue());
86 }
87
88 public void testHashCode() {
89 NameValuePair param1 = new NameValuePair("name1", "value1");
90 NameValuePair param2 = new NameValuePair("name2", "value2");
91 NameValuePair param3 = new NameValuePair("name1", "value1");
92 assertTrue(param1.hashCode() != param2.hashCode());
93 assertTrue(param1.hashCode() == param3.hashCode());
94 }
95
96 public void testEquals() {
97 NameValuePair param1 = new NameValuePair("name1", "value1");
98 NameValuePair param2 = new NameValuePair("name2", "value2");
99 NameValuePair param3 = new NameValuePair("name1", "value1");
100 assertFalse(param1.equals(param2));
101 assertFalse(param1.equals(null));
102 assertFalse(param1.equals("name1 = value1"));
103 assertTrue(param1.equals(param1));
104 assertTrue(param2.equals(param2));
105 assertTrue(param1.equals(param3));
106 }
107
108 }