Index: trunk/test/data/customconfigurator/append.xml
===================================================================
--- trunk/test/data/customconfigurator/append.xml (revision 9524)
+++ trunk/test/data/customconfigurator/append.xml (revision 9524)
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
Index: trunk/test/data/customconfigurator/replace.xml
===================================================================
--- trunk/test/data/customconfigurator/replace.xml (revision 9524)
+++ trunk/test/data/customconfigurator/replace.xml (revision 9524)
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: trunk/test/unit/org/openstreetmap/josm/data/CustomConfiguratorTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/data/CustomConfiguratorTest.java (revision 9504)
+++ trunk/test/unit/org/openstreetmap/josm/data/CustomConfiguratorTest.java (revision 9524)
@@ -3,4 +3,5 @@
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -10,9 +11,12 @@
import java.nio.file.Files;
import java.util.Arrays;
+import java.util.Collections;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openstreetmap.josm.JOSMFixture;
import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.tools.Utils;
@@ -26,6 +30,14 @@
*/
@BeforeClass
- public static void setUp() {
+ public static void setUpBeforeClass() {
JOSMFixture.createUnitTestFixture().init();
+ }
+
+ /**
+ * Setup test.
+ */
+ @Before
+ public void setUp() {
+ CustomConfigurator.resetLog();
}
@@ -79,3 +91,29 @@
Utils.deleteFile(tmp);
}
+
+ /**
+ * Test method for {@link CustomConfigurator#readXML}.
+ * @throws IOException if any I/O error occurs
+ */
+ @Test
+ public void testReadXML() throws IOException {
+ // Test 1 - read(dir, file) + append
+ Main.pref.putCollection("test", Collections.emptyList());
+ assertTrue(Main.pref.getCollection("test").isEmpty());
+ CustomConfigurator.readXML(TestUtils.getTestDataRoot() + "customconfigurator", "append.xml");
+ String log = CustomConfigurator.getLog();
+ System.out.println(log);
+ assertFalse(log.contains("Error"));
+ assertFalse(Main.pref.getCollection("test").isEmpty());
+
+ // Test 1 - read(file, pref) + replace
+ Preferences pref = new Preferences();
+ pref.putCollection("lorem_ipsum", Arrays.asList("only 1 string"));
+ assertEquals(1, pref.getCollection("lorem_ipsum").size());
+ CustomConfigurator.readXML(new File(TestUtils.getTestDataRoot() + "customconfigurator", "replace.xml"), pref);
+ log = CustomConfigurator.getLog();
+ System.out.println(log);
+ assertFalse(log.contains("Error"));
+ assertEquals(9, pref.getCollection("lorem_ipsum").size());
+ }
}