diff --git a/config/checkstyle/checkstyle-suppressions.xml b/config/checkstyle/checkstyle-suppressions.xml index 0eda6ac3fe3..98b51188c95 100644 --- a/config/checkstyle/checkstyle-suppressions.xml +++ b/config/checkstyle/checkstyle-suppressions.xml @@ -71,6 +71,9 @@ + + + diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 803d009e6ce..1f2778c9e92 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -80,6 +80,14 @@ value="Please use Collections.emptyList()/emptyMap()/emptySet() for creating empty lists/maps/sets." /> + + + + + + + diff --git a/core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeIntegrationTests.java b/core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeIntegrationTests.java index 1cd1f6de5d1..7a2b351deee 100644 --- a/core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeIntegrationTests.java +++ b/core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeIntegrationTests.java @@ -26,7 +26,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import org.assertj.core.api.Assertions; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -39,6 +38,7 @@ import org.springframework.boot.testsupport.process.DisabledIfProcessUnavailable import org.springframework.core.io.ClassPathResource; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link DefaultDockerCompose}. @@ -100,13 +100,13 @@ class DefaultDockerComposeIntegrationTests { private void assertThatDoesNotContainService(List runningServices, String service) { if (findService(runningServices, service) != null) { - Assertions.fail("Did not expect service '%s', but found it in [%s]", service, runningServices); + fail("Did not expect service '%s', but found it in [%s]", service, runningServices); } } private void assertThatContainsService(List runningServices, String service) { if (findService(runningServices, service) == null) { - Assertions.fail("Expected service '%s', but hasn't been found in [%s]", service, runningServices); + fail("Expected service '%s', but hasn't been found in [%s]", service, runningServices); } } diff --git a/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java index 73055475b9d..a16660e994f 100644 --- a/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java @@ -26,7 +26,6 @@ import java.io.Reader; import java.io.StringReader; import java.lang.reflect.Field; -import org.assertj.core.api.Assertions; import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.ObjectFactory; @@ -42,8 +41,10 @@ import org.springframework.util.ReflectionUtils; /** * Base class for AssertJ based JSON marshal testers. Exposes specific Asserts following a * {@code read}, {@code write} or {@code parse} of JSON content. Typically used in - * combination with an AssertJ {@link Assertions#assertThat(Object) assertThat} call. For - * example:
+ * combination with an AssertJ {@link org.assertj.core.api.Assertions#assertThat(Object)
+ * assertThat} call. For example:
+ *
+ * 
  * public class ExampleObjectJsonTests {
  *
  *     private AbstractJsonTester<ExampleObject> json = //...
@@ -56,7 +57,9 @@ import org.springframework.util.ReflectionUtils;
  *     }
  *
  * }
- * 
For a complete list of supported assertions see {@link JsonContentAssert} and + *
+ * + * For a complete list of supported assertions see {@link JsonContentAssert} and * {@link ObjectContentAssert}. *

* To use this library JSONAssert must be on the test classpath. diff --git a/core/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java b/core/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java index 7a822dff938..f7bff098c20 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java @@ -21,7 +21,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.function.Supplier; -import org.assertj.core.api.Assertions; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -31,6 +30,7 @@ import org.springframework.boot.context.properties.PropertyMapper.Source.Always; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.fail; /** * Tests for {@link PropertyMapper}. @@ -124,7 +124,7 @@ class PropertyMapperTests { @Test void whenTrueWhenValueIsFalseShouldNotMap() { - this.map.from(false).whenTrue().toCall(Assertions::fail); + this.map.from(false).whenTrue().toCall(this::failure); } @Test @@ -135,17 +135,17 @@ class PropertyMapperTests { @Test void whenFalseWhenValueIsTrueShouldNotMap() { - this.map.from(true).whenFalse().toCall(Assertions::fail); + this.map.from(true).whenFalse().toCall(this::failure); } @Test void whenHasTextWhenValueIsNullShouldNotMap() { - this.map.from(() -> null).whenHasText().toCall(Assertions::fail); + this.map.from(() -> null).whenHasText().toCall(this::failure); } @Test void whenHasTextWhenValueIsEmptyShouldNotMap() { - this.map.from("").whenHasText().toCall(Assertions::fail); + this.map.from("").whenHasText().toCall(this::failure); } @Test @@ -162,7 +162,7 @@ class PropertyMapperTests { @Test void whenEqualToWhenValueIsNotEqualShouldNotMatch() { - this.map.from("123").whenEqualTo("321").toCall(Assertions::fail); + this.map.from("123").whenEqualTo("321").toCall(this::failure); } @Test @@ -174,7 +174,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(this::failure); } @Test @@ -185,7 +185,7 @@ class PropertyMapperTests { @Test void whenWhenValueDoesNotMatchShouldNotMap() { - this.map.from("123").when("321"::equals).toCall(Assertions::fail); + this.map.from("123").when("321"::equals).toCall(this::failure); } @Test @@ -203,7 +203,7 @@ class PropertyMapperTests { @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(this::failure); } @Test @@ -256,6 +256,10 @@ class PropertyMapperTests { assertThat(called).isFalse(); } + private void failure() { + fail(); + } + /** * Tests for {@link Always}. */ diff --git a/module/spring-boot-micrometer-tracing-brave/src/test/java/org/springframework/boot/micrometer/tracing/brave/autoconfigure/BraveAutoConfigurationTests.java b/module/spring-boot-micrometer-tracing-brave/src/test/java/org/springframework/boot/micrometer/tracing/brave/autoconfigure/BraveAutoConfigurationTests.java index 38adff65ab8..aef08737410 100644 --- a/module/spring-boot-micrometer-tracing-brave/src/test/java/org/springframework/boot/micrometer/tracing/brave/autoconfigure/BraveAutoConfigurationTests.java +++ b/module/spring-boot-micrometer-tracing-brave/src/test/java/org/springframework/boot/micrometer/tracing/brave/autoconfigure/BraveAutoConfigurationTests.java @@ -46,7 +46,6 @@ import io.micrometer.tracing.brave.bridge.W3CPropagation; import io.micrometer.tracing.exporter.SpanExportingPredicate; import io.micrometer.tracing.exporter.SpanFilter; import io.micrometer.tracing.exporter.SpanReporter; -import org.assertj.core.api.Assertions; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; @@ -63,6 +62,7 @@ import org.springframework.core.annotation.Order; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; /** @@ -401,7 +401,7 @@ class BraveAutoConfigurationTests { if (factory instanceof CompositePropagationFactory compositePropagationFactory) { return compositePropagationFactory.getInjectors().toList(); } - Assertions.fail("Expected CompositePropagationFactory, found %s".formatted(factory.getClass())); + fail("Expected CompositePropagationFactory, found %s".formatted(factory.getClass())); throw new AssertionError("Unreachable"); } diff --git a/module/spring-boot-mustache/src/test/java/org/springframework/boot/mustache/autoconfigure/MustacheStandaloneIntegrationTests.java b/module/spring-boot-mustache/src/test/java/org/springframework/boot/mustache/autoconfigure/MustacheStandaloneIntegrationTests.java index 98641b33252..3c27b2a50ef 100644 --- a/module/spring-boot-mustache/src/test/java/org/springframework/boot/mustache/autoconfigure/MustacheStandaloneIntegrationTests.java +++ b/module/spring-boot-mustache/src/test/java/org/springframework/boot/mustache/autoconfigure/MustacheStandaloneIntegrationTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.mustache.autoconfigure; import java.util.Collections; import com.samskivert.mustache.Mustache; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +29,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration Tests for {@link MustacheAutoConfiguration} outside of a web application. * @@ -44,8 +45,7 @@ class MustacheStandaloneIntegrationTests { @Test void directCompilation() { - Assertions - .assertThat(this.compiler.compile("Hello: {{world}}").execute(Collections.singletonMap("world", "World"))) + assertThat(this.compiler.compile("Hello: {{world}}").execute(Collections.singletonMap("world", "World"))) .isEqualTo("Hello: World"); } diff --git a/module/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/autoconfigure/WebFluxAutoConfigurationTests.java b/module/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/autoconfigure/WebFluxAutoConfigurationTests.java index cd03fcdc0fd..7ca7f5ea8a3 100644 --- a/module/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/autoconfigure/WebFluxAutoConfigurationTests.java +++ b/module/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/autoconfigure/WebFluxAutoConfigurationTests.java @@ -36,7 +36,6 @@ import jakarta.validation.ValidatorFactory; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; -import org.assertj.core.api.Assertions; import org.assertj.core.api.InstanceOfAssertFactories; import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; @@ -133,6 +132,7 @@ import org.springframework.web.util.pattern.PathPattern; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.setExtractBareNamePropertyMethods; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; @@ -488,7 +488,7 @@ class WebFluxAutoConfigurationTests { @Test void cachePeriod() { - Assertions.setExtractBareNamePropertyMethods(false); + setExtractBareNamePropertyMethods(false); this.contextRunner.withPropertyValues("spring.web.resources.cache.period:5").run((context) -> { Map handlerMap = getHandlerMap(context); assertThat(handlerMap).hasSize(2); @@ -499,12 +499,12 @@ class WebFluxAutoConfigurationTests { } } }); - Assertions.setExtractBareNamePropertyMethods(true); + setExtractBareNamePropertyMethods(true); } @Test void cacheControl() { - Assertions.setExtractBareNamePropertyMethods(false); + setExtractBareNamePropertyMethods(false); this.contextRunner .withPropertyValues("spring.web.resources.cache.cachecontrol.max-age:5", "spring.web.resources.cache.cachecontrol.proxy-revalidate:true") @@ -518,7 +518,7 @@ class WebFluxAutoConfigurationTests { } } }); - Assertions.setExtractBareNamePropertyMethods(true); + setExtractBareNamePropertyMethods(true); } @Test