| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.data.gpx;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.Assert.assertEquals;
|
|---|
| 5 | import static org.junit.Assert.assertFalse;
|
|---|
| 6 | import static org.junit.Assert.assertNotNull;
|
|---|
| 7 | import static org.junit.Assert.assertNull;
|
|---|
| 8 | import static org.junit.Assert.assertTrue;
|
|---|
| 9 |
|
|---|
| 10 | import java.util.ArrayList;
|
|---|
| 11 | import java.util.Arrays;
|
|---|
| 12 | import java.util.Collections;
|
|---|
| 13 | import java.util.Date;
|
|---|
| 14 | import java.util.List;
|
|---|
| 15 | import java.util.stream.Collectors;
|
|---|
| 16 | import java.util.stream.Stream;
|
|---|
| 17 |
|
|---|
| 18 | import org.junit.Before;
|
|---|
| 19 | import org.junit.Rule;
|
|---|
| 20 | import org.junit.Test;
|
|---|
| 21 | import org.openstreetmap.josm.Main;
|
|---|
| 22 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| 23 | import org.openstreetmap.josm.data.DataSource;
|
|---|
| 24 | import org.openstreetmap.josm.data.coor.EastNorth;
|
|---|
| 25 | import org.openstreetmap.josm.data.coor.LatLon;
|
|---|
| 26 | import org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeEvent;
|
|---|
| 27 | import org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeListener;
|
|---|
| 28 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
|---|
| 29 | import org.openstreetmap.josm.tools.ListenerList;
|
|---|
| 30 |
|
|---|
| 31 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|---|
| 32 | import nl.jqno.equalsverifier.EqualsVerifier;
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * Unit tests for class {@link GpxData}.
|
|---|
| 36 | */
|
|---|
| 37 | public class GpxDataTest {
|
|---|
| 38 |
|
|---|
| 39 | /**
|
|---|
| 40 | * Setup test.
|
|---|
| 41 | */
|
|---|
| 42 | @Rule
|
|---|
| 43 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
|---|
| 44 | public JOSMTestRules test = new JOSMTestRules().projection();
|
|---|
| 45 |
|
|---|
| 46 | private GpxData data;
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * Set up empty test data
|
|---|
| 50 | */
|
|---|
| 51 | @Before
|
|---|
| 52 | public void setUp() {
|
|---|
| 53 | data = new GpxData();
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | /**
|
|---|
| 58 | * Test method for {@link GpxData#mergeFrom(GpxData)}.
|
|---|
| 59 | */
|
|---|
| 60 | @Test
|
|---|
| 61 | public void testMergeFrom() {
|
|---|
| 62 | ImmutableGpxTrack track = singleWaypointGpxTrack();
|
|---|
| 63 | GpxRoute route = singleWaypointRoute();
|
|---|
| 64 | WayPoint newWP = new WayPoint(LatLon.NORTH_POLE);
|
|---|
| 65 | WayPoint existingWP = new WayPoint(LatLon.SOUTH_POLE);
|
|---|
| 66 |
|
|---|
| 67 | GpxData dataToMerge = new GpxData();
|
|---|
| 68 | dataToMerge.addTrack(track);
|
|---|
| 69 | dataToMerge.addRoute(route);
|
|---|
| 70 | dataToMerge.addWaypoint(newWP);
|
|---|
| 71 |
|
|---|
| 72 | data.addWaypoint(existingWP);
|
|---|
| 73 | data.mergeFrom(dataToMerge);
|
|---|
| 74 |
|
|---|
| 75 | assertEquals(1, data.getTracks().size());
|
|---|
| 76 | assertEquals(1, data.getRoutes().size());
|
|---|
| 77 | assertEquals(2, data.getWaypoints().size());
|
|---|
| 78 |
|
|---|
| 79 | assertTrue(data.getTracks().contains(track));
|
|---|
| 80 | assertTrue(data.getRoutes().contains(route));
|
|---|
| 81 | assertTrue(data.getWaypoints().contains(newWP));
|
|---|
| 82 | assertTrue(data.getWaypoints().contains(existingWP));
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | /**
|
|---|
| 86 | * Test method for {@link GpxData#getTracks()}, {@link GpxData#addTrack(GpxTrack)}, {@link GpxData#removeTrack(GpxTrack)}.
|
|---|
| 87 | */
|
|---|
| 88 | @Test
|
|---|
| 89 | public void testTracks() {
|
|---|
| 90 | assertEquals(0, data.getTracks().size());
|
|---|
| 91 |
|
|---|
| 92 | ImmutableGpxTrack track1 = emptyGpxTrack();
|
|---|
| 93 | ImmutableGpxTrack track2 = singleWaypointGpxTrack();
|
|---|
| 94 | data.addTrack(track1);
|
|---|
| 95 | assertEquals(1, data.getTracks().size());
|
|---|
| 96 | data.addTrack(track2);
|
|---|
| 97 | assertEquals(2, data.getTracks().size());
|
|---|
| 98 | assertTrue(data.getTracks().contains(track1));
|
|---|
| 99 | assertTrue(data.getTracks().contains(track2));
|
|---|
| 100 |
|
|---|
| 101 | data.removeTrack(track1);
|
|---|
| 102 | assertEquals(1, data.getTracks().size());
|
|---|
| 103 | assertFalse(data.getTracks().contains(track1));
|
|---|
| 104 | assertTrue(data.getTracks().contains(track2));
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /**
|
|---|
| 108 | * Test method for {@link GpxData#addTrack(GpxTrack)}.
|
|---|
| 109 | */
|
|---|
| 110 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 111 | public void testAddTrackFails() {
|
|---|
| 112 | ImmutableGpxTrack track1 = emptyGpxTrack();
|
|---|
| 113 | data.addTrack(track1);
|
|---|
| 114 | data.addTrack(track1);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /**
|
|---|
| 118 | * Test method for {@link GpxData#removeTrack(GpxTrack)}.
|
|---|
| 119 | */
|
|---|
| 120 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 121 | public void testRemoveTrackFails() {
|
|---|
| 122 | ImmutableGpxTrack track1 = emptyGpxTrack();
|
|---|
| 123 | data.addTrack(track1);
|
|---|
| 124 | data.removeTrack(track1);
|
|---|
| 125 | data.removeTrack(track1);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /**
|
|---|
| 129 | * Test method for {@link GpxData#getRoutes()}, {@link GpxData#addRoute(GpxRoute)}, {@link GpxData#removeRoute(GpxRoute)}.
|
|---|
| 130 | */
|
|---|
| 131 | @Test
|
|---|
| 132 | public void testRoutes() {
|
|---|
| 133 | assertEquals(0, data.getTracks().size());
|
|---|
| 134 |
|
|---|
| 135 | GpxRoute route1 = new GpxRoute();
|
|---|
| 136 | GpxRoute route2 = new GpxRoute();
|
|---|
| 137 | route2.routePoints.add(new WayPoint(LatLon.NORTH_POLE));
|
|---|
| 138 | data.addRoute(route1);
|
|---|
| 139 | assertEquals(1, data.getRoutes().size());
|
|---|
| 140 | data.addRoute(route2);
|
|---|
| 141 | assertEquals(2, data.getRoutes().size());
|
|---|
| 142 | assertTrue(data.getRoutes().contains(route1));
|
|---|
| 143 | assertTrue(data.getRoutes().contains(route2));
|
|---|
| 144 |
|
|---|
| 145 | data.removeRoute(route1);
|
|---|
| 146 | assertEquals(1, data.getRoutes().size());
|
|---|
| 147 | assertFalse(data.getRoutes().contains(route1));
|
|---|
| 148 | assertTrue(data.getRoutes().contains(route2));
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /**
|
|---|
| 152 | * Test method for {@link GpxData#addRoute(GpxRoute)}.
|
|---|
| 153 | */
|
|---|
| 154 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 155 | public void testAddRouteFails() {
|
|---|
| 156 | GpxRoute route1 = new GpxRoute();
|
|---|
| 157 | data.addRoute(route1);
|
|---|
| 158 | data.addRoute(route1);
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | /**
|
|---|
| 162 | * Test method for {@link GpxData#removeRoute(GpxRoute)}.
|
|---|
| 163 | */
|
|---|
| 164 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 165 | public void testRemoveRouteFails() {
|
|---|
| 166 | GpxRoute route1 = new GpxRoute();
|
|---|
| 167 | data.addRoute(route1);
|
|---|
| 168 | data.removeRoute(route1);
|
|---|
| 169 | data.removeRoute(route1);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | /**
|
|---|
| 173 | * Test method for {@link GpxData#getWaypoints()}, {@link GpxData#addWaypoint(WayPoint)}, {@link GpxData#removeWaypoint(WayPoint)}.
|
|---|
| 174 | */
|
|---|
| 175 | @Test
|
|---|
| 176 | public void testWaypoints() {
|
|---|
| 177 | assertEquals(0, data.getTracks().size());
|
|---|
| 178 |
|
|---|
| 179 | WayPoint waypoint1 = new WayPoint(LatLon.ZERO);
|
|---|
| 180 | WayPoint waypoint2 = new WayPoint(LatLon.NORTH_POLE);
|
|---|
| 181 | data.addWaypoint(waypoint1);
|
|---|
| 182 | assertEquals(1, data.getWaypoints().size());
|
|---|
| 183 | data.addWaypoint(waypoint2);
|
|---|
| 184 | assertEquals(2, data.getWaypoints().size());
|
|---|
| 185 | assertTrue(data.getWaypoints().contains(waypoint1));
|
|---|
| 186 | assertTrue(data.getWaypoints().contains(waypoint2));
|
|---|
| 187 |
|
|---|
| 188 | data.removeWaypoint(waypoint1);
|
|---|
| 189 | assertEquals(1, data.getWaypoints().size());
|
|---|
| 190 | assertFalse(data.getWaypoints().contains(waypoint1));
|
|---|
| 191 | assertTrue(data.getWaypoints().contains(waypoint2));
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | /**
|
|---|
| 195 | * Test method for {@link GpxData#addWaypoint(WayPoint)}.
|
|---|
| 196 | */
|
|---|
| 197 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 198 | public void testAddWaypointFails() {
|
|---|
| 199 | WayPoint waypoint1 = new WayPoint(LatLon.ZERO);
|
|---|
| 200 | data.addWaypoint(waypoint1);
|
|---|
| 201 | data.addWaypoint(waypoint1);
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | /**
|
|---|
| 205 | * Test method for {@link GpxData#removeWaypoint(WayPoint)}.
|
|---|
| 206 | */
|
|---|
| 207 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 208 | public void testRemoveWaypointFails() {
|
|---|
| 209 | WayPoint waypoint1 = new WayPoint(LatLon.ZERO);
|
|---|
| 210 | data.addWaypoint(waypoint1);
|
|---|
| 211 | data.removeWaypoint(waypoint1);
|
|---|
| 212 | data.removeWaypoint(waypoint1);
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | /**
|
|---|
| 216 | * Test method for {@link GpxData#hasTrackPoints()}.
|
|---|
| 217 | */
|
|---|
| 218 | @Test
|
|---|
| 219 | public void testHasTrackPoints() {
|
|---|
| 220 | assertFalse(data.hasTrackPoints());
|
|---|
| 221 | ImmutableGpxTrack track1 = emptyGpxTrack();
|
|---|
| 222 | data.addTrack(track1);
|
|---|
| 223 | assertFalse(data.hasTrackPoints());
|
|---|
| 224 | ImmutableGpxTrack track2 = singleWaypointGpxTrack();
|
|---|
| 225 | data.addTrack(track2);
|
|---|
| 226 | assertTrue(data.hasTrackPoints());
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | /**
|
|---|
| 230 | * Test method for {@link GpxData#getTrackPoints()}.
|
|---|
| 231 | */
|
|---|
| 232 | @Test
|
|---|
| 233 | public void testGetTrackPoints() {
|
|---|
| 234 | assertEquals(0, data.getTrackPoints().count());
|
|---|
| 235 | ImmutableGpxTrack track1 = singleWaypointGpxTrack();
|
|---|
| 236 | data.addTrack(track1);
|
|---|
| 237 | assertEquals(1, data.getTrackPoints().count());
|
|---|
| 238 | ImmutableGpxTrack track2 = singleWaypointGpxTrack();
|
|---|
| 239 | data.addTrack(track2);
|
|---|
| 240 | assertEquals(2, data.getTrackPoints().count());
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | /**
|
|---|
| 244 | * Test method for {@link GpxData#hasRoutePoints()}.
|
|---|
| 245 | */
|
|---|
| 246 | @Test
|
|---|
| 247 | public void testHasRoutePoints() {
|
|---|
| 248 |
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | /**
|
|---|
| 252 | * Test method for {@link GpxData#isEmpty()}.
|
|---|
| 253 | */
|
|---|
| 254 | @Test
|
|---|
| 255 | public void testIsEmpty() {
|
|---|
| 256 | ImmutableGpxTrack track1 = singleWaypointGpxTrack();
|
|---|
| 257 | WayPoint waypoint = new WayPoint(LatLon.ZERO);
|
|---|
| 258 | GpxRoute route = singleWaypointRoute();
|
|---|
| 259 |
|
|---|
| 260 | assertTrue(data.isEmpty());
|
|---|
| 261 |
|
|---|
| 262 | data.addTrack(track1);
|
|---|
| 263 | assertFalse(data.isEmpty());
|
|---|
| 264 | data.removeTrack(track1);
|
|---|
| 265 | assertTrue(data.isEmpty());
|
|---|
| 266 |
|
|---|
| 267 | data.addWaypoint(waypoint);
|
|---|
| 268 | assertFalse(data.isEmpty());
|
|---|
| 269 | data.removeWaypoint(waypoint);
|
|---|
| 270 | assertTrue(data.isEmpty());
|
|---|
| 271 |
|
|---|
| 272 | data.addRoute(route);
|
|---|
| 273 | assertFalse(data.isEmpty());
|
|---|
| 274 | data.removeRoute(route);
|
|---|
| 275 | assertTrue(data.isEmpty());
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | /**
|
|---|
| 279 | * Test method for {@link GpxData#length()}.
|
|---|
| 280 | */
|
|---|
| 281 | @Test
|
|---|
| 282 | public void testLength() {
|
|---|
| 283 | ImmutableGpxTrack track1 = waypointGpxTrack(
|
|---|
| 284 | new WayPoint(new LatLon(0, 0)),
|
|---|
| 285 | new WayPoint(new LatLon(1, 1)),
|
|---|
| 286 | new WayPoint(new LatLon(0, 2)));
|
|---|
| 287 | ImmutableGpxTrack track2 = waypointGpxTrack(
|
|---|
| 288 | new WayPoint(new LatLon(0, 0)),
|
|---|
| 289 | new WayPoint(new LatLon(-1, 1)));
|
|---|
| 290 | data.addTrack(track1);
|
|---|
| 291 | data.addTrack(track2);
|
|---|
| 292 | assertEquals(3 * new LatLon(0, 0).greatCircleDistance(new LatLon(1, 1)), data.length(), 1);
|
|---|
| 293 |
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | /**
|
|---|
| 297 | * Test method for {@link GpxData#getMinMaxTimeForAllTracks()}.
|
|---|
| 298 | */
|
|---|
| 299 | @Test
|
|---|
| 300 | public void testGetMinMaxTimeForAllTracks() {
|
|---|
| 301 | assertEquals(0, data.getMinMaxTimeForAllTracks().length);
|
|---|
| 302 |
|
|---|
| 303 | WayPoint p1 = new WayPoint(LatLon.NORTH_POLE);
|
|---|
| 304 | WayPoint p2 = new WayPoint(LatLon.NORTH_POLE);
|
|---|
| 305 | WayPoint p3 = new WayPoint(LatLon.NORTH_POLE);
|
|---|
| 306 | WayPoint p4 = new WayPoint(LatLon.NORTH_POLE);
|
|---|
| 307 | WayPoint p5 = new WayPoint(LatLon.NORTH_POLE);
|
|---|
| 308 | p1.setTime(new Date(200020));
|
|---|
| 309 | p2.setTime(new Date(100020));
|
|---|
| 310 | p4.setTime(new Date(500020));
|
|---|
| 311 | data.addTrack(new ImmutableGpxTrack(Arrays.asList(Arrays.asList(p1, p2)), Collections.emptyMap()));
|
|---|
| 312 | data.addTrack(new ImmutableGpxTrack(Arrays.asList(Arrays.asList(p3, p4, p5)), Collections.emptyMap()));
|
|---|
| 313 |
|
|---|
| 314 | Date[] times = data.getMinMaxTimeForAllTracks();
|
|---|
| 315 | assertEquals(times.length, 2);
|
|---|
| 316 | assertEquals(new Date(100020), times[0]);
|
|---|
| 317 | assertEquals(new Date(500020), times[1]);
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | /**
|
|---|
| 321 | * Test method for {@link GpxData#nearestPointOnTrack(org.openstreetmap.josm.data.coor.EastNorth, double)}.
|
|---|
| 322 | */
|
|---|
| 323 | @Test
|
|---|
| 324 | public void testNearestPointOnTrack() {
|
|---|
| 325 | List<WayPoint> points = Stream
|
|---|
| 326 | .of(new EastNorth(10, 10), new EastNorth(10, 0), new EastNorth(-1, 0))
|
|---|
| 327 | .map(Main.getProjection()::eastNorth2latlon)
|
|---|
| 328 | .map(WayPoint::new)
|
|---|
| 329 | .collect(Collectors.toList());
|
|---|
| 330 | data.addTrack(new ImmutableGpxTrack(Arrays.asList(points), Collections.emptyMap()));
|
|---|
| 331 |
|
|---|
| 332 | WayPoint closeToMiddle = data.nearestPointOnTrack(new EastNorth(10, 0), 10);
|
|---|
| 333 | assertEquals(points.get(1), closeToMiddle);
|
|---|
| 334 |
|
|---|
| 335 | WayPoint close = data.nearestPointOnTrack(new EastNorth(5, 5), 10);
|
|---|
| 336 | assertEquals(10, close.getEastNorth(Main.getProjection()).east(), .01);
|
|---|
| 337 | assertEquals(5, close.getEastNorth(Main.getProjection()).north(), .01);
|
|---|
| 338 |
|
|---|
| 339 | close = data.nearestPointOnTrack(new EastNorth(15, 5), 10);
|
|---|
| 340 | assertEquals(10, close.getEastNorth(Main.getProjection()).east(), .01);
|
|---|
| 341 | assertEquals(5, close.getEastNorth(Main.getProjection()).north(), .01);
|
|---|
| 342 |
|
|---|
| 343 | assertNull(data.nearestPointOnTrack(new EastNorth(5, 5), 1));
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | /**
|
|---|
| 347 | * Test method for {@link GpxData#getDataSources()}.
|
|---|
| 348 | */
|
|---|
| 349 | @Test
|
|---|
| 350 | public void testGetDataSources() {
|
|---|
| 351 | DataSource ds = new DataSource(new Bounds(0, 0, 1, 1), "test");
|
|---|
| 352 | data.dataSources.add(ds);
|
|---|
| 353 | assertEquals(new ArrayList<>(Arrays.asList(ds)), new ArrayList<>(data.getDataSources()));
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | /**
|
|---|
| 357 | * Test method for {@link GpxData#getDataSourceArea()}.
|
|---|
| 358 | */
|
|---|
| 359 | @Test
|
|---|
| 360 | public void testGetDataSourceArea() {
|
|---|
| 361 | DataSource ds = new DataSource(new Bounds(0, 0, 1, 1), "test");
|
|---|
| 362 | data.dataSources.add(ds);
|
|---|
| 363 | assertNotNull(data.getDataSourceArea());
|
|---|
| 364 | assertTrue(data.getDataSourceArea().contains(0.5, 0.5));
|
|---|
| 365 | assertFalse(data.getDataSourceArea().contains(0.5, 1.5));
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | /**
|
|---|
| 369 | * Test method for {@link GpxData#getDataSourceBounds()}.
|
|---|
| 370 | */
|
|---|
| 371 | @Test
|
|---|
| 372 | public void testGetDataSourceBounds() {
|
|---|
| 373 | Bounds bounds = new Bounds(0, 0, 1, 1);
|
|---|
| 374 | DataSource ds = new DataSource(bounds, "test");
|
|---|
| 375 | data.dataSources.add(ds);
|
|---|
| 376 | assertEquals(Arrays.asList(bounds), data.getDataSourceBounds());
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | /**
|
|---|
| 380 | * Test method for {@link GpxData#addChangeListener(GpxData.GpxDataChangeListener)},
|
|---|
| 381 | * {@link GpxData#addWeakChangeListener(GpxData.GpxDataChangeListener)},
|
|---|
| 382 | * {@link GpxData#removeChangeListener(GpxData.GpxDataChangeListener)}.
|
|---|
| 383 | */
|
|---|
| 384 | @Test
|
|---|
| 385 | public void testChangeListener() {
|
|---|
| 386 | TestChangeListener cl1 = new TestChangeListener();
|
|---|
| 387 | TestChangeListener cl2 = new TestChangeListener();
|
|---|
| 388 |
|
|---|
| 389 | data.addChangeListener(cl1);
|
|---|
| 390 | data.addWeakChangeListener(cl2);
|
|---|
| 391 | assertNull(cl1.lastEvent);
|
|---|
| 392 | assertNull(cl2.lastEvent);
|
|---|
| 393 |
|
|---|
| 394 | data.addTrack(singleWaypointGpxTrack());
|
|---|
| 395 | assertEquals(data, cl1.lastEvent.getSource());
|
|---|
| 396 | assertEquals(data, cl2.lastEvent.getSource());
|
|---|
| 397 | cl1.lastEvent = null;
|
|---|
| 398 | cl2.lastEvent = null;
|
|---|
| 399 |
|
|---|
| 400 | data.addRoute(singleWaypointRoute());
|
|---|
| 401 | assertEquals(data, cl1.lastEvent.getSource());
|
|---|
| 402 | assertEquals(data, cl2.lastEvent.getSource());
|
|---|
| 403 | cl1.lastEvent = null;
|
|---|
| 404 | cl2.lastEvent = null;
|
|---|
| 405 |
|
|---|
| 406 | data.removeChangeListener(cl1);
|
|---|
| 407 | data.removeChangeListener(cl2);
|
|---|
| 408 | data.addTrack(singleWaypointGpxTrack());
|
|---|
| 409 | assertNull(cl1.lastEvent);
|
|---|
| 410 | assertNull(cl2.lastEvent);
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 | private static class TestChangeListener implements GpxDataChangeListener {
|
|---|
| 414 |
|
|---|
| 415 | private GpxDataChangeEvent lastEvent;
|
|---|
| 416 |
|
|---|
| 417 | @Override
|
|---|
| 418 | public void gpxDataChanged(GpxDataChangeEvent e) {
|
|---|
| 419 | lastEvent = e;
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | private static ImmutableGpxTrack emptyGpxTrack() {
|
|---|
| 425 | return new ImmutableGpxTrack(Collections.emptyList(), Collections.emptyMap());
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | private static ImmutableGpxTrack singleWaypointGpxTrack() {
|
|---|
| 429 | return new ImmutableGpxTrack(Collections.singleton(Collections.singleton(new WayPoint(LatLon.ZERO))), Collections.emptyMap());
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | private static ImmutableGpxTrack waypointGpxTrack(WayPoint... wps) {
|
|---|
| 433 | return new ImmutableGpxTrack(Collections.singleton(Arrays.asList(wps)), Collections.emptyMap());
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | private static GpxRoute singleWaypointRoute() {
|
|---|
| 437 | GpxRoute route = new GpxRoute();
|
|---|
| 438 | route.routePoints.add(new WayPoint(LatLon.ZERO));
|
|---|
| 439 | return route;
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | /**
|
|---|
| 443 | * Unit test of methods {@link GpxData#equals} and {@link GpxData#hashCode}.
|
|---|
| 444 | */
|
|---|
| 445 | @Test
|
|---|
| 446 | public void testEqualsContract() {
|
|---|
| 447 | EqualsVerifier.forClass(GpxData.class).usingGetClass()
|
|---|
| 448 | .withIgnoredFields("attr", "creator", "fromServer", "storageFile", "listeners", "tracks", "routes", "waypoints", "proxy")
|
|---|
| 449 | .withPrefabValues(WayPoint.class, new WayPoint(LatLon.NORTH_POLE), new WayPoint(LatLon.SOUTH_POLE))
|
|---|
| 450 | .withPrefabValues(ListenerList.class, ListenerList.create(), ListenerList.create())
|
|---|
| 451 | .verify();
|
|---|
| 452 | }
|
|---|
| 453 | }
|
|---|