Changeset 6512 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2013-12-22T22:43:24+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r6506 r6512 6 6 import org.openstreetmap.josm.data.Preferences; 7 7 import org.openstreetmap.josm.data.osm.Node; 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 import org.openstreetmap.josm.data.osm.Relation; 8 10 import org.openstreetmap.josm.data.osm.Tag; 11 import org.openstreetmap.josm.data.osm.Way; 9 12 10 13 import java.io.StringReader; 14 import java.util.LinkedHashSet; 11 15 import java.util.List; 16 import java.util.Map; 12 17 13 18 import static org.hamcrest.CoreMatchers.is; … … 49 54 } 50 55 56 OsmPrimitive createPrimitiveForAssertion(String assertion) { 57 final String[] x = assertion.split("\\s+"); 58 final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0]) 59 ? new Node() 60 : "w".equals(x[0]) || "way".equals(x[0]) 61 ? new Way() 62 : "r".equals(x[0]) || "relation".equals(x[0]) 63 ? new Relation() 64 : null; 65 if (p == null) { 66 throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]); 67 } 68 for (int i = 1; i < x.length; i++) { 69 final Tag tag = Tag.ofString(x[i]); 70 p.put(tag.getKey(), tag.getValue()); 71 } 72 return p; 73 } 74 75 @Test 76 public void testCreatePrimitiveForAssertion() throws Exception { 77 final OsmPrimitive p = createPrimitiveForAssertion("way name=Foo railway=rail"); 78 assertTrue(p instanceof Way); 79 assertThat(p.keySet().size(), is(2)); 80 assertThat(p.get("name"), is("Foo")); 81 assertThat(p.get("railway"), is("rail")); 82 } 83 84 @Test(expected = IllegalArgumentException.class) 85 public void testCreatePrimitiveForAssertionFail() throws Exception { 86 final OsmPrimitive p = createPrimitiveForAssertion("noway name=Foo"); 87 } 88 51 89 @Test 52 90 public void testInit() throws Exception { 53 91 final MapCSSTagChecker c = new MapCSSTagChecker(); 54 92 c.initialize(); 93 94 LinkedHashSet<String> assertionErrors = new LinkedHashSet<String>(); 95 for (final MapCSSTagChecker.TagCheck check : c.checks) { 96 for (final Map.Entry<String, Boolean> i : check.assertions.entrySet()) { 97 if (check.matchesPrimitive(createPrimitiveForAssertion(i.getKey())) != i.getValue()) { 98 final String error = "Expecting test '" + check.getMessage() + "' to " + (i.getValue() ? "" : "not ") + "match " + i.getKey(); 99 System.err.println(error); 100 assertionErrors.add(error); 101 } 102 } 103 } 104 assertTrue("not all assertions included in the tests are met", assertionErrors.isEmpty()); 105 55 106 } 56 107 }
Note:
See TracChangeset
for help on using the changeset viewer.