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:
@@ -94,7 +94,7 @@ public class TestRestTemplate {
|
||||
* @since 1.4.1
|
||||
*/
|
||||
public TestRestTemplate(RestTemplateBuilder restTemplateBuilder) {
|
||||
this(buildRestTemplate(restTemplateBuilder));
|
||||
this(restTemplateBuilder, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,14 +113,24 @@ public class TestRestTemplate {
|
||||
*/
|
||||
public TestRestTemplate(String username, String password,
|
||||
HttpClientOption... httpClientOptions) {
|
||||
this(new RestTemplate(), username, password, httpClientOptions);
|
||||
this(new RestTemplateBuilder(), username, password, httpClientOptions);
|
||||
}
|
||||
|
||||
public TestRestTemplate(RestTemplate restTemplate) {
|
||||
this(restTemplate, null, null);
|
||||
/**
|
||||
* Create a new {@link TestRestTemplate} instance with the specified credentials.
|
||||
* @param restTemplateBuilder builder used to configure underlying
|
||||
* {@link RestTemplate}
|
||||
* @param username the username to use (or {@code null})
|
||||
* @param password the password (or {@code null})
|
||||
* @param httpClientOptions client options to use if the Apache HTTP Client is used
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public TestRestTemplate(RestTemplateBuilder restTemplateBuilder, String username, String password,
|
||||
HttpClientOption... httpClientOptions) {
|
||||
this(buildRestTemplate(restTemplateBuilder), username, password, httpClientOptions);
|
||||
}
|
||||
|
||||
public TestRestTemplate(RestTemplate restTemplate, String username, String password,
|
||||
private TestRestTemplate(RestTemplate restTemplate, String username, String password,
|
||||
HttpClientOption... httpClientOptions) {
|
||||
Assert.notNull(restTemplate, "RestTemplate must not be null");
|
||||
this.httpClientOptions = httpClientOptions;
|
||||
|
||||
@@ -143,7 +143,7 @@ class TestRestTemplateTestContextCustomizer implements ContextCustomizer {
|
||||
throws BeansException {
|
||||
RestTemplateBuilder builder = getRestTemplateBuilder(applicationContext);
|
||||
boolean sslEnabled = isSslEnabled(applicationContext);
|
||||
TestRestTemplate template = new TestRestTemplate(builder.build(), null, null,
|
||||
TestRestTemplate template = new TestRestTemplate(builder, null, null,
|
||||
sslEnabled ? SSL_OPTIONS : DEFAULT_OPTIONS);
|
||||
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
|
||||
applicationContext.getEnvironment(), sslEnabled ? "https" : "http");
|
||||
|
||||
Reference in New Issue
Block a user