@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)));
}