Skip to content

Commit 533f6c3

Browse files
Refactor TestcontainersPropertySource to use MapPropertySource
Closes gh-39330
1 parent 8744cfb commit 533f6c3

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/properties/TestcontainersPropertySource.java

+6-15
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
import org.springframework.core.env.ConfigurableEnvironment;
3737
import org.springframework.core.env.EnumerablePropertySource;
3838
import org.springframework.core.env.Environment;
39+
import org.springframework.core.env.MapPropertySource;
3940
import org.springframework.core.env.PropertySource;
4041
import org.springframework.test.context.DynamicPropertyRegistry;
4142
import org.springframework.util.Assert;
42-
import org.springframework.util.StringUtils;
43+
import org.springframework.util.function.SupplierUtils;
4344

4445
/**
4546
* {@link EnumerablePropertySource} backed by a map with values supplied from one or more
@@ -48,7 +49,7 @@
4849
* @author Phillip Webb
4950
* @since 3.1.0
5051
*/
51-
public class TestcontainersPropertySource extends EnumerablePropertySource<Map<String, Supplier<Object>>> {
52+
public class TestcontainersPropertySource extends MapPropertySource {
5253

5354
static final String NAME = "testcontainersPropertySource";
5455

@@ -75,24 +76,14 @@ private void addEventPublisher(ApplicationEventPublisher eventPublisher) {
7576

7677
@Override
7778
public Object getProperty(String name) {
78-
Supplier<Object> valueSupplier = this.source.get(name);
79+
Object valueSupplier = this.source.get(name);
7980
return (valueSupplier != null) ? getProperty(name, valueSupplier) : null;
8081
}
8182

82-
private Object getProperty(String name, Supplier<Object> valueSupplier) {
83+
private Object getProperty(String name, Object valueSupplier) {
8384
BeforeTestcontainersPropertySuppliedEvent event = new BeforeTestcontainersPropertySuppliedEvent(this, name);
8485
this.eventPublishers.forEach((eventPublisher) -> eventPublisher.publishEvent(event));
85-
return valueSupplier.get();
86-
}
87-
88-
@Override
89-
public boolean containsProperty(String name) {
90-
return this.source.containsKey(name);
91-
}
92-
93-
@Override
94-
public String[] getPropertyNames() {
95-
return StringUtils.toStringArray(this.source.keySet());
86+
return SupplierUtils.resolve(valueSupplier);
9687
}
9788

9889
public static DynamicPropertyRegistry attach(Environment environment) {

0 commit comments

Comments
 (0)