public Form add(final String name, final String value) { this.params.add(new BasicNameValuePair(name, value)); return this; }
private List<NameValuePair> createParameters() { final List<NameValuePair> parameters = new ArrayList<>(); parameters.add(new BasicNameValuePair("parameter1", "value1")); parameters.add(new BasicNameValuePair("parameter2", "\"1\u00aa position\"")); parameters.add(new BasicNameValuePair("parameter3", "Jos\u00e9 Abra\u00e3o")); return parameters; }
@Test public void testValueNotEqual() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value2"); Assert.assertNotEquals(NameValuePair, NameValuePair2); final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "VALUE"); Assert.assertNotEquals(NameValuePair3, NameValuePair4); final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "VALUE"); final NameValuePair NameValuePair6 = new BasicNameValuePair("name", "value"); Assert.assertNotEquals(NameValuePair5, NameValuePair6); }
@Test public void testHashCode() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", null); final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", null); Assert.assertNotEquals(NameValuePair.hashCode(), NameValuePair2.hashCode()); final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "value2"); Assert.assertNotEquals(NameValuePair3.hashCode(), NameValuePair4.hashCode()); final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair6 = new BasicNameValuePair("name", null); Assert.assertNotEquals(NameValuePair5.hashCode(), NameValuePair6.hashCode()); }
@Test public void testNullValueNotEqual() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", null); final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value"); Assert.assertNotEquals(NameValuePair, NameValuePair2); }
@Test public void testNullValue2NotEqual() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair2 = new BasicNameValuePair("name", null); Assert.assertNotEquals(NameValuePair, NameValuePair2); }
@Test public void testToString() { final BasicHeaderElement element = new BasicHeaderElement("name", "value", new NameValuePair[] { new BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2", "value2") } ); Assert.assertEquals("name=value; param1=value1; param2=value2", element.toString()); }
@Test public void testNameNotEqual() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", "value"); Assert.assertNotEquals(NameValuePair, NameValuePair2); }
@Test public void testNameEquals() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair2 = new BasicNameValuePair("NAME", "value"); Assert.assertEquals(NameValuePair, NameValuePair2); Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode()); final NameValuePair NameValuePair3 = new BasicNameValuePair("NAME", "value"); final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "value"); Assert.assertEquals(NameValuePair3, NameValuePair4); Assert.assertEquals(NameValuePair3.hashCode(), NameValuePair4.hashCode()); }
@Test public void testToString() { final NameValuePair param1 = new BasicNameValuePair("name1", "value1"); Assert.assertEquals("name1=value1", param1.toString()); final NameValuePair param2 = new BasicNameValuePair("name1", null); Assert.assertEquals("name1", param2.toString()); }
@Test public void testValueEquals() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value"); Assert.assertEquals(NameValuePair, NameValuePair2); Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode()); }
@Test public void testNullValuesEquals() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", null); final NameValuePair NameValuePair2 = new BasicNameValuePair("name", null); Assert.assertEquals(NameValuePair, NameValuePair2); Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode()); }
@Test public void testObjectNotEqual() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); Assert.assertFalse(NameValuePair.equals(new Object())); }
@Test public void testHEFormatting() throws Exception { final NameValuePair param1 = new BasicNameValuePair("param", "regular_stuff"); final NameValuePair param2 = new BasicNameValuePair("param", "this\\that"); final NameValuePair param3 = new BasicNameValuePair("param", "this,that"); final NameValuePair param4 = new BasicNameValuePair("param", null); final NameValuePair[] params = new NameValuePair[] {param1, param2, param3, param4}; final HeaderElement element = new BasicHeaderElement("name", "value", params); final CharArrayBuffer buf = new CharArrayBuffer(64); this.formatter.formatHeaderElement(buf, element, false); Assert.assertEquals("name=value; param=regular_stuff; param=\"this\\\\that\"; param=\"this,that\"; param", buf.toString()); }
@Test public void testNullNotEqual() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); Assert.assertFalse(NameValuePair.equals(null)); }
@Test public void testEmptyQuery() throws Exception { final List<NameValuePair> result = URLEncodedUtils.parse("", StandardCharsets.UTF_8); Assert.assertEquals(0, result.size()); // [HTTPCLIENT-1889]: result.add(new BasicNameValuePair("key", "value")); }
@Test public void testInvalidName() { try { new BasicNameValuePair(null, null); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException ex) { //expected } }
@Test public void testEquals() throws Exception { final NameValuePair NameValuePair = new BasicNameValuePair("name", "value"); final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value"); Assert.assertEquals(NameValuePair, NameValuePair); Assert.assertEquals(NameValuePair.hashCode(), NameValuePair.hashCode()); Assert.assertEquals(NameValuePair2, NameValuePair2); Assert.assertEquals(NameValuePair2.hashCode(), NameValuePair2.hashCode()); Assert.assertEquals(NameValuePair, NameValuePair2); Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode()); }
@Test public void testParseUTF8Ampersand1String() throws Exception { final String ru_hello = constructString(RUSSIAN_HELLO); final String ch_hello = constructString(SWISS_GERMAN_HELLO); final List <NameValuePair> parameters = new ArrayList<>(); parameters.add(new BasicNameValuePair("russian", ru_hello)); parameters.add(new BasicNameValuePair("swiss", ch_hello)); final String s = URLEncodedUtils.format(parameters, StandardCharsets.UTF_8); final List <NameValuePair> result = URLEncodedUtils.parse(s, StandardCharsets.UTF_8); Assert.assertEquals(2, result.size()); assertNameValuePair(result.get(0), "russian", ru_hello); assertNameValuePair(result.get(1), "swiss", ch_hello); }
@Test public void testConstructor() { final NameValuePair param = new BasicNameValuePair("name", "value"); Assert.assertEquals("name", param.getName()); Assert.assertEquals("value", param.getValue()); }