mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-23 09:37:54 +01:00
[#844] Quoted String no longer double quoted
- 'Something' no longer changed to "'Something'" on config update. - Added failing tests for rest of the problems.
This commit is contained in:
parent
114e4f5fb6
commit
d34c5954b9
@ -49,8 +49,8 @@ public interface ConfigChange {
|
|||||||
ConfigNode newNode = config.getConfigNode(newPath);
|
ConfigNode newNode = config.getConfigNode(newPath);
|
||||||
ConfigNode oldNode = config.getConfigNode(oldPath);
|
ConfigNode oldNode = config.getConfigNode(oldPath);
|
||||||
newNode.copyDefaults(oldNode);
|
newNode.copyDefaults(oldNode);
|
||||||
newNode.set(oldNode.getValue());
|
newNode.set(oldNode.getString());
|
||||||
super.apply(config);
|
removeNode(oldNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,6 +97,10 @@ public interface ConfigChange {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void apply(Config config) {
|
public synchronized void apply(Config config) {
|
||||||
ConfigNode node = config.getConfigNode(oldPath);
|
ConfigNode node = config.getConfigNode(oldPath);
|
||||||
|
removeNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeNode(ConfigNode node) {
|
||||||
ConfigNode parent = node.getParent();
|
ConfigNode parent = node.getParent();
|
||||||
String key = node.getKey(false);
|
String key = node.getKey(false);
|
||||||
parent.getChildren().remove(key);
|
parent.getChildren().remove(key);
|
||||||
|
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.system.settings.changes;
|
||||||
|
|
||||||
|
import com.djrapitops.plugin.config.Config;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.junit.platform.runner.JUnitPlatform;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junitpioneer.jupiter.TempDirectory;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@RunWith(JUnitPlatform.class)
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
@ExtendWith(TempDirectory.class)
|
||||||
|
class ConfigChangeTest {
|
||||||
|
|
||||||
|
private Path temporaryFolder;
|
||||||
|
|
||||||
|
private Config config;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void prepareTemporaryFolder(@TempDirectory.TempDir Path temporaryFolder) {
|
||||||
|
this.temporaryFolder = temporaryFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Config prepareConfig(String withValue) {
|
||||||
|
return new Config(temporaryFolder.resolve("config.yml").toFile(), Collections.singletonList(withValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void moveChangeRecognizesItHasNotBeenApplied() {
|
||||||
|
config = prepareConfig("Test: 'value'");
|
||||||
|
|
||||||
|
assertFalse(new ConfigChange.Moved("Test", "MovedTo").hasBeenApplied(config));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void moveChangeRecognizesItHasBeenApplied() {
|
||||||
|
config = prepareConfig("Test: 'value'");
|
||||||
|
|
||||||
|
ConfigChange change = new ConfigChange.Moved("Test", "MovedTo");
|
||||||
|
change.apply(config);
|
||||||
|
|
||||||
|
assertFalse(config.getChildren().containsKey("Test"));
|
||||||
|
assertFalse(config.contains("Test"), "Old node was not removed");
|
||||||
|
assertTrue(config.contains("MovedTo"), "New node was not created");
|
||||||
|
assertTrue(change.hasBeenApplied(config), "Did not recognize it has been applied");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void stringSettingWithQuotesIsMovedAsString() {
|
||||||
|
config = prepareConfig("Test: 'value'");
|
||||||
|
|
||||||
|
new ConfigChange.Moved("Test", "MovedTo").apply(config);
|
||||||
|
|
||||||
|
assertFalse(config.contains("Test"), "Old node was not removed");
|
||||||
|
assertTrue(config.contains("MovedTo"), "New node was not created");
|
||||||
|
String result = config.getConfigNode("MovedTo").getValue();
|
||||||
|
assertEquals("value", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void stringSettingWithDoubleQuotesIsMovedAsString() {
|
||||||
|
config = prepareConfig("Test: \"value\"");
|
||||||
|
|
||||||
|
new ConfigChange.Moved("Test", "MovedTo").apply(config);
|
||||||
|
|
||||||
|
assertFalse(config.contains("Test"), "Old node was not removed");
|
||||||
|
assertTrue(config.contains("MovedTo"), "New node was not created");
|
||||||
|
String result = config.getConfigNode("MovedTo").getValue();
|
||||||
|
assertEquals("value", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void stringSettingWithQuotedDoubleQuotesIsMovedAsString() {
|
||||||
|
config = prepareConfig("Test: '\"value\"'");
|
||||||
|
|
||||||
|
new ConfigChange.Moved("Test", "MovedTo").apply(config);
|
||||||
|
|
||||||
|
assertFalse(config.contains("Test"), "Old node was not removed");
|
||||||
|
assertTrue(config.contains("MovedTo"), "New node was not created");
|
||||||
|
String result = config.getConfigNode("MovedTo").getValue();
|
||||||
|
assertEquals("\"value\"", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void stringSettingWithQuotedQuotesIsMovedAsString() {
|
||||||
|
config = prepareConfig("Test: \"'value'\"");
|
||||||
|
|
||||||
|
new ConfigChange.Moved("Test", "MovedTo").apply(config);
|
||||||
|
|
||||||
|
assertFalse(config.contains("Test"), "Old node was not removed");
|
||||||
|
assertTrue(config.contains("MovedTo"), "New node was not created");
|
||||||
|
String result = config.getConfigNode("MovedTo").getValue();
|
||||||
|
assertEquals("'value'", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void removedSettingIsNotPresent() {
|
||||||
|
config = prepareConfig("Test: \"value\"");
|
||||||
|
|
||||||
|
new ConfigChange.Removed("Test").apply(config);
|
||||||
|
|
||||||
|
assertFalse(config.contains("Test"), "Old node was not removed");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user