From 88f51fafeefe658b47a4bf7a4d98f69d714114ab Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Mon, 29 Dec 2025 00:09:07 +0900 Subject: [PATCH 1/2] Use static imports for Assertions.assertThat() consistently See gh-48630 Signed-off-by: Johnny Lim --- .../boot/test/json/JsonContentAssert.java | 15 ++++++++------- .../boot/image/assertions/ImageAssert.java | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java index 9ae8fa99f43..fb3f3dad18b 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java @@ -30,7 +30,6 @@ import org.assertj.core.api.AbstractBooleanAssert; import org.assertj.core.api.AbstractCharSequenceAssert; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.Assert; -import org.assertj.core.api.Assertions; import org.assertj.core.api.ListAssert; import org.assertj.core.api.MapAssert; import org.skyscreamer.jsonassert.JSONCompare; @@ -42,6 +41,8 @@ import org.springframework.core.io.Resource; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; +import static org.assertj.core.api.Assertions.assertThat; + /** * AssertJ {@link Assert} for {@link JsonContent}. * @@ -915,7 +916,7 @@ public class JsonContentAssert extends AbstractAssert extractingJsonPathValue(CharSequence expression, Object... args) { - return Assertions.assertThat(new JsonPathValue(expression, args).getValue(false)); + return assertThat(new JsonPathValue(expression, args).getValue(false)); } /** @@ -928,7 +929,7 @@ public class JsonContentAssert extends AbstractAssert extractingJsonPathStringValue(CharSequence expression, Object... args) { - return Assertions.assertThat(extractingJsonPathValue(expression, args, String.class, "a string")); + return assertThat(extractingJsonPathValue(expression, args, String.class, "a string")); } /** @@ -940,7 +941,7 @@ public class JsonContentAssert extends AbstractAssert extractingJsonPathNumberValue(CharSequence expression, Object... args) { - return Assertions.assertThat(extractingJsonPathValue(expression, args, Number.class, "a number")); + return assertThat(extractingJsonPathValue(expression, args, Number.class, "a number")); } /** @@ -952,7 +953,7 @@ public class JsonContentAssert extends AbstractAssert extractingJsonPathBooleanValue(CharSequence expression, Object... args) { - return Assertions.assertThat(extractingJsonPathValue(expression, args, Boolean.class, "a boolean")); + return assertThat(extractingJsonPathValue(expression, args, Boolean.class, "a boolean")); } /** @@ -966,7 +967,7 @@ public class JsonContentAssert extends AbstractAssert ListAssert extractingJsonPathArrayValue(CharSequence expression, Object... args) { - return Assertions.assertThat(extractingJsonPathValue(expression, args, List.class, "an array")); + return assertThat(extractingJsonPathValue(expression, args, List.class, "an array")); } /** @@ -981,7 +982,7 @@ public class JsonContentAssert extends AbstractAssert MapAssert extractingJsonPathMapValue(CharSequence expression, Object... args) { - return Assertions.assertThat(extractingJsonPathValue(expression, args, Map.class, "a map")); + return assertThat(extractingJsonPathValue(expression, args, Map.class, "a map")); } @SuppressWarnings("unchecked") diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java index fbc242a647d..1501c151463 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java @@ -27,7 +27,6 @@ import java.util.function.Consumer; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.Assertions; import org.assertj.core.api.ListAssert; import org.springframework.boot.buildpack.platform.docker.DockerApi; @@ -36,6 +35,8 @@ import org.springframework.boot.buildpack.platform.docker.type.Layer; import org.springframework.boot.test.json.JsonContentAssert; import org.springframework.util.StreamUtils; +import static org.assertj.core.api.Assertions.assertThat; + /** * AssertJ {@link org.assertj.core.api.Assert} for Docker image contents. * @@ -92,7 +93,7 @@ public class ImageAssert extends AbstractAssert { catch (IOException ex) { failWithMessage("IOException while reading image layer archive: '%s'", ex.getMessage()); } - return Assertions.assertThat(entryNames); + return assertThat(entryNames); } public void jsonEntry(String name, Consumer assertConsumer) { From 918325aecc941d59dec3add48aaef03d729a338d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 6 Jan 2026 12:23:07 +0100 Subject: [PATCH 2/2] Polish "Use static imports for Assertions.assertThat() consistently" See gh-48630 --- .../assertj/ApplicationContextAssert.java | 19 ++++++++----------- .../netty/NettyRSocketServerFactoryTests.java | 5 ++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssert.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssert.java index d1229b02273..2eb54b83036 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssert.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssert.java @@ -26,7 +26,6 @@ import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractObjectArrayAssert; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.AbstractThrowableAssert; -import org.assertj.core.api.Assertions; import org.assertj.core.api.MapAssert; import org.assertj.core.error.BasicErrorMessageFactory; @@ -223,8 +222,8 @@ public class ApplicationContextAssert if (this.startupFailure != null) { throwAssertionError(contextFailedToStartWhenExpecting("to get beans names with type:%n <%s>", type)); } - return Assertions.assertThat(getApplicationContext().getBeanNamesForType(type)) - .as("Bean names of type <%s> from <%s>", type, getApplicationContext()); + return assertThat(getApplicationContext().getBeanNamesForType(type)).as("Bean names of type <%s> from <%s>", + type, getApplicationContext()); } /** @@ -277,7 +276,7 @@ public class ApplicationContextAssert getApplicationContext(), type, names)); } T bean = (name != null) ? getApplicationContext().getBean(name, type) : null; - return Assertions.assertThat(bean).as("Bean of type <%s> from <%s>", type, getApplicationContext()); + return assertThat(bean).as("Bean of type <%s> from <%s>", type, getApplicationContext()); } private String getPrimary(String[] names, Scope scope) { @@ -328,7 +327,7 @@ public class ApplicationContextAssert throwAssertionError(contextFailedToStartWhenExpecting("to contain a bean of name:%n <%s>", name)); } Object bean = findBean(name); - return Assertions.assertThat(bean).as("Bean of name <%s> from <%s>", name, getApplicationContext()); + return assertThat(bean).as("Bean of name <%s> from <%s>", name, getApplicationContext()); } /** @@ -360,8 +359,8 @@ public class ApplicationContextAssert "%nExpecting:%n <%s>%nto contain a bean of name:%n <%s> (%s)%nbut found:%n <%s> of type <%s>", getApplicationContext(), name, type, bean, bean.getClass())); } - return Assertions.assertThat((T) bean) - .as("Bean of name <%s> and type <%s> from <%s>", name, type, getApplicationContext()); + return assertThat((T) bean).as("Bean of name <%s> and type <%s> from <%s>", name, type, + getApplicationContext()); } private Object findBean(String name) { @@ -411,8 +410,8 @@ public class ApplicationContextAssert if (this.startupFailure != null) { throwAssertionError(contextFailedToStartWhenExpecting("to get beans of type:%n <%s>", type)); } - return Assertions.assertThat(scope.getBeansOfType(getApplicationContext(), type)) - .as("Beans of type <%s> from <%s>", type, getApplicationContext()); + return assertThat(scope.getBeansOfType(getApplicationContext(), type)).as("Beans of type <%s> from <%s>", type, + getApplicationContext()); } /** @@ -482,7 +481,6 @@ public class ApplicationContextAssert * Limited to the current context. */ NO_ANCESTORS { - @Override String[] getBeanNamesForType(ApplicationContext applicationContext, Class type) { return applicationContext.getBeanNamesForType(type); @@ -499,7 +497,6 @@ public class ApplicationContextAssert * Consider the ancestor contexts as well as the current context. */ INCLUDE_ANCESTORS { - @Override String[] getBeanNamesForType(ApplicationContext applicationContext, Class type) { return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, type); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactoryTests.java index d94644a71ee..723540acdd7 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactoryTests.java @@ -32,7 +32,6 @@ import io.rsocket.SocketAcceptor; import io.rsocket.transport.netty.client.TcpClientTransport; import io.rsocket.transport.netty.client.WebsocketClientTransport; import io.rsocket.util.DefaultPayload; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -375,7 +374,7 @@ class NettyRSocketServerFactoryTests { } private HttpClient createHttpClient() { - Assertions.assertThat(this.server).isNotNull(); + assertThat(this.server).isNotNull(); InetSocketAddress address = this.server.address(); return HttpClient.create().host(address.getHostName()).port(address.getPort()); } @@ -389,7 +388,7 @@ class NettyRSocketServerFactoryTests { } private TcpClient createTcpClient() { - Assertions.assertThat(this.server).isNotNull(); + assertThat(this.server).isNotNull(); InetSocketAddress address = this.server.address(); return TcpClient.create().host(address.getHostName()).port(address.getPort()); }