ViewUtils { public static String buildUrlWithParameters(final String url, final Parameters parameters) { checkNotNull(url); checkNotNull(parameters); try { URIBuilder builder = new URIBuilder(url); for (Entry<String, String> parameter : parameters.entries()) { builder.addParameter(parameter.getKey(), parameter.getValue()); } URI uri = builder.build(); return uri.toString(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Unable to build url with base url " + url + " and parameters " + parameters, e); } } private  ViewUtils(); static String buildUrlWithParameters(final String url, final Parameters parameters); static void copyLocalContextAttributes(final Context existingContext, final Context newContext);  }
@Test public void buildUrlsWithoutParameters() { Parameters parameters = new Parameters(); assertThat(buildUrlWithParameters("http: is("http: assertThat(buildUrlWithParameters("https: is("https: }
@Test public void buildUrlsWithSubpathsWithoutParameters() { Parameters parameters = new Parameters(); assertThat(buildUrlWithParameters("http: is("http: assertThat(buildUrlWithParameters("https: is("https: }
@Test public void buildUrlsWithSingleParameter() { Parameters parameters = new Parameters(); parameters.set("a", "1"); assertThat(buildUrlWithParameters("http: is("http: assertThat(buildUrlWithParameters("http: is("http: }
@Test public void buildUrlsWithMultipleParameters() { Parameters parameters = new Parameters(); parameters.set("a", "1"); parameters.set("b", "2"); assertThat(buildUrlWithParameters("http: is("http: assertThat(buildUrlWithParameters("http: is("http: }
@Test public void buildUrlsWithDuplicateParameters() { Parameters parameters = new Parameters(); parameters.set("a", "1", "2"); assertThat(buildUrlWithParameters("http: is("http: assertThat(buildUrlWithParameters("http: is("http: }
@Test public void buildUrlsWithCorrectlyEncodedParameters() { Parameters parameters = new Parameters(); parameters.set("a", "what?"); parameters.set("b", "F=ma"); parameters.set("c", "hello world"); parameters.set("d", "1+2"); assertThat(buildUrlWithParameters("http: is("http: }
@Test public void exceptionIsThrownOnInvalidUrl() { exception.expect(IllegalArgumentException.class); exception.expectCause(any(URISyntaxException.class)); exception.expectMessage("http: exception.expectMessage("test-parameter"); exception.expectMessage("test-value"); Parameters parameters = new Parameters(); parameters.set("test-parameter", "test-value"); buildUrlWithParameters("http: }