mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Replaced mapbox to osmdroid (Upload Activity) (#5443)
* Fixed Grey empty screen at Upload wizard caption step after denying files permission * Empty commit * Fixed loop issue * Created docs for earlier commits * Fixed javadoc * Fixed spaces * Added added basic features to OSM Maps * Added search location feature * Added filter to Open Street Maps * Fixed chipGroup in Open Street Maps * Removed mapBox code * Removed mapBox's code * Reformat code * Reformatted code * Removed rotation feature to map * Removed rotation files and Fixed Marker click problem * Ignored failing tests * Added voice input feature * Fixed test cases * Changed caption and description text * Replaced mapbox to osmdroid in upload activity * Fixed Unit Tests * Made selected marker to be fixed on map * Changed color of map marker
This commit is contained in:
parent
11e7b1cde7
commit
6319da5445
9 changed files with 206 additions and 382 deletions
|
|
@ -32,6 +32,8 @@ import org.junit.runner.RunWith
|
|||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.osmdroid.api.IMapController
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
|
@ -54,7 +56,7 @@ class LocationPickerActivityUnitTests {
|
|||
private lateinit var applicationKvStore: JsonKvStore
|
||||
|
||||
@Mock
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
private lateinit var mapView: org.osmdroid.views.MapView
|
||||
|
||||
@Mock
|
||||
private lateinit var cameraPosition: CameraPosition
|
||||
|
|
@ -68,9 +70,6 @@ class LocationPickerActivityUnitTests {
|
|||
@Mock
|
||||
private lateinit var showInMapButton: TextView
|
||||
|
||||
@Mock
|
||||
private lateinit var droppedMarkerLayer: Layer
|
||||
|
||||
@Mock
|
||||
private lateinit var markerImage: ImageView
|
||||
|
||||
|
|
@ -89,22 +88,18 @@ class LocationPickerActivityUnitTests {
|
|||
@Mock
|
||||
private lateinit var tvAttribution: AppCompatTextView
|
||||
|
||||
@Mock
|
||||
private lateinit var style: Style
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
context = RuntimeEnvironment.getApplication().applicationContext
|
||||
activity = Robolectric.buildActivity(LocationPickerActivity::class.java).get()
|
||||
|
||||
Whitebox.setInternalState(activity, "mapboxMap", mapboxMap)
|
||||
Whitebox.setInternalState(activity, "mapView", mapView)
|
||||
Whitebox.setInternalState(activity, "applicationKvStore", applicationKvStore)
|
||||
Whitebox.setInternalState(activity, "cameraPosition", cameraPosition)
|
||||
Whitebox.setInternalState(activity, "modifyLocationButton", modifyLocationButton)
|
||||
Whitebox.setInternalState(activity, "placeSelectedButton", placeSelectedButton)
|
||||
Whitebox.setInternalState(activity, "showInMapButton", showInMapButton)
|
||||
Whitebox.setInternalState(activity, "droppedMarkerLayer", droppedMarkerLayer)
|
||||
Whitebox.setInternalState(activity, "markerImage", markerImage)
|
||||
Whitebox.setInternalState(activity, "shadow", shadow)
|
||||
Whitebox.setInternalState(activity, "largeToolbarText", largeToolbarText)
|
||||
|
|
@ -119,42 +114,6 @@ class LocationPickerActivityUnitTests {
|
|||
Assert.assertNotNull(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testBindListeners() {
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"bindListeners"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
verify(mapboxMap, times(1)).addOnCameraMoveStartedListener(activity)
|
||||
verify(mapboxMap, times(1)).addOnCameraIdleListener(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnMapReady() {
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"onMapReady",
|
||||
MapboxMap::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
try {
|
||||
method.invoke(activity, mapboxMap)
|
||||
fail("Expected an exception to be thrown")
|
||||
} catch (e: InvocationTargetException) {
|
||||
assertTrue((e.targetException is MapboxConfigurationException) ||
|
||||
(e.targetException is ExceptionInInitializerError))
|
||||
if (e.targetException is MapboxConfigurationException) {
|
||||
assertEquals(
|
||||
"\nUsing MapView requires calling Mapbox.getInstance(Context context, String apiKey,"
|
||||
+ " WellKnownTileServer wellKnownTileServer) before inflating or creating the view.",
|
||||
e.targetException.message
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testAddCredits() {
|
||||
|
|
@ -167,49 +126,6 @@ class LocationPickerActivityUnitTests {
|
|||
verify(tvAttribution).movementMethod = any()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testAdjustCameraBasedOnOptions() {
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"adjustCameraBasedOnOptions"
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
verify(mapboxMap, times(1))
|
||||
.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnChanged() {
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"onChanged",
|
||||
CameraPosition::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, mock(CameraPosition::class.java))
|
||||
verify(mapboxMap, times(0)).cameraPosition
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnStyleLoaded() {
|
||||
whenever(modifyLocationButton.visibility).thenReturn(View.INVISIBLE)
|
||||
whenever(mapboxMap.uiSettings).thenReturn(mock(UiSettings::class.java))
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"onStyleLoaded",
|
||||
Style::class.java
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity, style)
|
||||
verify(modifyLocationButton, times(1)).visibility
|
||||
verify(mapboxMap, times(1))
|
||||
.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
|
||||
verify(mapboxMap, times(1)).uiSettings
|
||||
verify(mapboxMap, times(1)).addOnCameraMoveStartedListener(activity)
|
||||
verify(mapboxMap, times(1)).addOnCameraIdleListener(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnClickModifyLocation() {
|
||||
|
|
@ -223,12 +139,9 @@ class LocationPickerActivityUnitTests {
|
|||
verify(showInMapButton, times(1)).visibility = View.GONE
|
||||
verify(markerImage, times(1)).visibility = View.VISIBLE
|
||||
verify(shadow, times(1)).visibility = View.VISIBLE
|
||||
verify(droppedMarkerLayer, times(1)).setProperties(any())
|
||||
verify(largeToolbarText, times(1)).text = "Choose a location"
|
||||
verify(smallToolbarText, times(1)).text = "Pan and zoom to adjust"
|
||||
verify(fabCenterOnLocation, times(1)).visibility = View.VISIBLE
|
||||
verify(mapboxMap, times(1)).addOnCameraMoveStartedListener(activity)
|
||||
verify(mapboxMap, times(1)).addOnCameraIdleListener(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -236,27 +149,20 @@ class LocationPickerActivityUnitTests {
|
|||
fun testPlaceSelected() {
|
||||
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||
Whitebox.setInternalState(activity,"activity", "NoLocationUploadActivity")
|
||||
val position = CameraPosition.Builder().target(
|
||||
LatLng(
|
||||
51.50550,
|
||||
-0.07520,
|
||||
0.0
|
||||
)
|
||||
).zoom(15.0).build()
|
||||
`when`(mapboxMap.cameraPosition).thenReturn(position)
|
||||
val position = GeoPoint(51.50550, -0.07520)
|
||||
val method: Method = LocationPickerActivity::class.java.getDeclaredMethod(
|
||||
"placeSelected"
|
||||
)
|
||||
`when`(mapView.mapCenter).thenReturn(position)
|
||||
`when`(mapView.zoomLevel).thenReturn(15)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
verify(applicationKvStore, times(1))
|
||||
.putString(LAST_LOCATION, position.target!!.latitude.toString()
|
||||
+ ","
|
||||
+ position.target!!.longitude
|
||||
)
|
||||
verify(applicationKvStore, times(1))
|
||||
.putString(LAST_ZOOM, position.zoom.toString())
|
||||
verify(mapboxMap, times(4)).cameraPosition
|
||||
verify(applicationKvStore, times(1)).putString(
|
||||
LAST_LOCATION,
|
||||
position.latitude.toString() + "," + position.longitude.toString()
|
||||
)
|
||||
verify(applicationKvStore, times(1)).putString(LAST_ZOOM, mapView.zoomLevel.toString())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue