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

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

see #16550 - fix unit test

  • Property svn:eol-style set to native
File size: 2.4 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.Rule;
15import org.junit.Test;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.data.gpx.GpxConstants;
18import org.openstreetmap.josm.data.gpx.GpxData;
19import org.openstreetmap.josm.data.gpx.WayPoint;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21
22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
23
24/**
25 * Tests the {@link GpxWriter}.
26 */
27public class GpxWriterTest {
28
29 /**
30 * Setup rule
31 */
32 @Rule
33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
34 public JOSMTestRules test = new JOSMTestRules();
35
36 /**
37 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/16550">#16550</a>
38 * @throws IOException never
39 */
40 @Test
41 public void testTicket16550() throws IOException {
42 GpxData gpx = new GpxData();
43 WayPoint waypoint = new WayPoint(LatLon.ZERO);
44 waypoint.put(GpxConstants.PT_TIME, Date.from(LocalDate.of(2018, Month.AUGUST, 2).atStartOfDay(ZoneOffset.UTC).toInstant()));
45 gpx.addWaypoint(waypoint);
46 ByteArrayOutputStream baos = new ByteArrayOutputStream();
47 try (GpxWriter writer = new GpxWriter(baos)) {
48 writer.write(gpx);
49 }
50 // Checks that time stored as date is correctly written into XML timestamp
51 assertEquals(String.format("<?xml version='1.0' encoding='UTF-8'?>%n" +
52 "<gpx version=\"1.1\" creator=\"JOSM GPX export\" xmlns=\"http://www.topografix.com/GPX/1/1\"%n" +
53 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"%n" +
54 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">%n" +
55 " <metadata>%n" +
56 " <bounds minlat=\"0.0\" minlon=\"0.0\" maxlat=\"0.0\" maxlon=\"0.0\"/>%n" +
57 " </metadata>%n" +
58 " <wpt lat=\"0.0\" lon=\"0.0\">%n" +
59 " <time>2018-08-02T00:00:00.000Z</time>%n" +
60 " </wpt>%n" +
61 "</gpx>"), baos.toString(StandardCharsets.UTF_8.name()));
62 }
63}
Note: See TracBrowser for help on using the repository browser.