mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
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:
parent
0872eb0dd9
commit
2cdc93cf19
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user