Ticket #8954: 8954-test.2.patch

File 8954-test.2.patch, 3.8 KB (added by AlfonZ, 8 years ago)

Regression test. If property josm.test.data is not set, use ./test/data.

  • build.xml

     
    184184        <jacoco:coverage destfile="${test.dir}/jacoco.exec">
    185185            <junit printsummary="yes" fork="true" forkmode="once">
    186186                <sysproperty key="josm.home" value="${test.dir}/config/unit-josm.home"/>
     187                <sysproperty key="josm.test.data" value="${test.dir}/data"/>
    187188                <sysproperty key="java.awt.headless" value="true"/>
    188             <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
     189                <sysproperty key="suppressPermanentFailure" value="${suppressPermanentFailure}"/>
    189190                <classpath>
    190191                    <path refid="test.classpath"/>
    191192                    <pathelement path="${test.dir}/build"/>
  • test/data/regress/8954/preset.xml

     
     1<?xml version="1.0" encoding="UTF-8"?>
     2<presets xmlns="http://josm.openstreetmap.de/tagging-preset-1.0">
     3    <item name="ItemName" type="node">
     4        <check key="foo" text="Foo" default="off" />
     5    </item>
     6</presets>
  • test/unit/org/openstreetmap/josm/gui/tagging/TaggingPresetReaderTest.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui.tagging;
     3
     4import java.io.IOException;
     5import java.util.Collection;
     6
     7import org.junit.Assert;
     8import org.junit.BeforeClass;
     9import org.junit.Test;
     10import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.Preferences;
     12import org.xml.sax.SAXException;
     13
     14/**
     15 * Unit tests of {@link TaggingPresetReader} class.
     16 */
     17public class TaggingPresetReaderTest {
     18    /**
     19     * path to test data root directory
     20     */
     21    private static String testdataroot;
     22   
     23    @BeforeClass
     24    public static void setUpClass() {
     25        Main.pref = new Preferences();
     26        testdataroot = System.getProperty("josm.test.data");
     27        if (testdataroot == null || testdataroot.isEmpty()) {
     28            testdataroot = "test/data";
     29            System.out.println("System property josm.test.data is not set, using '" + testdataroot + "'");
     30        }
     31    }
     32
     33    /**
     34     * Gets path to test data directory for given ticketid.
     35     * @param ticketid
     36     * @return
     37     */
     38    protected static String getRegressionDataDir(int ticketid) {
     39        return testdataroot + "/regress/" + ticketid;
     40    }
     41
     42    /**
     43     * Gets path to given file in test data directory for given ticketid.
     44     * @param ticketid
     45     * @param filename
     46     * @return
     47     */
     48    protected static String getRegressionDataFile(int ticketid, String filename) {
     49        return getRegressionDataDir(ticketid) + '/' + filename;
     50    }
     51
     52    /**
     53     * #8954 - last checkbox in the preset is not added
     54     */
     55    @Test
     56    public void test8954() throws SAXException, IOException {
     57        String presetfile = getRegressionDataFile(8954, "preset.xml");
     58        final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(presetfile, false);
     59        Assert.assertEquals("Number of preset items", 1, presets.size());
     60        final TaggingPreset preset = presets.iterator().next();
     61        Assert.assertEquals("Number of entries", 1, preset.data.size());
     62        final TaggingPresetItem item = preset.data.get(0);
     63        Assert.assertTrue("Entry is not checkbox", item instanceof TaggingPresetItems.Check);
     64    }
     65
     66}