mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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…
Reference in New Issue
Block a user