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 package org.apache.hc.core5.http.message;
29
30 import org.apache.hc.core5.http.NameValuePair;
31 import org.junit.Assert;
32 import org.junit.Test;
33
34
35
36
37
38 public class TestNameValuePair {
39
40 @Test
41 public void testConstructor() {
42 final NameValuePair param = new BasicNameValuePair("name", "value");
43 Assert.assertEquals("name", param.getName());
44 Assert.assertEquals("value", param.getValue());
45 }
46
47 @Test
48 public void testInvalidName() {
49 try {
50 new BasicNameValuePair(null, null);
51 Assert.fail("NullPointerException should have been thrown");
52 } catch (final NullPointerException ex) {
53
54 }
55 }
56
57 @Test
58 public void testToString() {
59 final NameValuePair param1 = new BasicNameValuePair("name1", "value1");
60 Assert.assertEquals("name1=value1", param1.toString());
61 final NameValuePair param2 = new BasicNameValuePair("name1", null);
62 Assert.assertEquals("name1", param2.toString());
63 }
64
65 @Test
66 public void testNullNotEqual() throws Exception {
67 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
68
69 Assert.assertFalse(NameValuePair.equals(null));
70 }
71
72 @Test
73 public void testObjectNotEqual() throws Exception {
74 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
75
76 Assert.assertFalse(NameValuePair.equals(new Object()));
77 }
78
79 @Test
80 public void testNameEquals() throws Exception {
81 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
82 final NameValuePair NameValuePair2 = new BasicNameValuePair("NAME", "value");
83
84 Assert.assertEquals(NameValuePair, NameValuePair2);
85 Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
86
87 final NameValuePair NameValuePair3 = new BasicNameValuePair("NAME", "value");
88 final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "value");
89
90 Assert.assertEquals(NameValuePair3, NameValuePair4);
91 Assert.assertEquals(NameValuePair3.hashCode(), NameValuePair4.hashCode());
92 }
93
94 @Test
95 public void testValueEquals() throws Exception {
96 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
97 final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value");
98
99 Assert.assertEquals(NameValuePair, NameValuePair2);
100 Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
101 }
102
103 @Test
104 public void testNameNotEqual() throws Exception {
105 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
106 final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", "value");
107
108 Assert.assertNotEquals(NameValuePair, NameValuePair2);
109 }
110
111 @Test
112 public void testValueNotEqual() throws Exception {
113 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
114 final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value2");
115
116 Assert.assertNotEquals(NameValuePair, NameValuePair2);
117
118 final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value");
119 final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "VALUE");
120
121 Assert.assertNotEquals(NameValuePair3, NameValuePair4);
122
123 final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "VALUE");
124 final NameValuePair NameValuePair6 = new BasicNameValuePair("name", "value");
125
126 Assert.assertNotEquals(NameValuePair5, NameValuePair6);
127 }
128
129 @Test
130 public void testNullValuesEquals() throws Exception {
131 final NameValuePair NameValuePair = new BasicNameValuePair("name", null);
132 final NameValuePair NameValuePair2 = new BasicNameValuePair("name", null);
133
134 Assert.assertEquals(NameValuePair, NameValuePair2);
135 Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
136 }
137
138 @Test
139 public void testNullValueNotEqual() throws Exception {
140 final NameValuePair NameValuePair = new BasicNameValuePair("name", null);
141 final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value");
142
143 Assert.assertNotEquals(NameValuePair, NameValuePair2);
144 }
145
146 @Test
147 public void testNullValue2NotEqual() throws Exception {
148 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
149 final NameValuePair NameValuePair2 = new BasicNameValuePair("name", null);
150
151 Assert.assertNotEquals(NameValuePair, NameValuePair2);
152 }
153
154 @Test
155 public void testEquals() throws Exception {
156 final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
157 final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value");
158
159 Assert.assertEquals(NameValuePair, NameValuePair);
160 Assert.assertEquals(NameValuePair.hashCode(), NameValuePair.hashCode());
161 Assert.assertEquals(NameValuePair2, NameValuePair2);
162 Assert.assertEquals(NameValuePair2.hashCode(), NameValuePair2.hashCode());
163 Assert.assertEquals(NameValuePair, NameValuePair2);
164 Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
165 }
166
167 @Test
168 public void testHashCode() throws Exception {
169 final NameValuePair NameValuePair = new BasicNameValuePair("name", null);
170 final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", null);
171
172 Assert.assertNotEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
173
174 final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value");
175 final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "value2");
176
177 Assert.assertNotEquals(NameValuePair3.hashCode(), NameValuePair4.hashCode());
178
179 final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "value");
180 final NameValuePair NameValuePair6 = new BasicNameValuePair("name", null);
181
182 Assert.assertNotEquals(NameValuePair5.hashCode(), NameValuePair6.hashCode());
183 }
184
185 }