Changeset 7356 in josm for trunk/test/unit/org
- Timestamp:
- 2014-08-01T19:17:40+02:00 (10 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r7109 r7356 9 9 import java.util.Arrays; 10 10 import java.util.Comparator; 11 import java.util.Map;12 11 13 12 import org.junit.Test; 14 import org.openstreetmap.josm.data.osm.Node;15 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm. Relation;14 import org.openstreetmap.josm.data.osm.OsmUtils; 17 15 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.tools.TextTagParser;19 16 17 /** 18 * Various utils, useful for unit tests. 19 */ 20 20 public class TestUtils { 21 21 … … 32 32 } 33 33 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 55 34 @Test 56 35 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"); 58 37 assertTrue(p instanceof Way); 59 38 assertThat(p.keySet().size(), is(2)); … … 64 43 @Test(expected = IllegalArgumentException.class) 65 44 public void testCreatePrimitiveFail() throws Exception { 66 TestUtils.createPrimitive("noway name=Foo");45 OsmUtils.createPrimitive("noway name=Foo"); 67 46 } 68 47 -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r7275 r7356 8 8 9 9 import java.io.StringReader; 10 import java.text.MessageFormat;11 10 import java.util.LinkedHashSet; 12 11 import java.util.List; 13 import java.util.Map;14 12 import java.util.Set; 15 13 … … 17 15 import org.junit.Test; 18 16 import org.openstreetmap.josm.JOSMFixture; 19 import org.openstreetmap.josm. TestUtils;17 import org.openstreetmap.josm.Main; 20 18 import org.openstreetmap.josm.command.ChangePropertyCommand; 21 19 import org.openstreetmap.josm.data.osm.Node; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive;23 20 import org.openstreetmap.josm.data.osm.Tag; 24 21 import org.openstreetmap.josm.data.validation.Severity; 25 import org.openstreetmap.josm.data.validation.TestError;26 22 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck; 27 import org.openstreetmap.josm.tools.Predicate;28 import org.openstreetmap.josm.tools.Utils;29 23 24 /** 25 * JUnit Test of MapCSS TagChecker. 26 */ 30 27 public class MapCSSTagCheckerTest { 31 28 … … 72 69 @Test 73 70 public void testInit() throws Exception { 74 finalMapCSSTagChecker c = new MapCSSTagChecker();71 MapCSSTagChecker c = new MapCSSTagChecker(); 75 72 c.initialize(); 76 73 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); 99 80 } 100 81 assertTrue("not all assertions included in the tests are met", assertionErrors.isEmpty()); -
trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java
r7307 r7356 18 18 import org.openstreetmap.josm.data.osm.DataSet; 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 20 import org.openstreetmap.josm.data.osm.OsmUtils; 20 21 import org.openstreetmap.josm.data.osm.Relation; 21 22 import org.openstreetmap.josm.data.osm.Way; … … 106 107 107 108 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)) 109 110 .replace("\u200E", "").replace("\u200F", ""); 110 111 } 111 112 112 113 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)) 114 115 .replace("\u200E", "").replace("\u200F", ""); 115 116 } -
trunk/test/unit/org/openstreetmap/josm/gui/tagging/PresetClassificationsTest.java
r7210 r7356 2 2 package org.openstreetmap.josm.gui.tagging; 3 3 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; 4 import static org.junit.Assert.assertTrue; 13 5 14 6 import java.io.IOException; … … 18 10 import java.util.List; 19 11 20 import static org.junit.Assert.assertTrue; 12 import org.junit.BeforeClass; 13 import org.junit.Test; 14 import org.openstreetmap.josm.JOSMFixture; 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.OsmUtils; 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.tools.Utils; 20 import org.xml.sax.SAXException; 21 21 22 22 public class PresetClassificationsTest { … … 61 61 @Test 62 62 public void testRelationsForTram() { 63 final OsmPrimitive tram = TestUtils.createPrimitive("way railway=tram");63 final OsmPrimitive tram = OsmUtils.createPrimitive("way railway=tram"); 64 64 assertTrue("railway=tram should match 'Railway route' for relation creation", getMatchingPresetNames("route", tram).contains("Railway route")); 65 65 assertTrue("railway=tram should match 'Public transport route' for relation creation", getMatchingPresetNames("route", tram).contains("Public transport route")); 66 66 assertTrue("railway=tram should not match 'Bus route'", !getMatchingPresetNames("route", tram).contains("Bus route")); 67 67 } 68 69 68 }
Note:
See TracChangeset
for help on using the changeset viewer.