Make TestRestTemplate withBasicAuth fault tolerant
It's part of TestRestTemplate's contract that it's fault tolerant. This commit aligns the behavior of `withBasicAuth` with that expectation. Closes gh-15780
This commit is contained in:
@@ -1034,11 +1034,8 @@ public class TestRestTemplate {
|
||||
.messageConverters(getRestTemplate().getMessageConverters())
|
||||
.interceptors(getRestTemplate().getInterceptors())
|
||||
.uriTemplateHandler(getRestTemplate().getUriTemplateHandler()).build();
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplate, username,
|
||||
password, this.httpClientOptions);
|
||||
testRestTemplate.getRestTemplate()
|
||||
.setErrorHandler(getRestTemplate().getErrorHandler());
|
||||
return testRestTemplate;
|
||||
return new TestRestTemplate(restTemplate, username, password,
|
||||
this.httpClientOptions);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
|
||||
@@ -237,14 +237,15 @@ public class TestRestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withBasicAuthDoesNotResetErrorHandler() {
|
||||
public void withBasicAuthShouldUseNoOpErrorHandler() throws Exception {
|
||||
TestRestTemplate originalTemplate = new TestRestTemplate("foo", "bar");
|
||||
ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
|
||||
originalTemplate.getRestTemplate().setErrorHandler(errorHandler);
|
||||
TestRestTemplate basicAuthTemplate = originalTemplate.withBasicAuth("user",
|
||||
"password");
|
||||
assertThat(basicAuthTemplate.getRestTemplate().getErrorHandler())
|
||||
.isSameAs(errorHandler);
|
||||
.isInstanceOf(Class.forName(
|
||||
"org.springframework.boot.test.web.client.TestRestTemplate$NoOpResponseErrorHandler"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user