mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-22 07:43:49 -07:00
SPIGOT-6830: Fix addDefaults with Configuration overrides child Sections in the defaults
By: Wolf2323 <gabrielpatrikurban@gmail.com>
This commit is contained in:
@@ -54,7 +54,11 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
|||||||
public void addDefaults(@NotNull Configuration defaults) {
|
public void addDefaults(@NotNull Configuration defaults) {
|
||||||
Validate.notNull(defaults, "Defaults may not be null");
|
Validate.notNull(defaults, "Defaults may not be null");
|
||||||
|
|
||||||
addDefaults(defaults.getValues(true));
|
for (String key : defaults.getKeys(true)) {
|
||||||
|
if (!defaults.isConfigurationSection(key)) {
|
||||||
|
addDefault(key, defaults.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -103,6 +103,43 @@ public abstract class ConfigurationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of addDefaults method, of class Configuration but with existing
|
||||||
|
* defaults in a child section.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testAddDefaults_Configuration_WithExisting() {
|
||||||
|
Configuration config = getConfig();
|
||||||
|
Map<String, Object> values = getTestValues();
|
||||||
|
values.put("default-section.string", "String Value");
|
||||||
|
Configuration defaults = getConfig();
|
||||||
|
Configuration defaultsAdditional = getConfig();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||||
|
defaults.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
config.addDefaults(defaults);
|
||||||
|
|
||||||
|
Map<String, Object> additionalValues = new HashMap<>();
|
||||||
|
additionalValues.put("default-section.additionalString", "Additional String");
|
||||||
|
additionalValues.put("default-section.additionalInt", 42);
|
||||||
|
for (Map.Entry<String, Object> entry : additionalValues.entrySet()) {
|
||||||
|
defaultsAdditional.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
config.addDefaults(defaultsAdditional);
|
||||||
|
values.putAll(additionalValues);
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||||
|
String path = entry.getKey();
|
||||||
|
Object object = entry.getValue();
|
||||||
|
|
||||||
|
assertEquals(object, config.get(path));
|
||||||
|
assertTrue(config.contains(path));
|
||||||
|
assertFalse(config.isSet(path));
|
||||||
|
assertTrue(config.getDefaults().isSet(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of setDefaults method, of class Configuration.
|
* Test of setDefaults method, of class Configuration.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user