Changeset 12166 in josm
- Timestamp:
- 2017-05-15T16:53:55+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDataTest.java
r12164 r12166 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNotNull; 7 import static org.junit.Assert.assertNull; 6 8 import static org.junit.Assert.assertTrue; 7 import static org.junit.Assert.fail; 8 9 10 import java.util.ArrayList; 11 import java.util.Arrays; 9 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; 10 17 11 18 import org.junit.Before; 12 19 import org.junit.Rule; 13 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; 14 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; 15 28 import org.openstreetmap.josm.testutils.JOSMTestRules; 29 import org.openstreetmap.josm.tools.ListenerList; 16 30 17 31 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 28 42 @Rule 29 43 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 30 public JOSMTestRules test = new JOSMTestRules() ;44 public JOSMTestRules test = new JOSMTestRules().projection(); 31 45 32 46 private GpxData data; … … 46 60 @Test 47 61 public void testMergeFrom() { 48 fail("Not yet implemented"); 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)); 49 83 } 50 84 … … 57 91 58 92 ImmutableGpxTrack track1 = emptyGpxTrack(); 59 ImmutableGpxTrack track2 = emptyGpxTrack();93 ImmutableGpxTrack track2 = singleWaypointGpxTrack(); 60 94 data.addTrack(track1); 61 95 assertEquals(1, data.getTracks().size()); … … 101 135 GpxRoute route1 = new GpxRoute(); 102 136 GpxRoute route2 = new GpxRoute(); 137 route2.routePoints.add(new WayPoint(LatLon.NORTH_POLE)); 103 138 data.addRoute(route1); 104 139 assertEquals(1, data.getRoutes().size()); … … 143 178 144 179 WayPoint waypoint1 = new WayPoint(LatLon.ZERO); 145 WayPoint waypoint2 = new WayPoint(LatLon. ZERO);180 WayPoint waypoint2 = new WayPoint(LatLon.NORTH_POLE); 146 181 data.addWaypoint(waypoint1); 147 182 assertEquals(1, data.getWaypoints().size()); … … 211 246 @Test 212 247 public void testHasRoutePoints() { 213 fail("Not yet implemented"); 248 214 249 } 215 250 … … 219 254 @Test 220 255 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"); 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()); 238 276 } 239 277 … … 243 281 @Test 244 282 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"); 283 ImmutableGpxTrack track1 = waypointGpxTrack(new WayPoint(new LatLon(0, 0)), new WayPoint(new LatLon(1, 1)), new WayPoint(new LatLon(0, 2))); 284 ImmutableGpxTrack track2 = waypointGpxTrack(new WayPoint(new LatLon(0, 0)), new WayPoint(new LatLon(-1, 1))); 285 data.addTrack(track1); 286 data.addTrack(track2); 287 assertEquals(3 * new LatLon(0, 0).greatCircleDistance(new LatLon(1, 1)), data.length(), 1); 288 254 289 } 255 290 … … 259 294 @Test 260 295 public void testGetMinMaxTimeForAllTracks() { 261 fail("Not yet implemented"); 296 assertEquals(0, data.getMinMaxTimeForAllTracks().length); 297 298 WayPoint p1 = new WayPoint(LatLon.NORTH_POLE); 299 WayPoint p2 = new WayPoint(LatLon.NORTH_POLE); 300 WayPoint p3 = new WayPoint(LatLon.NORTH_POLE); 301 WayPoint p4 = new WayPoint(LatLon.NORTH_POLE); 302 WayPoint p5 = new WayPoint(LatLon.NORTH_POLE); 303 p1.setTime(new Date(200020)); 304 p2.setTime(new Date(100020)); 305 p4.setTime(new Date(500020)); 306 data.addTrack(new ImmutableGpxTrack(Arrays.asList(Arrays.asList(p1, p2)), Collections.emptyMap())); 307 data.addTrack(new ImmutableGpxTrack(Arrays.asList(Arrays.asList(p3, p4, p5)), Collections.emptyMap())); 308 309 Date[] times = data.getMinMaxTimeForAllTracks(); 310 assertEquals(times.length, 2); 311 assertEquals(new Date(100020), times[0]); 312 assertEquals(new Date(500020), times[1]); 262 313 } 263 314 … … 267 318 @Test 268 319 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"); 320 List<WayPoint> points = Stream 321 .of(new EastNorth(10, 10), new EastNorth(10, 0), new EastNorth(-1, 0)) 322 .map(Main.getProjection()::eastNorth2latlon) 323 .map(WayPoint::new) 324 .collect(Collectors.toList()); 325 data.addTrack(new ImmutableGpxTrack(Arrays.asList(points), Collections.emptyMap())); 326 327 assertEquals(points.get(1), data.nearestPointOnTrack(new EastNorth(10, 0), 10)); 328 329 WayPoint close = data.nearestPointOnTrack(new EastNorth(5, 5), 10); 330 assertEquals(10, close.getEastNorth().east(), .01); 331 assertEquals(5, close.getEastNorth().north(), .01); 332 333 assertNull(data.nearestPointOnTrack(new EastNorth(5, 5), 1)); 286 334 } 287 335 … … 291 339 @Test 292 340 public void testGetDataSources() { 293 fail("Not yet implemented"); 341 DataSource ds = new DataSource(new Bounds(0, 0, 1, 1), "test"); 342 data.dataSources.add(ds); 343 assertEquals(new ArrayList<>(Arrays.asList(ds)), new ArrayList<>(data.getDataSources())); 294 344 } 295 345 … … 299 349 @Test 300 350 public void testGetDataSourceArea() { 301 fail("Not yet implemented"); 351 DataSource ds = new DataSource(new Bounds(0, 0, 1, 1), "test"); 352 data.dataSources.add(ds); 353 assertNotNull(data.getDataSourceArea()); 354 assertTrue(data.getDataSourceArea().contains(0.5, 0.5)); 355 assertFalse(data.getDataSourceArea().contains(0.5, 1.5)); 302 356 } 303 357 … … 307 361 @Test 308 362 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"); 363 Bounds bounds = new Bounds(0, 0, 1, 1); 364 DataSource ds = new DataSource(bounds, "test"); 365 data.dataSources.add(ds); 366 assertEquals(Arrays.asList(bounds), data.getDataSourceBounds()); 367 } 368 369 /** 370 * Test method for {@link GpxData#addChangeListener(GpxData.GpxDataChangeListener)}, 371 * {@link GpxData#addWeakChangeListener(GpxData.GpxDataChangeListener)}, 372 * {@link GpxData#removeChangeListener(GpxData.GpxDataChangeListener)}. 373 */ 374 @Test 375 public void testChangeListener() { 376 TestChangeListener cl1 = new TestChangeListener(); 377 TestChangeListener cl2 = new TestChangeListener(); 378 379 data.addChangeListener(cl1); 380 data.addWeakChangeListener(cl2); 381 assertNull(cl1.lastEvent); 382 assertNull(cl2.lastEvent); 383 384 data.addTrack(singleWaypointGpxTrack()); 385 assertEquals(data, cl1.lastEvent.getSource()); 386 assertEquals(data, cl2.lastEvent.getSource()); 387 cl1.lastEvent = null; 388 cl2.lastEvent = null; 389 390 data.addRoute(singleWaypointRoute()); 391 assertEquals(data, cl1.lastEvent.getSource()); 392 assertEquals(data, cl2.lastEvent.getSource()); 393 cl1.lastEvent = null; 394 cl2.lastEvent = null; 395 396 data.removeChangeListener(cl1); 397 data.removeChangeListener(cl2); 398 data.addTrack(singleWaypointGpxTrack()); 399 assertNull(cl1.lastEvent); 400 assertNull(cl2.lastEvent); 401 } 402 403 private static class TestChangeListener implements GpxDataChangeListener { 404 405 private GpxDataChangeEvent lastEvent; 406 407 @Override 408 public void gpxDataChanged(GpxDataChangeEvent e) { 409 lastEvent = e; 410 } 411 334 412 } 335 413 … … 342 420 } 343 421 422 private static ImmutableGpxTrack waypointGpxTrack(WayPoint... wps) { 423 return new ImmutableGpxTrack(Collections.singleton(Arrays.asList(wps)), Collections.emptyMap()); 424 } 425 426 private static GpxRoute singleWaypointRoute() { 427 GpxRoute route = new GpxRoute(); 428 route.routePoints.add(new WayPoint(LatLon.ZERO)); 429 return route; 430 } 431 344 432 /** 345 433 * Unit test of methods {@link GpxData#equals} and {@link GpxData#hashCode}. … … 348 436 public void testEqualsContract() { 349 437 EqualsVerifier.forClass(GpxData.class).usingGetClass() 350 .withIgnoredFields("attr", "creator", "fromServer", "storageFile", "listeners" )438 .withIgnoredFields("attr", "creator", "fromServer", "storageFile", "listeners", "tracks", "routes", "waypoints", "proxy") 351 439 .withPrefabValues(WayPoint.class, new WayPoint(LatLon.NORTH_POLE), new WayPoint(LatLon.SOUTH_POLE)) 440 .withPrefabValues(ListenerList.class, ListenerList.create(), ListenerList.create()) 352 441 .verify(); 353 442 }
Note:
See TracChangeset
for help on using the changeset viewer.