Polish "Provide access to root URI from TestRestTemplate"
See gh-10641
This commit is contained in:
parent
c1205c3243
commit
71632ac767
|
|
@ -166,10 +166,14 @@ public class TestRestTemplate {
|
||||||
this.restTemplate.setUriTemplateHandler(handler);
|
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() {
|
public String getRootUri() {
|
||||||
UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
|
UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
|
||||||
if (RootUriTemplateHandler.class
|
if (uriTemplateHandler instanceof RootUriTemplateHandler) {
|
||||||
.isAssignableFrom(uriTemplateHandler.getClass())) {
|
|
||||||
return ((RootUriTemplateHandler) uriTemplateHandler).getRootUri();
|
return ((RootUriTemplateHandler) uriTemplateHandler).getRootUri();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,6 @@ public class TestRestTemplateTests {
|
||||||
public void getRootUriRootUriSetViaRestTemplateBuilder() {
|
public void getRootUriRootUriSetViaRestTemplateBuilder() {
|
||||||
String rootUri = "http://example.com";
|
String rootUri = "http://example.com";
|
||||||
RestTemplate delegate = new RestTemplateBuilder().rootUri(rootUri).build();
|
RestTemplate delegate = new RestTemplateBuilder().rootUri(rootUri).build();
|
||||||
|
|
||||||
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(rootUri);
|
assertThat(new TestRestTemplate(delegate).getRootUri()).isEqualTo(rootUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +97,6 @@ public class TestRestTemplateTests {
|
||||||
LocalHostUriTemplateHandler.class);
|
LocalHostUriTemplateHandler.class);
|
||||||
given(templateHandler.getRootUri()).willReturn(rootUri);
|
given(templateHandler.getRootUri()).willReturn(rootUri);
|
||||||
template.setUriTemplateHandler(templateHandler);
|
template.setUriTemplateHandler(templateHandler);
|
||||||
|
|
||||||
assertThat(template.getRootUri()).isEqualTo(rootUri);
|
assertThat(template.getRootUri()).isEqualTo(rootUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue