Changeset 14075 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2018-08-02T22:48:59+02:00 (6 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java
r13174 r14075 7 7 import static org.junit.Assert.assertTrue; 8 8 9 import java.io.ByteArrayInputStream; 9 10 import java.io.File; 11 import java.nio.charset.StandardCharsets; 12 import java.text.DateFormat; 13 import java.util.Collection; 14 import java.util.Iterator; 10 15 11 16 import org.junit.Before; … … 16 21 import org.openstreetmap.josm.data.Bounds; 17 22 import org.openstreetmap.josm.data.coor.LatLon; 23 import org.openstreetmap.josm.data.gpx.GpxConstants; 24 import org.openstreetmap.josm.data.gpx.GpxData; 25 import org.openstreetmap.josm.data.gpx.GpxTrack; 26 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 27 import org.openstreetmap.josm.data.gpx.WayPoint; 18 28 import org.openstreetmap.josm.data.osm.DataSet; 19 29 import org.openstreetmap.josm.data.osm.Node; … … 22 32 import org.openstreetmap.josm.data.osm.Way; 23 33 import org.openstreetmap.josm.gui.MainApplication; 34 import org.openstreetmap.josm.io.IllegalDataException; 35 import org.openstreetmap.josm.io.OsmReader; 24 36 import org.openstreetmap.josm.testutils.JOSMTestRules; 37 import org.openstreetmap.josm.tools.date.DateUtils; 25 38 26 39 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 190 203 /** 191 204 * Unit test of {@link OsmDataLayer#toGpxData}. 192 */ 193 @Test 194 public void testToGpxData() { 195 fillDataSet(ds); 196 assertNotNull(layer.toGpxData()); 205 * @throws IllegalDataException never 206 */ 207 @Test 208 public void testToGpxData() throws IllegalDataException { 209 ds.mergeFrom(OsmReader.parseDataSet(new ByteArrayInputStream(( 210 "<?xml version='1.0' encoding='UTF-8'?>\n" + 211 "<osm version='0.6' upload='false' generator='JOSM'>\n" + 212 " <node id='-546306' timestamp='2018-08-01T10:00:00Z' lat='47.0' lon='9.0'>\n" + 213 " <tag k='ele' v='123' />\n" + 214 " <tag k='time' v='2018-08-01T10:00:00Z' />\n" + 215 " </node>\n" + 216 " <node id='-546307' timestamp='2018-08-01T10:01:00Z' lat='47.1' lon='9.1'>\n" + 217 " <tag k='ele' v='456' />\n" + 218 " <tag k='time' v='2018-08-01T10:01:00Z' />\n" + 219 " </node>\n" + 220 " <way id='-546308'>\n" + 221 " <nd ref='-546306' />\n" + 222 " <nd ref='-546307' />\n" + 223 " </way>\r\n" + 224 "</osm>").getBytes(StandardCharsets.UTF_8)), null)); 225 GpxData gpx = layer.toGpxData(); 226 assertNotNull(gpx); 227 // Check metadata 228 assertEquals(new Bounds(47.0, 9.0, 47.1, 9.1), gpx.recalculateBounds()); 229 // Check there is no waypoint 230 assertTrue(gpx.getWaypoints().isEmpty()); 231 // Check that track is correct 232 assertEquals(1, gpx.getTrackCount()); 233 GpxTrack track = gpx.getTracks().iterator().next(); 234 Collection<GpxTrackSegment> segments = track.getSegments(); 235 assertEquals(1, segments.size()); 236 Collection<WayPoint> trackpoints = segments.iterator().next().getWayPoints(); 237 assertEquals(2, trackpoints.size()); 238 Iterator<WayPoint> it = trackpoints.iterator(); 239 DateFormat gpxFormat = DateUtils.getGpxFormat(); 240 WayPoint p1 = it.next(); 241 assertEquals(new LatLon(47.0, 9.0), p1.getCoor()); 242 assertEquals("123", p1.get(GpxConstants.PT_ELE)); 243 assertEquals("2018-08-01T10:00:00.000Z", gpxFormat.format(p1.get(GpxConstants.PT_TIME))); 244 WayPoint p2 = it.next(); 245 assertEquals(new LatLon(47.1, 9.1), p2.getCoor()); 246 assertEquals("456", p2.get(GpxConstants.PT_ELE)); 247 assertEquals("2018-08-01T10:01:00.000Z", gpxFormat.format(p2.get(GpxConstants.PT_TIME))); 197 248 } 198 249
Note:
See TracChangeset
for help on using the changeset viewer.