-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Nearby tab accessible without GPS #4771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dda5fa3
Nearby accessible without GPS
Ayan-10 477134e
Java doc added
Ayan-10 f5e722d
Merge branch 'commons-app:master' into 3732_gps_issue
Ayan-10 26f499b
Added NearbyParentFragment test
Ayan-10 0dc9a85
Test added
Ayan-10 a85897c
merged two method and tests updates
Ayan-10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentUnitTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package fr.free.nrw.commons.nearby | ||
|
||
import com.mapbox.mapboxsdk.camera.CameraPosition | ||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory | ||
import com.mapbox.mapboxsdk.geometry.LatLng | ||
import com.mapbox.mapboxsdk.maps.MapView | ||
import com.mapbox.mapboxsdk.maps.MapboxMap | ||
import fr.free.nrw.commons.TestCommonsApplication | ||
import fr.free.nrw.commons.kvstore.JsonKvStore | ||
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment | ||
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.* | ||
import org.mockito.MockitoAnnotations | ||
import org.powermock.reflect.Whitebox | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
import org.robolectric.annotation.LooperMode | ||
import java.lang.reflect.Method | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(sdk = [21], application = TestCommonsApplication::class) | ||
@LooperMode(LooperMode.Mode.PAUSED) | ||
class NearbyParentFragmentUnitTest { | ||
|
||
@Mock | ||
private lateinit var mapView: MapView | ||
|
||
@Mock | ||
private lateinit var applicationKvStore: JsonKvStore | ||
|
||
@Mock | ||
private lateinit var mapBox: MapboxMap | ||
|
||
@Mock | ||
private lateinit var presenter: NearbyParentFragmentPresenter | ||
|
||
private lateinit var fragment: NearbyParentFragment | ||
|
||
@Before | ||
fun setUp() { | ||
MockitoAnnotations.initMocks(this) | ||
fragment = NearbyParentFragment() | ||
Whitebox.setInternalState(fragment, "mapView", mapView) | ||
Whitebox.setInternalState(fragment, "applicationKvStore", applicationKvStore) | ||
Whitebox.setInternalState(fragment, "mapBox", mapBox) | ||
Whitebox.setInternalState(fragment, "presenter", presenter) | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun `Start map without gps test when last location known`() { | ||
val method: Method = NearbyParentFragment::class.java.getDeclaredMethod( | ||
"startMapWithCondition", | ||
String::class.java | ||
) | ||
method.isAccessible = true | ||
method.invoke(fragment, "Without GPS") | ||
verify(mapView, times(1)).onStart() | ||
verify(applicationKvStore, times(1)).getString("LastLocation") | ||
verify(presenter, times(1)).onMapReady() | ||
val position = CameraPosition.Builder() | ||
.target(LatLng( | ||
51.50550, | ||
-0.07520, 0.0 | ||
)) | ||
.zoom(0.0) | ||
.build() | ||
verify(mapBox, times(1)) | ||
.moveCamera(CameraUpdateFactory.newCameraPosition(position)) | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun `Start map without gps test when last location unknown`() { | ||
`when`(applicationKvStore.getString("LastLocation")).thenReturn("23.76,56.876") | ||
val method: Method = NearbyParentFragment::class.java.getDeclaredMethod( | ||
"startMapWithCondition", | ||
String::class.java | ||
) | ||
method.isAccessible = true | ||
method.invoke(fragment, "Without GPS") | ||
verify(mapView, times(1)).onStart() | ||
verify(applicationKvStore, times(2)).getString("LastLocation") | ||
verify(presenter, times(1)).onMapReady() | ||
val position = CameraPosition.Builder() | ||
.target(LatLng( | ||
23.76, | ||
56.876, 0.0 | ||
)) | ||
.zoom(14.0) | ||
.build() | ||
verify(mapBox, times(1)) | ||
.moveCamera(CameraUpdateFactory.newCameraPosition(position)) | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun `Start map without location permission test when last location known`() { | ||
val method: Method = NearbyParentFragment::class.java.getDeclaredMethod( | ||
"startMapWithCondition", | ||
String::class.java | ||
) | ||
method.isAccessible = true | ||
method.invoke(fragment, "Without Permission") | ||
verify(mapView, times(1)).onStart() | ||
verify(applicationKvStore, times(1)).getString("LastLocation") | ||
verify(applicationKvStore, times(1)) | ||
.putBoolean("doNotAskForLocationPermission", true) | ||
verify(presenter, times(1)).onMapReady() | ||
val position = CameraPosition.Builder() | ||
.target(LatLng( | ||
51.50550, | ||
-0.07520, 0.0 | ||
)) | ||
.zoom(0.0) | ||
.build() | ||
verify(mapBox, times(1)) | ||
.moveCamera(CameraUpdateFactory.newCameraPosition(position)) | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun `Start map without location permission test when last location unknown`() { | ||
`when`(applicationKvStore.getString("LastLocation")).thenReturn("23.76,56.876") | ||
val method: Method = NearbyParentFragment::class.java.getDeclaredMethod( | ||
"startMapWithCondition", | ||
String::class.java | ||
) | ||
method.isAccessible = true | ||
method.invoke(fragment, "Without Permission") | ||
verify(mapView, times(1)).onStart() | ||
verify(applicationKvStore, times(2)).getString("LastLocation") | ||
verify(applicationKvStore, times(1)) | ||
.putBoolean("doNotAskForLocationPermission", true) | ||
verify(presenter, times(1)).onMapReady() | ||
val position = CameraPosition.Builder() | ||
.target(LatLng( | ||
23.76, | ||
56.876, 0.0 | ||
)) | ||
.zoom(14.0) | ||
.build() | ||
verify(mapBox, times(1)) | ||
.moveCamera(CameraUpdateFactory.newCameraPosition(position)) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ayan-10 can you also add mock verification for all mocked objects to both of your tests, for example
you can also check for number of calls like