@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()); }
@Override public void formatNameValuePair( final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote) { Args.notNull(buffer, "Char array buffer"); Args.notNull(nvp, "Name / value pair"); buffer.append(nvp.getName()); final String value = nvp.getValue(); if (value != null) { buffer.append('='); formatValue(buffer, value, quote); } }
BasicHeaderValueFormatter implements HeaderValueFormatter { @Override public void formatNameValuePair( final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote) { Args.notNull(buffer, "Char array buffer"); Args.notNull(nvp, "Name / value pair"); buffer.append(nvp.getName()); final String value = nvp.getValue(); if (value != null) { buffer.append('='); formatValue(buffer, value, quote); } } }
BasicHeaderValueFormatter implements HeaderValueFormatter { @Override public void formatNameValuePair( final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote) { Args.notNull(buffer, "Char array buffer"); Args.notNull(nvp, "Name / value pair"); buffer.append(nvp.getName()); final String value = nvp.getValue(); if (value != null) { buffer.append('='); formatValue(buffer, value, quote); } } BasicHeaderValueFormatter(); }
BasicHeaderValueFormatter implements HeaderValueFormatter { @Override public void formatNameValuePair( final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote) { Args.notNull(buffer, "Char array buffer"); Args.notNull(nvp, "Name / value pair"); buffer.append(nvp.getName()); final String value = nvp.getValue(); if (value != null) { buffer.append('='); formatValue(buffer, value, quote); } } BasicHeaderValueFormatter(); @Override void formatElements(
            final CharArrayBuffer buffer, final HeaderElement[] elems, final boolean quote); @Override void formatHeaderElement(
            final CharArrayBuffer buffer, final HeaderElement elem, final boolean quote); @Override void formatParameters(
            final CharArrayBuffer buffer, final NameValuePair[] nvps, final boolean quote); @Override void formatNameValuePair(
            final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote); }
BasicHeaderValueFormatter implements HeaderValueFormatter { @Override public void formatNameValuePair( final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote) { Args.notNull(buffer, "Char array buffer"); Args.notNull(nvp, "Name / value pair"); buffer.append(nvp.getName()); final String value = nvp.getValue(); if (value != null) { buffer.append('='); formatValue(buffer, value, quote); } } BasicHeaderValueFormatter(); @Override void formatElements(
            final CharArrayBuffer buffer, final HeaderElement[] elems, final boolean quote); @Override void formatHeaderElement(
            final CharArrayBuffer buffer, final HeaderElement elem, final boolean quote); @Override void formatParameters(
            final CharArrayBuffer buffer, final NameValuePair[] nvps, final boolean quote); @Override void formatNameValuePair(
            final CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote); final static BasicHeaderValueFormatter INSTANCE; }