From 533f6c3bb1dc30838b8f506c49d53b716ce7144c Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Thu, 1 Feb 2024 14:57:47 -0600 Subject: [PATCH] Refactor TestcontainersPropertySource to use MapPropertySource Closes gh-39330 --- .../TestcontainersPropertySource.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java index d2df1e65b10..ee84759fe5b 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java @@ -36,10 +36,11 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.Environment; +import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; +import org.springframework.util.function.SupplierUtils; /** * {@link EnumerablePropertySource} backed by a map with values supplied from one or more @@ -48,7 +49,7 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @since 3.1.0 */ -public class TestcontainersPropertySource extends EnumerablePropertySource>> { +public class TestcontainersPropertySource extends MapPropertySource { static final String NAME = "testcontainersPropertySource"; @@ -75,24 +76,14 @@ public class TestcontainersPropertySource extends EnumerablePropertySource valueSupplier = this.source.get(name); + Object valueSupplier = this.source.get(name); return (valueSupplier != null) ? getProperty(name, valueSupplier) : null; } - private Object getProperty(String name, Supplier valueSupplier) { + private Object getProperty(String name, Object valueSupplier) { BeforeTestcontainersPropertySuppliedEvent event = new BeforeTestcontainersPropertySuppliedEvent(this, name); this.eventPublishers.forEach((eventPublisher) -> eventPublisher.publishEvent(event)); - return valueSupplier.get(); - } - - @Override - public boolean containsProperty(String name) { - return this.source.containsKey(name); - } - - @Override - public String[] getPropertyNames() { - return StringUtils.toStringArray(this.source.keySet()); + return SupplierUtils.resolve(valueSupplier); } public static DynamicPropertyRegistry attach(Environment environment) {