Remove TestRestTemplate constructors taking template args

As discussed in gh-11872, `TestRestTemplate` constructor variants taking
a `RestTemplate` argument are confusing since the main goal of that
class is to mutate `RestTemplate`.

This commit removes all those constructor variants and replaces them
with `RestTemplateBuilder` arguments when possible.

Closes gh-11872
This commit is contained in:
Brian Clozel
2018-02-12 16:44:32 +01:00
parent eec3eed5f5
commit 2be0c46562
5 changed files with 27 additions and 18 deletions

View File

@@ -27,14 +27,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,12 +54,11 @@ public class CorsSampleActuatorApplicationTests {
@Before
public void setUp() {
RestTemplate restTemplate = new RestTemplate();
RestTemplateBuilder builder = new RestTemplateBuilder();
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
this.applicationContext.getEnvironment(), "http");
restTemplate.setUriTemplateHandler(handler);
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
this.testRestTemplate = new TestRestTemplate(restTemplate);
builder = builder.uriTemplateHandler(handler);
this.testRestTemplate = new TestRestTemplate(builder);
}
@Test