Skip to content

Commit

Permalink
Use Spring Framework's NoOpResponseErrorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed May 2, 2024
1 parent 6bf9eb1 commit 6851c70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.boot.test.web.client;

import java.io.IOException;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
Expand Down Expand Up @@ -58,10 +57,9 @@
import org.springframework.http.RequestEntity.UriTemplateRequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.Assert;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.NoOpResponseErrorHandler;
import org.springframework.web.client.RequestCallback;
import org.springframework.web.client.ResponseExtractor;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -1078,14 +1076,6 @@ protected RequestConfig createRequestConfig() {

}

private static final class NoOpResponseErrorHandler extends DefaultResponseErrorHandler {

@Override
public void handleError(ClientHttpResponse response) throws IOException {
}

}

private static final class TrustSelfSignedStrategy implements TrustStrategy {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.MethodCallback;
import org.springframework.web.client.NoOpResponseErrorHandler;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -223,13 +224,12 @@ private Stream<Class<?>> getConverterClasses(TestRestTemplate testRestTemplate)
}

@Test
void withBasicAuthShouldUseNoOpErrorHandler() throws Exception {
void withBasicAuthShouldUseNoOpErrorHandler() {
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()).isInstanceOf(
Class.forName("org.springframework.boot.test.web.client.TestRestTemplate$NoOpResponseErrorHandler"));
assertThat(basicAuthTemplate.getRestTemplate().getErrorHandler()).isInstanceOf(NoOpResponseErrorHandler.class);
}

@Test
Expand Down

0 comments on commit 6851c70

Please sign in to comment.