Changeset 18918 in josm for trunk/test/unit


Ignore:
Timestamp:
2023-12-19T17:09:19+01:00 (12 months ago)
Author:
taylor.smock
Message:

Fix #23290: Validate the regions a tag is expected to be in (patch by Sarabjeet108, modified)

Modifications are as follows:

  • Allow the use of the new region attributes for keys inside a preset
  • Basic tests

regions comes from Vespucci's extensions: https://vespucci.io/tutorials/presets/#extensions

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java

    r18870 r18918  
    225225        assertEquals("Value 'Residential' for key 'highway' is unknown, maybe 'residential' is meant?",
    226226                errors.get(0).getDescription());
     227        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
     228        assertFalse(errors.get(0).isFixable());
     229    }
     230
     231    @Test
     232    void testRegionKey() throws IOException {
     233        final List<TestError> errors = test(OsmUtils.createPrimitive("node highway=crossing crossing_ref=zebra"));
     234        assertEquals(1, errors.size());
     235        assertEquals("Invalid region for this preset", errors.get(0).getMessage());
     236        assertEquals("Preset Pedestrian Crossing should not have the key crossing_ref", errors.get(0).getDescription());
     237        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
     238        assertFalse(errors.get(0).isFixable());
     239
     240    }
     241
     242    @Test
     243    void testRegionTag() throws IOException {
     244        final List<TestError> errors = test(OsmUtils.createPrimitive("relation type=waterway ref:gnis=123456"));
     245        assertEquals(1, errors.size());
     246        assertEquals("Invalid region for this preset", errors.get(0).getMessage());
     247        assertEquals("Preset Waterway should not have the key ref:gnis", errors.get(0).getDescription());
    227248        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
    228249        assertFalse(errors.get(0).isFixable());
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroupTest.java

    r18853 r18918  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.assertFalse;
    6 import static org.junit.jupiter.api.Assertions.assertTrue;
    7 
    8 import javax.swing.JPanel;
    9 
    10 import org.junit.jupiter.api.Test;
    11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     4import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
     5import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    126
    137/**
    148 * Unit tests of {@link CheckGroup} class.
    159 */
    16 class CheckGroupTest {
    17     /**
    18      * Unit test for {@link CheckGroup#addToPanel}.
    19      */
    20     @Test
    21     void testAddToPanel() {
    22         CheckGroup cg = new CheckGroup();
    23         JPanel p = new JPanel();
    24         assertEquals(0, p.getComponentCount());
    25         assertFalse(cg.addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    26         assertTrue(p.getComponentCount() > 0);
     10class CheckGroupTest implements TaggingPresetItemTest {
     11    @Override
     12    public TaggingPresetItem getInstance() {
     13        return new CheckGroup();
    2714    }
    2815}
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckTest.java

    r18870 r18918  
    99import org.junit.jupiter.api.Test;
    1010import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    1112import org.openstreetmap.josm.testutils.annotations.Main;
    1213
     
    1516 */
    1617@Main
    17 class CheckTest {
     18class CheckTest implements RegionSpecificTest, TaggingPresetItemTest {
     19    @Override
     20    public Check getInstance() {
     21        final Check check = new Check();
     22        check.key = "crossing:island";
     23        return check;
     24    }
     25
    1826    /**
    1927     * Unit test for {@link Check#addToPanel}.
    2028     */
     29    @Override
    2130    @Test
    22     void testAddToPanel() {
     31    public void testAddToPanel() {
    2332        JPanel p = new JPanel();
    2433        assertEquals(0, p.getComponentCount());
    25         assertTrue(new Check().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
     34        assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    2635        assertTrue(p.getComponentCount() > 0);
    2736    }
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java

    r18870 r18918  
    1313import org.openstreetmap.josm.data.osm.OsmUtils;
    1414import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     15import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    1516import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    1617import org.openstreetmap.josm.testutils.annotations.I18n;
     
    2324@I18n("de")
    2425@Main
    25 class ComboTest {
     26class ComboTest implements TaggingPresetItemTest {
     27    @Override
     28    public Combo getInstance() {
     29        return new Combo();
     30    }
     31
    2632    /**
    27      * Unit test for {@link Combo#addToPanel}.
     33     * Unit test for {@link Check#addToPanel}.
    2834     */
     35    @Override
    2936    @Test
    30     void testAddToPanel() {
     37    public void testAddToPanel() {
    3138        JPanel p = new JPanel();
    3239        assertEquals(0, p.getComponentCount());
    33         assertTrue(new Combo().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
     40        assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    3441        assertTrue(p.getComponentCount() > 0);
    3542    }
     
    4047    @Test
    4148    void testUseLastAsDefault() {
    42         Combo combo = new Combo();
     49        final Combo combo = getInstance();
    4350        combo.key = "addr:country";
    4451        combo.values_from = "java.util.Locale#getISOCountries";
     
    119126    @Test
    120127    void testColor() {
    121         Combo combo = new Combo();
     128        final Combo combo = getInstance();
    122129        combo.key = "colour";
    123130        combo.values = "red;green;blue;black";
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ItemSeparatorTest.java

    r18853 r18918  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.assertFalse;
    6 import static org.junit.jupiter.api.Assertions.assertTrue;
    7 
    8 import javax.swing.JPanel;
    9 
    10 import org.junit.jupiter.api.Test;
    11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     4import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    125
    136/**
    147 * Unit tests of {@link ItemSeparator} class.
    158 */
    16 class ItemSeparatorTest {
    17     /**
    18      * Unit test for {@link ItemSeparator#addToPanel}.
    19      */
    20     @Test
    21     void testAddToPanel() {
    22         JPanel p = new JPanel();
    23         assertEquals(0, p.getComponentCount());
    24         assertFalse(new ItemSeparator().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    25         assertTrue(p.getComponentCount() > 0);
     9class ItemSeparatorTest implements TaggingPresetItemTest {
     10    @Override
     11    public ItemSeparator getInstance() {
     12        return new ItemSeparator();
    2613    }
    2714}
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/KeyTest.java

    r18853 r18918  
    99import org.junit.jupiter.api.Test;
    1010import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    1112
    1213/**
    1314 * Unit tests of {@link Key} class.
    1415 */
    15 class KeyTest {
     16class KeyTest implements RegionSpecificTest, TaggingPresetItemTest {
     17    @Override
     18    public Key getInstance() {
     19        final Key key = new Key();
     20        key.key = "highway";
     21        key.value = "residential";
     22        return key;
     23    }
     24
    1625    /**
    1726     * Unit test for {@link Key#addToPanel}.
    1827     */
    1928    @Test
    20     void testAddToPanel() {
     29    @Override
     30    public void testAddToPanel() {
    2131        JPanel p = new JPanel();
    2232        assertEquals(0, p.getComponentCount());
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LabelTest.java

    r18853 r18918  
    99import org.junit.jupiter.api.Test;
    1010import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    1112
    1213/**
    1314 * Unit tests of {@link Label} class.
    1415 */
    15 class LabelTest {
     16class LabelTest implements TaggingPresetItemTest {
     17    @Override
     18    public Label getInstance() {
     19        return new Label();
     20    }
     21
    1622    /**
    17      * Unit test for {@link Label#addToPanel}.
     23     * Unit test for {@link Check#addToPanel}.
    1824     */
     25    @Override
    1926    @Test
    20     void testAddToPanel() {
     27    public void testAddToPanel() {
    2128        JPanel p = new JPanel();
    2229        assertEquals(0, p.getComponentCount());
    23         assertTrue(new Label().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
     30        assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    2431        assertTrue(p.getComponentCount() > 0);
    2532    }
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LinkTest.java

    r18853 r18918  
    1010import org.junit.jupiter.api.Test;
    1111import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     12import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    1213import org.openstreetmap.josm.spi.preferences.Config;
    1314
     
    1516 * Unit tests of {@link Link} class.
    1617 */
    17 class LinkTest {
     18class LinkTest implements TaggingPresetItemTest {
     19    @Override
     20    public Link getInstance() {
     21        return new Link();
     22    }
     23
    1824    /**
    1925     * Unit test for {@link Link#addToPanel}.
    2026     */
     27    @Override
    2128    @Test
    22     void testAddToPanel() {
    23         Link l = new Link();
     29    public void testAddToPanel() {
     30        Link l = getInstance();
    2431        JPanel p = new JPanel();
    2532        assertEquals(0, p.getComponentCount());
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelectTest.java

    r18870 r18918  
    99import org.junit.jupiter.api.Test;
    1010import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    1112import org.openstreetmap.josm.testutils.annotations.Main;
    1213
     
    1516 */
    1617@Main
    17 class MultiSelectTest {
     18class MultiSelectTest implements TaggingPresetItemTest {
     19    @Override
     20    public MultiSelect getInstance() {
     21        return new MultiSelect();
     22    }
     23
    1824    /**
    19      * Unit test for {@link MultiSelect#addToPanel}.
     25     * Unit test for {@link Check#addToPanel}.
    2026     */
     27    @Override
    2128    @Test
    22     void testAddToPanel() {
     29    public void testAddToPanel() {
    2330        JPanel p = new JPanel();
    2431        assertEquals(0, p.getComponentCount());
    25         assertTrue(new MultiSelect().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
     32        assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    2633        assertTrue(p.getComponentCount() > 0);
    2734    }
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/OptionalTest.java

    r18853 r18918  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.assertFalse;
    6 import static org.junit.jupiter.api.Assertions.assertTrue;
    7 
    8 import javax.swing.JPanel;
    9 
    10 import org.junit.jupiter.api.Test;
    11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     4import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    125
    136/**
    147 * Unit tests of {@link Optional} class.
    158 */
    16 class OptionalTest {
    17     /**
    18      * Unit test for {@link Optional#addToPanel}.
    19      */
    20     @Test
    21     void testAddToPanel() {
    22         JPanel p = new JPanel();
    23         assertEquals(0, p.getComponentCount());
    24         assertFalse(new Optional().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    25         assertTrue(p.getComponentCount() > 0);
     9class OptionalTest implements TaggingPresetItemTest {
     10    @Override
     11    public Optional getInstance() {
     12        return new Optional();
    2613    }
    2714}
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/PresetLinkTest.java

    r18870 r18918  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.assertFalse;
    6 import static org.junit.jupiter.api.Assertions.assertTrue;
    7 
    8 import javax.swing.JPanel;
    9 
    10 import org.junit.jupiter.api.Test;
    11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     4import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    125import org.openstreetmap.josm.testutils.annotations.TaggingPresets;
    136
     
    169 */
    1710@TaggingPresets
    18 class PresetLinkTest {
    19     /**
    20      * Unit test for {@link PresetLink#addToPanel}.
    21      */
    22     @Test
    23     void testAddToPanel() {
    24         PresetLink l = new PresetLink();
    25         l.preset_name = "River";
    26         JPanel p = new JPanel();
    27         assertEquals(0, p.getComponentCount());
    28         assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    29         assertTrue(p.getComponentCount() > 0);
     11class PresetLinkTest implements TaggingPresetItemTest {
     12    @Override
     13    public PresetLink getInstance() {
     14        PresetLink presetLink = new PresetLink();
     15        presetLink.preset_name = "River";
     16        return presetLink;
    3017    }
    3118}
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RolesTest.java

    r18853 r18918  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.assertFalse;
    6 import static org.junit.jupiter.api.Assertions.assertTrue;
    7 
    8 import javax.swing.JPanel;
    9 
    10 import org.junit.jupiter.api.Test;
    11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     4import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
     5import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    126
    137/**
    148 * Unit tests of {@link Roles} class.
    159 */
    16 class RolesTest {
    17     /**
    18      * Unit test for {@link Roles#addToPanel}.
    19      */
    20     @Test
    21     void testAddToPanel() {
    22         JPanel p = new JPanel();
    23         assertEquals(0, p.getComponentCount());
    24         assertFalse(new Roles().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    25         assertTrue(p.getComponentCount() > 0);
     10class RolesTest implements TaggingPresetItemTest {
     11    @Override
     12    public TaggingPresetItem getInstance() {
     13        return new Roles();
    2614    }
    2715}
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/SpaceTest.java

    r18853 r18918  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.assertFalse;
    6 import static org.junit.jupiter.api.Assertions.assertTrue;
    7 
    8 import javax.swing.JPanel;
    9 
    10 import org.junit.jupiter.api.Test;
    11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     4import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    125
    136/**
    147 * Unit tests of {@link Space} class.
    158 */
    16 class SpaceTest {
    17     /**
    18      * Unit test for {@link Space#addToPanel}.
    19      */
    20     @Test
    21     void testAddToPanel() {
    22         JPanel p = new JPanel();
    23         assertEquals(0, p.getComponentCount());
    24         assertFalse(new Space().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    25         assertTrue(p.getComponentCount() > 0);
     9class SpaceTest implements TaggingPresetItemTest {
     10    @Override
     11    public Space getInstance() {
     12        return new Space();
    2613    }
    2714}
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/TextTest.java

    r18870 r18918  
    99import org.junit.jupiter.api.Test;
    1010import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemTest;
    1112import org.openstreetmap.josm.testutils.annotations.Main;
    1213
     
    1516 */
    1617@Main
    17 class TextTest {
     18class TextTest implements TaggingPresetItemTest {
     19    @Override
     20    public Text getInstance() {
     21        return new Text();
     22    }
     23
    1824    /**
    19      * Unit test for {@link Text#addToPanel}.
     25     * Unit test for {@link Check#addToPanel}.
    2026     */
     27    @Override
    2128    @Test
    22     void testAddToPanel() {
     29    public void testAddToPanel() {
    2330        JPanel p = new JPanel();
    2431        assertEquals(0, p.getComponentCount());
    25         assertTrue(new Text().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
     32        assertTrue(getInstance().addToPanel(p, TaggingPresetItemGuiSupport.create(false)));
    2633        assertTrue(p.getComponentCount() > 0);
    2734    }
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/TaggingPresets.java

    r18867 r18918  
    99import java.util.Collection;
    1010
     11import org.junit.jupiter.api.extension.BeforeAllCallback;
    1112import org.junit.jupiter.api.extension.BeforeEachCallback;
    1213import org.junit.jupiter.api.extension.ExtendWith;
     
    2526@Target({ ElementType.METHOD, ElementType.TYPE })
    2627@BasicPreferences
     28@Territories
    2729@ExtendWith(TaggingPresets.TaggingPresetsExtension.class)
    2830public @interface TaggingPresets {
    2931
    30     class TaggingPresetsExtension implements BeforeEachCallback {
     32    class TaggingPresetsExtension implements BeforeEachCallback, BeforeAllCallback {
    3133        private static int expectedHashcode = 0;
     34
     35        @Override
     36        public void beforeAll(ExtensionContext extensionContext) throws Exception {
     37            setup();
     38        }
    3239
    3340        @Override
     
    3744
    3845        /**
    39          * Setup the tagging presets
     46         * Set up the tagging presets
    4047         */
    4148        public static synchronized void setup() {
Note: See TracChangeset for help on using the changeset viewer.