WWWFormCodec { public static void format( final StringBuilder buf, final Iterable<? extends NameValuePair> params, final Charset charset) { URIBuilder.formatQuery(buf, params, charset, true); }  static List<NameValuePair> parse(final CharSequence s, final Charset charset); static void format(
            final StringBuilder buf, final Iterable<? extends NameValuePair> params, final Charset charset); static String format(final Iterable<? extends NameValuePair> params, final Charset charset);  }
@Test public void testFormat() throws Exception { MatcherAssert.assertThat(format(new BasicNameValuePair("Name0", null)), CoreMatchers.equalTo("Name0")); MatcherAssert.assertThat(format(new BasicNameValuePair("Name1", "Value1")), CoreMatchers.equalTo("Name1=Value1")); MatcherAssert.assertThat(format(new BasicNameValuePair("Name2", "")), CoreMatchers.equalTo("Name2=")); MatcherAssert.assertThat(format(new BasicNameValuePair("Name4", "Value 4&")), CoreMatchers.equalTo("Name4=Value+4%26")); MatcherAssert.assertThat(format(new BasicNameValuePair("Name4", "Value+4&")), CoreMatchers.equalTo("Name4=Value%2B4%26")); MatcherAssert.assertThat(format(new BasicNameValuePair("Name4", "Value 4& =4")), CoreMatchers.equalTo("Name4=Value+4%26+%3D4")); MatcherAssert.assertThat(format( new BasicNameValuePair("Name5", "aaa"), new BasicNameValuePair("Name6", "bbb")), CoreMatchers.equalTo("Name5=aaa&Name6=bbb")); MatcherAssert.assertThat(format( new BasicNameValuePair("Name7", "aaa"), new BasicNameValuePair("Name7", "b,b"), new BasicNameValuePair("Name7", "ccc") ), CoreMatchers.equalTo("Name7=aaa&Name7=b%2Cb&Name7=ccc")); MatcherAssert.assertThat(format(new BasicNameValuePair("Name8", "xx, yy ,zz")), CoreMatchers.equalTo("Name8=xx%2C++yy++%2Czz")); MatcherAssert.assertThat(format( new BasicNameValuePair("russian", RU_HELLO), new BasicNameValuePair("swiss", CH_HELLO)), CoreMatchers.equalTo("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8))); }