UriEncoding { public static String encodeQuery(final String query, final EncodingType encType) { requireNonNull(query); requireNonNull(encType); if (encType == EncodingType.FORM_URL_ENCODED) { return encodeFormUrlEncoded(query) .replaceAll("%3D", "=") .replaceAll("%26", "&"); } else { return encodeRFC3986UriComponent(query, ALLOWED_IN_QUERY); } }  static String encodePath(final String path); static String encodePathSegment(final String pathSegment); static String encodeQuery(final String query, final EncodingType encType); static String encodeQueryParam(final String queryParam, final EncodingType encType); static String decode(final String source, final EncodingType encType);  }
@Test public void encodeQueryRfc3986() { assertEquals("foo", UriEncoding.encodeQuery("foo", RFC3986)); assertEquals("foo=bar/%2B&baz=1", UriEncoding.encodeQuery("foo=bar/+&baz=1", RFC3986)); assertEquals("!%22%23$%25&'()*%2B,/:;=?@%5B%5C%5D%7B%7C%7D%20%C3%A4aZ0", UriEncoding.encodeQuery(MANY_DIFFERENT_CHARS, RFC3986)); }
@Test public void encodeQueryFormUrlEncoded() { assertEquals("foo", UriEncoding.encodeQuery("foo", FORM_URL_ENCODED)); assertEquals("foo=bar%2F%2B&baz=1", UriEncoding.encodeQuery("foo=bar/+&baz=1", FORM_URL_ENCODED)); assertEquals("%21%22%23%24%25&%27%28%29*%2B%2C%2F%3A%3B=%3F%40%5B%5C%5D%7B%7C%7D+%C3%A4aZ0", UriEncoding.encodeQuery(MANY_DIFFERENT_CHARS, FORM_URL_ENCODED)); }