Skip to content

Commit d31dbac

Browse files
mihhail-lapushkinsnicoll
authored andcommitted
Support custom UriTemplateHandler in LocalHostUriTemplateHandler
See gh-13208
1 parent 48cf025 commit d31dbac

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandler.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,23 @@ public LocalHostUriTemplateHandler(Environment environment) {
5858
* @since 1.4.1
5959
*/
6060
public LocalHostUriTemplateHandler(Environment environment, String scheme) {
61-
super(new DefaultUriBuilderFactory());
61+
this(environment, scheme, new DefaultUriBuilderFactory());
62+
}
63+
64+
/**
65+
* Create a new {@code LocalHostUriTemplateHandler} that will generate URIs with the
66+
* given {@code scheme}, use the given {@code environment} to determine the
67+
* context-path and port and delegate to the given template {@code handler}.
68+
* @param environment the environment used to determine the port
69+
* @param scheme the scheme of the root uri
70+
* @param handler the delegate handler
71+
* @since 2.0.3
72+
*/
73+
public LocalHostUriTemplateHandler(Environment environment, String scheme, UriTemplateHandler handler) {
74+
super(handler);
6275
Assert.notNull(environment, "Environment must not be null");
6376
Assert.notNull(scheme, "Scheme must not be null");
77+
Assert.notNull(handler, "Handler must not be null");
6478
this.environment = environment;
6579
this.scheme = scheme;
6680
}

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public void createWhenSchemeIsNullShouldThrowException() {
5050
new LocalHostUriTemplateHandler(new MockEnvironment(), null);
5151
}
5252

53+
@Test
54+
public void createWhenHandlerIsNullShouldThrowException() {
55+
this.thrown.expect(IllegalArgumentException.class);
56+
this.thrown.expectMessage("Handler must not be null");
57+
new LocalHostUriTemplateHandler(new MockEnvironment(), "http", null);
58+
}
59+
5360
@Test
5461
public void getRootUriShouldUseLocalServerPort() {
5562
MockEnvironment environment = new MockEnvironment();

0 commit comments

Comments
 (0)