Polish "Provide access to root URI from TestRestTemplate"

See gh-10641
pull/10986/head
Andy Wilkinson 7 years ago
parent c1205c3243
commit 71632ac767

@ -166,10 +166,14 @@ public class TestRestTemplate {
this.restTemplate.setUriTemplateHandler(handler);
}
/**
* Returns the root URI applied by a {@link RootUriTemplateHandler} or {@code ""} if
* the root URI is not available.
* @return the root URI
*/
public String getRootUri() {
UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
if (RootUriTemplateHandler.class
.isAssignableFrom(uriTemplateHandler.getClass())) {
if (uriTemplateHandler instanceof RootUriTemplateHandler) {
return ((RootUriTemplateHandler) uriTemplateHandler).getRootUri();
}
return "";

@ -86,7 +86,6 @@ public class TestRestTemplateTests {
public void getRootUriRootUriSetViaRestTemplateBuilder() {
String rootUri = "http://example.com";
RestTemplate delegate = new RestTemplateBuilder().rootUri(rootUri).build();
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(rootUri);
}
@ -98,7 +97,6 @@ public class TestRestTemplateTests {
LocalHostUriTemplateHandler.class);
given(templateHandler.getRootUri()).willReturn(rootUri);
template.setUriTemplateHandler(templateHandler);
assertThat(template.getRootUri()).isEqualTo(rootUri);
}

Loading…
Cancel
Save