### Question:
UriUtil { public static URI replaceSubdomain(@Nonnull URI uri, @Nullable String subdomain) { Assertions.assertNotNull(uri, "the uri parameter must not be null"); if (hasText(subdomain) && hasSubdomain(uri)) { String newHost = subdomain + uri.getHost().substring(uri.getHost().indexOf('.')); try { return uri.resolve(new URI(uri.getScheme(), uri.getUserInfo(), newHost, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment())); } catch (URISyntaxException e) { logger.error("Could not replace subdomain {} in given uri {}", subdomain, uri); throw new IllegalArgumentException(e); } } logger.info("the subdomain of the URI '{}' is not replaced by subdomain '{}'", uri, subdomain); return uri; } private  UriUtil(); static URI replaceSubdomain(@Nonnull URI uri, @Nullable String subdomain); @Nonnull static URI expandPath(URI baseUri, String pathToAppend);  }### Answer:
@Test public void replaceSubdomain_replacesNothingWhenSubdomainIsNull() { URI replacedURI = UriUtil.replaceSubdomain(tokenEndpointUri, null); assertThat(replacedURI, is(tokenEndpointUri)); }
@Test public void replaceSubdomain() { URI replacedURI = UriUtil.replaceSubdomain(tokenEndpointUri, "newsubdomain"); assertThat(replacedURI.toString(), is("https: }
@Test public void replaceSubdomain_replacesNothingWhenSubdomainIsEmpty() { URI replacedURI = UriUtil.replaceSubdomain(tokenEndpointUri, ""); assertThat(replacedURI, is(tokenEndpointUri)); }
@Test public void replaceSubdomain_replacesNothingWhenUrlContainsNoSubdomain() { URI replacedURI = UriUtil.replaceSubdomain(URI.create("http: assertThat(replacedURI.toString(), is("http: }