@Test
public void extendUriWithQuery() throws URISyntaxException {

    String query = "key1=value1&key2=value2";
    String basePath = UriUtils.buildUriPath("some", UUID.randomUUID().toString());
    URI baseUri = new URI("http://localhost:8000");
    URI baseHttpsUri = new URI("https://localhost:8000");
    URI httpBase = UriUtils.buildUri(baseUri, basePath);
    URI httpsBase = UriUtils.buildUri(baseHttpsUri, basePath);
    URI u = UriUtils.extendUriWithQuery(httpBase, "key1", "value1", "key2", "value2");
    assertEquals("http", u.getScheme());
    assertEquals(basePath, u.getPath());
    assertEquals(u.getQuery(), query);
    u = UriUtils.extendUriWithQuery(httpsBase, "key1", "value1", "key2", "value2");
    assertEquals("https", u.getScheme());
    assertEquals(basePath, u.getPath());
    assertEquals(8000, u.getPort());
    assertEquals(u.getQuery(), query);
    u = UriUtils.extendUriWithQuery(new URI("http://localhost/path?param1=value1"), "key1", "value1", "key2", "value2");
    assertEquals("/path", u.getPath());
    assertEquals(u.getQuery(), "param1=value1&key1=value1&key2=value2");
}