summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AttributionDialogManagerTest.java
blob: 42dfecf4926d2e9d6c7f492548b1ff932a10a8c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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.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.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.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));
  }


}