source: josm/trunk/test/unit/org/openstreetmap/josm/io/rtklib/RtkLibPosReaderTest.java@ 17360

Last change on this file since 17360 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.rtklib;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5
6import java.io.IOException;
7import java.nio.file.Files;
8import java.nio.file.Paths;
9import java.text.SimpleDateFormat;
10import java.util.ArrayList;
11import java.util.List;
12import java.util.TimeZone;
13
14import org.junit.jupiter.api.BeforeEach;
15import org.junit.jupiter.api.Test;
16import org.junit.jupiter.api.extension.RegisterExtension;
17import org.openstreetmap.josm.data.coor.LatLon;
18import org.openstreetmap.josm.data.gpx.GpxConstants;
19import org.openstreetmap.josm.data.gpx.WayPoint;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21import org.openstreetmap.josm.tools.date.DateUtils;
22import org.xml.sax.SAXException;
23
24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
25
26/**
27 * Unit tests of {@link RtkLibPosReader} class.
28 */
29class RtkLibPosReaderTest {
30 /**
31 * Set the timezone and timeout.
32 */
33 @RegisterExtension
34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
35 public JOSMTestRules test = new JOSMTestRules();
36
37 private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
38
39 /**
40 * Forces the timezone.
41 */
42 @BeforeEach
43 public void setUp() {
44 iso8601.setTimeZone(DateUtils.UTC);
45 }
46
47 private static RtkLibPosReader read(String path) throws IOException, SAXException {
48 TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
49 RtkLibPosReader in = new RtkLibPosReader(Files.newInputStream(Paths.get(path)));
50 in.parse(true);
51 return in;
52 }
53
54 /**
55 * Tests reading a RTKLib pos file.
56 * @throws Exception if any error occurs
57 */
58 @Test
59 void testReader() throws Exception {
60 RtkLibPosReader in = read("nodist/data/rtklib_example.pos");
61 assertEquals(137, in.getNumberOfCoordinates());
62
63 List<WayPoint> wayPoints = new ArrayList<>(in.getGpxData().tracks.iterator().next().getSegments().iterator().next().getWayPoints());
64 assertEquals(DateUtils.fromString("2019-06-08T08:23:12.000Z"), wayPoints.get(0).get(GpxConstants.PT_TIME));
65 assertEquals(DateUtils.fromString("2019-06-08T08:23:12.300Z"), wayPoints.get(1).get(GpxConstants.PT_TIME));
66 assertEquals(DateUtils.fromString("2019-06-08T08:23:12.600Z"), wayPoints.get(2).get(GpxConstants.PT_TIME));
67 assertEquals(wayPoints.get(0).getDate(), wayPoints.get(0).get(GpxConstants.PT_TIME));
68
69 assertEquals("2019-06-08T08:23:12.000Z", iso8601.format(wayPoints.get(0).getDate()));
70 assertEquals("2019-06-08T08:23:12.300Z", iso8601.format(wayPoints.get(1).getDate()));
71 assertEquals("2019-06-08T08:23:12.600Z", iso8601.format(wayPoints.get(2).getDate()));
72
73 assertEquals(new LatLon(46.948881673, -1.484757046), wayPoints.get(0).getCoor());
74 assertEquals(5, wayPoints.get(0).get(GpxConstants.RTKLIB_Q));
75 assertEquals("92.3955", wayPoints.get(0).get(GpxConstants.PT_ELE));
76 assertEquals("2", wayPoints.get(0).get(GpxConstants.PT_SAT));
77 assertEquals("2.2090015", wayPoints.get(0).get(GpxConstants.PT_HDOP).toString().trim());
78 }
79
80 /**
81 * Tests reading another RTKLib pos file with different date format.
82 * @throws Exception if any error occurs
83 */
84 @Test
85 void testReader2() throws Exception {
86 RtkLibPosReader in = read("nodist/data/rtklib_example2.pos");
87 assertEquals(6, in.getNumberOfCoordinates());
88 }
89}
Note: See TracBrowser for help on using the repository browser.