HttpUtils { public static String addQueryParameters(String url, Map<String, ?> params) { return addQueryParameters(url, params, false); } private  HttpUtils(); static T waitFor(Future<? extends T> future); static Throwable unwrapCompletionException(Throwable ex); static boolean isSuccessStatus(int status); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor,
                                                         Predicate<Response> successPredicate,
                                                         String tag); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor,
                                                         Predicate<Response> successPredicate); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor, String tag); static ResponseProcessor<T> checkResponse(ResponseProcessor<T> processor); static Predicate<Response> hasStatus(int status); static FailedRequestException createExceptionForResponse(Response response, String tag); static ResponseProcessor<T> jsonResult(ObjectMapper mapper, Class<T> resultClass); static ResponseProcessor<T> jsonResult(ObjectMapper mapper, TypeReference<T> typeReference); static Consumer<RequestBuilder> get(String uri); static ResponseProcessor<T> nullProcessor(); static String urlEncode(String src); static String addQueryParameters(String url, Map<String, ?> params); static String addQueryParameters(String url, Map<String, ?> params, boolean filterUndefined); static String addQueryParameter(String url, String key, Object value); static final Predicate<Response> SUCCESS_STATUS; }
@Test public void testAddQueryParametersNoParams() { String url = "https: assertThat(HttpUtils.addQueryParameters(url, Collections.emptyMap())).isEqualTo(url); }
@Test(expected = NullPointerException.class) public void testAddQueryParametersNullURL() { HttpUtils.addQueryParameters(null, Collections.singletonMap("foo", "bar")); }
@Test public void testAddQueryParameters() { Map<String, Object> params = new LinkedHashMap<>(); params.put("foo", "bar"); params.put("test", Boolean.TRUE); params.put("complex param", "this must be encoded"); params.put("nullValue", null); params.put("emptyValue", ""); String url = "https: String expResult = url + "?foo=bar&test=true&complex+param=this+must+be+encoded&nullValue=&emptyValue="; assertThat(HttpUtils.addQueryParameters(url, params)).isEqualTo(expResult); }
@Test public void testAddQueryParametersFiltersNullOrEmptyValues() { Map<String, Object> params = new LinkedHashMap<>(); params.put("nullValue", null); params.put("emptyValue", ""); params.put("foo", "bar"); String url = "https: String expResult = url + "?foo=bar"; assertThat(HttpUtils.addQueryParameters(url, params, true)).isEqualTo(expResult); }