From 71632ac767ab0137c1ae3b776cfb33109549f6a8 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Sun, 12 Nov 2017 12:11:57 +0000 Subject: [PATCH] Polish "Provide access to root URI from TestRestTemplate" See gh-10641 --- .../boot/test/web/client/TestRestTemplate.java | 8 ++++++-- .../boot/test/web/client/TestRestTemplateTests.java | 2 -- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java index 8b0ac4d801..4e47fffa32 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java @@ -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 ""; diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java index ec053b0054..3740c0e4e2 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java @@ -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); }