HttpRequest { public HttpRequest addParameter(String name, String value) { checkNotNull(name, "name"); checkNotNull(value, "value"); final List<String> oldValues = parameters.containsKey(name) ? parameters.get(name) : new ArrayList<String>(); final List<String> newValues = new ArrayList<>(oldValues); newValues.add(value); final Map<String, List<String>> params = new HashMap<>(parameters); params.put(name, newValues); return new HttpRequest(requestURL, params, queryString); } @Deprecated  HttpRequest(String requestURL);  HttpRequest(String requestURL, String queryString); @Deprecated  HttpRequest(String requestURL, Map<String, List<String>> parameters);  HttpRequest(String requestURL, Map<String, List<String>> parameters, String queryString); HttpRequest addParameter(String name, String value); HttpRequest removeParameter(String name); String getRequestURL(); String getParameter(String name); List<String> getParameters(String name); Map<String, List<String>> getParameters(); String getEncodedParameter(String name); String getEncodedParameter(String name, String defaultValue); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final Map<String, List<String>> EMPTY_PARAMETERS; }
@Test public void testAddParameter() throws Exception { final String url = "some_url"; final String name = "name"; final String value = "value"; final HttpRequest request = new HttpRequest(url, (String)null).addParameter(name, value); assertThat(request.getRequestURL(), equalTo(url)); assertThat(request.getParameters(), equalTo(singletonMap(name, singletonList(value)))); assertThat(request.getParameters(name), equalTo(singletonList(value))); assertThat(request.getParameter(name), equalTo(value)); final HttpRequest request2 = request.addParameter(name, value); assertThat(request2.getParameters(name), equalTo(Arrays.asList(value, value))); }