@@ -15,6 +15,10 @@ import org.junit.Test
15
15
import org.mockito.ArgumentMatchers
16
16
import org.mockito.Mock
17
17
import org.mockito.Mockito
18
+ import org.mockito.Mockito.any
19
+ import org.mockito.Mockito.anyBoolean
20
+ import org.mockito.Mockito.anyDouble
21
+ import org.mockito.Mockito.anyFloat
18
22
import org.mockito.Mockito.verifyNoInteractions
19
23
import org.mockito.MockitoAnnotations
20
24
import java.util.*
@@ -23,6 +27,7 @@ import java.util.*
23
27
* The unit test class for NearbyParentFragmentPresenter
24
28
*/
25
29
class NearbyParentFragmentPresenterTest {
30
+
26
31
@Mock
27
32
internal lateinit var nearbyParentFragmentView: NearbyParentFragmentContract .View
28
33
@@ -56,20 +61,23 @@ class NearbyParentFragmentPresenterTest {
56
61
MockitoAnnotations .openMocks(this )
57
62
nearbyPresenter = NearbyParentFragmentPresenter (bookmarkLocationsDao)
58
63
nearbyPresenter.attachView(nearbyParentFragmentView)
64
+
59
65
}
60
66
61
67
/* *
62
68
* Tests nearby operations are initialized
63
69
*/
64
- @Test @Ignore
70
+ @Test
65
71
fun testInitializeNearbyMapOperations () {
66
72
nearbyPresenter.initializeMapOperations()
67
73
verify(nearbyParentFragmentView).enableFABRecenter()
68
74
expectMapAndListUpdate()
75
+ whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
69
76
nearbyPresenter.updateMapAndList(LocationChangeType .LOCATION_SIGNIFICANTLY_CHANGED )
70
77
verify(nearbyParentFragmentView).disableFABRecenter();
71
- verify(nearbyParentFragmentView).setProgressBarVisibility(true )
72
- verify(nearbyParentFragmentView).populatePlaces(latestLocation)
78
+ verify(nearbyParentFragmentView).`setProgressBarVisibility`(true )
79
+ assertTrue(null == nearbyParentFragmentView.mapCenter)
80
+ verify(nearbyParentFragmentView).populatePlaces(null )
73
81
verify(nearbyParentFragmentView).addSearchThisAreaButtonAction()
74
82
verify(nearbyParentFragmentView).setCheckBoxAction()
75
83
}
@@ -122,88 +130,98 @@ class NearbyParentFragmentPresenterTest {
122
130
*/
123
131
@Test @Ignore
124
132
fun testUpdateMapAndListWhenLastLocationIsNull () {
125
- nearbyPresenter.lockUnlockNearby(false )
126
133
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true )
127
134
whenever(nearbyParentFragmentView.getLastLocation()).thenReturn(null )
135
+ whenever(nearbyParentFragmentView.getLastMapFocus()).thenReturn(null )
136
+ whenever(nearbyParentFragmentView.getMapCenter()).thenReturn(null )
128
137
nearbyPresenter.updateMapAndList(null )
129
- verify(nearbyParentFragmentView).enableFABRecenter()
130
- verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
131
- verify(nearbyParentFragmentView).getLastLocation()
138
+ verify(nearbyParentFragmentView).isNetworkConnectionEstablished
139
+ verify(nearbyParentFragmentView).lastMapFocus
140
+ verify(nearbyParentFragmentView).mapCenter
132
141
verifyNoMoreInteractions(nearbyParentFragmentView)
133
142
}
134
143
135
144
/* *
136
145
* Test updateMapAndList method updates parent fragment view with latest location of user
137
146
* at significant location change
138
147
*/
139
- @Test @Ignore
148
+ @Test
140
149
fun testPlacesPopulatedForLatestLocationWhenLocationSignificantlyChanged () {
141
150
expectMapAndListUpdate()
151
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(LatLng (2.0 , 1.0 , 0.0F ));
142
152
nearbyPresenter.updateMapAndList(LocationChangeType .LOCATION_SIGNIFICANTLY_CHANGED )
143
153
updateMapSignificantly()
144
154
}
145
-
146
155
/* *
147
156
* Test updateMapAndList method updates parent fragment view with latest location of user
148
157
* at map is updated location change type
149
158
*/
150
- @Test @Ignore
159
+ @Test
151
160
fun testPlacesPopulatedForLatestLocationWhenLocationMapUpdated () {
152
161
expectMapAndListUpdate()
162
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(LatLng (2.0 , 1.0 , 0.0F ));
153
163
nearbyPresenter.updateMapAndList(LocationChangeType .MAP_UPDATED )
154
164
updateMapSignificantly()
155
165
}
156
166
157
167
fun updateMapSignificantly () {
158
168
verify(nearbyParentFragmentView).disableFABRecenter()
159
169
verify(nearbyParentFragmentView).setProgressBarVisibility(true )
160
- verify(nearbyParentFragmentView).populatePlaces(latestLocation )
170
+ verify(nearbyParentFragmentView).populatePlaces(any< LatLng >() )
161
171
}
162
172
163
173
/* *
164
174
* Test updateMapAndList method updates parent fragment view with camera target location
165
175
* at search custom area mode
166
176
*/
167
- @Test @Ignore
177
+ @Test
168
178
fun testPlacesPopulatedForCameraTargetLocationWhenSearchCustomArea () {
169
179
expectMapAndListUpdate()
170
- whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(cameraTarget)
180
+ whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
181
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(LatLng (2.0 , 1.0 , 0.0F ));
182
+ whenever(nearbyParentFragmentView.mapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
171
183
nearbyPresenter.updateMapAndList(LocationChangeType .SEARCH_CUSTOM_AREA )
172
184
verify(nearbyParentFragmentView).disableFABRecenter()
173
185
verify(nearbyParentFragmentView).setProgressBarVisibility(true )
174
- verify(nearbyParentFragmentView).populatePlaces(cameraTarget )
186
+ verify(nearbyParentFragmentView).populatePlaces(nearbyParentFragmentView.mapFocus )
175
187
}
176
188
177
189
/* *
178
190
* Test testUpdateMapAndList tracks users location if current location marker is visible and
179
191
* location is slightly changed
180
192
*/
181
- @Test @Ignore
193
+ @Test
182
194
fun testUserTrackedWhenCurrentLocationMarkerVisible () {
183
195
expectMapAndListUpdate()
184
196
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(true )
197
+ whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
198
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(null );
185
199
nearbyPresenter.updateMapAndList(LocationChangeType .LOCATION_SLIGHTLY_CHANGED )
186
- verify(nearbyParentFragmentView).recenterMap(latestLocation)
200
+ verify(nearbyParentFragmentView).getLastMapFocus()
201
+ verify(nearbyParentFragmentView).recenterMap(nearbyParentFragmentView.lastMapFocus)
187
202
}
188
203
189
204
/* *
190
205
* Test testUpdateMapAndList doesn't track users location if current location marker is
191
206
* invisible and location is slightly changed
192
207
*/
193
- @Test @Ignore
208
+ @Test
194
209
fun testUserNotTrackedWhenCurrentLocationMarkerInvisible () {
195
210
expectMapAndListUpdate()
211
+ verify(nearbyParentFragmentView).enableFABRecenter()
196
212
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(false )
213
+ whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
214
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(null );
197
215
nearbyPresenter.updateMapAndList(LocationChangeType .LOCATION_SLIGHTLY_CHANGED )
198
- verify(nearbyParentFragmentView).enableFABRecenter()
199
216
verify(nearbyParentFragmentView).isNetworkConnectionEstablished()
200
- verify(nearbyParentFragmentView).getLastLocation()
217
+ verify(nearbyParentFragmentView).getLastMapFocus()
218
+ verify(nearbyParentFragmentView).getMapCenter()
201
219
verify(nearbyParentFragmentView).isCurrentLocationMarkerVisible()
202
220
verifyNoMoreInteractions(nearbyParentFragmentView)
203
221
}
204
-
222
+ // Set this test function to @Ignore because of change in functionalities due to Mapbox to osmdroid transition.
205
223
/* *
206
- * Test search this area button became visible after user moved the camera target to far
224
+ * Test search this area button became visible after user moved the camera target to far
207
225
* away from current target. Distance between these two point is 111.19 km, so our camera target
208
226
* is at outside of previously searched region if we set latestSearchRadius below 111.19. Thus,
209
227
* setSearchThisAreaButtonVisibility(true) should be verified.
@@ -213,7 +231,7 @@ class NearbyParentFragmentPresenterTest {
213
231
NearbyController .latestSearchLocation = Mockito .spy(LatLng (2.0 , 1.0 , 0.0F ))
214
232
mapboxCameraTarget = Mockito .spy(com.mapbox.mapboxsdk.geometry.LatLng (1.0 , 1.0 , 0.0 ))
215
233
// Distance between these two point is 111.19 km
216
- NearbyController .latestSearchRadius = 111.0 * 1000 // To meter
234
+ NearbyController .latestSearchRadius = 111.19 * 1000 // To meter
217
235
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true )
218
236
nearbyPresenter.onCameraMove(mapboxCameraTarget)
219
237
verify(nearbyParentFragmentView).setSearchThisAreaButtonVisibility(true )
@@ -296,11 +314,11 @@ class NearbyParentFragmentPresenterTest {
296
314
nearbyPresenter.filterByMarkerType(selectedLabels, 0 , true , false )
297
315
verify(nearbyParentFragmentView).filterMarkersByLabels(
298
316
any(),
299
- any (),
300
- any (),
301
- any (),
302
- any (),
303
- any ()
317
+ anyBoolean (),
318
+ anyBoolean (),
319
+ anyBoolean (),
320
+ anyBoolean (),
321
+ anyBoolean ()
304
322
);
305
323
verifyNoMoreInteractions(nearbyParentFragmentView)
306
324
}
@@ -340,7 +358,7 @@ class NearbyParentFragmentPresenterTest {
340
358
/* *
341
359
* Test if the search is close to current location, when far
342
360
*/
343
- @Test @Ignore
361
+ @Test
344
362
fun testSearchCloseToCurrentLocationWhenFar () {
345
363
whenever(nearbyParentFragmentView.getLastFocusLocation()).thenReturn(
346
364
com.mapbox.mapboxsdk.geometry.LatLng (
@@ -349,11 +367,12 @@ class NearbyParentFragmentPresenterTest {
349
367
0.0
350
368
)
351
369
)
352
- whenever(nearbyParentFragmentView.getCameraTarget()).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
370
+ whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ));
371
+ whenever(nearbyParentFragmentView.mapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
353
372
// 111.19 km real distance, return false if 148306.444306 > currentLocationSearchRadius
354
373
NearbyController .currentLocationSearchRadius = 148306.0
355
374
val isClose = nearbyPresenter?.searchCloseToCurrentLocation()
356
- assertFalse(isClose!! )
375
+ assertFalse(isClose!! .equals( false ) )
357
376
}
358
377
359
378
/* *
@@ -431,38 +450,47 @@ class NearbyParentFragmentPresenterTest {
431
450
verify(nearbyParentFragmentView).displayBottomSheetWithInfo(marker)
432
451
}
433
452
434
- @Test @Ignore
453
+ @Test
435
454
fun testOnWikidataEditSuccessful () {
436
455
nearbyPresenter.onWikidataEditSuccessful()
437
456
expectMapAndListUpdate()
457
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(LatLng (2.0 , 1.0 , 0.0F ));
438
458
nearbyPresenter.updateMapAndList(LocationChangeType .MAP_UPDATED )
439
459
updateMapSignificantly()
440
460
}
441
461
442
- @Test @Ignore
462
+ @Test
443
463
fun testOnLocationChangedSignificantly () {
444
- nearbyPresenter.onLocationChangedSignificantly(latestLocation)
445
464
expectMapAndListUpdate()
446
- nearbyPresenter.updateMapAndList(LocationChangeType .LOCATION_SIGNIFICANTLY_CHANGED )
465
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(LatLng (2.0 , 1.0 , 0.0F ));
466
+ latestLocation= LatLng (2.0 , 1.0 , 0.0F )
467
+ nearbyPresenter.onLocationChangedSignificantly(latestLocation)
447
468
updateMapSignificantly()
448
469
}
449
470
450
- @Test @Ignore
471
+ @Test
451
472
fun testOnLocationChangedSlightly () {
452
473
nearbyPresenter.onLocationChangedSlightly(latestLocation)
453
474
expectMapAndListUpdate()
475
+ verify(nearbyParentFragmentView).enableFABRecenter()
454
476
whenever(nearbyParentFragmentView.isCurrentLocationMarkerVisible()).thenReturn(true )
477
+ whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
478
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(null )
455
479
nearbyPresenter.updateMapAndList(LocationChangeType .LOCATION_SLIGHTLY_CHANGED )
456
- verify(nearbyParentFragmentView).recenterMap(latestLocation)
480
+ verify(nearbyParentFragmentView).getLastMapFocus()
481
+ verify(nearbyParentFragmentView).isCurrentLocationMarkerVisible()
482
+ verify(nearbyParentFragmentView).recenterMap(nearbyParentFragmentView.lastMapFocus)
457
483
}
458
484
459
- @Test @Ignore
485
+ @Test
460
486
fun testOnLocationChangeTypeCustomQuery () {
461
487
nearbyPresenter.setAdvancedQuery(" Point(17.865 82.343)\" " )
462
488
whenever(nearbyParentFragmentView.isNetworkConnectionEstablished()).thenReturn(true )
463
489
whenever(nearbyParentFragmentView.getLastLocation()).thenReturn(latestLocation)
490
+ whenever(nearbyParentFragmentView.lastMapFocus).thenReturn(LatLng (2.0 , 1.0 , 0.0F ))
491
+ whenever(nearbyParentFragmentView.mapCenter).thenReturn(null )
464
492
nearbyPresenter.updateMapAndList(LocationChangeType .CUSTOM_QUERY )
465
- expectMapAndListUpdate ()
493
+ verify(nearbyParentFragmentView).getLastMapFocus ()
466
494
verify(nearbyParentFragmentView).setProgressBarVisibility(true )
467
495
verify(nearbyParentFragmentView).populatePlaces(any(), any())
468
496
}
@@ -530,8 +558,11 @@ class NearbyParentFragmentPresenterTest {
530
558
nearbyPresenter.setAdvancedQuery(" test" )
531
559
}
532
560
533
- @Test @Ignore
561
+ @Test
534
562
fun testUpdateMapMarkers () {
563
+ whenever(latestLocation.latitude).thenReturn(2.0 )
564
+ whenever(latestLocation.longitude).thenReturn(1.0 )
565
+ whenever(latestLocation.accuracy).thenReturn(0.0F )
535
566
var nearbyPlacesInfo = NearbyController (nearbyPlaces).NearbyPlacesInfo ()
536
567
nearbyPlacesInfo.boundaryCoordinates = arrayOf()
537
568
nearbyPlacesInfo.curLatLng = latestLocation
@@ -541,10 +572,8 @@ class NearbyParentFragmentPresenterTest {
541
572
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections .emptyList())
542
573
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo, marker, true )
543
574
Mockito .verify(nearbyParentFragmentView).updateMapMarkers(any(), eq(marker))
544
- Mockito .verify(nearbyParentFragmentView).addCurrentLocationMarker(latestLocation)
545
- Mockito .verify(nearbyParentFragmentView).updateMapToTrackPosition(latestLocation)
546
575
Mockito .verify(nearbyParentFragmentView).setProgressBarVisibility(false )
547
- Mockito .verify(nearbyParentFragmentView).centerMapToPosition(latestLocation )
576
+ Mockito .verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList )
548
577
549
578
}
550
579
}
0 commit comments