summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorNathan Adams <dinnerbone@dinnerbone.com>2011-10-12 13:24:57 +0100
committerNathan Adams <dinnerbone@dinnerbone.com>2011-10-12 13:24:57 +0100
commit5993f1cc165159e129f70bfd34af1df910bca06b (patch)
treed50c8284b46ca7b636fd1d001357f9cf9c2b8d74 /src/test
parentdb7bdbbd582c37e7606119dfa8650a9a4c91066d (diff)
downloadbukkit-5993f1cc165159e129f70bfd34af1df910bca06b.tar
bukkit-5993f1cc165159e129f70bfd34af1df910bca06b.tar.gz
bukkit-5993f1cc165159e129f70bfd34af1df910bca06b.tar.lz
bukkit-5993f1cc165159e129f70bfd34af1df910bca06b.tar.xz
bukkit-5993f1cc165159e129f70bfd34af1df910bca06b.zip
Added new FileConfigurationOptions.copyHeader, defaulting to true. Copies the header from default config, if there is one.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java66
-rw-r--r--src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java60
2 files changed, 74 insertions, 52 deletions
diff --git a/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java b/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java
index 5deb4581..2b976725 100644
--- a/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java
+++ b/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java
@@ -1,9 +1,7 @@
package org.bukkit.configuration.file;
-import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileReader;
import java.io.FileWriter;
import java.util.Map;
import org.bukkit.configuration.MemoryConfigurationTest;
@@ -21,6 +19,10 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
public abstract String getTestValuesString();
+ public abstract String getTestHeaderInput();
+
+ public abstract String getTestHeaderResult();
+
@Test
public void testSave_File() throws Exception {
FileConfiguration config = getConfig();
@@ -122,5 +124,65 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
}
assertEquals(values.keySet(), config.getKeys(true));
+ assertEquals(saved, config.saveToString());
+ }
+
+ @Test
+ public void testSaveToStringWithHeader() {
+ FileConfiguration config = getConfig();
+ config.options().header(getTestHeaderInput());
+
+ for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
+ config.set(entry.getKey(), entry.getValue());
+ }
+
+ String result = config.saveToString();
+ String expected = getTestHeaderResult() + "\n" + getTestValuesString();
+
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testParseHeader() throws Exception {
+ FileConfiguration config = getConfig();
+ Map<String, Object> values = getTestValues();
+ String saved = getTestValuesString();
+ String header = getTestHeaderResult();
+ String expected = getTestHeaderInput();
+
+ config.loadFromString(header + "\n" + saved);
+
+ assertEquals(expected, config.options().header());
+
+ for (Map.Entry<String, Object> entry : values.entrySet()) {
+ assertEquals(entry.getValue(), config.get(entry.getKey()));
+ }
+
+ assertEquals(values.keySet(), config.getKeys(true));
+ assertEquals(header + "\n" + saved, config.saveToString());
+ }
+
+ @Test
+ public void testCopyHeader() throws Exception {
+ FileConfiguration config = getConfig();
+ FileConfiguration defaults = getConfig();
+ Map<String, Object> values = getTestValues();
+ String saved = getTestValuesString();
+ String header = getTestHeaderResult();
+ String expected = getTestHeaderInput();
+
+ defaults.loadFromString(header);
+ config.loadFromString(saved);
+ config.setDefaults(defaults);
+
+ assertNull(config.options().header());
+ assertEquals(expected, defaults.options().header());
+
+ for (Map.Entry<String, Object> entry : values.entrySet()) {
+ assertEquals(entry.getValue(), config.get(entry.getKey()));
+ }
+
+ assertEquals(values.keySet(), config.getKeys(true));
+ assertEquals(header + "\n" + saved, config.saveToString());
}
}
diff --git a/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java b/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java
index 488ce208..239b2f83 100644
--- a/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java
+++ b/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java
@@ -1,6 +1,5 @@
package org.bukkit.configuration.file;
-import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -9,6 +8,16 @@ public class YamlConfigurationTest extends FileConfigurationTest {
public YamlConfiguration getConfig() {
return new YamlConfiguration();
}
+
+ @Override
+ public String getTestHeaderInput() {
+ return "This is a sample\nheader.\n\nNewline above should be commented.\n\n";
+ }
+
+ @Override
+ public String getTestHeaderResult() {
+ return "# This is a sample\n# header.\n# \n# Newline above should be commented.\n\n";
+ }
@Override
public String getTestValuesString() {
@@ -31,55 +40,6 @@ public class YamlConfigurationTest extends FileConfigurationTest {
}
@Test
- public void testSaveToStringWithHeader() {
- YamlConfiguration config = getConfig();
- config.options().header("This is a sample\nheader.");
-
- for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
- config.set(entry.getKey(), entry.getValue());
- }
-
- String result = config.saveToString();
- String expected = "# This is a sample\n# header.\n" + getTestValuesString();
-
- assertEquals(expected, result);
- }
-
- @Test
- public void testSaveToStringWithLongHeader() {
- YamlConfiguration config = getConfig();
- config.options().header("This is a sample\nheader.\n\nNewline above should be commented.\n\n");
-
- for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
- config.set(entry.getKey(), entry.getValue());
- }
-
- String result = config.saveToString();
- String expected = "# This is a sample\n# header.\n# \n# Newline above should be commented.\n\n\n" + getTestValuesString();
-
- assertEquals(expected, result);
- }
-
- @Test
- public void testParseHeader() throws Exception {
- YamlConfiguration config = getConfig();
- Map<String, Object> values = getTestValues();
- String saved = getTestValuesString();
- String header = "# This is a sample\n# header.\n# \n# Newline above should be commented.\n\n\n";
- String expected = "This is a sample\nheader.\n\nNewline above should be commented.\n\n";
-
- config.loadFromString(header + saved);
-
- assertEquals(expected, config.options().header());
-
- for (Map.Entry<String, Object> entry : values.entrySet()) {
- assertEquals(entry.getValue(), config.get(entry.getKey()));
- }
-
- assertEquals(values.keySet(), config.getKeys(true));
- }
-
- @Test
public void testSaveToStringWithIndent() {
YamlConfiguration config = getConfig();
config.options().indent(9);