@@ -12,6 +12,7 @@ import android.graphics.Canvas
1212import io.mockk.mockk
1313import io.mockk.verify
1414import org.junit.Assert.assertEquals
15+ import org.junit.Assert.assertFalse
1516import org.junit.Assert.assertNotNull
1617import org.junit.Assert.assertNull
1718import org.junit.Assert.assertTrue
@@ -304,4 +305,181 @@ class MapControllerTest {
304305 controller.onPause()
305306 // Should not crash
306307 }
308+
309+ @Test
310+ fun testAddPolyline () {
311+ val points =
312+ listOf (
313+ LatLng (51.4661 , 7.2491 ),
314+ LatLng (51.4700 , 7.2550 ),
315+ )
316+ val polyline = Polyline (points = points)
317+
318+ val result = controller.addPolyline(polyline)
319+
320+ assertEquals(polyline, result)
321+ assertEquals(1 , controller.getPolylines().size)
322+ assertEquals(polyline, controller.getPolylines()[0 ])
323+ }
324+
325+ @Test
326+ fun testRemovePolyline () {
327+ val points =
328+ listOf (
329+ LatLng (51.4661 , 7.2491 ),
330+ LatLng (51.4700 , 7.2550 ),
331+ )
332+ val polyline = Polyline (points = points)
333+ controller.addPolyline(polyline)
334+
335+ val result = controller.removePolyline(polyline)
336+
337+ assertTrue(result)
338+ assertEquals(0 , controller.getPolylines().size)
339+ }
340+
341+ @Test
342+ fun testRemoveNonExistentPolyline () {
343+ val points =
344+ listOf (
345+ LatLng (51.4661 , 7.2491 ),
346+ LatLng (51.4700 , 7.2550 ),
347+ )
348+ val polyline = Polyline (points = points)
349+
350+ val result = controller.removePolyline(polyline)
351+
352+ assertFalse(result)
353+ }
354+
355+ @Test
356+ fun testClearPolylines () {
357+ val polyline1 = Polyline (listOf (LatLng (51.4661 , 7.2491 ), LatLng (51.4700 , 7.2550 )))
358+ val polyline2 = Polyline (listOf (LatLng (51.4620 , 7.2430 ), LatLng (51.4640 , 7.2460 )))
359+ controller.addPolyline(polyline1)
360+ controller.addPolyline(polyline2)
361+
362+ controller.clearPolylines()
363+
364+ assertEquals(0 , controller.getPolylines().size)
365+ }
366+
367+ @Test
368+ fun testGetPolylines_ReturnsImmutableCopy () {
369+ val polyline = Polyline (listOf (LatLng (51.4661 , 7.2491 ), LatLng (51.4700 , 7.2550 )))
370+ controller.addPolyline(polyline)
371+
372+ val polylines = controller.getPolylines()
373+ assertEquals(1 , polylines.size)
374+
375+ // Original list should remain unchanged even if returned list is modified
376+ // (though returned list is immutable)
377+ }
378+
379+ @Test
380+ fun testAddMultiplePolylines () {
381+ val polyline1 = Polyline (listOf (LatLng (51.4661 , 7.2491 ), LatLng (51.4700 , 7.2550 )))
382+ val polyline2 = Polyline (listOf (LatLng (51.4620 , 7.2430 ), LatLng (51.4640 , 7.2460 )))
383+ val polyline3 = Polyline (listOf (LatLng (51.4680 , 7.2520 ), LatLng (51.4690 , 7.2530 )))
384+
385+ controller.addPolyline(polyline1)
386+ controller.addPolyline(polyline2)
387+ controller.addPolyline(polyline3)
388+
389+ val polylines = controller.getPolylines()
390+ assertEquals(3 , polylines.size)
391+ assertEquals(polyline1, polylines[0 ])
392+ assertEquals(polyline2, polylines[1 ])
393+ assertEquals(polyline3, polylines[2 ])
394+ }
395+
396+ @Test
397+ fun testAddPolygon () {
398+ val points =
399+ listOf (
400+ LatLng (51.4661 , 7.2491 ),
401+ LatLng (51.4700 , 7.2550 ),
402+ LatLng (51.4620 , 7.2430 ),
403+ )
404+ val polygon = Polygon (points = points)
405+
406+ val result = controller.addPolygon(polygon)
407+
408+ assertEquals(polygon, result)
409+ assertEquals(1 , controller.getPolygons().size)
410+ assertEquals(polygon, controller.getPolygons()[0 ])
411+ }
412+
413+ @Test
414+ fun testRemovePolygon () {
415+ val points =
416+ listOf (
417+ LatLng (51.4661 , 7.2491 ),
418+ LatLng (51.4700 , 7.2550 ),
419+ LatLng (51.4620 , 7.2430 ),
420+ )
421+ val polygon = Polygon (points = points)
422+ controller.addPolygon(polygon)
423+
424+ val result = controller.removePolygon(polygon)
425+
426+ assertTrue(result)
427+ assertEquals(0 , controller.getPolygons().size)
428+ }
429+
430+ @Test
431+ fun testRemoveNonExistentPolygon () {
432+ val points =
433+ listOf (
434+ LatLng (51.4661 , 7.2491 ),
435+ LatLng (51.4700 , 7.2550 ),
436+ LatLng (51.4620 , 7.2430 ),
437+ )
438+ val polygon = Polygon (points = points)
439+
440+ val result = controller.removePolygon(polygon)
441+
442+ assertFalse(result)
443+ }
444+
445+ @Test
446+ fun testClearPolygons () {
447+ val polygon1 = Polygon (listOf (LatLng (51.4661 , 7.2491 ), LatLng (51.4700 , 7.2550 ), LatLng (51.4620 , 7.2430 )))
448+ val polygon2 = Polygon (listOf (LatLng (51.4640 , 7.2420 ), LatLng (51.4660 , 7.2440 ), LatLng (51.4650 , 7.2450 )))
449+ controller.addPolygon(polygon1)
450+ controller.addPolygon(polygon2)
451+
452+ controller.clearPolygons()
453+
454+ assertEquals(0 , controller.getPolygons().size)
455+ }
456+
457+ @Test
458+ fun testGetPolygons_ReturnsImmutableCopy () {
459+ val polygon = Polygon (listOf (LatLng (51.4661 , 7.2491 ), LatLng (51.4700 , 7.2550 ), LatLng (51.4620 , 7.2430 )))
460+ controller.addPolygon(polygon)
461+
462+ val polygons = controller.getPolygons()
463+ assertEquals(1 , polygons.size)
464+
465+ // Original list should remain unchanged even if returned list is modified
466+ // (though returned list is immutable)
467+ }
468+
469+ @Test
470+ fun testAddMultiplePolygons () {
471+ val polygon1 = Polygon (listOf (LatLng (51.4661 , 7.2491 ), LatLng (51.4700 , 7.2550 ), LatLng (51.4620 , 7.2430 )))
472+ val polygon2 = Polygon (listOf (LatLng (51.4640 , 7.2420 ), LatLng (51.4660 , 7.2440 ), LatLng (51.4650 , 7.2450 )))
473+ val polygon3 = Polygon (listOf (LatLng (51.4680 , 7.2520 ), LatLng (51.4690 , 7.2530 ), LatLng (51.4685 , 7.2540 )))
474+
475+ controller.addPolygon(polygon1)
476+ controller.addPolygon(polygon2)
477+ controller.addPolygon(polygon3)
478+
479+ val polygons = controller.getPolygons()
480+ assertEquals(3 , polygons.size)
481+ assertEquals(polygon1, polygons[0 ])
482+ assertEquals(polygon2, polygons[1 ])
483+ assertEquals(polygon3, polygons[2 ])
484+ }
307485}
0 commit comments