summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraInternalApiTest.java
blob: 2d01347d22f8db83f2badf5de97e4ab8e69c4642 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.mapbox.mapboxsdk.testapp.camera;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.rule.ActivityTestRule;
import android.view.View;

import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapViewUtils;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
import com.mapbox.mapboxsdk.testapp.utils.ViewUtils;

import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;

/**
 * Tests camera transformations that aren't part of our public API
 */
public class CameraInternalApiTest {

  @Rule
  public final ActivityTestRule<EspressoTestActivity> rule = new ActivityTestRule<>(EspressoTestActivity.class);

  private OnMapReadyIdlingResource idlingResource;

  @Before
  public void registerIdlingResource() {
    idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
    Espresso.registerIdlingResources(idlingResource);
  }

  @Test
  @Ignore
  public void testBearing() {
    ViewUtils.checkViewIsDisplayed(R.id.mapView);
    EspressoTestActivity activity = rule.getActivity();
    MapboxMap mapboxMap = activity.getMapboxMap();

    CameraPosition initialPosition = new
      CameraPosition.Builder().target(new LatLng()).zoom(1).bearing(0).tilt(0).build();
    CameraPosition cameraPosition = mapboxMap.getCameraPosition();
    assertEquals("Default camera position should match default", cameraPosition, initialPosition);

    onView(withId(R.id.mapView)).perform(new BearingAction(mapboxMap));
    assertEquals("Bearing should match", 45.1f, MapViewUtils.getDirection(mapboxMap), TestConstants.BEARING_DELTA);
  }

  @Test
  @Ignore
  public void testTilt() {
    ViewUtils.checkViewIsDisplayed(R.id.mapView);
    EspressoTestActivity activity = rule.getActivity();
    MapboxMap mapboxMap = activity.getMapboxMap();

    CameraPosition initialPosition = new CameraPosition.Builder().target(
      new LatLng()).zoom(1).bearing(0).tilt(0).build();
    CameraPosition cameraPosition = mapboxMap.getCameraPosition();
    assertEquals("Default camera position should match default", cameraPosition, initialPosition);

    onView(withId(R.id.mapView)).perform(new TiltAction(mapboxMap));
    assertEquals("Tilt should match", 40.0f, MapViewUtils.getTilt(mapboxMap), TestConstants.TILT_DELTA);
  }

  @Test
  @Ignore
  public void testLatLng() {
    ViewUtils.checkViewIsDisplayed(R.id.mapView);
    EspressoTestActivity activity = rule.getActivity();
    MapboxMap mapboxMap = activity.getMapboxMap();

    CameraPosition initialPosition = new CameraPosition.Builder().target(
      new LatLng()).zoom(1).bearing(0).tilt(0).build();
    CameraPosition cameraPosition = mapboxMap.getCameraPosition();
    assertEquals("Default camera position should match default", cameraPosition, initialPosition);

    onView(withId(R.id.mapView)).perform(new LatLngAction(mapboxMap));
    LatLng centerCoordinate = MapViewUtils.getLatLng(mapboxMap);
    assertEquals("Latitude should match", 1.1f, centerCoordinate.getLatitude(), TestConstants.LAT_LNG_DELTA);
    assertEquals("Longitude should match", 2.2f, centerCoordinate.getLongitude(), TestConstants.LAT_LNG_DELTA);
  }

  @After
  public void unregisterIdlingResource() {
    Espresso.unregisterIdlingResources(idlingResource);
  }

  private class BearingAction implements ViewAction {

    private MapboxMap mapboxMap;

    BearingAction(MapboxMap mapboxMap) {
      this.mapboxMap = mapboxMap;
    }

    @Override
    public Matcher<View> getConstraints() {
      return isDisplayed();
    }

    @Override
    public String getDescription() {
      return getClass().getSimpleName();
    }

    @Override
    public void perform(UiController uiController, View view) {
      MapViewUtils.setDirection(mapboxMap, -45.1f);
    }
  }

  private class TiltAction implements ViewAction {

    private MapboxMap mapboxMap;

    TiltAction(MapboxMap mapboxMap) {
      this.mapboxMap = mapboxMap;
    }

    @Override
    public Matcher<View> getConstraints() {
      return isDisplayed();
    }

    @Override
    public String getDescription() {
      return getClass().getSimpleName();
    }

    @Override
    public void perform(UiController uiController, View view) {
      MapViewUtils.setTilt(mapboxMap, 40.0f);
    }
  }

  private class LatLngAction implements ViewAction {

    private MapboxMap mapboxMap;

    LatLngAction(MapboxMap mapboxMap) {
      this.mapboxMap = mapboxMap;
    }

    @Override
    public Matcher<View> getConstraints() {
      return isDisplayed();
    }

    @Override
    public String getDescription() {
      return getClass().getSimpleName();
    }

    @Override
    public void perform(UiController uiController, View view) {
      MapViewUtils.setLatLng(mapboxMap, new LatLng(1.1, 2.2));
    }
  }
}