Skip to content

Commit 300f6bf

Browse files
committed
Polish contribution
Closes gh-13208
1 parent d31dbac commit 300f6bf

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public LocalHostUriTemplateHandler(Environment environment, String scheme) {
7070
* @param handler the delegate handler
7171
* @since 2.0.3
7272
*/
73-
public LocalHostUriTemplateHandler(Environment environment, String scheme, UriTemplateHandler handler) {
73+
public LocalHostUriTemplateHandler(Environment environment, String scheme,
74+
UriTemplateHandler handler) {
7475
super(handler);
7576
Assert.notNull(environment, "Environment must not be null");
7677
Assert.notNull(scheme, "Scheme must not be null");
77-
Assert.notNull(handler, "Handler must not be null");
7878
this.environment = environment;
7979
this.scheme = scheme;
8080
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,21 @@
1616

1717
package org.springframework.boot.test.web.client;
1818

19+
import java.net.URI;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
1923
import org.junit.Rule;
2024
import org.junit.Test;
2125
import org.junit.rules.ExpectedException;
2226

2327
import org.springframework.mock.env.MockEnvironment;
28+
import org.springframework.web.util.UriTemplateHandler;
2429

2530
import static org.assertj.core.api.Assertions.assertThat;
31+
import static org.mockito.BDDMockito.given;
32+
import static org.mockito.Mockito.mock;
33+
import static org.mockito.Mockito.verify;
2634

2735
/**
2836
* Tests for {@link LocalHostUriTemplateHandler}.
@@ -91,4 +99,18 @@ public void getRootUriShouldUseContextPath() {
9199
assertThat(handler.getRootUri()).isEqualTo("http://localhost:8080/foo");
92100
}
93101

102+
@Test
103+
public void expandShouldUseCustomHandler() {
104+
MockEnvironment environment = new MockEnvironment();
105+
UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);
106+
Map<String, ?> uriVariables = new HashMap<>();
107+
URI uri = URI.create("http://www.example.com");
108+
given(uriTemplateHandler.expand("https://localhost:8080/", uriVariables))
109+
.willReturn(uri);
110+
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
111+
environment, "https", uriTemplateHandler);
112+
assertThat(handler.expand("/", uriVariables)).isEqualTo(uri);
113+
verify(uriTemplateHandler).expand("https://localhost:8080/", uriVariables);
114+
}
115+
94116
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ public class RootUriTemplateHandler implements UriTemplateHandler {
3838
private final UriTemplateHandler handler;
3939

4040
protected RootUriTemplateHandler(UriTemplateHandler handler) {
41+
Assert.notNull(handler, "Handler must not be null");
4142
this.rootUri = null;
4243
this.handler = handler;
4344
}

0 commit comments

Comments
 (0)