@Test
public void testNVPFormatting() 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", "quote marks (\") must be escaped");
    final NameValuePair param5 = new BasicNameValuePair("param", "back slash (\\) must be escaped too");
    final NameValuePair param6 = new BasicNameValuePair("param", "values with\tblanks must always be quoted");
    final NameValuePair param7 = new BasicNameValuePair("param", null);
    final CharArrayBuffer buf = new CharArrayBuffer(64);
    buf.clear();
    this.formatter.formatNameValuePair(buf, param1, false);
    Assert.assertEquals("param=regular_stuff", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param2, false);
    Assert.assertEquals("param=\"this\\\\that\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param3, false);
    Assert.assertEquals("param=\"this,that\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param4, false);
    Assert.assertEquals("param=\"quote marks (\\\") must be escaped\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param5, false);
    Assert.assertEquals("param=\"back slash (\\\\) must be escaped too\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param6, false);
    Assert.assertEquals("param=\"values with\tblanks must always be quoted\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param7, false);
    Assert.assertEquals("param", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param1, true);
    Assert.assertEquals("param=\"regular_stuff\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param2, true);
    Assert.assertEquals("param=\"this\\\\that\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param3, true);
    Assert.assertEquals("param=\"this,that\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param4, true);
    Assert.assertEquals("param=\"quote marks (\\\") must be escaped\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param5, true);
    Assert.assertEquals("param=\"back slash (\\\\) must be escaped too\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param6, true);
    Assert.assertEquals("param=\"values with\tblanks must always be quoted\"", buf.toString());
    buf.clear();
    this.formatter.formatNameValuePair(buf, param7, true);
    Assert.assertEquals("param", buf.toString());
}