@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 2017 the original author or authors .
* Copyright 2012 - 2018 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -16,13 +16,21 @@
@@ -16,13 +16,21 @@
package org.springframework.boot.test.web.client ;
import java.net.URI ;
import java.util.HashMap ;
import java.util.Map ;
import org.junit.Rule ;
import org.junit.Test ;
import org.junit.rules.ExpectedException ;
import org.springframework.mock.env.MockEnvironment ;
import org.springframework.web.util.UriTemplateHandler ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.mockito.BDDMockito.given ;
import static org.mockito.Mockito.mock ;
import static org.mockito.Mockito.verify ;
/ * *
* Tests for { @link LocalHostUriTemplateHandler } .
@ -91,4 +99,18 @@ public class LocalHostUriTemplateHandlerTests {
@@ -91,4 +99,18 @@ public class LocalHostUriTemplateHandlerTests {
assertThat ( handler . getRootUri ( ) ) . isEqualTo ( "http://localhost:8080/foo" ) ;
}
@Test
public void expandShouldUseCustomHandler ( ) {
MockEnvironment environment = new MockEnvironment ( ) ;
UriTemplateHandler uriTemplateHandler = mock ( UriTemplateHandler . class ) ;
Map < String , ? > uriVariables = new HashMap < > ( ) ;
URI uri = URI . create ( "http://www.example.com" ) ;
given ( uriTemplateHandler . expand ( "https://localhost:8080/" , uriVariables ) )
. willReturn ( uri ) ;
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler (
environment , "https" , uriTemplateHandler ) ;
assertThat ( handler . expand ( "/" , uriVariables ) ) . isEqualTo ( uri ) ;
verify ( uriTemplateHandler ) . expand ( "https://localhost:8080/" , uriVariables ) ;
}
}