source: josm/trunk/test/unit/org/openstreetmap/josm/io/GpxWriterTest.java@ 14075

Last change on this file since 14075 was 14075, checked in by Don-vip, 6 years ago

fix #16550 - fix regressions in OSM -> GPX conversion

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.Assert.assertEquals;
5
6import java.io.ByteArrayOutputStream;
7import java.io.IOException;
8import java.nio.charset.StandardCharsets;
9import java.time.LocalDate;
10import java.time.Month;
11import java.time.ZoneOffset;
12import java.util.Date;
13
14import org.junit.Test;
15import org.openstreetmap.josm.data.coor.LatLon;
16import org.openstreetmap.josm.data.gpx.GpxConstants;
17import org.openstreetmap.josm.data.gpx.GpxData;
18import org.openstreetmap.josm.data.gpx.WayPoint;
19
20/**
21 * Tests the {@link GpxWriter}.
22 */
23public class GpxWriterTest {
24
25 /**
26 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/16550">#16550</a>
27 * @throws IOException never
28 */
29 @Test
30 public void testTicket16550() throws IOException {
31 GpxData gpx = new GpxData();
32 WayPoint waypoint = new WayPoint(LatLon.ZERO);
33 waypoint.put(GpxConstants.PT_TIME, Date.from(LocalDate.of(2018, Month.AUGUST, 2).atStartOfDay(ZoneOffset.UTC).toInstant()));
34 gpx.addWaypoint(waypoint);
35 ByteArrayOutputStream baos = new ByteArrayOutputStream();
36 try (GpxWriter writer = new GpxWriter(baos)) {
37 writer.write(gpx);
38 }
39 // Checks that time stored as date is correctly written into XML timestamp
40 assertEquals(String.format("<?xml version='1.0' encoding='UTF-8'?>%n" +
41 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"%n" +
42 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"%n" +
43 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">%n" +
44 " <metadata>%n" +
45 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>%n" +
46 " </metadata>%n" +
47 " <wpt lat=\"0.0\" lon=\"0.0\">%n" +
48 " <time>2018-08-02T02:00:00.000Z</time>%n" +
49 " </wpt>%n" +
50 "</gpx>"), baos.toString(StandardCharsets.UTF_8.name()));
51 }
52}
Note: See TracBrowser for help on using the repository browser.