### Question:
UrlBuilder { public String createUrl(String urlPattern) { return protocol.format(urlPattern, host, selectPort()); } UrlBuilder(HttpServletRequest request, Integer restPort); static void clearHistory(); String createUrl(String urlPattern); void reportSuccess(); void reportFailure(WebClientException connectionException);  }### Answer:
@Test public void whenNoRestPortDefined_generateUrl() { UrlBuilder builder = new UrlBuilder(request, null); assertThat(builder.createUrl(URL_PATTERN), equalTo(String.format(URL_PATTERN, "http", "localhost", LOCAL_PORT))); }
@Test public void whenRestPortDefined_generateUrlWithRestPort() { UrlBuilder builder = new UrlBuilder(request, REST_PORT); assertThat(builder.createUrl(URL_PATTERN), equalTo(String.format(URL_PATTERN, "http", "localhost", REST_PORT))); }