From c9932bb73a4a6fc005daf93d5b6c67db916c732d Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 3 Oct 2023 14:50:51 +0900 Subject: [PATCH] Use AssertJ's fail, not JUnit's This commit also updates Checkstyle to prevent use of JUnit's assertions from being reintroduced. See gh-37655 --- .../ValidationFailureAnalyzerTests.java | 2 +- ...icationAdminJmxAutoConfigurationTests.java | 2 +- .../TomcatDataSourceConfigurationTests.java | 2 +- ...SocketMessagingAutoConfigurationTests.java | 2 +- .../SilentExitExceptionHandlerTests.java | 2 +- .../properties/PropertyMapperTests.java | 26 +++++++++---------- ...rrentlyInCreationFailureAnalyzerTests.java | 2 +- ...NotOfRequiredTypeFailureAnalyzerTests.java | 2 +- .../boot/util/LambdaSafeTests.java | 2 +- .../AbstractServletWebServerFactoryTests.java | 2 +- src/checkstyle/checkstyle.xml | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzerTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzerTests.java index c71c149dbf1..030377f8301 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzerTests.java @@ -30,7 +30,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link ValidationFailureAnalyzer}. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java index cbf6b84edf7..3e08cc6530c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java @@ -43,7 +43,7 @@ import org.springframework.jmx.export.MBeanExporter; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link SpringApplicationAdminJmxAutoConfiguration}. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java index ff193868912..3f2e5864bab 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java @@ -34,7 +34,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableMBeanExport; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link TomcatDataSourceConfiguration}. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java index 21019ab6932..21ebb9162cc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java @@ -69,7 +69,7 @@ import org.springframework.web.socket.sockjs.client.Transport; import org.springframework.web.socket.sockjs.client.WebSocketTransport; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link WebSocketMessagingAutoConfiguration}. diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java index 9b15295a699..84539500ffd 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java @@ -21,7 +21,7 @@ import java.util.concurrent.CountDownLatch; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link SilentExitExceptionHandler}. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java index 46fa6d42053..8a64370bfde 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java @@ -18,11 +18,11 @@ package org.springframework.boot.context.properties; import java.util.function.Supplier; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link PropertyMapper}. @@ -56,7 +56,7 @@ class PropertyMapperTests { @Test void fromValueAlwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() { - this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(Assertions::fail); + this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(() -> fail(null)); } @Test @@ -100,14 +100,14 @@ class PropertyMapperTests { @Test void whenNonNullWhenSuppliedNullShouldNotMap() { - this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(Assertions::fail); + this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(() -> fail(null)); } @Test void whenNonNullWhenSuppliedThrowsNullPointerExceptionShouldNotMap() { this.map.from(() -> { throw new NullPointerException(); - }).whenNonNull().as(String::valueOf).toCall(Assertions::fail); + }).whenNonNull().as(String::valueOf).toCall(() -> fail(null)); } @Test @@ -118,7 +118,7 @@ class PropertyMapperTests { @Test void whenTrueWhenValueIsFalseShouldNotMap() { - this.map.from(false).whenTrue().toCall(Assertions::fail); + this.map.from(false).whenTrue().toCall(() -> fail(null)); } @Test @@ -129,17 +129,17 @@ class PropertyMapperTests { @Test void whenFalseWhenValueIsTrueShouldNotMap() { - this.map.from(true).whenFalse().toCall(Assertions::fail); + this.map.from(true).whenFalse().toCall(() -> fail(null)); } @Test void whenHasTextWhenValueIsNullShouldNotMap() { - this.map.from(() -> null).whenHasText().toCall(Assertions::fail); + this.map.from(() -> null).whenHasText().toCall(() -> fail(null)); } @Test void whenHasTextWhenValueIsEmptyShouldNotMap() { - this.map.from("").whenHasText().toCall(Assertions::fail); + this.map.from("").whenHasText().toCall(() -> fail(null)); } @Test @@ -156,7 +156,7 @@ class PropertyMapperTests { @Test void whenEqualToWhenValueIsNotEqualShouldNotMatch() { - this.map.from("123").whenEqualTo("321").toCall(Assertions::fail); + this.map.from("123").whenEqualTo("321").toCall(() -> fail(null)); } @Test @@ -168,7 +168,7 @@ class PropertyMapperTests { @Test void whenInstanceOfWhenValueIsNotTargetTypeShouldNotMatch() { Supplier supplier = () -> 123L; - this.map.from(supplier).whenInstanceOf(Double.class).toCall(Assertions::fail); + this.map.from(supplier).whenInstanceOf(Double.class).toCall(() -> fail(null)); } @Test @@ -179,7 +179,7 @@ class PropertyMapperTests { @Test void whenWhenValueDoesNotMatchShouldNotMap() { - this.map.from("123").when("321"::equals).toCall(Assertions::fail); + this.map.from("123").when("321"::equals).toCall(() -> fail(null)); } @Test @@ -197,12 +197,12 @@ class PropertyMapperTests { @Test void alwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() { - this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(Assertions::fail); + this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(() -> fail(null)); } @Test void whenWhenValueNotMatchesShouldSupportChainedCalls() { - this.map.from("123").when("456"::equals).when("123"::equals).toCall(Assertions::fail); + this.map.from("123").when("456"::equals).when("123"::equals).toCall(() -> fail(null)); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java index 6c24467283f..1921f8068d8 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java @@ -37,7 +37,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link BeanCurrentlyInCreationFailureAnalyzer}. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanNotOfRequiredTypeFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanNotOfRequiredTypeFailureAnalyzerTests.java index f93bde14516..ac15c97b794 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanNotOfRequiredTypeFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanNotOfRequiredTypeFailureAnalyzerTests.java @@ -29,7 +29,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link BeanNotOfRequiredTypeFailureAnalyzer}. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java index 0c3c50f5319..0e890533fa4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java @@ -29,7 +29,7 @@ import org.springframework.boot.util.LambdaSafe.InvocationResult; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.BDDMockito.given; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index f0a4be27969..ee4f802a618 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -149,7 +149,7 @@ import static org.assertj.core.api.Assertions.assertThatIOException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index c1911867148..c2e87b11b23 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -32,7 +32,7 @@ - +