source: josm/trunk/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java@ 9749

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

upgrade to checkstyle 6.15

File size: 2.5 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.FileInputStream;
7import java.text.SimpleDateFormat;
8import java.util.ArrayList;
9import java.util.List;
10
11import org.junit.Test;
12import org.openstreetmap.josm.data.coor.LatLon;
13import org.openstreetmap.josm.data.gpx.GpxConstants;
14import org.openstreetmap.josm.data.gpx.WayPoint;
15import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE;
16
17import nl.jqno.equalsverifier.EqualsVerifier;
18
19/**
20 * Unit tests of {@link NmeaReader} class.
21 */
22public class NmeaReaderTest {
23
24 /**
25 * Unit test of methods {@link NMEA_TYPE#equals} and {@link NMEA_TYPE#hashCode}.
26 */
27 @Test
28 public void equalsContract() {
29 EqualsVerifier.forClass(NMEA_TYPE.class).verify();
30 }
31
32 /**
33 * Tests reading a nmea file.
34 * @throws Exception if any error occurs
35 */
36 @Test
37 public void testReader() throws Exception {
38 final NmeaReader in = new NmeaReader(new FileInputStream("data_nodist/btnmeatrack_2016-01-25.nmea"));
39 assertEquals(30, in.getNumberOfCoordinates());
40 assertEquals(0, in.getParserMalformed());
41
42 final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints());
43 assertEquals("2016-01-25T04:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME));
44 assertEquals("2016-01-25T04:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME));
45 assertEquals("2016-01-25T04:05:09.600Z", wayPoints.get(2).get(GpxConstants.PT_TIME));
46
47 final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
48 assertEquals("2016-01-25T05:05:09.200+01", iso8601.format(wayPoints.get(0).getTime()));
49 assertEquals("2016-01-25T05:05:09.400+01", iso8601.format(wayPoints.get(1).getTime()));
50 assertEquals("2016-01-25T05:05:09.600+01", iso8601.format(wayPoints.get(2).getTime()));
51
52 assertEquals(new LatLon(46.98807, -1.400525), wayPoints.get(0).getCoor());
53 assertEquals("38.9", wayPoints.get(0).get(GpxConstants.PT_ELE));
54 assertEquals("16", wayPoints.get(0).get(GpxConstants.PT_SAT));
55 assertEquals("3d", wayPoints.get(0).get(GpxConstants.PT_FIX));
56 assertEquals("0.7", wayPoints.get(0).get(GpxConstants.PT_HDOP).toString().trim());
57 assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_VDOP));
58 assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_PDOP));
59 }
60}
Note: See TracBrowser for help on using the repository browser.