@@ -8,35 +8,43 @@ import org.maplibre.android.annotations.MarkerOptions
8
8
import org.maplibre.android.geometry.LatLng
9
9
import org.junit.Assert
10
10
import org.junit.Test
11
+ import org.maplibre.android.annotations.PolygonOptions
12
+ import org.maplibre.android.annotations.PolylineOptions
11
13
import org.mockito.ArgumentMatchers
12
14
import org.mockito.Mockito
13
15
14
16
class AnnotationManagerTest {
17
+
18
+ private val aNativeMapView: NativeMap = Mockito .mock(NativeMapView ::class .java)
19
+ private val aMapView = Mockito .mock(MapView ::class .java)
20
+ private val annotationsArray = LongSparseArray <Annotation >()
21
+ private val aIconManager = Mockito .mock(
22
+ IconManager ::class .java
23
+ )
24
+ private val aMapLibreMap = Mockito .mock(MapLibreMap ::class .java)
25
+
26
+ private val annotations: Annotations = AnnotationContainer (aNativeMapView, annotationsArray)
27
+ private val markers: Markers = MarkerContainer (aNativeMapView, annotationsArray, aIconManager)
28
+ private val polygons: Polygons = PolygonContainer (aNativeMapView, annotationsArray)
29
+ private val polylines: Polylines = PolylineContainer (aNativeMapView, annotationsArray)
30
+ private val shapeAnnotations: ShapeAnnotations =
31
+ ShapeAnnotationContainer (aNativeMapView, annotationsArray)
32
+
33
+
34
+ private val annotationManager = AnnotationManager (
35
+ aMapView,
36
+ annotationsArray,
37
+ aIconManager,
38
+ annotations,
39
+ markers,
40
+ polygons,
41
+ polylines,
42
+ shapeAnnotations
43
+ )
44
+
15
45
@Test
16
46
@Throws(Exception ::class )
17
47
fun checksAddAMarker () {
18
- val aNativeMapView: NativeMap = Mockito .mock(NativeMapView ::class .java)
19
- val aMapView = Mockito .mock(MapView ::class .java)
20
- val annotationsArray = LongSparseArray <Annotation >()
21
- val aIconManager = Mockito .mock(
22
- IconManager ::class .java
23
- )
24
- val annotations: Annotations = AnnotationContainer (aNativeMapView, annotationsArray)
25
- val markers: Markers = MarkerContainer (aNativeMapView, annotationsArray, aIconManager)
26
- val polygons: Polygons = PolygonContainer (aNativeMapView, annotationsArray)
27
- val polylines: Polylines = PolylineContainer (aNativeMapView, annotationsArray)
28
- val shapeAnnotations: ShapeAnnotations =
29
- ShapeAnnotationContainer (aNativeMapView, annotationsArray)
30
- val annotationManager = AnnotationManager (
31
- aMapView,
32
- annotationsArray,
33
- aIconManager,
34
- annotations,
35
- markers,
36
- polygons,
37
- polylines,
38
- shapeAnnotations
39
- )
40
48
val aMarker = Mockito .mock(
41
49
Marker ::class .java
42
50
)
@@ -55,28 +63,6 @@ class AnnotationManagerTest {
55
63
@Test
56
64
@Throws(Exception ::class )
57
65
fun checksAddMarkers () {
58
- val aNativeMapView = Mockito .mock(NativeMapView ::class .java)
59
- val aMapView = Mockito .mock(MapView ::class .java)
60
- val annotationsArray = LongSparseArray <Annotation >()
61
- val aIconManager = Mockito .mock(
62
- IconManager ::class .java
63
- )
64
- val annotations: Annotations = AnnotationContainer (aNativeMapView, annotationsArray)
65
- val markers: Markers = MarkerContainer (aNativeMapView, annotationsArray, aIconManager)
66
- val polygons: Polygons = PolygonContainer (aNativeMapView, annotationsArray)
67
- val polylines: Polylines = PolylineContainer (aNativeMapView, annotationsArray)
68
- val shapeAnnotations: ShapeAnnotations =
69
- ShapeAnnotationContainer (aNativeMapView, annotationsArray)
70
- val annotationManager = AnnotationManager (
71
- aMapView,
72
- annotationsArray,
73
- aIconManager,
74
- annotations,
75
- markers,
76
- polygons,
77
- polylines,
78
- shapeAnnotations
79
- )
80
66
val firstId = 1L
81
67
val secondId = 2L
82
68
val markerList: MutableList <BaseMarkerOptions <* , * >> = ArrayList ()
@@ -101,4 +87,33 @@ class AnnotationManagerTest {
101
87
Assert .assertEquals(" first" , (annotationManager.getAnnotation(firstId) as Marker ).title)
102
88
Assert .assertEquals(" second" , (annotationManager.getAnnotation(secondId) as Marker ).title)
103
89
}
90
+
91
+ @Test
92
+ @Throws(Exception ::class )
93
+ fun checksAddEmptyPolygon () {
94
+ val pId = 5L
95
+ val polygonOptions = PolygonOptions ()
96
+ val polygon = polygonOptions.polygon
97
+ Mockito .`when `(aNativeMapView.addPolygon(polygon)).thenReturn(pId)
98
+ val resultPolygon = annotationManager.addPolygon(polygonOptions, aMapLibreMap)
99
+ Assert .assertEquals(polygon, resultPolygon)
100
+ Assert .assertEquals(pId, resultPolygon.id)
101
+ Assert .assertEquals(1 , annotationManager.annotations.size)
102
+ Assert .assertEquals(polygon, annotationManager.annotations[0 ])
103
+
104
+ }
105
+
106
+ @Test
107
+ @Throws(Exception ::class )
108
+ fun checksAddEmptyPolyline () {
109
+ val pId = 5L
110
+ val polylineOptions = PolylineOptions ()
111
+ val polyline = polylineOptions.polyline
112
+ Mockito .`when `(aNativeMapView.addPolyline(polyline)).thenReturn(pId)
113
+ val resultPolyline = annotationManager.addPolyline(polylineOptions, aMapLibreMap)
114
+ Assert .assertEquals(polyline, resultPolyline)
115
+ Assert .assertEquals(pId, resultPolyline.id)
116
+ Assert .assertEquals(1 , annotationManager.annotations.size)
117
+ Assert .assertEquals(polyline, annotationManager.annotations[0 ])
118
+ }
104
119
}
0 commit comments