Reuse MapPropertySource for DynamicValuesPropertySource implementation

Closes gh-32110
This commit is contained in:
Juergen Hoeller
2024-01-29 13:04:02 +01:00
parent 08e6df8832
commit 7e5efdd8dd
2 changed files with 22 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,38 +19,27 @@ package org.springframework.test.context.support;
import java.util.Map;
import java.util.function.Supplier;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.util.StringUtils;
import org.springframework.core.env.MapPropertySource;
import org.springframework.util.function.SupplierUtils;
/**
* {@link EnumerablePropertySource} backed by a map with dynamically supplied
* values.
* {@link MapPropertySource} backed by a map with dynamically supplied values.
*
* @author Phillip Webb
* @author Sam Brannen
* @author Juergen Hoeller
* @since 5.2.5
*/
class DynamicValuesPropertySource extends EnumerablePropertySource<Map<String, Supplier<Object>>> {
class DynamicValuesPropertySource extends MapPropertySource {
@SuppressWarnings({"rawtypes", "unchecked"})
DynamicValuesPropertySource(String name, Map<String, Supplier<Object>> valueSuppliers) {
super(name, valueSuppliers);
super(name, (Map) valueSuppliers);
}
@Override
public Object getProperty(String name) {
Supplier<Object> valueSupplier = this.source.get(name);
return (valueSupplier != null ? valueSupplier.get() : null);
}
@Override
public boolean containsProperty(String name) {
return this.source.containsKey(name);
}
@Override
public String[] getPropertyNames() {
return StringUtils.toStringArray(this.source.keySet());
return SupplierUtils.resolve(super.getProperty(name));
}
}