source: josm/trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java@ 12164

Last change on this file since 12164 was 12164, checked in by michael2402, 7 years ago

Added missing ILatLon.java file.

  • Property svn:eol-style set to native
File size: 9.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.gpx;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertTrue;
7import static org.junit.Assert.fail;
8
9import java.util.Collections;
10
11import org.junit.Before;
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.data.coor.LatLon;
15import org.openstreetmap.josm.testutils.JOSMTestRules;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18import nl.jqno.equalsverifier.EqualsVerifier;
19
20/**
21 * Unit tests for class {@link GpxData}.
22 */
23public class GpxDataTest {
24
25 /**
26 * Setup test.
27 */
28 @Rule
29 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
30 public JOSMTestRules test = new JOSMTestRules();
31
32 private GpxData data;
33
34 /**
35 * @throws java.lang.Exception
36 */
37 @Before
38 public void setUp() throws Exception {
39 data = new GpxData();
40 }
41
42
43 /**
44 * Test method for {@link GpxData#mergeFrom(GpxData)}.
45 */
46 @Test
47 public void testMergeFrom() {
48 fail("Not yet implemented");
49 }
50
51 /**
52 * Test method for {@link GpxData#getTracks()}, {@link GpxData#addTrack(GpxTrack)}, {@link GpxData#removeTrack(GpxTrack)}.
53 */
54 @Test
55 public void testTracks() {
56 assertEquals(0, data.getTracks().size());
57
58 ImmutableGpxTrack track1 = emptyGpxTrack();
59 ImmutableGpxTrack track2 = emptyGpxTrack();
60 data.addTrack(track1);
61 assertEquals(1, data.getTracks().size());
62 data.addTrack(track2);
63 assertEquals(2, data.getTracks().size());
64 assertTrue(data.getTracks().contains(track1));
65 assertTrue(data.getTracks().contains(track2));
66
67 data.removeTrack(track1);
68 assertEquals(1, data.getTracks().size());
69 assertFalse(data.getTracks().contains(track1));
70 assertTrue(data.getTracks().contains(track2));
71 }
72
73 /**
74 * Test method for {@link GpxData#addTrack(GpxTrack)}.
75 */
76 @Test(expected = IllegalArgumentException.class)
77 public void testAddTrackFails() {
78 ImmutableGpxTrack track1 = emptyGpxTrack();
79 data.addTrack(track1);
80 data.addTrack(track1);
81 }
82
83 /**
84 * Test method for {@link GpxData#removeTrack(GpxTrack)}.
85 */
86 @Test(expected = IllegalArgumentException.class)
87 public void testRemoveTrackFails() {
88 ImmutableGpxTrack track1 = emptyGpxTrack();
89 data.addTrack(track1);
90 data.removeTrack(track1);
91 data.removeTrack(track1);
92 }
93
94 /**
95 * Test method for {@link GpxData#getRoutes()}, {@link GpxData#addRoute(GpxRoute)}, {@link GpxData#removeRoute(GpxRoute)}.
96 */
97 @Test
98 public void testRoutes() {
99 assertEquals(0, data.getTracks().size());
100
101 GpxRoute route1 = new GpxRoute();
102 GpxRoute route2 = new GpxRoute();
103 data.addRoute(route1);
104 assertEquals(1, data.getRoutes().size());
105 data.addRoute(route2);
106 assertEquals(2, data.getRoutes().size());
107 assertTrue(data.getRoutes().contains(route1));
108 assertTrue(data.getRoutes().contains(route2));
109
110 data.removeRoute(route1);
111 assertEquals(1, data.getRoutes().size());
112 assertFalse(data.getRoutes().contains(route1));
113 assertTrue(data.getRoutes().contains(route2));
114 }
115
116 /**
117 * Test method for {@link GpxData#addRoute(GpxRoute)}.
118 */
119 @Test(expected = IllegalArgumentException.class)
120 public void testAddRouteFails() {
121 GpxRoute route1 = new GpxRoute();
122 data.addRoute(route1);
123 data.addRoute(route1);
124 }
125
126 /**
127 * Test method for {@link GpxData#removeRoute(GpxRoute)}.
128 */
129 @Test(expected = IllegalArgumentException.class)
130 public void testRemoveRouteFails() {
131 GpxRoute route1 = new GpxRoute();
132 data.addRoute(route1);
133 data.removeRoute(route1);
134 data.removeRoute(route1);
135 }
136
137 /**
138 * Test method for {@link GpxData#getWaypoints()}, {@link GpxData#addWaypoint(WayPoint)}, {@link GpxData#removeWaypoint(WayPoint)}.
139 */
140 @Test
141 public void testWaypoints() {
142 assertEquals(0, data.getTracks().size());
143
144 WayPoint waypoint1 = new WayPoint(LatLon.ZERO);
145 WayPoint waypoint2 = new WayPoint(LatLon.ZERO);
146 data.addWaypoint(waypoint1);
147 assertEquals(1, data.getWaypoints().size());
148 data.addWaypoint(waypoint2);
149 assertEquals(2, data.getWaypoints().size());
150 assertTrue(data.getWaypoints().contains(waypoint1));
151 assertTrue(data.getWaypoints().contains(waypoint2));
152
153 data.removeWaypoint(waypoint1);
154 assertEquals(1, data.getWaypoints().size());
155 assertFalse(data.getWaypoints().contains(waypoint1));
156 assertTrue(data.getWaypoints().contains(waypoint2));
157 }
158
159 /**
160 * Test method for {@link GpxData#addWaypoint(WayPoint)}.
161 */
162 @Test(expected = IllegalArgumentException.class)
163 public void testAddWaypointFails() {
164 WayPoint waypoint1 = new WayPoint(LatLon.ZERO);
165 data.addWaypoint(waypoint1);
166 data.addWaypoint(waypoint1);
167 }
168
169 /**
170 * Test method for {@link GpxData#removeWaypoint(WayPoint)}.
171 */
172 @Test(expected = IllegalArgumentException.class)
173 public void testRemoveWaypointFails() {
174 WayPoint waypoint1 = new WayPoint(LatLon.ZERO);
175 data.addWaypoint(waypoint1);
176 data.removeWaypoint(waypoint1);
177 data.removeWaypoint(waypoint1);
178 }
179
180 /**
181 * Test method for {@link GpxData#hasTrackPoints()}.
182 */
183 @Test
184 public void testHasTrackPoints() {
185 assertFalse(data.hasTrackPoints());
186 ImmutableGpxTrack track1 = emptyGpxTrack();
187 data.addTrack(track1);
188 assertFalse(data.hasTrackPoints());
189 ImmutableGpxTrack track2 = singleWaypointGpxTrack();
190 data.addTrack(track2);
191 assertTrue(data.hasTrackPoints());
192 }
193
194 /**
195 * Test method for {@link GpxData#getTrackPoints()}.
196 */
197 @Test
198 public void testGetTrackPoints() {
199 assertEquals(0, data.getTrackPoints().count());
200 ImmutableGpxTrack track1 = singleWaypointGpxTrack();
201 data.addTrack(track1);
202 assertEquals(1, data.getTrackPoints().count());
203 ImmutableGpxTrack track2 = singleWaypointGpxTrack();
204 data.addTrack(track2);
205 assertEquals(2, data.getTrackPoints().count());
206 }
207
208 /**
209 * Test method for {@link GpxData#hasRoutePoints()}.
210 */
211 @Test
212 public void testHasRoutePoints() {
213 fail("Not yet implemented");
214 }
215
216 /**
217 * Test method for {@link GpxData#isEmpty()}.
218 */
219 @Test
220 public void testIsEmpty() {
221 fail("Not yet implemented");
222 }
223
224 /**
225 * Test method for {@link GpxData#getMetaBounds()}.
226 */
227 @Test
228 public void testGetMetaBounds() {
229 fail("Not yet implemented");
230 }
231
232 /**
233 * Test method for {@link GpxData#recalculateBounds()}.
234 */
235 @Test
236 public void testRecalculateBounds() {
237 fail("Not yet implemented");
238 }
239
240 /**
241 * Test method for {@link GpxData#length()}.
242 */
243 @Test
244 public void testLength() {
245 fail("Not yet implemented");
246 }
247
248 /**
249 * Test method for {@link GpxData#getMinMaxTimeForTrack(GpxTrack)}.
250 */
251 @Test
252 public void testGetMinMaxTimeForTrack() {
253 fail("Not yet implemented");
254 }
255
256 /**
257 * Test method for {@link GpxData#getMinMaxTimeForAllTracks()}.
258 */
259 @Test
260 public void testGetMinMaxTimeForAllTracks() {
261 fail("Not yet implemented");
262 }
263
264 /**
265 * Test method for {@link GpxData#nearestPointOnTrack(org.openstreetmap.josm.data.coor.EastNorth, double)}.
266 */
267 @Test
268 public void testNearestPointOnTrack() {
269 fail("Not yet implemented");
270 }
271
272 /**
273 * Test method for {@link GpxData#getLinesIterable(boolean[])}.
274 */
275 @Test
276 public void testGetLinesIterable() {
277 fail("Not yet implemented");
278 }
279
280 /**
281 * Test method for {@link GpxData#resetEastNorthCache()}.
282 */
283 @Test
284 public void testResetEastNorthCache() {
285 fail("Not yet implemented");
286 }
287
288 /**
289 * Test method for {@link GpxData#getDataSources()}.
290 */
291 @Test
292 public void testGetDataSources() {
293 fail("Not yet implemented");
294 }
295
296 /**
297 * Test method for {@link GpxData#getDataSourceArea()}.
298 */
299 @Test
300 public void testGetDataSourceArea() {
301 fail("Not yet implemented");
302 }
303
304 /**
305 * Test method for {@link GpxData#getDataSourceBounds()}.
306 */
307 @Test
308 public void testGetDataSourceBounds() {
309 fail("Not yet implemented");
310 }
311
312 /**
313 * Test method for {@link GpxData#addChangeListener(GpxData.GpxDataChangeListener)}.
314 */
315 @Test
316 public void testAddChangeListener() {
317 fail("Not yet implemented");
318 }
319
320 /**
321 * Test method for {@link GpxData#addWeakChangeListener(GpxData.GpxDataChangeListener)}.
322 */
323 @Test
324 public void testAddWeakChangeListener() {
325 fail("Not yet implemented");
326 }
327
328 /**
329 * Test method for {@link GpxData#removeChangeListener(GpxData.GpxDataChangeListener)}.
330 */
331 @Test
332 public void testRemoveChangeListener() {
333 fail("Not yet implemented");
334 }
335
336 private static ImmutableGpxTrack emptyGpxTrack() {
337 return new ImmutableGpxTrack(Collections.emptyList(), Collections.emptyMap());
338 }
339
340 private static ImmutableGpxTrack singleWaypointGpxTrack() {
341 return new ImmutableGpxTrack(Collections.singleton(Collections.singleton(new WayPoint(LatLon.ZERO))), Collections.emptyMap());
342 }
343
344 /**
345 * Unit test of methods {@link GpxData#equals} and {@link GpxData#hashCode}.
346 */
347 @Test
348 public void testEqualsContract() {
349 EqualsVerifier.forClass(GpxData.class).usingGetClass()
350 .withIgnoredFields("attr", "creator", "fromServer", "storageFile", "listeners")
351 .withPrefabValues(WayPoint.class, new WayPoint(LatLon.NORTH_POLE), new WayPoint(LatLon.SOUTH_POLE))
352 .verify();
353 }
354}
Note: See TracBrowser for help on using the repository browser.