### Question:
UriHelper { public URI fromResourceUri(URI resourceUri) { URI baseUri = UriBuilder.fromUri(this.baseUri).build(); return UriBuilder.fromUri(resourceUri) .userInfo(baseUri.getUserInfo()) .scheme(baseUri.getScheme()) .host(baseUri.getHost()) .port(baseUri.getPort()) .replacePath(baseUri.getPath()).path(resourceUri.getPath()) .build(); } @JsonCreator(mode = JsonCreator.Mode.DELEGATING)  UriHelper(URI baseUri); URI fromResourceUri(URI resourceUri); URI getBaseUri(); void notifyOfPort(int port);  }### Answer:
@Test public void normalizesSlashes() { UriHelper helperOpen = new UriHelper(URI.create("http: UriHelper helperSlash = new UriHelper(URI.create("http: URI resourceOpen = UriBuilder.fromUri("/path2/path3").build(); URI resourceSlash = UriBuilder.fromUri("path2/path3").build(); String expectation = "http: assertThat(helperOpen.fromResourceUri(resourceSlash).toString(), is(expectation)); assertThat(helperOpen.fromResourceUri(resourceOpen).toString(), is(expectation)); assertThat(helperSlash.fromResourceUri(resourceSlash).toString(), is(expectation)); assertThat(helperSlash.fromResourceUri(resourceOpen).toString(), is(expectation)); }
@Test public void normalizesSlashesWithoutBaseUriPath() { UriHelper helperOpen = new UriHelper(URI.create("http: UriHelper helperSlash = new UriHelper(URI.create("http: URI resourceOpen = UriBuilder.fromUri("/path2/path3").build(); URI resourceSlash = UriBuilder.fromUri("path2/path3").build(); String expectation = "http: assertThat(helperOpen.fromResourceUri(resourceSlash).toString(), is(expectation)); assertThat(helperOpen.fromResourceUri(resourceOpen).toString(), is(expectation)); assertThat(helperSlash.fromResourceUri(resourceSlash).toString(), is(expectation)); assertThat(helperSlash.fromResourceUri(resourceOpen).toString(), is(expectation)); }
@Test public void keepsEverythingFromBaseUriExceptQuery() { UriHelper instance = new UriHelper(URI.create("http: URI resourceUri = UriBuilder.fromUri("/path2/path3").queryParam("q1", "v1").queryParam("q2", "v2").build(); String uri = instance.fromResourceUri(resourceUri).toString(); assertThat(uri, is("http: }
@Test public void keepsOnlyPathAndQueryFromResourceUri() { UriHelper instance = new UriHelper(URI.create("http: String uri = instance.fromResourceUri(URI.create("http: assertThat(uri, is("http: }