This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] Migrate Android SDK to GL JS–powered feedback form (#15623)
* [android] Add debug info. * [android] Generate feedback url. * [android] Add unit test for buildMapFeedbackMapUrl. * [android] Remove debug logging. * [android] Add github issue link to the TODO. * [android] Change getPackageName to application context.
- Loading branch information
Showing
2 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
99 changes: 99 additions & 0 deletions
99
...boxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AttributionDialogManagerTest.java
This file contains 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,99 @@ | ||
package com.mapbox.mapboxsdk.maps; | ||
|
||
import android.content.Context; | ||
|
||
import com.mapbox.mapboxsdk.camera.CameraPosition; | ||
import com.mapbox.mapboxsdk.geometry.LatLng; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class AttributionDialogManagerTest { | ||
@InjectMocks | ||
Context context = mock(Context.class); | ||
|
||
@InjectMocks | ||
MapboxMap mapboxMap = mock(MapboxMap.class); | ||
|
||
@InjectMocks | ||
Style style = mock(Style.class); | ||
|
||
private AttributionDialogManager attributionDialogManager; | ||
private CameraPosition cameraPosition; | ||
|
||
private static final String ASSERT_MAPBOX_TOKEN = "TestAccessToken"; | ||
|
||
private static final String ASSERT_MAPBOX_STYLE_URI = "mapbox://styles/mapbox/streets-v11"; | ||
private static final String ASSERT_MAPBOX_LOCAL_STYLE_URI = "asset://style.json"; | ||
|
||
private static final String ASSERT_MAPBOX_PACKAGE_NAME = "com.mapbox.attributionmanagertest"; | ||
|
||
private static final String ASSERT_MAPBOX_FEEDBACK_FINAL_URL = | ||
"https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&" | ||
+ "access_token=TestAccessToken&owner=mapbox&id=streets-v11" | ||
+ "#/22.200001/11.100000/12.000000/24.000000/5"; | ||
private static final String ASSERT_MAPBOX_FEEDHACK_FINAL_URL_LOCAL_STYLE = | ||
"https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&" | ||
+ "access_token=TestAccessToken#/22.200001/11.100000/12.000000/24.000000/5"; | ||
private static final String ASSERT_MAPBOX_FEEDBACL_FINAL_URL_NULL_CAMERA_POSITION = | ||
"https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&access_token=TestAccessToken"; | ||
|
||
@Before | ||
public void beforeTest() { | ||
attributionDialogManager = new AttributionDialogManager(context, mapboxMap); | ||
cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT) | ||
.tilt(5.0f).zoom(12).bearing(24.0f).target(new LatLng(11.1f, 22.2f)).build(); | ||
} | ||
|
||
@Test | ||
public void testSanity() { | ||
assertNotNull("AttributionDialogManager should not be null", attributionDialogManager); | ||
} | ||
|
||
@Test | ||
public void testBuildMapFeedbackMapUrl() { | ||
when(context.getApplicationContext()).thenReturn(context); | ||
when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME); | ||
when(style.getUri()).thenReturn(ASSERT_MAPBOX_STYLE_URI); | ||
when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition); | ||
when(mapboxMap.getStyle()).thenReturn(style); | ||
|
||
Assert.assertEquals(ASSERT_MAPBOX_FEEDBACK_FINAL_URL, | ||
attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN)); | ||
} | ||
|
||
@Test | ||
public void testBuildMapFeedbackMapUrlWithLocalStyleJson() { | ||
when(context.getApplicationContext()).thenReturn(context); | ||
when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME); | ||
when(style.getUri()).thenReturn(ASSERT_MAPBOX_LOCAL_STYLE_URI); | ||
when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition); | ||
when(mapboxMap.getStyle()).thenReturn(style); | ||
|
||
Assert.assertEquals(ASSERT_MAPBOX_FEEDHACK_FINAL_URL_LOCAL_STYLE, | ||
attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN)); | ||
} | ||
|
||
@Test | ||
public void testBuildMapFeedbackMapUrlWithNullCameraPosition() { | ||
when(context.getApplicationContext()).thenReturn(context); | ||
when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME); | ||
when(style.getUri()).thenReturn(ASSERT_MAPBOX_LOCAL_STYLE_URI); | ||
when(mapboxMap.getCameraPosition()).thenReturn(null); | ||
when(mapboxMap.getStyle()).thenReturn(style); | ||
|
||
Assert.assertEquals(ASSERT_MAPBOX_FEEDBACL_FINAL_URL_NULL_CAMERA_POSITION, | ||
attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN)); | ||
} | ||
|
||
|
||
} |