From 1585c5a10991d120c57c8c870fa4dd0f5d962845 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Thu, 3 Oct 2024 14:25:57 +0900 Subject: [PATCH] Polish See gh-42503 --- ...ventPublisherBeansApplicationListener.java | 19 +++++++++++-------- .../BaggagePropagationIntegrationTests.java | 1 - .../data/ldap/DataLdapTestDockerTests.java | 3 +-- ...nectionDetailsFactoryIntegrationTests.java | 3 +-- .../ContainerConnectionDetailsFactory.java | 2 +- .../connection/ContainerConnectionSource.java | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryEventPublisherBeansApplicationListener.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryEventPublisherBeansApplicationListener.java index d43cf33428e5..724bb850fd91 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryEventPublisherBeansApplicationListener.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryEventPublisherBeansApplicationListener.java @@ -99,8 +99,8 @@ public void onApplicationEvent(ApplicationEvent event) { /** * {@link ContextStorage#addWrapper(java.util.function.Function) Add} the - * {@link ContextStorage} wrapper to ensure that {@link EventPublisher} are propagated - * correctly. + * {@link ContextStorage} wrapper to ensure that {@link EventPublisher + * EventPublishers} are propagated correctly. */ public static void addWrapper() { if (isInstallable() && added.compareAndSet(false, true)) { @@ -118,7 +118,7 @@ private static boolean isInstallable() { */ static final class Wrapper { - static Wrapper instance = new Wrapper(); + static final Wrapper instance = new Wrapper(); private final MultiValueMap beans = new LinkedMultiValueMap<>(); @@ -149,13 +149,16 @@ ContextStorage getStorageDelegate(ContextStorage parent) { ContextStorage delegate = this.storageDelegate; if (delegate == null) { synchronized (this) { - delegate = parent; - for (List publishers : this.beans.values()) { - for (EventPublishingContextWrapper publisher : publishers) { - delegate = publisher.apply(delegate); + delegate = this.storageDelegate; + if (delegate == null) { + delegate = parent; + for (List publishers : this.beans.values()) { + for (EventPublishingContextWrapper publisher : publishers) { + delegate = publisher.apply(delegate); + } } + this.storageDelegate = delegate; } - this.storageDelegate = delegate; } } return delegate; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java index f7663b90f537..61681e3428c0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java @@ -57,7 +57,6 @@ class BaggagePropagationIntegrationTests { @BeforeEach @AfterEach void setup() { - OpenTelemetryEventPublisherBeansApplicationListener.addWrapper(); MDC.clear(); } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/dockerTest/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestDockerTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/dockerTest/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestDockerTests.java index a0bd5d145108..5ce48a457214 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/dockerTest/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestDockerTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/dockerTest/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestDockerTests.java @@ -58,8 +58,7 @@ class DataLdapTestDockerTests { void connectionCanBeMadeToLdapContainer() { List cn = this.ldapTemplate.search(LdapQueryBuilder.query().where("objectclass").is("dcObject"), (AttributesMapper) (attributes) -> attributes.get("dc").get().toString()); - assertThat(cn).hasSize(1); - assertThat(cn.get(0)).isEqualTo("example"); + assertThat(cn).singleElement().isEqualTo("example"); } @Test diff --git a/spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/ldap/OpenLdapContainerConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/ldap/OpenLdapContainerConnectionDetailsFactoryIntegrationTests.java index d269c3cb43d3..bc9e201dadd5 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/ldap/OpenLdapContainerConnectionDetailsFactoryIntegrationTests.java +++ b/spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/ldap/OpenLdapContainerConnectionDetailsFactoryIntegrationTests.java @@ -56,8 +56,7 @@ class OpenLdapContainerConnectionDetailsFactoryIntegrationTests { void connectionCanBeMadeToLdapContainer() { List cn = this.ldapTemplate.search(LdapQueryBuilder.query().where("objectclass").is("dcObject"), (AttributesMapper) (attributes) -> attributes.get("dc").get().toString()); - assertThat(cn).hasSize(1); - assertThat(cn.get(0)).isEqualTo("example"); + assertThat(cn).singleElement().isEqualTo("example"); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java index 4b601d423ab3..968c34b56fa5 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionDetailsFactory.java @@ -117,7 +117,7 @@ public final D getConnectionDetails(ContainerConnectionSource source) { } /** - * Return if the give source accepts the connection. By default this method checks + * Return if the given source accepts the connection. By default this method checks * each connection name. * @param source the container connection source * @param requiredContainerType the required container type diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java index 06a09e4e4a87..d589b4274dd6 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ContainerConnectionSource.java @@ -95,7 +95,7 @@ private static String getOrDeduceConnectionName(String connectionName, String co } /** - * Return is this source accepts the given connection. + * Return if this source accepts the given connection. * @param requiredConnectionName the required connection name or {@code null} * @param requiredContainerType the required container type * @param requiredConnectionDetailsType the required connection details type