Changeset 7356 in josm for trunk/test


Ignore:
Timestamp:
2014-08-01T19:17:40+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #10206 - Check MapCSS validator assertions for local rules if new advanced option validator.check_assert_local_rules is enabled in preferences

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r7109 r7356  
    99import java.util.Arrays;
    1010import java.util.Comparator;
    11 import java.util.Map;
    1211
    1312import org.junit.Test;
    14 import org.openstreetmap.josm.data.osm.Node;
    1513import org.openstreetmap.josm.data.osm.OsmPrimitive;
    16 import org.openstreetmap.josm.data.osm.Relation;
     14import org.openstreetmap.josm.data.osm.OsmUtils;
    1715import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.tools.TextTagParser;
    1916
     17/**
     18 * Various utils, useful for unit tests.
     19 */
    2020public class TestUtils {
    2121
     
    3232    }
    3333
    34     public static OsmPrimitive createPrimitive(String assertion) {
    35         if (Main.pref == null) {
    36             Main.initApplicationPreferences();
    37         }
    38         final String[] x = assertion.split("\\s+", 2);
    39         final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0])
    40                 ? new Node()
    41                 : "w".equals(x[0]) || "way".equals(x[0])
    42                 ? new Way()
    43                 : "r".equals(x[0]) || "relation".equals(x[0])
    44                 ? new Relation()
    45                 : null;
    46         if (p == null) {
    47             throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]);
    48         }
    49         for (final Map.Entry<String, String> i : TextTagParser.readTagsFromText(x[1]).entrySet()) {
    50             p.put(i.getKey(), i.getValue());
    51         }
    52         return p;
    53     }
    54 
    5534    @Test
    5635    public void testCreatePrimitive() throws Exception {
    57         final OsmPrimitive p = createPrimitive("way name=Foo railway=rail");
     36        final OsmPrimitive p = OsmUtils.createPrimitive("way name=Foo railway=rail");
    5837        assertTrue(p instanceof Way);
    5938        assertThat(p.keySet().size(), is(2));
     
    6443    @Test(expected = IllegalArgumentException.class)
    6544    public void testCreatePrimitiveFail() throws Exception {
    66         TestUtils.createPrimitive("noway name=Foo");
     45        OsmUtils.createPrimitive("noway name=Foo");
    6746    }
    6847
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r7275 r7356  
    88
    99import java.io.StringReader;
    10 import java.text.MessageFormat;
    1110import java.util.LinkedHashSet;
    1211import java.util.List;
    13 import java.util.Map;
    1412import java.util.Set;
    1513
     
    1715import org.junit.Test;
    1816import org.openstreetmap.josm.JOSMFixture;
    19 import org.openstreetmap.josm.TestUtils;
     17import org.openstreetmap.josm.Main;
    2018import org.openstreetmap.josm.command.ChangePropertyCommand;
    2119import org.openstreetmap.josm.data.osm.Node;
    22 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2320import org.openstreetmap.josm.data.osm.Tag;
    2421import org.openstreetmap.josm.data.validation.Severity;
    25 import org.openstreetmap.josm.data.validation.TestError;
    2622import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck;
    27 import org.openstreetmap.josm.tools.Predicate;
    28 import org.openstreetmap.josm.tools.Utils;
    2923
     24/**
     25 * JUnit Test of MapCSS TagChecker.
     26 */
    3027public class MapCSSTagCheckerTest {
    3128
     
    7269    @Test
    7370    public void testInit() throws Exception {
    74         final MapCSSTagChecker c = new MapCSSTagChecker();
     71        MapCSSTagChecker c = new MapCSSTagChecker();
    7572        c.initialize();
    7673
    77         LinkedHashSet<String> assertionErrors = new LinkedHashSet<>();
    78         for (final Set<TagCheck> schecks : c.checks.values()) {
    79             for (final TagCheck check : schecks) {
    80                 System.out.println("Check: "+check);
    81                 for (final Map.Entry<String, Boolean> i : check.assertions.entrySet()) {
    82                     System.out.println("- Assertion: "+i);
    83                     final OsmPrimitive p = TestUtils.createPrimitive(i.getKey());
    84                     final boolean isError = Utils.exists(c.getErrorsForPrimitive(p, true), new Predicate<TestError>() {
    85                         @Override
    86                         public boolean evaluate(TestError e) {
    87                             //noinspection EqualsBetweenInconvertibleTypes
    88                             return e.getTester().equals(check.rule);
    89                         }
    90                     });
    91                     if (isError != i.getValue()) {
    92                         final String error = MessageFormat.format("Expecting test ''{0}'' (i.e., {1}) to {2} {3} (i.e., {4})",
    93                                 check.getMessage(p), check.rule.selectors, i.getValue() ? "match" : "not match", i.getKey(), p.getKeys());
    94                         System.err.println(error);
    95                         assertionErrors.add(error);
    96                     }
    97                 }
    98             }
     74        Set<String> assertionErrors = new LinkedHashSet<>();
     75        for (Set<TagCheck> schecks : c.checks.values()) {
     76            assertionErrors.addAll(c.checkAsserts(schecks));
     77        }
     78        for (String msg : assertionErrors) {
     79            Main.error(msg);
    9980        }
    10081        assertTrue("not all assertions included in the tests are met", assertionErrors.isEmpty());
  • trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java

    r7307 r7356  
    1818import org.openstreetmap.josm.data.osm.DataSet;
    1919import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     20import org.openstreetmap.josm.data.osm.OsmUtils;
    2021import org.openstreetmap.josm.data.osm.Relation;
    2122import org.openstreetmap.josm.data.osm.Way;
     
    106107
    107108    static String getFormattedRelationName(String tagsString) {
    108         return DefaultNameFormatter.getInstance().format((Relation) TestUtils.createPrimitive("relation " + tagsString))
     109        return DefaultNameFormatter.getInstance().format((Relation) OsmUtils.createPrimitive("relation " + tagsString))
    109110                .replace("\u200E", "").replace("\u200F", "");
    110111    }
    111112
    112113    static String getFormattedWayName(String tagsString) {
    113         return DefaultNameFormatter.getInstance().format((Way) TestUtils.createPrimitive("way " + tagsString))
     114        return DefaultNameFormatter.getInstance().format((Way) OsmUtils.createPrimitive("way " + tagsString))
    114115                .replace("\u200E", "").replace("\u200F", "");
    115116    }
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/PresetClassificationsTest.java

    r7210 r7356  
    22package org.openstreetmap.josm.gui.tagging;
    33
    4 import org.junit.BeforeClass;
    5 import org.junit.Test;
    6 import org.openstreetmap.josm.JOSMFixture;
    7 import org.openstreetmap.josm.TestUtils;
    8 import org.openstreetmap.josm.data.osm.Node;
    9 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    10 import org.openstreetmap.josm.data.osm.Way;
    11 import org.openstreetmap.josm.tools.Utils;
    12 import org.xml.sax.SAXException;
     4import static org.junit.Assert.assertTrue;
    135
    146import java.io.IOException;
     
    1810import java.util.List;
    1911
    20 import static org.junit.Assert.assertTrue;
     12import org.junit.BeforeClass;
     13import org.junit.Test;
     14import org.openstreetmap.josm.JOSMFixture;
     15import org.openstreetmap.josm.data.osm.Node;
     16import org.openstreetmap.josm.data.osm.OsmPrimitive;
     17import org.openstreetmap.josm.data.osm.OsmUtils;
     18import org.openstreetmap.josm.data.osm.Way;
     19import org.openstreetmap.josm.tools.Utils;
     20import org.xml.sax.SAXException;
    2121
    2222public class PresetClassificationsTest {
     
    6161    @Test
    6262    public void testRelationsForTram() {
    63         final OsmPrimitive tram = TestUtils.createPrimitive("way railway=tram");
     63        final OsmPrimitive tram = OsmUtils.createPrimitive("way railway=tram");
    6464        assertTrue("railway=tram should match 'Railway route' for relation creation", getMatchingPresetNames("route", tram).contains("Railway route"));
    6565        assertTrue("railway=tram should match 'Public transport route' for relation creation", getMatchingPresetNames("route", tram).contains("Public transport route"));
    6666        assertTrue("railway=tram should not match 'Bus route'", !getMatchingPresetNames("route", tram).contains("Bus route"));
    6767    }
    68 
    6968}
Note: See TracChangeset for help on using the changeset viewer.