UriEncoding { public static String encodeQueryParam(final String queryParam, final EncodingType encType) { requireNonNull(queryParam); requireNonNull(encType); if (encType == EncodingType.FORM_URL_ENCODED) { return encodeFormUrlEncoded(queryParam); } else { return encodeRFC3986UriComponent(queryParam, ALLOWED_IN_QUERY_PARAM); } }  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 encodeQueryParamRfc3986() { assertEquals("foo", UriEncoding.encodeQueryParam("foo", RFC3986)); assertEquals("foo%3Dbar/%2B%26baz%3D1", UriEncoding.encodeQueryParam("foo=bar/+&baz=1", RFC3986)); assertEquals(MANY_DIFFERENT_CHARS_QUERY_PARAM_ENCODED_RFC3986, UriEncoding.encodeQueryParam(MANY_DIFFERENT_CHARS, RFC3986)); }
@Test public void encodeQueryParamFormUrlEncoded() { assertEquals("foo", UriEncoding.encodeQueryParam("foo", FORM_URL_ENCODED)); assertEquals("foo%3Dbar%2F%2B%26baz%3D1", UriEncoding.encodeQueryParam("foo=bar/+&baz=1", FORM_URL_ENCODED)); assertEquals("%21%22%23%24%25%26%27%28%29*%2B%2C%2F%3A%3B%3D%3F%40%5B%5C%5D%7B%7C%7D+%C3%A4aZ0", UriEncoding.encodeQueryParam(MANY_DIFFERENT_CHARS, FORM_URL_ENCODED)); }