From 5873e4078216db222a2dc1a59a13b659bfb0f789 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Thu, 2 Apr 2026 11:16:42 +0200 Subject: [PATCH] Enforce use of AssertJ assumptions via Checkstyle Closes gh-36582 (cherry picked from commit b6fc3a1b6f9310f3dd740e8f8b0792466ecadad2) --- .../serviceloader/ServiceLoaderTests.java | 4 +-- .../access/MBeanClientInterceptorTests.java | 33 ++++++++++--------- .../RemoteMBeanClientInterceptorTests.java | 6 ++-- .../core/io/buffer/DataBufferTests.java | 30 ++++++++--------- .../core/testfixture/TestGroupTests.java | 13 ++++++-- .../response/DefaultResponseCreatorTests.java | 3 +- .../reactive/ClientHttpConnectorTests.java | 7 ++-- .../reactive/CookieIntegrationTests.java | 9 +++-- .../reactive/ZeroCopyIntegrationTests.java | 6 ++-- .../client/RestClientIntegrationTests.java | 9 +++-- .../client/RestTemplateIntegrationTests.java | 15 +++++---- ...ltipartRouterFunctionIntegrationTests.java | 8 +++-- .../MultipartWebClientIntegrationTests.java | 5 +-- .../annotation/SseIntegrationTests.java | 6 ++-- .../view/ResourceBundleViewResolverTests.java | 4 +-- src/checkstyle/checkstyle.xml | 4 +-- 16 files changed, 91 insertions(+), 71 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java index 9b058d1745c..656c7f66ab2 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java @@ -28,7 +28,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assumptions.assumeThat; /** * @author Juergen Hoeller @@ -38,7 +38,7 @@ class ServiceLoaderTests { @BeforeAll static void assumeDocumentBuilderFactoryCanBeLoaded() { - assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()); + assumeThat(ServiceLoader.load(DocumentBuilderFactory.class).iterator()).hasNext(); } @Test diff --git a/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java b/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java index db4a63cbe9f..b4d55580914 100644 --- a/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java @@ -31,8 +31,8 @@ import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; +import org.opentest4j.TestAbortedException; import org.springframework.aop.framework.ProxyFactory; import org.springframework.core.testfixture.net.TestSocketUtils; @@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIOException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assumptions.assumeThat; /** * @author Rob Harrop @@ -92,14 +92,14 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests { @Test void proxyClassIsDifferent() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); assertThat(proxy.getClass()).as("The proxy class should be different than the base class").isNotSameAs(IJmxTestBean.class); } @Test void differentProxiesSameClass() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy1 = getProxy(); IJmxTestBean proxy2 = getProxy(); @@ -109,7 +109,7 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests { @Test void getAttributeValue() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy1 = getProxy(); int age = proxy1.getAge(); assertThat(age).as("The age should be 100").isEqualTo(100); @@ -117,7 +117,7 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests { @Test void setAttributeValue() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); proxy.setName("Rob Harrop"); assertThat(target.getName()).as("The name of the bean should have been updated").isEqualTo("Rob Harrop"); @@ -125,35 +125,35 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests { @Test void setAttributeValueWithRuntimeException() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); assertThatIllegalArgumentException().isThrownBy(() -> proxy.setName("Juergen")); } @Test void setAttributeValueWithCheckedException() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); assertThatExceptionOfType(ClassNotFoundException.class).isThrownBy(() -> proxy.setName("Juergen Class")); } @Test void setAttributeValueWithIOException() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); assertThatIOException().isThrownBy(() -> proxy.setName("Juergen IO")); } @Test void setReadOnlyAttribute() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); assertThatExceptionOfType(InvalidInvocationException.class).isThrownBy(() -> proxy.setAge(900)); } @Test void invokeNoArgs() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); long result = proxy.myOperation(); assertThat(result).as("The operation should return 1").isEqualTo(1); @@ -161,7 +161,7 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests { @Test void invokeArgs() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean proxy = getProxy(); int result = proxy.add(1, 2); assertThat(result).as("The operation should return 3").isEqualTo(3); @@ -169,14 +169,14 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests { @Test void invokeUnexposedMethodWithException() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); IJmxTestBean bean = getProxy(); assertThatExceptionOfType(InvalidInvocationException.class).isThrownBy(bean::dontExposeMe); } @Test void lazyConnectionToRemote() throws Exception { - assumeTrue(runTests); + assumeThat(runTests).isTrue(); @SuppressWarnings("deprecation") final int port = TestSocketUtils.findAvailableTcpPort(); @@ -199,8 +199,9 @@ class MBeanClientInterceptorTests extends AbstractMBeanServerTests { connector.start(); } catch (BindException ex) { - Assumptions.abort("Skipping remainder of JMX LazyConnectionToRemote test because binding to local port [" + - port + "] failed: " + ex.getMessage()); + throw new TestAbortedException( + "Skipping remainder of JMX LazyConnectionToRemote test because binding to local port [%s] failed: " + .formatted(port, ex.getMessage())); } // should now be able to access data via the lazy proxy diff --git a/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java b/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java index d2e45421d0c..bd5754efb02 100644 --- a/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java @@ -27,7 +27,7 @@ import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assumptions; +import org.opentest4j.TestAbortedException; import org.springframework.core.testfixture.net.TestSocketUtils; @@ -58,8 +58,8 @@ class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTests { } catch (BindException ex) { runTests = false; - Assumptions.abort("Skipping remote JMX tests because binding to local port [" + - this.servicePort + "] failed: " + ex.getMessage()); + throw new TestAbortedException("Skipping remote JMX tests because binding to local port [%s] failed: %s" + .formatted(this.servicePort, ex.getMessage())); } } diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java index 55f82ce23a0..30690dfa085 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java @@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.assertj.core.api.Assumptions.assumeThat; /** * @author Arjen Poutsma @@ -459,8 +459,8 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest @SuppressWarnings("deprecation") void decreaseCapacityLowReadPosition(DataBufferFactory bufferFactory) { - assumeFalse(bufferFactory instanceof Netty5DataBufferFactory, - "Netty 5 does not support decreasing the capacity"); + assumeThat(bufferFactory).as("Netty 5 does not support decreasing the capacity") + .isNotInstanceOf(Netty5DataBufferFactory.class); super.bufferFactory = bufferFactory; @@ -475,8 +475,8 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest @SuppressWarnings("deprecation") void decreaseCapacityHighReadPosition(DataBufferFactory bufferFactory) { - assumeFalse(bufferFactory instanceof Netty5DataBufferFactory, - "Netty 5 does not support decreasing the capacity"); + assumeThat(bufferFactory).as("Netty 5 does not support decreasing the capacity") + .isNotInstanceOf(Netty5DataBufferFactory.class); super.bufferFactory = bufferFactory; @@ -588,10 +588,10 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests { ByteBuffer result = buffer.asByteBuffer(1, 2); assertThat(result.capacity()).isEqualTo(2); - assumeFalse(bufferFactory instanceof Netty5DataBufferFactory, () -> { - DataBufferUtils.release(buffer); - return "Netty 5 does share the internal buffer"; - }); + assumeThat(bufferFactory).as(() -> { + DataBufferUtils.release(buffer); + return "Netty 5 does share the internal buffer"; + }).isNotInstanceOf(Netty5DataBufferFactory.class); buffer.write((byte) 'c'); assertThat(result.remaining()).isEqualTo(2); @@ -606,8 +606,8 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest @SuppressWarnings("deprecation") void byteBufferContainsDataBufferChanges(DataBufferFactory bufferFactory) { - assumeFalse(bufferFactory instanceof Netty5DataBufferFactory, - "Netty 5 does not support sharing data between buffers"); + assumeThat(bufferFactory).as("Netty 5 does not support sharing data between buffers") + .isNotInstanceOf(Netty5DataBufferFactory.class); super.bufferFactory = bufferFactory; @@ -626,8 +626,8 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest @SuppressWarnings("deprecation") void dataBufferContainsByteBufferChanges(DataBufferFactory bufferFactory) { - assumeFalse(bufferFactory instanceof Netty5DataBufferFactory, - "Netty 5 does not support sharing data between buffers"); + assumeThat(bufferFactory).as("Netty 5 does not support sharing data between buffers") + .isNotInstanceOf(Netty5DataBufferFactory.class); super.bufferFactory = bufferFactory; @@ -887,8 +887,8 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests { @ParameterizedDataBufferAllocatingTest @SuppressWarnings("deprecation") void retainedSlice(DataBufferFactory bufferFactory) { - assumeFalse(bufferFactory instanceof Netty5DataBufferFactory, - "Netty 5 does not support retainedSlice"); + assumeThat(bufferFactory).as("Netty 5 does not support retainedSlice") + .isNotInstanceOf(Netty5DataBufferFactory.class); super.bufferFactory = bufferFactory; diff --git a/spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java b/spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java index 582d8db2afb..124686fc94c 100644 --- a/spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java +++ b/spring-core/src/test/java/org/springframework/core/testfixture/TestGroupTests.java @@ -20,6 +20,8 @@ import java.util.Arrays; import java.util.Objects; import java.util.Set; +import org.assertj.core.api.Assumptions; +import org.assertj.core.configuration.PreferredAssumptionException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +31,7 @@ import static java.util.stream.Collectors.joining; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assumptions.assumeThat; import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING; /** @@ -42,6 +44,10 @@ class TestGroupTests { private static final String TEST_GROUPS_SYSTEM_PROPERTY = "testGroups"; + static { + Assumptions.setPreferredAssumptionException(PreferredAssumptionException.JUNIT5); + } + private String originalTestGroups; @@ -114,8 +120,9 @@ class TestGroupTests { */ private static void assumeGroup(TestGroup group) { Set testGroups = TestGroup.loadTestGroups(); - assumeTrue(testGroups.contains(group), - () -> "Requires inactive test group " + group + "; active test groups: " + testGroups); + assumeThat(testGroups) + .as(() -> "Requires inactive test group " + group + "; active test groups: " + testGroups) + .contains(group); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/client/response/DefaultResponseCreatorTests.java b/spring-test/src/test/java/org/springframework/test/web/client/response/DefaultResponseCreatorTests.java index 3880f11700a..5692b059491 100644 --- a/spring-test/src/test/java/org/springframework/test/web/client/response/DefaultResponseCreatorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/client/response/DefaultResponseCreatorTests.java @@ -77,9 +77,8 @@ class DefaultResponseCreatorTests { @ParameterizedTest(name = "setBodyFromStringWithCharset [{0}]") @ValueSource(strings = {"Cp1047", "UTF-8", "UTF-16", "US-ASCII", "ISO-8859-1"}) void setBodyFromStringWithCharset(String charset) throws IOException { - assumeThat(Charset.isSupported(charset)) - .overridingErrorMessage("charset %s is not supported by this JVM", charset) + .as("charset %s is not supported by this JVM", charset) .isTrue(); Charset charsetObj = Charset.forName(charset); diff --git a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java index a695f934f00..b9b658cf648 100644 --- a/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/reactive/ClientHttpConnectorTests.java @@ -41,7 +41,6 @@ import okhttp3.mockwebserver.RecordedRequest; import okio.Buffer; import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Named; import org.junit.jupiter.api.Test; @@ -61,6 +60,7 @@ import org.springframework.http.ReactiveHttpOutputMessage; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.Assumptions.assumeThat; import static org.junit.jupiter.api.Named.named; /** @@ -204,8 +204,9 @@ class ClientHttpConnectorTests { @ParameterizedConnectorTest void partitionedCookieSupport(ClientHttpConnector connector) { - Assumptions.assumeFalse(connector instanceof JettyClientHttpConnector, "Jetty client does not support partitioned cookies"); - Assumptions.assumeFalse(connector instanceof JdkClientHttpConnector, "JDK client does not support partitioned cookies"); + assumeThat(connector).as("Jetty and JDK clients do not support partitioned cookies") + .isNotInstanceOfAny(JettyClientHttpConnector.class, JdkClientHttpConnector.class); + prepareResponse(response -> { response.setResponseCode(200); response.addHeader("Set-Cookie", "id=test; Partitioned;"); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java index 523cfa10eae..21cdc87cf11 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java @@ -33,7 +33,7 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpSe import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.assertj.core.api.Assumptions.assumeThat; /** * @author Rossen Stoyanchev @@ -79,7 +79,9 @@ class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests { @ParameterizedHttpServerTest public void partitionedAttributeTest(HttpServer httpServer) throws Exception { - assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow does not support Partitioned cookies"); + assumeThat(httpServer).as("Undertow does not support Partitioned cookies") + .isNotInstanceOf(UndertowHttpServer.class); + startServer(httpServer); URI url = URI.create("http://localhost:" + port); @@ -98,7 +100,8 @@ class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests { @ParameterizedHttpServerTest public void cookiesWithSameNameTest(HttpServer httpServer) throws Exception { - assumeFalse(httpServer instanceof UndertowHttpServer, "Bug in Undertow in Cookies with same name handling"); + assumeThat(httpServer).as("Bug in Undertow in Cookies with same name handling") + .isNotInstanceOf(UndertowHttpServer.class); startServer(httpServer); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java index d6c55c5e02a..7ce63460387 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java @@ -35,7 +35,7 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.Reacto import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assumptions.assumeThat; /** * @author Arjen Poutsma @@ -55,8 +55,8 @@ class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTests { @ParameterizedHttpServerTest void zeroCopy(HttpServer httpServer) throws Exception { - assumeTrue(httpServer instanceof ReactorHttpServer || httpServer instanceof UndertowHttpServer || - httpServer instanceof JettyCoreHttpServer, "Zero-copy does not support Servlet"); + assumeThat(httpServer).as("Zero-copy does not support Servlet") + .isInstanceOfAny(ReactorHttpServer.class, UndertowHttpServer.class, JettyCoreHttpServer.class); startServer(httpServer); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java index 9fbd9ad7c4d..a2472d51344 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java @@ -62,7 +62,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; -import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.assertj.core.api.Assumptions.assumeThat; import static org.junit.jupiter.params.provider.Arguments.argumentSet; /** @@ -423,7 +423,8 @@ class RestClientIntegrationTests { } catch (HttpServerErrorException ex) { assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - assumeFalse(requestFactory instanceof JdkClientHttpRequestFactory, "JDK HttpClient does not expose status text"); + assumeThat(requestFactory).as("JDK HttpClient does not expose status text") + .isNotInstanceOf(JdkClientHttpRequestFactory.class); assertThat(ex.getStatusText()).isEqualTo("Server Error"); assertThat(ex.getResponseHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN); assertThat(ex.getResponseBodyAsString()).isEqualTo(errorMessage); @@ -493,7 +494,9 @@ class RestClientIntegrationTests { } catch (HttpServerErrorException ex) { - assumeFalse(requestFactory instanceof JdkClientHttpRequestFactory, "JDK HttpClient does not expose status text"); + assumeThat(requestFactory).as("JDK HttpClient does not expose status text") + .isNotInstanceOf(JdkClientHttpRequestFactory.class); + assertThat(ex.getMessage()).isEqualTo("555 Server Error: \"Something went wrong\""); assertThat(ex.getStatusText()).isEqualTo("Server Error"); assertThat(ex.getResponseHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java index 0827e009ade..f9f4696646d 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java @@ -59,7 +59,7 @@ import org.springframework.util.MultiValueMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.assertj.core.api.Assumptions.assumeThat; import static org.junit.jupiter.params.provider.Arguments.argumentSet; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.MediaType.MULTIPART_MIXED; @@ -228,8 +228,8 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { @ParameterizedRestTemplateTest void patchForObject(ClientHttpRequestFactory clientHttpRequestFactory) { - assumeFalse(clientHttpRequestFactory instanceof SimpleClientHttpRequestFactory, - "HttpURLConnection does not support the PATCH method"); + assumeThat(clientHttpRequestFactory).as("HttpURLConnection does not support the PATCH method") + .isNotInstanceOf(SimpleClientHttpRequestFactory.class); setUpClient(clientHttpRequestFactory); @@ -249,7 +249,8 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { assertThat(ex.getStatusText()).isNotNull(); assertThat(ex.getResponseBodyAsString()).isNotNull(); assertThat(ex.getMessage()).containsSubsequence("404", "on GET request for \"" + url + "\": [no body]"); - assumeFalse(clientHttpRequestFactory instanceof JdkClientHttpRequestFactory, "JDK HttpClient does not expose status text"); + assumeThat(clientHttpRequestFactory).as("JDK HttpClient does not expose status text") + .isNotInstanceOf(JdkClientHttpRequestFactory.class); assertThat(ex.getMessage()).isEqualTo("404 Client Error on GET request for \"" + url + "\": [no body]"); }); } @@ -264,7 +265,8 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { .satisfies(ex -> { assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); assertThat(ex.getMessage()).containsSubsequence("400", "on GET request for \""+url+ "\": [no body]"); - assumeFalse(clientHttpRequestFactory instanceof JdkClientHttpRequestFactory, "JDK HttpClient does not expose status text"); + assumeThat(clientHttpRequestFactory).as("JDK HttpClient does not expose status text") + .isNotInstanceOf(JdkClientHttpRequestFactory.class); assertThat(ex.getMessage()).isEqualTo("400 Client Error on GET request for \""+url+ "\": [no body]"); }); } @@ -281,7 +283,8 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { assertThat(ex.getStatusText()).isNotNull(); assertThat(ex.getResponseBodyAsString()).isNotNull(); assertThat(ex.getMessage()).containsSubsequence("500", "on GET request for \"" + url + "\": [no body]"); - assumeFalse(clientHttpRequestFactory instanceof JdkClientHttpRequestFactory, "JDK HttpClient does not expose status text"); + assumeThat(clientHttpRequestFactory).as("JDK HttpClient does not expose status text") + .isNotInstanceOf(JdkClientHttpRequestFactory.class); assertThat(ex.getMessage()).isEqualTo("500 Server Error on GET request for \"" + url + "\": [no body]"); }); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java index 8c1e1c83e78..92f72f597e4 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java @@ -53,7 +53,7 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.Undert import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.assertj.core.api.Assumptions.assumeThat; import static org.springframework.web.reactive.function.server.RouterFunctions.route; /** @@ -105,7 +105,8 @@ class MultipartRouterFunctionIntegrationTests extends AbstractRouterFunctionInte @ParameterizedHttpServerTest void transferTo(HttpServer httpServer) throws Exception { // TODO Determine why Undertow fails: https://github.com/spring-projects/spring-framework/issues/25310 - assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails with transferTo"); + assumeThat(httpServer).as("Undertow currently fails with transferTo") + .isNotInstanceOf(UndertowHttpServer.class); verifyTransferTo(httpServer); } @@ -162,7 +163,8 @@ class MultipartRouterFunctionIntegrationTests extends AbstractRouterFunctionInte @ParameterizedHttpServerTest void proxy(HttpServer httpServer) throws Exception { - assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails proxying requests"); + assumeThat(httpServer).as("Undertow currently fails proxying requests") + .isNotInstanceOf(UndertowHttpServer.class); startServer(httpServer); Mono> result = webClient diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java index 0b15010e4b9..7f3fad520ab 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java @@ -63,7 +63,7 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpSe import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.assertj.core.api.Assumptions.assumeThat; class MultipartWebClientIntegrationTests extends AbstractHttpHandlerIntegrationTests { @@ -169,7 +169,8 @@ class MultipartWebClientIntegrationTests extends AbstractHttpHandlerIntegrationT @ParameterizedHttpServerTest void transferTo(HttpServer httpServer) throws Exception { // TODO Determine why Undertow fails: https://github.com/spring-projects/spring-framework/issues/25310 - assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails with transferTo"); + assumeThat(httpServer).as("Undertow currently fails with transferTo") + .isNotInstanceOf(UndertowHttpServer.class); startServer(httpServer); Flux result = webClient diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index 558c80d16a4..2ae6caf8ff6 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -60,7 +60,7 @@ import org.springframework.web.testfixture.http.server.reactive.bootstrap.Tomcat import org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assumptions.assumeThat; import static org.junit.jupiter.api.Named.named; import static org.springframework.http.MediaType.TEXT_EVENT_STREAM; @@ -128,7 +128,7 @@ class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { @ParameterizedSseTest void sseAsEvent(HttpServer httpServer, ClientHttpConnector connector) throws Exception { - assumeTrue(httpServer instanceof JettyHttpServer || httpServer instanceof JettyCoreHttpServer); + assumeThat(httpServer).isInstanceOfAny(JettyHttpServer.class, JettyCoreHttpServer.class); startServer(httpServer, connector); @@ -177,7 +177,7 @@ class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { @ParameterizedSseTest // SPR-16494 @Disabled // https://github.com/reactor/reactor-netty/issues/283 void serverDetectsClientDisconnect(HttpServer httpServer, ClientHttpConnector connector) throws Exception { - assumeTrue(httpServer instanceof ReactorHttpServer); + assumeThat(httpServer).isInstanceOf(ReactorHttpServer.class); startServer(httpServer, connector); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java index 317a3146919..eee1ae6b4ea 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java @@ -34,7 +34,7 @@ import org.springframework.web.testfixture.servlet.MockServletContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assumptions.assumeThat; /** * @author Rod Johnson @@ -124,7 +124,7 @@ class ResourceBundleViewResolverTests { @Test void sameBundleOnlyCachedOnce() throws Exception { - assumeTrue(rb.isCache()); + assumeThat(rb.isCache()).isTrue(); View v1 = rb.resolveViewName("debugView", Locale.ENGLISH); View v2 = rb.resolveViewName("debugView", Locale.UK); diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 6df21bb629a..da9abd65674 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -290,8 +290,8 @@ - - + +