mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
SPIGOT-6830: Fix addDefaults with Configuration overrides child Sections in the defaults
By: Wolf2323 <gabrielpatrikurban@gmail.com>
This commit is contained in:
parent
36fb1f9c00
commit
3ddde21487
@ -54,7 +54,11 @@ public class MemoryConfiguration extends MemorySection implements Configuration
|
||||
public void addDefaults(@NotNull Configuration defaults) {
|
||||
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
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user