URLEncodedUtils { public static List <NameValuePair> parse (final URI uri, final String encoding) { List <NameValuePair> result = Collections.emptyList(); final String query = uri.getRawQuery(); if (query != null && query.length() > 0) { result = new ArrayList <NameValuePair>(); parse(result, new Scanner(query), encoding); } return result; }  static List <NameValuePair> parse(final URI uri, final String encoding); static List <NameValuePair> parse(
            final HttpEntity entity); static boolean isEncoded(final HttpEntity entity); static void parse(
            final List <NameValuePair> parameters,
            final Scanner scanner,
            final String encoding); static String format(
            final List <? extends NameValuePair> parameters,
            final String encoding); static final String CONTENT_TYPE; }
@Test public void testParseURI () throws Exception { List <NameValuePair> result; result = parse("", null); Assert.assertTrue(result.isEmpty()); result = parse("Name1=Value1", null); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name1", "Value1"); result = parse("Name2=", null); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name2", null); result = parse("Name3", null); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name3", null); result = parse("Name4=Value+4%21", null); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name4", "Value 4!"); result = parse("Name4=Value%2B4%21", null); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name4", "Value+4!"); result = parse("Name4=Value+4%21+%214", null); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name4", "Value 4! !4"); result = parse("Name5=aaa&Name6=bbb", null); Assert.assertEquals(2, result.size()); assertNameValuePair(result.get(0), "Name5", "aaa"); assertNameValuePair(result.get(1), "Name6", "bbb"); result = parse("Name7=aaa&Name7=b%2Cb&Name7=ccc", null); Assert.assertEquals(3, result.size()); assertNameValuePair(result.get(0), "Name7", "aaa"); assertNameValuePair(result.get(1), "Name7", "b,b"); assertNameValuePair(result.get(2), "Name7", "ccc"); result = parse("Name8=xx%2C++yy++%2Czz", null); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name8", "xx, yy ,zz"); }
@Test public void testParseEntity () throws Exception { final StringEntity entity = new StringEntity("Name1=Value1", null); entity.setContentType(URLEncodedUtils.CONTENT_TYPE); final List <NameValuePair> result = URLEncodedUtils.parse(entity); Assert.assertEquals(1, result.size()); assertNameValuePair(result.get(0), "Name1", "Value1"); entity.setContentType("text/test"); Assert.assertTrue(URLEncodedUtils.parse(entity).isEmpty()); }