From e9eeac9028998a496d40503294452aa6de2cb774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Thu, 2 May 2024 11:05:17 +0200 Subject: [PATCH] Use Spring Framework's NoOpResponseErrorHandler See spring-projects/spring-framework#32750 Closes gh-41183 --- .../boot/test/web/client/TestRestTemplate.java | 12 +----------- .../boot/test/web/client/TestRestTemplateTests.java | 6 +++--- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java index 5f44bac53b4..a0f975d3f43 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java @@ -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; @@ -57,10 +56,9 @@ import org.springframework.http.RequestEntity; 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; @@ -1077,12 +1075,4 @@ public class TestRestTemplate { } - private static final class NoOpResponseErrorHandler extends DefaultResponseErrorHandler { - - @Override - public void handleError(ClientHttpResponse response) throws IOException { - } - - } - } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java index 8a1af79ce16..022000e0be3 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java @@ -45,6 +45,7 @@ import org.springframework.mock.http.client.MockClientHttpResponse; 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; @@ -223,13 +224,12 @@ class TestRestTemplateTests { } @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