Changeset 6592 in josm for trunk/test/unit/org/openstreetmap/TestUtils.java
- Timestamp:
- 2014-01-01T15:27:25+01:00 (12 years ago)
- File:
-
- 1 edited
-
trunk/test/unit/org/openstreetmap/TestUtils.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/TestUtils.java
r6562 r6592 2 2 package org.openstreetmap; 3 3 4 import org.junit.Ignore; 4 import org.junit.Before; 5 import org.junit.Test; 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.data.osm.Node; 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 import org.openstreetmap.josm.data.osm.Relation; 10 import org.openstreetmap.josm.data.osm.Way; 11 import org.openstreetmap.josm.tools.TextTagParser; 5 12 6 @Ignore 13 import java.util.Map; 14 15 import static org.hamcrest.CoreMatchers.is; 16 import static org.junit.Assert.assertThat; 17 import static org.junit.Assert.assertTrue; 18 7 19 public class TestUtils { 8 private TestUtils() {9 }10 20 11 21 /** … … 20 30 return testDataRoot.endsWith("/") ? testDataRoot : testDataRoot + "/"; 21 31 } 32 33 public static OsmPrimitive createPrimitive(String assertion) { 34 if (Main.pref == null) { 35 Main.initApplicationPreferences(); 36 } 37 final String[] x = assertion.split("\\s+", 2); 38 final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0]) 39 ? new Node() 40 : "w".equals(x[0]) || "way".equals(x[0]) 41 ? new Way() 42 : "r".equals(x[0]) || "relation".equals(x[0]) 43 ? new Relation() 44 : null; 45 if (p == null) { 46 throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]); 47 } 48 for (final Map.Entry<String, String> i : TextTagParser.readTagsFromText(x[1]).entrySet()) { 49 p.put(i.getKey(), i.getValue()); 50 } 51 return p; 52 } 53 54 @Test 55 public void testCreatePrimitive() throws Exception { 56 final OsmPrimitive p = createPrimitive("way name=Foo railway=rail"); 57 assertTrue(p instanceof Way); 58 assertThat(p.keySet().size(), is(2)); 59 assertThat(p.get("name"), is("Foo")); 60 assertThat(p.get("railway"), is("rail")); 61 } 22 62 }
Note:
See TracChangeset
for help on using the changeset viewer.
