Changeset 9524 in josm for trunk/test


Ignore:
Timestamp:
2016-01-18T01:46:48+01:00 (4 years ago)
Author:
Don-vip
Message:

CustomConfigurator - add unit test, javadoc, and use JavaScript engine instead of rhino, gone with Java 8 (replaced by Nashorn)

Location:
trunk/test
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/CustomConfiguratorTest.java

    r9498 r9524  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
    56import static org.junit.Assert.assertTrue;
    67
     
    1011import java.nio.file.Files;
    1112import java.util.Arrays;
     13import java.util.Collections;
    1214
     15import org.junit.Before;
    1316import org.junit.BeforeClass;
    1417import org.junit.Test;
    1518import org.openstreetmap.josm.JOSMFixture;
    1619import org.openstreetmap.josm.Main;
     20import org.openstreetmap.josm.TestUtils;
    1721import org.openstreetmap.josm.tools.Utils;
    1822
     
    2630     */
    2731    @BeforeClass
    28     public static void setUp() {
     32    public static void setUpBeforeClass() {
    2933        JOSMFixture.createUnitTestFixture().init();
     34    }
     35
     36    /**
     37     * Setup test.
     38     */
     39    @Before
     40    public void setUp() {
     41        CustomConfigurator.resetLog();
    3042    }
    3143
     
    7991        Utils.deleteFile(tmp);
    8092    }
     93
     94    /**
     95     * Test method for {@link CustomConfigurator#readXML}.
     96     * @throws IOException if any I/O error occurs
     97     */
     98    @Test
     99    public void testReadXML() throws IOException {
     100        // Test 1 - read(dir, file) + append
     101        Main.pref.putCollection("test", Collections.<String>emptyList());
     102        assertTrue(Main.pref.getCollection("test").isEmpty());
     103        CustomConfigurator.readXML(TestUtils.getTestDataRoot() + "customconfigurator", "append.xml");
     104        String log = CustomConfigurator.getLog();
     105        System.out.println(log);
     106        assertFalse(log.contains("Error"));
     107        assertFalse(Main.pref.getCollection("test").isEmpty());
     108
     109        // Test 1 - read(file, pref) + replace
     110        Preferences pref = new Preferences();
     111        pref.putCollection("lorem_ipsum", Arrays.asList("only 1 string"));
     112        assertEquals(1, pref.getCollection("lorem_ipsum").size());
     113        CustomConfigurator.readXML(new File(TestUtils.getTestDataRoot() + "customconfigurator", "replace.xml"), pref);
     114        log = CustomConfigurator.getLog();
     115        System.out.println(log);
     116        assertFalse(log.contains("Error"));
     117        assertEquals(9, pref.getCollection("lorem_ipsum").size());
     118    }
    81119}
Note: See TracChangeset for help on using the changeset viewer.