[android] - replace anonymous inner classes with lambda

This commit is contained in:
Tobrun
2017-11-23 10:09:05 +01:00
committed by Tobrun
parent 7f14f0270d
commit 1b0a5f633a
100 changed files with 7444 additions and 9585 deletions

View File

@@ -1,8 +1,6 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.view.View;
@@ -70,26 +68,24 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testTransitionDuration() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
long transitionDuration = 600;
mapboxMap.setTransitionDuration(transitionDuration);
assertEquals("TransitionDuration should match", transitionDuration, mapboxMap.getTransitionDuration(), 0);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
long transitionDuration = 600;
mapboxMap.setTransitionDuration(transitionDuration);
assertEquals(
"TransitionDuration should match", transitionDuration, mapboxMap.getTransitionDuration(), 0
);
}));
}
@Test
public void testTransitionDelay() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
long transitionDelay = 50;
mapboxMap.setTransitionDelay(transitionDelay);
assertEquals("TransitionDelay should match", transitionDelay, mapboxMap.getTransitionDelay(), 0);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
long transitionDelay = 50;
mapboxMap.setTransitionDelay(transitionDelay);
assertEquals(
"TransitionDelay should match", transitionDelay, mapboxMap.getTransitionDelay(), 0
);
}));
}
@@ -99,40 +95,34 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testCameraPositionOnFinish() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
final LatLng latLng = new LatLng(30.0, 30.0);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(latLng), new MapboxMap.CancelableCallback() {
@Override
public void onCancel() {
}
final LatLng latLng = new LatLng(30.0, 30.0);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(latLng), new MapboxMap.CancelableCallback() {
@Override
public void onCancel() {
}
@Override
public void onFinish() {
LatLng cameraPositionLatLng = mapboxMap.getCameraPosition().target;
Timber.d(cameraPositionLatLng.toString());
assertEquals(cameraPositionLatLng.getLatitude(), latLng.getLatitude(), LAT_LNG_DELTA);
assertEquals(cameraPositionLatLng.getLongitude(), latLng.getLongitude(), LAT_LNG_DELTA);
}
});
}
@Override
public void onFinish() {
LatLng cameraPositionLatLng = mapboxMap.getCameraPosition().target;
Timber.d(cameraPositionLatLng.toString());
assertEquals(cameraPositionLatLng.getLatitude(), latLng.getLatitude(), LAT_LNG_DELTA);
assertEquals(cameraPositionLatLng.getLongitude(), latLng.getLongitude(), LAT_LNG_DELTA);
}
});
}));
}
@Test
public void testCameraForLatLngBounds() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
// set
mapboxMap.setLatLngBoundsForCameraTarget(
new LatLngBounds.Builder().include(new LatLng()).include(new LatLng(1, 1)).build());
// reset
mapboxMap.setLatLngBoundsForCameraTarget(null);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
// set
mapboxMap.setLatLngBoundsForCameraTarget(
new LatLngBounds.Builder().include(new LatLng()).include(new LatLng(1, 1)).build());
// reset
mapboxMap.setLatLngBoundsForCameraTarget(null);
}));
}
@@ -143,12 +133,9 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testMinZoom() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.setMinZoomPreference(10);
assertEquals("MinZoom should match", 10, mapboxMap.getMinZoomLevel(), 10);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setMinZoomPreference(10);
assertEquals("MinZoom should match", 10, mapboxMap.getMinZoomLevel(), 10);
}));
}
@@ -156,12 +143,9 @@ public class MapboxMapTest extends BaseActivityTest {
public void testMaxZoom() {
validateTestSetup();
final double zoom = 10;
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.setMaxZoomPreference(zoom);
assertEquals("MaxZoom should match", zoom, mapboxMap.getMaxZoomLevel(), 10);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setMaxZoomPreference(zoom);
assertEquals("MaxZoom should match", zoom, mapboxMap.getMaxZoomLevel(), 10);
}));
}
@@ -169,14 +153,11 @@ public class MapboxMapTest extends BaseActivityTest {
@Ignore
public void testInitialZoomLevels() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
assertEquals("MaxZoom should match", MapboxConstants.MAXIMUM_ZOOM, mapboxMap.getMaxZoomLevel(),
TestConstants.ZOOM_DELTA);
assertEquals("MinZoom should match", MapboxConstants.MINIMUM_ZOOM, mapboxMap.getMinZoomLevel(),
TestConstants.ZOOM_DELTA);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
assertEquals("MaxZoom should match", MapboxConstants.MAXIMUM_ZOOM, mapboxMap.getMaxZoomLevel(),
TestConstants.ZOOM_DELTA);
assertEquals("MinZoom should match", MapboxConstants.MINIMUM_ZOOM, mapboxMap.getMinZoomLevel(),
TestConstants.ZOOM_DELTA);
}));
}
@@ -197,43 +178,28 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testConcurrentInfoWindowEnabled() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true);
assertTrue("ConcurrentWindows should be true", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(true);
assertTrue("ConcurrentWindows should be true", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
}));
}
@Test
public void testConcurrentInfoWindowDisabled() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false);
assertFalse("ConcurrentWindows should be false", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(false);
assertFalse("ConcurrentWindows should be false", mapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
}));
}
@Test
public void testInfoWindowAdapter() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MapboxMap.InfoWindowAdapter infoWindowAdapter = new MapboxMap.InfoWindowAdapter() {
@Nullable
@Override
public View getInfoWindow(@NonNull Marker marker) {
return null;
}
};
mapboxMap.setInfoWindowAdapter(infoWindowAdapter);
assertEquals("InfoWindowAdpter should be the same", infoWindowAdapter, mapboxMap.getInfoWindowAdapter());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MapboxMap.InfoWindowAdapter infoWindowAdapter = marker -> null;
mapboxMap.setInfoWindowAdapter(infoWindowAdapter);
assertEquals("InfoWindowAdpter should be the same", infoWindowAdapter, mapboxMap.getInfoWindowAdapter());
}));
}
@@ -245,12 +211,9 @@ public class MapboxMapTest extends BaseActivityTest {
@Ignore /* disabled due to enabling permissions during test #7177 */
public void testMyLocationEnabled() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.setMyLocationEnabled(true);
assertTrue("MyLocationEnabled should be true", mapboxMap.isMyLocationEnabled());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setMyLocationEnabled(true);
assertTrue("MyLocationEnabled should be true", mapboxMap.isMyLocationEnabled());
}));
}
@@ -258,12 +221,9 @@ public class MapboxMapTest extends BaseActivityTest {
@Ignore /* can't create handler inside thread that not called Looper.prepare() */
public void testMyLocationDisabled() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.setMyLocationEnabled(false);
assertFalse("MyLocationEnabled should be false", mapboxMap.isMyLocationEnabled());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setMyLocationEnabled(false);
assertFalse("MyLocationEnabled should be false", mapboxMap.isMyLocationEnabled());
}));
}
@@ -274,73 +234,49 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testFpsListener() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MapboxMap.OnFpsChangedListener fpsChangedListener = new MapboxMap.OnFpsChangedListener() {
@Override
public void onFpsChanged(double fps) {
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MapboxMap.OnFpsChangedListener fpsChangedListener = fps -> {
}
};
mapboxMap.setOnFpsChangedListener(fpsChangedListener);
assertEquals("FpsListener should match", fpsChangedListener, mapboxMap.getOnFpsChangedListener());
}
};
mapboxMap.setOnFpsChangedListener(fpsChangedListener);
assertEquals("FpsListener should match", fpsChangedListener, mapboxMap.getOnFpsChangedListener());
}));
}
@Test
public void testInfoWindowClickListener() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MapboxMap.OnInfoWindowClickListener clickListener = new MapboxMap.OnInfoWindowClickListener() {
@Override
public boolean onInfoWindowClick(@NonNull Marker marker) {
return false;
}
};
mapboxMap.setOnInfoWindowClickListener(clickListener);
assertEquals("InfoWidowClickListener should match", clickListener, mapboxMap.getOnInfoWindowClickListener());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MapboxMap.OnInfoWindowClickListener clickListener = marker -> false;
mapboxMap.setOnInfoWindowClickListener(clickListener);
assertEquals(
"InfoWidowClickListener should match", clickListener, mapboxMap.getOnInfoWindowClickListener()
);
}));
}
@Test
public void testInfoWindowCloseListener() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MapboxMap.OnInfoWindowCloseListener listener = new MapboxMap.OnInfoWindowCloseListener() {
@Override
public void onInfoWindowClose(Marker marker) {
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MapboxMap.OnInfoWindowCloseListener listener = marker -> {
}
};
mapboxMap.setOnInfoWindowCloseListener(listener);
assertEquals("InfoWindowCloseListener should match", listener, mapboxMap.getOnInfoWindowCloseListener());
}
};
mapboxMap.setOnInfoWindowCloseListener(listener);
assertEquals("InfoWindowCloseListener should match", listener, mapboxMap.getOnInfoWindowCloseListener());
}));
}
@Test
public void testInfoWindowLongClickListener() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MapboxMap.OnInfoWindowLongClickListener listener = new MapboxMap.OnInfoWindowLongClickListener() {
@Override
public void onInfoWindowLongClick(Marker marker) {
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MapboxMap.OnInfoWindowLongClickListener listener = marker -> {
}
};
mapboxMap.setOnInfoWindowLongClickListener(listener);
assertEquals("InfoWindowLongClickListener should match", listener,
mapboxMap.getOnInfoWindowLongClickListener());
}
};
mapboxMap.setOnInfoWindowLongClickListener(listener);
assertEquals("InfoWindowLongClickListener should match", listener,
mapboxMap.getOnInfoWindowLongClickListener());
}));
}
@@ -351,13 +287,10 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testAddMarker() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
assertTrue("Marker should be contained", mapboxMap.getMarkers().contains(marker));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
assertTrue("Marker should be contained", mapboxMap.getMarkers().contains(marker));
}));
}
@@ -369,442 +302,356 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testAddMarkers() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a");
MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b");
markerList.add(markerOptions1);
markerList.add(markerOptions2);
List<Marker> markers = mapboxMap.addMarkers(markerList);
assertEquals("Markers size should be 2", 2, mapboxMap.getMarkers().size());
assertTrue(mapboxMap.getMarkers().contains(markers.get(0)));
assertTrue(mapboxMap.getMarkers().contains(markers.get(1)));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a");
MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b");
markerList.add(markerOptions1);
markerList.add(markerOptions2);
List<Marker> markers = mapboxMap.addMarkers(markerList);
assertEquals("Markers size should be 2", 2, mapboxMap.getMarkers().size());
assertTrue(mapboxMap.getMarkers().contains(markers.get(0)));
assertTrue(mapboxMap.getMarkers().contains(markers.get(1)));
}));
}
@Test
public void testAddMarkersEmpty() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<BaseMarkerOptions> markerList = new ArrayList<>();
mapboxMap.addMarkers(markerList);
assertEquals("Markers size should be 0", 0, mapboxMap.getMarkers().size());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<BaseMarkerOptions> markerList = new ArrayList<>();
mapboxMap.addMarkers(markerList);
assertEquals("Markers size should be 0", 0, mapboxMap.getMarkers().size());
}));
}
@Test
public void testAddMarkersSingleMarker() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng());
markerList.add(markerOptions);
List<Marker> markers = mapboxMap.addMarkers(markerList);
assertEquals("Markers size should be 1", 1, mapboxMap.getMarkers().size());
assertTrue(mapboxMap.getMarkers().contains(markers.get(0)));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng());
markerList.add(markerOptions);
List<Marker> markers = mapboxMap.addMarkers(markerList);
assertEquals("Markers size should be 1", 1, mapboxMap.getMarkers().size());
assertTrue(mapboxMap.getMarkers().contains(markers.get(0)));
}));
}
@Test
public void testAddPolygon() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
PolygonOptions polygonOptions = new PolygonOptions().add(new LatLng());
Polygon polygon = mapboxMap.addPolygon(polygonOptions);
assertTrue("Polygon should be contained", mapboxMap.getPolygons().contains(polygon));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
PolygonOptions polygonOptions = new PolygonOptions().add(new LatLng());
Polygon polygon = mapboxMap.addPolygon(polygonOptions);
assertTrue("Polygon should be contained", mapboxMap.getPolygons().contains(polygon));
}));
}
@Test
public void testAddEmptyPolygon() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
PolygonOptions polygonOptions = new PolygonOptions();
Polygon polygon = mapboxMap.addPolygon(polygonOptions);
assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygon));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
PolygonOptions polygonOptions = new PolygonOptions();
Polygon polygon = mapboxMap.addPolygon(polygonOptions);
assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygon));
}));
}
@Test
public void testAddPolygons() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<PolygonOptions> polygonList = new ArrayList<>();
PolygonOptions polygonOptions1 = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng());
PolygonOptions polygonOptions2 = new PolygonOptions().fillColor(Color.WHITE).add(new LatLng());
PolygonOptions polygonOptions3 = new PolygonOptions();
polygonList.add(polygonOptions1);
polygonList.add(polygonOptions2);
polygonList.add(polygonOptions3);
mapboxMap.addPolygons(polygonList);
assertEquals("Polygons size should be 2", 2, mapboxMap.getPolygons().size());
assertTrue(mapboxMap.getPolygons().contains(polygonOptions1.getPolygon()));
assertTrue(mapboxMap.getPolygons().contains(polygonOptions2.getPolygon()));
assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygonOptions3.getPolygon()));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<PolygonOptions> polygonList = new ArrayList<>();
PolygonOptions polygonOptions1 = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng());
PolygonOptions polygonOptions2 = new PolygonOptions().fillColor(Color.WHITE).add(new LatLng());
PolygonOptions polygonOptions3 = new PolygonOptions();
polygonList.add(polygonOptions1);
polygonList.add(polygonOptions2);
polygonList.add(polygonOptions3);
mapboxMap.addPolygons(polygonList);
assertEquals("Polygons size should be 2", 2, mapboxMap.getPolygons().size());
assertTrue(mapboxMap.getPolygons().contains(polygonOptions1.getPolygon()));
assertTrue(mapboxMap.getPolygons().contains(polygonOptions2.getPolygon()));
assertTrue("Polygon should be ignored", !mapboxMap.getPolygons().contains(polygonOptions3.getPolygon()));
}));
}
@Test
public void addPolygonsEmpty() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.addPolygons(new ArrayList<PolygonOptions>());
assertEquals("Polygons size should be 0", 0, mapboxMap.getPolygons().size());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.addPolygons(new ArrayList<PolygonOptions>());
assertEquals("Polygons size should be 0", 0, mapboxMap.getPolygons().size());
}));
}
@Test
public void addPolygonsSingle() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<PolygonOptions> polygonList = new ArrayList<>();
PolygonOptions polygonOptions = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng());
polygonList.add(polygonOptions);
mapboxMap.addPolygons(polygonList);
assertEquals("Polygons size should be 1", 1, mapboxMap.getPolygons().size());
assertTrue(mapboxMap.getPolygons().contains(polygonOptions.getPolygon()));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<PolygonOptions> polygonList = new ArrayList<>();
PolygonOptions polygonOptions = new PolygonOptions().fillColor(Color.BLACK).add(new LatLng());
polygonList.add(polygonOptions);
mapboxMap.addPolygons(polygonList);
assertEquals("Polygons size should be 1", 1, mapboxMap.getPolygons().size());
assertTrue(mapboxMap.getPolygons().contains(polygonOptions.getPolygon()));
}));
}
@Test
public void testAddPolyline() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
PolylineOptions polylineOptions = new PolylineOptions().add(new LatLng());
Polyline polyline = mapboxMap.addPolyline(polylineOptions);
assertTrue("Polyline should be contained", mapboxMap.getPolylines().contains(polyline));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
PolylineOptions polylineOptions = new PolylineOptions().add(new LatLng());
Polyline polyline = mapboxMap.addPolyline(polylineOptions);
assertTrue("Polyline should be contained", mapboxMap.getPolylines().contains(polyline));
}));
}
@Test
public void testAddEmptyPolyline() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
PolylineOptions polylineOptions = new PolylineOptions();
Polyline polyline = mapboxMap.addPolyline(polylineOptions);
assertTrue("Polyline should be ignored", !mapboxMap.getPolylines().contains(polyline));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
PolylineOptions polylineOptions = new PolylineOptions();
Polyline polyline = mapboxMap.addPolyline(polylineOptions);
assertTrue("Polyline should be ignored", !mapboxMap.getPolylines().contains(polyline));
}));
}
@Test
public void testAddPolylines() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<PolylineOptions> polylineList = new ArrayList<>();
PolylineOptions polygonOptions1 = new PolylineOptions().color(Color.BLACK).add(new LatLng());
PolylineOptions polygonOptions2 = new PolylineOptions().color(Color.WHITE).add(new LatLng());
PolylineOptions polygonOptions3 = new PolylineOptions();
polylineList.add(polygonOptions1);
polylineList.add(polygonOptions2);
polylineList.add(polygonOptions3);
mapboxMap.addPolylines(polylineList);
assertEquals("Polygons size should be 2", 2, mapboxMap.getPolylines().size());
assertTrue(mapboxMap.getPolylines().contains(polygonOptions1.getPolyline()));
assertTrue(mapboxMap.getPolylines().contains(polygonOptions2.getPolyline()));
assertTrue("Polyline should be ignored", !mapboxMap.getPolylines().contains(polygonOptions3.getPolyline()));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<PolylineOptions> polylineList = new ArrayList<>();
PolylineOptions polygonOptions1 = new PolylineOptions().color(Color.BLACK).add(new LatLng());
PolylineOptions polygonOptions2 = new PolylineOptions().color(Color.WHITE).add(new LatLng());
PolylineOptions polygonOptions3 = new PolylineOptions();
polylineList.add(polygonOptions1);
polylineList.add(polygonOptions2);
polylineList.add(polygonOptions3);
mapboxMap.addPolylines(polylineList);
assertEquals("Polygons size should be 2", 2, mapboxMap.getPolylines().size());
assertTrue(mapboxMap.getPolylines().contains(polygonOptions1.getPolyline()));
assertTrue(mapboxMap.getPolylines().contains(polygonOptions2.getPolyline()));
assertTrue(
"Polyline should be ignored", !mapboxMap.getPolylines().contains(polygonOptions3.getPolyline())
);
}));
}
@Test
public void testAddPolylinesEmpty() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.addPolylines(new ArrayList<PolylineOptions>());
assertEquals("Polygons size should be 0", 0, mapboxMap.getPolylines().size());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.addPolylines(new ArrayList<PolylineOptions>());
assertEquals("Polygons size should be 0", 0, mapboxMap.getPolylines().size());
}));
}
@Test
public void testAddPolylinesSingle() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<PolylineOptions> polylineList = new ArrayList<>();
PolylineOptions polygonOptions = new PolylineOptions().color(Color.BLACK).add(new LatLng());
polylineList.add(polygonOptions);
mapboxMap.addPolylines(polylineList);
assertEquals("Polygons size should be 1", 1, mapboxMap.getPolylines().size());
assertTrue(mapboxMap.getPolylines().contains(polygonOptions.getPolyline()));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<PolylineOptions> polylineList = new ArrayList<>();
PolylineOptions polygonOptions = new PolylineOptions().color(Color.BLACK).add(new LatLng());
polylineList.add(polygonOptions);
mapboxMap.addPolylines(polylineList);
assertEquals("Polygons size should be 1", 1, mapboxMap.getPolylines().size());
assertTrue(mapboxMap.getPolylines().contains(polygonOptions.getPolyline()));
}));
}
@Test
public void testRemoveMarker() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.removeMarker(marker);
assertTrue("Markers should be empty", mapboxMap.getMarkers().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.removeMarker(marker);
assertTrue("Markers should be empty", mapboxMap.getMarkers().isEmpty());
}));
}
@Test
public void testRemovePolygon() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
PolygonOptions polygonOptions = new PolygonOptions();
Polygon polygon = mapboxMap.addPolygon(polygonOptions);
mapboxMap.removePolygon(polygon);
assertTrue("Polygons should be empty", mapboxMap.getPolylines().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
PolygonOptions polygonOptions = new PolygonOptions();
Polygon polygon = mapboxMap.addPolygon(polygonOptions);
mapboxMap.removePolygon(polygon);
assertTrue("Polygons should be empty", mapboxMap.getPolylines().isEmpty());
}));
}
@Test
public void testRemovePolyline() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
PolylineOptions polylineOptions = new PolylineOptions();
Polyline polyline = mapboxMap.addPolyline(polylineOptions);
mapboxMap.removePolyline(polyline);
assertTrue("Polylines should be empty", mapboxMap.getPolylines().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
PolylineOptions polylineOptions = new PolylineOptions();
Polyline polyline = mapboxMap.addPolyline(polylineOptions);
mapboxMap.removePolyline(polyline);
assertTrue("Polylines should be empty", mapboxMap.getPolylines().isEmpty());
}));
}
@Test
public void testRemoveAnnotation() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.removeAnnotation(marker);
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.removeAnnotation(marker);
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}));
}
@Test
public void testRemoveAnnotationById() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
mapboxMap.addMarker(markerOptions);
// id will always be 0 in unit tests
mapboxMap.removeAnnotation(0);
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
mapboxMap.addMarker(markerOptions);
// id will always be 0 in unit tests
mapboxMap.removeAnnotation(0);
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}));
}
@Test
public void testRemoveAnnotations() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
markerList.add(markerOptions1);
markerList.add(markerOptions2);
mapboxMap.addMarkers(markerList);
mapboxMap.removeAnnotations();
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
markerList.add(markerOptions1);
markerList.add(markerOptions2);
mapboxMap.addMarkers(markerList);
mapboxMap.removeAnnotations();
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}));
}
@Test
public void testClear() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
markerList.add(markerOptions1);
markerList.add(markerOptions2);
mapboxMap.addMarkers(markerList);
mapboxMap.clear();
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
markerList.add(markerOptions1);
markerList.add(markerOptions2);
mapboxMap.addMarkers(markerList);
mapboxMap.clear();
assertTrue("Annotations should be empty", mapboxMap.getAnnotations().isEmpty());
}));
}
@Test
public void testRemoveAnnotationsByList() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
markerList.add(markerOptions1);
markerList.add(markerOptions2);
List<Marker> markers = mapboxMap.addMarkers(markerList);
Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng()).title("c"));
mapboxMap.removeAnnotations(markers);
assertTrue("Annotations should not be empty", mapboxMap.getAnnotations().size() == 1);
assertTrue("Marker should be contained", mapboxMap.getAnnotations().contains(marker));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
List<BaseMarkerOptions> markerList = new ArrayList<>();
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
markerList.add(markerOptions1);
markerList.add(markerOptions2);
List<Marker> markers = mapboxMap.addMarkers(markerList);
Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng()).title("c"));
mapboxMap.removeAnnotations(markers);
assertTrue("Annotations should not be empty", mapboxMap.getAnnotations().size() == 1);
assertTrue("Marker should be contained", mapboxMap.getAnnotations().contains(marker));
}));
}
@Test
public void testGetAnnotationById() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker initialMarker = mapboxMap.addMarker(markerOptions);
Marker retrievedMarker = (Marker) mapboxMap.getAnnotation(0);
assertEquals("Markers should match", initialMarker, retrievedMarker);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker initialMarker = mapboxMap.addMarker(markerOptions);
Marker retrievedMarker = (Marker) mapboxMap.getAnnotation(0);
assertEquals("Markers should match", initialMarker, retrievedMarker);
}));
}
@Test
public void testGetAnnotations() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
assertNotNull("Annotations should be non null", mapboxMap.getAnnotations());
}
}));
onView(withId(R.id.mapView)).perform(
new MapboxMapAction((uiController, view) ->
assertNotNull("Annotations should be non null", mapboxMap.getAnnotations()))
);
}
@Test
public void testGetMarkers() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
assertNotNull("Markers should be non null", mapboxMap.getMarkers());
}
}));
onView(withId(R.id.mapView)).perform(
new MapboxMapAction((uiController, view) ->
assertNotNull("Markers should be non null", mapboxMap.getMarkers()))
);
}
@Test
public void testGetPolygons() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
assertNotNull("Polygons should be non null", mapboxMap.getPolygons());
}
}));
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) ->
assertNotNull("Polygons should be non null", mapboxMap.getPolygons()))
);
}
@Test
public void testGetPolylines() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
assertNotNull("Polylines should be non null", mapboxMap.getPolylines());
}
}));
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) ->
assertNotNull("Polylines should be non null", mapboxMap.getPolylines()))
);
}
@Test
public void testGetSelectedMarkers() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
assertNotNull("Selected markers should be non null", mapboxMap.getSelectedMarkers());
}
}));
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) ->
assertNotNull("Selected markers should be non null", mapboxMap.getSelectedMarkers()))
);
}
@Test
public void testSelectMarker() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.selectMarker(marker);
assertTrue("Marker should be contained", mapboxMap.getSelectedMarkers().contains(marker));
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.selectMarker(marker);
assertTrue("Marker should be contained", mapboxMap.getSelectedMarkers().contains(marker));
}));
}
@Test
public void testDeselectMarker() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.selectMarker(marker);
mapboxMap.deselectMarker(marker);
assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker = mapboxMap.addMarker(markerOptions);
mapboxMap.selectMarker(marker);
mapboxMap.deselectMarker(marker);
assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty());
}));
}
@Test
public void testDeselectMarkers() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker1 = mapboxMap.addMarker(markerOptions);
Marker marker2 = mapboxMap.addMarker(markerOptions);
mapboxMap.selectMarker(marker1);
mapboxMap.selectMarker(marker2);
mapboxMap.deselectMarkers();
assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
Marker marker1 = mapboxMap.addMarker(markerOptions);
Marker marker2 = mapboxMap.addMarker(markerOptions);
mapboxMap.selectMarker(marker1);
mapboxMap.selectMarker(marker2);
mapboxMap.deselectMarkers();
assertTrue("Selected markers should be empty", mapboxMap.getSelectedMarkers().isEmpty());
}));
}
@@ -813,14 +660,11 @@ public class MapboxMapTest extends BaseActivityTest {
@Test
public void testTilePrefetch() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
mapboxMap.setPrefetchesTiles(true);
assertTrue(mapboxMap.getPrefetchesTiles());
mapboxMap.setPrefetchesTiles(false);
assertFalse(mapboxMap.getPrefetchesTiles());
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setPrefetchesTiles(true);
assertTrue(mapboxMap.getPrefetchesTiles());
mapboxMap.setPrefetchesTiles(false);
assertFalse(mapboxMap.getPrefetchesTiles());
}));
}

View File

@@ -1,11 +1,8 @@
package com.mapbox.mapboxsdk.testapp.annotations;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
@@ -34,25 +31,22 @@ public class MarkerTest extends BaseActivityTest {
@Ignore
public void addMarkerTest() {
validateTestSetup();
MapboxMapAction.invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());
MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());
MarkerOptions options = new MarkerOptions();
options.setPosition(new LatLng());
options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET);
options.setTitle(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
MarkerOptions options = new MarkerOptions();
options.setPosition(new LatLng());
options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET);
options.setTitle(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
assertEquals("Markers size should be 1, ", 1, mapboxMap.getMarkers().size());
assertEquals("Marker id should be 0", 0, marker.getId());
assertEquals("Marker target should match", new LatLng(), marker.getPosition());
assertEquals("Marker snippet should match", TestConstants.TEXT_MARKER_SNIPPET, marker.getSnippet());
assertEquals("Marker target should match", TestConstants.TEXT_MARKER_TITLE, marker.getTitle());
mapboxMap.clear();
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());
}
assertEquals("Markers size should be 1, ", 1, mapboxMap.getMarkers().size());
assertEquals("Marker id should be 0", 0, marker.getId());
assertEquals("Marker target should match", new LatLng(), marker.getPosition());
assertEquals("Marker snippet should match", TestConstants.TEXT_MARKER_SNIPPET, marker.getSnippet());
assertEquals("Marker target should match", TestConstants.TEXT_MARKER_TITLE, marker.getTitle());
mapboxMap.clear();
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());
});
}
@@ -60,16 +54,13 @@ public class MarkerTest extends BaseActivityTest {
@Ignore
public void showInfoWindowTest() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final MarkerOptions options = new MarkerOptions();
options.setPosition(new LatLng());
options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET);
options.setTitle(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
mapboxMap.selectMarker(marker);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final MarkerOptions options = new MarkerOptions();
options.setPosition(new LatLng());
options.setSnippet(TestConstants.TEXT_MARKER_SNIPPET);
options.setTitle(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
mapboxMap.selectMarker(marker);
});
onView(withText(TestConstants.TEXT_MARKER_TITLE)).check(matches(isDisplayed()));
onView(withText(TestConstants.TEXT_MARKER_SNIPPET)).check(matches(isDisplayed()));

View File

@@ -1,11 +1,7 @@
package com.mapbox.mapboxsdk.testapp.annotations;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.annotation.MarkerViewActivity;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
@@ -36,24 +32,21 @@ public class MarkerViewTest extends BaseActivityTest {
public void addMarkerViewTest() {
validateTestSetup();
addAdapter();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());
TextMarkerViewOptions options = new TextMarkerViewOptions();
options.text(TestConstants.TEXT_MARKER_TEXT);
options.position(new LatLng());
options.snippet(TestConstants.TEXT_MARKER_SNIPPET);
options.title(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
assertEquals("Markers size should be 1, ", 1, mapboxMap.getMarkers().size());
assertEquals("Marker id should be 0", 0, marker.getId());
assertEquals("Marker target should match", new LatLng(), marker.getPosition());
assertEquals("Marker snippet should match", TestConstants.TEXT_MARKER_SNIPPET, marker.getSnippet());
assertEquals("Marker target should match", TestConstants.TEXT_MARKER_TITLE, marker.getTitle());
uiController.loopMainThreadForAtLeast(500);
}
TextMarkerViewOptions options = new TextMarkerViewOptions();
options.text(TestConstants.TEXT_MARKER_TEXT);
options.position(new LatLng());
options.snippet(TestConstants.TEXT_MARKER_SNIPPET);
options.title(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
assertEquals("Markers size should be 1, ", 1, mapboxMap.getMarkers().size());
assertEquals("Marker id should be 0", 0, marker.getId());
assertEquals("Marker target should match", new LatLng(), marker.getPosition());
assertEquals("Marker snippet should match", TestConstants.TEXT_MARKER_SNIPPET, marker.getSnippet());
assertEquals("Marker target should match", TestConstants.TEXT_MARKER_TITLE, marker.getTitle());
uiController.loopMainThreadForAtLeast(500);
});
onView(withText(TestConstants.TEXT_MARKER_TEXT)).check(matches(isDisplayed()));
}
@@ -63,18 +56,15 @@ public class MarkerViewTest extends BaseActivityTest {
public void showInfoWindowTest() {
validateTestSetup();
addAdapter();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final TextMarkerViewOptions options = new TextMarkerViewOptions();
options.position(new LatLng());
options.text(TestConstants.TEXT_MARKER_TEXT);
options.snippet(TestConstants.TEXT_MARKER_SNIPPET);
options.title(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
uiController.loopMainThreadForAtLeast(500);
mapboxMap.selectMarker(marker);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final TextMarkerViewOptions options = new TextMarkerViewOptions();
options.position(new LatLng());
options.text(TestConstants.TEXT_MARKER_TEXT);
options.snippet(TestConstants.TEXT_MARKER_SNIPPET);
options.title(TestConstants.TEXT_MARKER_TITLE);
marker = mapboxMap.addMarker(options);
uiController.loopMainThreadForAtLeast(500);
mapboxMap.selectMarker(marker);
});
onView(withText(TestConstants.TEXT_MARKER_TEXT)).check(matches(isDisplayed()));
onView(withText(TestConstants.TEXT_MARKER_TITLE)).check(matches(isDisplayed()));
@@ -82,13 +72,8 @@ public class MarkerViewTest extends BaseActivityTest {
}
private void addAdapter() {
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
mapboxMap.getMarkerViewManager().addMarkerViewAdapter(
new MarkerViewActivity.TextAdapter(rule.getActivity(), mapboxMap));
}
});
invoke(mapboxMap, (uiController, mapboxMap) -> mapboxMap.getMarkerViewManager().addMarkerViewAdapter(
new MarkerViewActivity.TextAdapter(rule.getActivity(), mapboxMap)));
}
}

View File

@@ -1,13 +1,10 @@
package com.mapbox.mapboxsdk.testapp.annotations;
import android.graphics.Color;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
@@ -28,31 +25,28 @@ public class PolygonTest extends BaseActivityTest {
@Ignore
public void addPolygonTest() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
LatLng latLngOne = new LatLng();
LatLng latLngTwo = new LatLng(1, 0);
LatLng latLngThree = new LatLng(1, 1);
invoke(mapboxMap, (uiController, mapboxMap) -> {
LatLng latLngOne = new LatLng();
LatLng latLngTwo = new LatLng(1, 0);
LatLng latLngThree = new LatLng(1, 1);
assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size());
assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size());
final PolygonOptions options = new PolygonOptions();
options.strokeColor(Color.BLUE);
options.fillColor(Color.RED);
options.add(latLngOne);
options.add(latLngTwo);
options.add(latLngThree);
Polygon polygon = mapboxMap.addPolygon(options);
final PolygonOptions options = new PolygonOptions();
options.strokeColor(Color.BLUE);
options.fillColor(Color.RED);
options.add(latLngOne);
options.add(latLngTwo);
options.add(latLngThree);
Polygon polygon = mapboxMap.addPolygon(options);
assertEquals("Polygons should be 1", 1, mapboxMap.getPolygons().size());
assertEquals("Polygon id should be 0", 0, polygon.getId());
assertEquals("Polygon points size should match", 3, polygon.getPoints().size());
assertEquals("Polygon stroke color should match", Color.BLUE, polygon.getStrokeColor());
assertEquals("Polygon target should match", Color.RED, polygon.getFillColor());
mapboxMap.clear();
assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size());
}
assertEquals("Polygons should be 1", 1, mapboxMap.getPolygons().size());
assertEquals("Polygon id should be 0", 0, polygon.getId());
assertEquals("Polygon points size should match", 3, polygon.getPoints().size());
assertEquals("Polygon stroke color should match", Color.BLUE, polygon.getStrokeColor());
assertEquals("Polygon target should match", Color.RED, polygon.getFillColor());
mapboxMap.clear();
assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size());
});
}
}

View File

@@ -1,13 +1,10 @@
package com.mapbox.mapboxsdk.testapp.annotations;
import android.graphics.Color;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
@@ -28,27 +25,24 @@ public class PolylineTest extends BaseActivityTest {
@Ignore
public void addPolylineTest() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
LatLng latLngOne = new LatLng();
LatLng latLngTwo = new LatLng(1, 0);
invoke(mapboxMap, (uiController, mapboxMap) -> {
LatLng latLngOne = new LatLng();
LatLng latLngTwo = new LatLng(1, 0);
assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size());
assertEquals("Polygons should be empty", 0, mapboxMap.getPolygons().size());
final PolylineOptions options = new PolylineOptions();
options.color(Color.BLUE);
options.add(latLngOne);
options.add(latLngTwo);
Polyline polyline = mapboxMap.addPolyline(options);
final PolylineOptions options = new PolylineOptions();
options.color(Color.BLUE);
options.add(latLngOne);
options.add(latLngTwo);
Polyline polyline = mapboxMap.addPolyline(options);
assertEquals("Polylines should be 1", 1, mapboxMap.getPolylines().size());
assertEquals("Polyline id should be 0", 0, polyline.getId());
assertEquals("Polyline points size should match", 2, polyline.getPoints().size());
assertEquals("Polyline stroke color should match", Color.BLUE, polyline.getColor());
mapboxMap.clear();
assertEquals("Polyline should be empty", 0, mapboxMap.getPolylines().size());
}
assertEquals("Polylines should be 1", 1, mapboxMap.getPolylines().size());
assertEquals("Polyline id should be 0", 0, polyline.getId());
assertEquals("Polyline points size should match", 2, polyline.getPoints().size());
assertEquals("Polyline stroke color should match", Color.BLUE, polyline.getColor());
mapboxMap.clear();
assertEquals("Polyline should be empty", 0, mapboxMap.getPolylines().size());
});
}
}

View File

@@ -1,14 +1,11 @@
package com.mapbox.mapboxsdk.testapp.camera;
import android.graphics.PointF;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
@@ -30,23 +27,20 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToCameraPositionTarget() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
LatLng moveTarget = new LatLng(1, 1);
CameraPosition initialPosition = new CameraPosition.Builder().target(
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(moveTarget));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
LatLng moveTarget = new LatLng(1, 1);
CameraPosition initialPosition = new CameraPosition.Builder().target(
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(moveTarget));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
});
}
@@ -54,20 +48,17 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToCameraPositionTargetZoom() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final float moveZoom = 15.5f;
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final float moveZoom = 15.5f;
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
});
}
@@ -75,32 +66,29 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToCameraPosition() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
final float moveZoom = 15.5f;
final float moveTilt = 45.5f;
final float moveBearing = 12.5f;
invoke(mapboxMap, (uiController, mapboxMap) -> {
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
final float moveZoom = 15.5f;
final float moveTilt = 45.5f;
final float moveBearing = 12.5f;
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(moveTarget)
.zoom(moveZoom)
.tilt(moveTilt)
.bearing(moveBearing)
.build())
);
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
}
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(moveTarget)
.zoom(moveZoom)
.tilt(moveTilt)
.bearing(moveBearing)
.build())
);
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
});
}
@@ -108,27 +96,24 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToBounds() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final LatLng centerBounds = new LatLng(1, 1);
LatLng cornerOne = new LatLng();
LatLng cornerTwo = new LatLng(2, 2);
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(cornerOne);
builder.include(cornerTwo);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match center bounds",
cameraPosition.target.getLatitude(),
centerBounds.getLatitude(),
TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match center bounds",
cameraPosition.target.getLongitude(),
centerBounds.getLongitude(),
TestConstants.LAT_LNG_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final LatLng centerBounds = new LatLng(1, 1);
LatLng cornerOne = new LatLng();
LatLng cornerTwo = new LatLng(2, 2);
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(cornerOne);
builder.include(cornerTwo);
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match center bounds",
cameraPosition.target.getLatitude(),
centerBounds.getLatitude(),
TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match center bounds",
cameraPosition.target.getLongitude(),
centerBounds.getLongitude(),
TestConstants.LAT_LNG_DELTA);
});
}
@@ -136,21 +121,18 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToMoveBy() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target);
final LatLng moveTarget = new LatLng(2, 2);
final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget);
mapboxMap.animateCamera(CameraUpdateFactory.scrollBy(
moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target);
final LatLng moveTarget = new LatLng(2, 2);
final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget);
mapboxMap.animateCamera(CameraUpdateFactory.scrollBy(
moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE);
});
}
@@ -158,16 +140,13 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToZoomIn() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
mapboxMap.animateCamera(CameraUpdateFactory.zoomIn());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
mapboxMap.animateCamera(CameraUpdateFactory.zoomIn());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1,
TestConstants.ZOOM_DELTA);
});
}
@@ -175,18 +154,15 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToZoomOut() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 10.0f;
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
mapboxMap.animateCamera(CameraUpdateFactory.zoomOut());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 10.0f;
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
mapboxMap.animateCamera(CameraUpdateFactory.zoomOut());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1,
TestConstants.ZOOM_DELTA);
});
}
@@ -194,17 +170,14 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToZoomBy() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
final float zoomBy = 2.45f;
mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(zoomBy));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
final float zoomBy = 2.45f;
mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(zoomBy));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy,
TestConstants.ZOOM_DELTA);
});
}
@@ -212,16 +185,13 @@ public class CameraAnimateTest extends BaseActivityTest {
@Ignore
public void testAnimateToZoomTo() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final float zoomTo = 2.45f;
mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(zoomTo));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final float zoomTo = 2.45f;
mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(zoomTo));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo,
TestConstants.ZOOM_DELTA);
});
}
}

View File

@@ -1,14 +1,11 @@
package com.mapbox.mapboxsdk.testapp.camera;
import android.graphics.PointF;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
@@ -30,23 +27,20 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToCameraPositionTarget() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
LatLng moveTarget = new LatLng(1, 1);
CameraPosition initialPosition = new CameraPosition.Builder().target(
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(moveTarget));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
LatLng moveTarget = new LatLng(1, 1);
CameraPosition initialPosition = new CameraPosition.Builder().target(
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(moveTarget));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
});
}
@@ -54,20 +48,17 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToCameraPositionTargetZoom() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final float moveZoom = 15.5f;
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final float moveZoom = 15.5f;
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
});
}
@@ -75,32 +66,29 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToCameraPosition() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
final float moveZoom = 15.5f;
final float moveTilt = 45.5f;
final float moveBearing = 12.5f;
invoke(mapboxMap, (uiController, mapboxMap) -> {
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
final float moveZoom = 15.5f;
final float moveTilt = 45.5f;
final float moveBearing = 12.5f;
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(moveTarget)
.zoom(moveZoom)
.tilt(moveTilt)
.bearing(moveBearing)
.build())
);
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
}
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(moveTarget)
.zoom(moveZoom)
.tilt(moveTilt)
.bearing(moveBearing)
.build())
);
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
});
}
@@ -108,27 +96,24 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToBounds() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final LatLng centerBounds = new LatLng(1, 1);
LatLng cornerOne = new LatLng();
LatLng cornerTwo = new LatLng(2, 2);
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(cornerOne);
builder.include(cornerTwo);
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match center bounds",
cameraPosition.target.getLatitude(),
centerBounds.getLatitude(),
TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match center bounds",
cameraPosition.target.getLongitude(),
centerBounds.getLongitude(),
TestConstants.LAT_LNG_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final LatLng centerBounds = new LatLng(1, 1);
LatLng cornerOne = new LatLng();
LatLng cornerTwo = new LatLng(2, 2);
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(cornerOne);
builder.include(cornerTwo);
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match center bounds",
cameraPosition.target.getLatitude(),
centerBounds.getLatitude(),
TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match center bounds",
cameraPosition.target.getLongitude(),
centerBounds.getLongitude(),
TestConstants.LAT_LNG_DELTA);
});
}
@@ -136,21 +121,18 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToMoveBy() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target);
final LatLng moveTarget = new LatLng(2, 2);
final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget);
mapboxMap.easeCamera(CameraUpdateFactory.scrollBy(
moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target);
final LatLng moveTarget = new LatLng(2, 2);
final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget);
mapboxMap.easeCamera(CameraUpdateFactory.scrollBy(
moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE);
});
}
@@ -158,16 +140,13 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToZoomIn() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
mapboxMap.easeCamera(CameraUpdateFactory.zoomIn());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
mapboxMap.easeCamera(CameraUpdateFactory.zoomIn());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1,
TestConstants.ZOOM_DELTA);
});
}
@@ -175,18 +154,15 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToZoomOut() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 10.0f;
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
mapboxMap.easeCamera(CameraUpdateFactory.zoomOut());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 10.0f;
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
mapboxMap.easeCamera(CameraUpdateFactory.zoomOut());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1,
TestConstants.ZOOM_DELTA);
});
}
@@ -194,17 +170,14 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToZoomBy() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
final float zoomBy = 2.45f;
mapboxMap.easeCamera(CameraUpdateFactory.zoomBy(zoomBy));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
final float zoomBy = 2.45f;
mapboxMap.easeCamera(CameraUpdateFactory.zoomBy(zoomBy));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy,
TestConstants.ZOOM_DELTA);
});
}
@@ -212,16 +185,13 @@ public class CameraEaseTest extends BaseActivityTest {
@Ignore
public void testEaseToZoomTo() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final float zoomTo = 2.45f;
mapboxMap.easeCamera(CameraUpdateFactory.zoomTo(zoomTo));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final float zoomTo = 2.45f;
mapboxMap.easeCamera(CameraUpdateFactory.zoomTo(zoomTo));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo,
TestConstants.ZOOM_DELTA);
});
}
}

View File

@@ -1,14 +1,12 @@
package com.mapbox.mapboxsdk.testapp.camera;
import android.graphics.PointF;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
@@ -30,23 +28,20 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToCameraPositionTarget() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
LatLng moveTarget = new LatLng(1, 1);
CameraPosition initialPosition = new CameraPosition.Builder().target(
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(moveTarget));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
LatLng moveTarget = new LatLng(1, 1);
CameraPosition initialPosition = new CameraPosition.Builder().target(
new LatLng()).zoom(zoom).bearing(0).tilt(0).build();
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Default camera position should match default", cameraPosition, initialPosition);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(moveTarget));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
});
}
@@ -54,20 +49,17 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToCameraPositionTargetZoom() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final float moveZoom = 15.5f;
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final float moveZoom = 15.5f;
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(moveTarget, moveZoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
});
}
@@ -75,32 +67,29 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToCameraPosition() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
final float moveZoom = 15.5f;
final float moveTilt = 45.5f;
final float moveBearing = 12.5f;
invoke(mapboxMap, (uiController, mapboxMap) -> {
final LatLng moveTarget = new LatLng(1.0000000001, 1.0000000003);
final float moveZoom = 15.5f;
final float moveTilt = 45.5f;
final float moveBearing = 12.5f;
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(moveTarget)
.zoom(moveZoom)
.tilt(moveTilt)
.bearing(moveBearing)
.build())
);
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
}
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(moveTarget)
.zoom(moveZoom)
.tilt(moveTilt)
.bearing(moveBearing)
.build())
);
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA);
assertEquals("Moved zoom should match", cameraPosition.zoom, moveZoom, TestConstants.ZOOM_DELTA);
assertEquals("Moved zoom should match", cameraPosition.tilt, moveTilt, TestConstants.TILT_DELTA);
assertEquals("Moved bearing should match", cameraPosition.bearing, moveBearing, TestConstants.BEARING_DELTA);
});
}
@@ -108,27 +97,24 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToBounds() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final LatLng centerBounds = new LatLng(1, 1);
LatLng cornerOne = new LatLng();
LatLng cornerTwo = new LatLng(2, 2);
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(cornerOne);
builder.include(cornerTwo);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match center bounds",
cameraPosition.target.getLatitude(),
centerBounds.getLatitude(),
TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match center bounds",
cameraPosition.target.getLongitude(),
centerBounds.getLongitude(),
TestConstants.LAT_LNG_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final LatLng centerBounds = new LatLng(1, 1);
LatLng cornerOne = new LatLng();
LatLng cornerTwo = new LatLng(2, 2);
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(cornerOne);
builder.include(cornerTwo);
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 0));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match center bounds",
cameraPosition.target.getLatitude(),
centerBounds.getLatitude(),
TestConstants.LAT_LNG_DELTA);
assertEquals("Moved camera position longitude should match center bounds",
cameraPosition.target.getLongitude(),
centerBounds.getLongitude(),
TestConstants.LAT_LNG_DELTA);
});
}
@@ -136,21 +122,18 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToMoveBy() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target);
final LatLng moveTarget = new LatLng(2, 2);
final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget);
mapboxMap.moveCamera(CameraUpdateFactory.scrollBy(
moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final PointF centerPoint = mapboxMap.getProjection().toScreenLocation(mapboxMap.getCameraPosition().target);
final LatLng moveTarget = new LatLng(2, 2);
final PointF moveTargetPoint = mapboxMap.getProjection().toScreenLocation(moveTarget);
mapboxMap.moveCamera(CameraUpdateFactory.scrollBy(
moveTargetPoint.x - centerPoint.x, moveTargetPoint.y - centerPoint.y));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera position latitude should match", cameraPosition.target.getLatitude(),
moveTarget.getLatitude(), TestConstants.LAT_LNG_DELTA_LARGE);
assertEquals("Moved camera position longitude should match", cameraPosition.target.getLongitude(),
moveTarget.getLongitude(), TestConstants.LAT_LNG_DELTA_LARGE);
});
}
@@ -158,16 +141,13 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToZoomIn() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
mapboxMap.moveCamera(CameraUpdateFactory.zoomIn());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
mapboxMap.moveCamera(CameraUpdateFactory.zoomIn());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + 1,
TestConstants.ZOOM_DELTA);
});
}
@@ -175,18 +155,15 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToZoomOut() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 10.0f;
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
mapboxMap.moveCamera(CameraUpdateFactory.zoomOut());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 10.0f;
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(), zoom));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
mapboxMap.moveCamera(CameraUpdateFactory.zoomOut());
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom - 1,
TestConstants.ZOOM_DELTA);
});
}
@@ -194,17 +171,14 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToZoomBy() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
float zoom = 1.0f;
final float zoomBy = 2.45f;
mapboxMap.moveCamera(CameraUpdateFactory.zoomBy(zoomBy));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
float zoom = 1.0f;
final float zoomBy = 2.45f;
mapboxMap.moveCamera(CameraUpdateFactory.zoomBy(zoomBy));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoom + zoomBy,
TestConstants.ZOOM_DELTA);
});
}
@@ -212,16 +186,13 @@ public class CameraMoveTest extends BaseActivityTest {
@Ignore
public void testMoveToZoomTo() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
final float zoomTo = 2.45f;
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(zoomTo));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo,
TestConstants.ZOOM_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
final float zoomTo = 2.45f;
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(zoomTo));
uiController.loopMainThreadForAtLeast(TestConstants.ANIMATION_TEST_TIME);
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Moved camera zoom should match moved camera zoom", cameraPosition.zoom, zoomTo,
TestConstants.ZOOM_DELTA);
});
}
}

View File

@@ -2,11 +2,9 @@ package com.mapbox.mapboxsdk.testapp.feature;
import android.graphics.PointF;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.CoordinatesProvider;
import android.support.test.espresso.action.GeneralClickAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Tap;
import android.view.View;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.testapp.R;
@@ -44,15 +42,12 @@ public class QueryRenderedFeaturesPropertiesTest extends BaseActivityTest {
private static ViewAction clickXY(final float x, final float y) {
return new GeneralClickAction(
Tap.SINGLE,
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final float screenX = screenPos[0] + x;
final float screenY = screenPos[1] + y;
return new float[] {screenX, screenY};
}
view -> {
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final float screenX = screenPos[0] + x;
final float screenY = screenPos[1] + y;
return new float[] {screenX, screenY};
},
Press.FINGER);
}

View File

@@ -1,11 +1,8 @@
package com.mapbox.mapboxsdk.testapp.geometry;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.feature.QueryRenderedFeaturesBoxHighlightActivity;
@@ -26,15 +23,12 @@ public class LatLngBoundsTest extends BaseActivityTest {
public void testLatLngBounds() {
// regression test for #9322
validateTestSetup();
MapboxMapAction.invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
LatLngBounds bounds = new LatLngBounds.Builder()
.include(new LatLng(48.8589506, 2.2773457))
.include(new LatLng(47.2383171, -1.6309316))
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
}
MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
LatLngBounds bounds = new LatLngBounds.Builder()
.include(new LatLng(48.8589506, 2.2773457))
.include(new LatLng(47.2383171, -1.6309316))
.build();
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
});
}
}

View File

@@ -150,15 +150,12 @@ public class AttributionTest extends BaseActivityTest {
}
private void buildUrlSpans() {
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
for (Source source : mapboxMap.getSources()) {
String attributionSource = source.getAttribution();
if (!TextUtils.isEmpty(attributionSource)) {
SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attributionSource);
urlSpans = htmlBuilder.getSpans(0, htmlBuilder.length(), URLSpan.class);
}
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
for (Source source : mapboxMap.getSources()) {
String attributionSource = source.getAttribution();
if (!TextUtils.isEmpty(attributionSource)) {
SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attributionSource);
urlSpans = htmlBuilder.getSpans(0, htmlBuilder.length(), URLSpan.class);
}
}
}));

View File

@@ -1,13 +1,9 @@
package com.mapbox.mapboxsdk.testapp.maps.widgets;
import android.support.test.espresso.UiController;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
@@ -41,18 +37,15 @@ public class CompassViewTest extends BaseActivityTest {
@Ignore
public void testVisible() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.bearing(45)
.zoom(1)
.target(new LatLng())
.build()
));
uiController.loopMainThreadForAtLeast(500);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.bearing(45)
.zoom(1)
.target(new LatLng())
.build()
));
uiController.loopMainThreadForAtLeast(500);
});
onView(withId(R.id.compassView)).check(matches(isDisplayed()));
}
@@ -61,27 +54,19 @@ public class CompassViewTest extends BaseActivityTest {
@Ignore
public void testClick() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.bearing(45)
.zoom(1)
.target(new LatLng())
.build()
));
}
});
invoke(mapboxMap, (uiController, mapboxMap) -> mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.bearing(45)
.zoom(1)
.target(new LatLng())
.build()
)));
onView(withId(R.id.compassView)).perform(click());
waitLoop();
onView(withId(R.id.compassView)).check(matches(not(isDisplayed())));
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Camera bearing should face north, ", 0, cameraPosition.bearing, TestConstants.BEARING_DELTA);
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
CameraPosition cameraPosition = mapboxMap.getCameraPosition();
assertEquals("Camera bearing should face north, ", 0, cameraPosition.bearing, TestConstants.BEARING_DELTA);
});
}
}

View File

@@ -3,38 +3,34 @@
package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
import android.support.test.espresso.UiController;
import android.support.test.runner.AndroidJUnit4;
import timber.log.Timber;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops;
import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops;
import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops;
import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops;
import com.mapbox.mapboxsdk.style.functions.stops.Stop;
import com.mapbox.mapboxsdk.style.functions.stops.Stops;
import com.mapbox.mapboxsdk.style.layers.BackgroundLayer;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import org.junit.Test;
import org.junit.runner.RunWith;
import static com.mapbox.mapboxsdk.style.functions.Function.*;
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.junit.Assert.*;
import static com.mapbox.mapboxsdk.style.layers.Property.*;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*;
import timber.log.Timber;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import static com.mapbox.mapboxsdk.style.functions.Function.zoom;
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.exponential;
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.interval;
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundOpacity;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundPattern;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Basic smoke tests for BackgroundLayer
@@ -51,12 +47,7 @@ public class BackgroundLayerTest extends BaseActivityTest {
private void setupLayer() {
Timber.i("Retrieving layer");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
layer = mapboxMap.getLayerAs("background");
}
});
invoke(mapboxMap, (uiController, mapboxMap) -> layer = mapboxMap.getLayerAs("background"));
}
@Test
@@ -64,18 +55,15 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("Visibility");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get initial
assertEquals(layer.getVisibility().getValue(), VISIBLE);
// Get initial
assertEquals(layer.getVisibility().getValue(), VISIBLE);
// Set
layer.setProperties(visibility(NONE));
assertEquals(layer.getVisibility().getValue(), NONE);
}
// Set
layer.setProperties(visibility(NONE));
assertEquals(layer.getVisibility().getValue(), NONE);
});
}
@@ -84,16 +72,13 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-colorTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setBackgroundColorTransition(options);
assertEquals(layer.getBackgroundColorTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setBackgroundColorTransition(options);
assertEquals(layer.getBackgroundColorTransition(), options);
});
}
@@ -102,15 +87,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-color");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)"));
assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)");
}
// Set and Get
layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)"));
assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)");
});
}
@@ -119,30 +101,27 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-color");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
backgroundColor(
zoom(
exponential(
stop(2, backgroundColor("rgba(0, 0, 0, 1)"))
).withBase(0.5f)
)
// Set
layer.setProperties(
backgroundColor(
zoom(
exponential(
stop(2, backgroundColor("rgba(0, 0, 0, 1)"))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getBackgroundColor());
assertNotNull(layer.getBackgroundColor().getFunction());
assertEquals(CameraFunction.class, layer.getBackgroundColor().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getBackgroundColor().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getBackgroundColor());
assertNotNull(layer.getBackgroundColor().getFunction());
assertEquals(CameraFunction.class, layer.getBackgroundColor().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getBackgroundColor().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).size());
});
}
@@ -151,15 +130,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-color");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(backgroundColor(Color.RED));
assertEquals(layer.getBackgroundColorAsInt(), Color.RED);
}
// Set and Get
layer.setProperties(backgroundColor(Color.RED));
assertEquals(layer.getBackgroundColorAsInt(), Color.RED);
});
}
@@ -168,16 +144,13 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-patternTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setBackgroundPatternTransition(options);
assertEquals(layer.getBackgroundPatternTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setBackgroundPatternTransition(options);
assertEquals(layer.getBackgroundPatternTransition(), options);
});
}
@@ -186,15 +159,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-pattern");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(backgroundPattern("pedestrian-polygon"));
assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon");
}
// Set and Get
layer.setProperties(backgroundPattern("pedestrian-polygon"));
assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon");
});
}
@@ -203,29 +173,26 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-pattern");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
backgroundPattern(
zoom(
interval(
stop(2, backgroundPattern("pedestrian-polygon"))
)
// Set
layer.setProperties(
backgroundPattern(
zoom(
interval(
stop(2, backgroundPattern("pedestrian-polygon"))
)
)
);
)
);
// Verify
assertNotNull(layer.getBackgroundPattern());
assertNotNull(layer.getBackgroundPattern().getFunction());
assertEquals(CameraFunction.class, layer.getBackgroundPattern().getFunction().getClass());
assertEquals(IntervalStops.class, layer.getBackgroundPattern().getFunction().getStops().getClass());
assertEquals(1, ((IntervalStops) layer.getBackgroundPattern().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getBackgroundPattern());
assertNotNull(layer.getBackgroundPattern().getFunction());
assertEquals(CameraFunction.class, layer.getBackgroundPattern().getFunction().getClass());
assertEquals(IntervalStops.class, layer.getBackgroundPattern().getFunction().getStops().getClass());
assertEquals(1, ((IntervalStops) layer.getBackgroundPattern().getFunction().getStops()).size());
});
}
@@ -234,16 +201,13 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-opacityTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setBackgroundOpacityTransition(options);
assertEquals(layer.getBackgroundOpacityTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setBackgroundOpacityTransition(options);
assertEquals(layer.getBackgroundOpacityTransition(), options);
});
}
@@ -252,15 +216,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-opacity");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(backgroundOpacity(0.3f));
assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(backgroundOpacity(0.3f));
assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f);
});
}
@@ -269,30 +230,27 @@ public class BackgroundLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("background-opacity");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
backgroundOpacity(
zoom(
exponential(
stop(2, backgroundOpacity(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
backgroundOpacity(
zoom(
exponential(
stop(2, backgroundOpacity(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getBackgroundOpacity());
assertNotNull(layer.getBackgroundOpacity().getFunction());
assertEquals(CameraFunction.class, layer.getBackgroundOpacity().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getBackgroundOpacity().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getBackgroundOpacity());
assertNotNull(layer.getBackgroundOpacity().getFunction());
assertEquals(CameraFunction.class, layer.getBackgroundOpacity().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getBackgroundOpacity().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).size());
});
}

View File

@@ -3,10 +3,8 @@ package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.test.espresso.UiController;
import android.support.test.runner.AndroidJUnit4;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
@@ -34,21 +32,18 @@ public class ImageTest extends BaseActivityTest {
@Test
public void testAddGetImage() {
validateTestSetup();
MapboxMapAction.invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
Drawable drawable = rule.getActivity().getResources().getDrawable(R.drawable.ic_launcher_round);
assertTrue(drawable instanceof BitmapDrawable);
MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
Drawable drawable = rule.getActivity().getResources().getDrawable(R.drawable.ic_launcher_round);
assertTrue(drawable instanceof BitmapDrawable);
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
mapboxMap.addImage(IMAGE_ID, bitmapSet);
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
mapboxMap.addImage(IMAGE_ID, bitmapSet);
Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID);
assertTrue(bitmapGet.sameAs(bitmapSet));
Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID);
assertTrue(bitmapGet.sameAs(bitmapSet));
mapboxMap.removeImage(IMAGE_ID);
assertNull(mapboxMap.getImage(IMAGE_ID));
}
mapboxMap.removeImage(IMAGE_ID);
assertNull(mapboxMap.getImage(IMAGE_ID));
});
}
}

View File

@@ -6,24 +6,22 @@ import android.support.test.espresso.ViewAction;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.functions.Function;
import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops;
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.light.Position;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.style.FillExtrusionStyleTestActivity;
import timber.log.Timber;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import timber.log.Timber;
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;
@@ -33,7 +31,6 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBas
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionHeight;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionOpacity;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
@@ -48,14 +45,11 @@ public class LightTest extends BaseActivityTest {
validateTestSetup();
setupLight();
Timber.i("anchor");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(light);
// Set and Get
light.setAnchor(ANCHOR_MAP);
assertEquals("Anchor should match", ANCHOR_MAP, light.getAnchor());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(light);
// Set and Get
light.setAnchor(ANCHOR_MAP);
assertEquals("Anchor should match", ANCHOR_MAP, light.getAnchor());
});
}
@@ -64,15 +58,12 @@ public class LightTest extends BaseActivityTest {
validateTestSetup();
setupLight();
Timber.i("positionTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(light);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
light.setPositionTransition(options);
assertEquals("Transition options should match", options, light.getPositionTransition());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(light);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
light.setPositionTransition(options);
assertEquals("Transition options should match", options, light.getPositionTransition());
});
}
@@ -81,15 +72,12 @@ public class LightTest extends BaseActivityTest {
validateTestSetup();
setupLight();
Timber.i("position");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(light);
// Set and Get
Position position = new Position(1, 2, 3);
light.setPosition(position);
assertEquals("Position should match", position, light.getPosition());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(light);
// Set and Get
Position position = new Position(1, 2, 3);
light.setPosition(position);
assertEquals("Position should match", position, light.getPosition());
});
}
@@ -98,15 +86,12 @@ public class LightTest extends BaseActivityTest {
validateTestSetup();
setupLight();
Timber.i("colorTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(light);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
light.setColorTransition(options);
assertEquals("Transition options should match", options, light.getColorTransition());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(light);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
light.setColorTransition(options);
assertEquals("Transition options should match", options, light.getColorTransition());
});
}
@@ -115,14 +100,11 @@ public class LightTest extends BaseActivityTest {
validateTestSetup();
setupLight();
Timber.i("color");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(light);
// Set and Get
light.setColor("rgba(0, 0, 0, 1)");
assertEquals("Color should match", "rgba(0, 0, 0, 1)".replaceAll("\\s+", ""), light.getColor());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(light);
// Set and Get
light.setColor("rgba(0, 0, 0, 1)");
assertEquals("Color should match", "rgba(0, 0, 0, 1)".replaceAll("\\s+", ""), light.getColor());
});
}
@@ -131,15 +113,12 @@ public class LightTest extends BaseActivityTest {
validateTestSetup();
setupLight();
Timber.i("intensityTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(light);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
light.setIntensityTransition(options);
assertEquals("Transition options should match", options, light.getIntensityTransition());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(light);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
light.setIntensityTransition(options);
assertEquals("Transition options should match", options, light.getIntensityTransition());
});
}
@@ -148,14 +127,11 @@ public class LightTest extends BaseActivityTest {
validateTestSetup();
setupLight();
Timber.i("intensity");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(light);
// Set and Get
light.setIntensity(0.3f);
assertEquals("Intensity should match", 0.3f, light.getIntensity());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(light);
// Set and Get
light.setIntensity(0.3f);
assertEquals("Intensity should match", 0.3f, light.getIntensity());
});
}

View File

@@ -2,39 +2,36 @@
package com.mapbox.mapboxsdk.testapp.style;
import android.graphics.Color;
import android.support.test.espresso.UiController;
import android.support.test.runner.AndroidJUnit4;
import timber.log.Timber;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops;
import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops;
import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops;
import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops;
import com.mapbox.mapboxsdk.style.functions.stops.Stop;
import com.mapbox.mapboxsdk.style.functions.stops.Stops;
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import org.junit.Test;
import org.junit.runner.RunWith;
import static com.mapbox.mapboxsdk.style.functions.Function.*;
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.junit.Assert.*;
import static com.mapbox.mapboxsdk.style.layers.Property.*;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*;
import timber.log.Timber;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import static com.mapbox.mapboxsdk.style.functions.Function.zoom;
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.exponential;
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMax;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMin;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterContrast;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterFadeDuration;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterHueRotate;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterOpacity;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterSaturation;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Basic smoke tests for RasterLayer
@@ -51,17 +48,14 @@ public class RasterLayerTest extends BaseActivityTest {
private void setupLayer() {
Timber.i("Retrieving layer");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
Timber.i("Adding layer");
layer = new RasterLayer("my-layer", "composite");
layer.setSourceLayer("composite");
mapboxMap.addLayer(layer);
// Layer reference is now stale, get new reference
layer = mapboxMap.getLayerAs("my-layer");
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
Timber.i("Adding layer");
layer = new RasterLayer("my-layer", "composite");
layer.setSourceLayer("composite");
mapboxMap.addLayer(layer);
// Layer reference is now stale, get new reference
layer = mapboxMap.getLayerAs("my-layer");
}
});
}
@@ -71,18 +65,15 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("Visibility");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Get initial
assertEquals(layer.getVisibility().getValue(), VISIBLE);
// Get initial
assertEquals(layer.getVisibility().getValue(), VISIBLE);
// Set
layer.setProperties(visibility(NONE));
assertEquals(layer.getVisibility().getValue(), NONE);
}
// Set
layer.setProperties(visibility(NONE));
assertEquals(layer.getVisibility().getValue(), NONE);
});
}
@@ -91,16 +82,13 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-opacityTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterOpacityTransition(options);
assertEquals(layer.getRasterOpacityTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterOpacityTransition(options);
assertEquals(layer.getRasterOpacityTransition(), options);
});
}
@@ -109,15 +97,12 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-opacity");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterOpacity(0.3f));
assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(rasterOpacity(0.3f));
assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f);
});
}
@@ -126,30 +111,27 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-opacity");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
rasterOpacity(
zoom(
exponential(
stop(2, rasterOpacity(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
rasterOpacity(
zoom(
exponential(
stop(2, rasterOpacity(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getRasterOpacity());
assertNotNull(layer.getRasterOpacity().getFunction());
assertEquals(CameraFunction.class, layer.getRasterOpacity().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterOpacity().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getRasterOpacity());
assertNotNull(layer.getRasterOpacity().getFunction());
assertEquals(CameraFunction.class, layer.getRasterOpacity().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterOpacity().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).size());
});
}
@@ -158,16 +140,13 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-hue-rotateTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterHueRotateTransition(options);
assertEquals(layer.getRasterHueRotateTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterHueRotateTransition(options);
assertEquals(layer.getRasterHueRotateTransition(), options);
});
}
@@ -176,15 +155,12 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-hue-rotate");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterHueRotate(0.3f));
assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(rasterHueRotate(0.3f));
assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f);
});
}
@@ -193,30 +169,27 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-hue-rotate");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
rasterHueRotate(
zoom(
exponential(
stop(2, rasterHueRotate(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
rasterHueRotate(
zoom(
exponential(
stop(2, rasterHueRotate(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getRasterHueRotate());
assertNotNull(layer.getRasterHueRotate().getFunction());
assertEquals(CameraFunction.class, layer.getRasterHueRotate().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterHueRotate().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getRasterHueRotate());
assertNotNull(layer.getRasterHueRotate().getFunction());
assertEquals(CameraFunction.class, layer.getRasterHueRotate().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterHueRotate().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).size());
});
}
@@ -225,16 +198,13 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-brightness-minTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterBrightnessMinTransition(options);
assertEquals(layer.getRasterBrightnessMinTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterBrightnessMinTransition(options);
assertEquals(layer.getRasterBrightnessMinTransition(), options);
});
}
@@ -243,15 +213,12 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-brightness-min");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterBrightnessMin(0.3f));
assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(rasterBrightnessMin(0.3f));
assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f);
});
}
@@ -260,30 +227,27 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-brightness-min");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
rasterBrightnessMin(
zoom(
exponential(
stop(2, rasterBrightnessMin(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
rasterBrightnessMin(
zoom(
exponential(
stop(2, rasterBrightnessMin(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getRasterBrightnessMin());
assertNotNull(layer.getRasterBrightnessMin().getFunction());
assertEquals(CameraFunction.class, layer.getRasterBrightnessMin().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterBrightnessMin().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getRasterBrightnessMin());
assertNotNull(layer.getRasterBrightnessMin().getFunction());
assertEquals(CameraFunction.class, layer.getRasterBrightnessMin().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterBrightnessMin().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).size());
});
}
@@ -292,16 +256,13 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-brightness-maxTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterBrightnessMaxTransition(options);
assertEquals(layer.getRasterBrightnessMaxTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterBrightnessMaxTransition(options);
assertEquals(layer.getRasterBrightnessMaxTransition(), options);
});
}
@@ -310,15 +271,12 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-brightness-max");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterBrightnessMax(0.3f));
assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(rasterBrightnessMax(0.3f));
assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f);
});
}
@@ -327,30 +285,27 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-brightness-max");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
rasterBrightnessMax(
zoom(
exponential(
stop(2, rasterBrightnessMax(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
rasterBrightnessMax(
zoom(
exponential(
stop(2, rasterBrightnessMax(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getRasterBrightnessMax());
assertNotNull(layer.getRasterBrightnessMax().getFunction());
assertEquals(CameraFunction.class, layer.getRasterBrightnessMax().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterBrightnessMax().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getRasterBrightnessMax());
assertNotNull(layer.getRasterBrightnessMax().getFunction());
assertEquals(CameraFunction.class, layer.getRasterBrightnessMax().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterBrightnessMax().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).size());
});
}
@@ -359,16 +314,13 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-saturationTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterSaturationTransition(options);
assertEquals(layer.getRasterSaturationTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterSaturationTransition(options);
assertEquals(layer.getRasterSaturationTransition(), options);
});
}
@@ -377,15 +329,12 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-saturation");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterSaturation(0.3f));
assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(rasterSaturation(0.3f));
assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f);
});
}
@@ -394,30 +343,27 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-saturation");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
rasterSaturation(
zoom(
exponential(
stop(2, rasterSaturation(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
rasterSaturation(
zoom(
exponential(
stop(2, rasterSaturation(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getRasterSaturation());
assertNotNull(layer.getRasterSaturation().getFunction());
assertEquals(CameraFunction.class, layer.getRasterSaturation().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterSaturation().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getRasterSaturation());
assertNotNull(layer.getRasterSaturation().getFunction());
assertEquals(CameraFunction.class, layer.getRasterSaturation().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterSaturation().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).size());
});
}
@@ -426,16 +372,13 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-contrastTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterContrastTransition(options);
assertEquals(layer.getRasterContrastTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterContrastTransition(options);
assertEquals(layer.getRasterContrastTransition(), options);
});
}
@@ -444,15 +387,12 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-contrast");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterContrast(0.3f));
assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(rasterContrast(0.3f));
assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f);
});
}
@@ -461,30 +401,27 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-contrast");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
rasterContrast(
zoom(
exponential(
stop(2, rasterContrast(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
rasterContrast(
zoom(
exponential(
stop(2, rasterContrast(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getRasterContrast());
assertNotNull(layer.getRasterContrast().getFunction());
assertEquals(CameraFunction.class, layer.getRasterContrast().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterContrast().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getRasterContrast());
assertNotNull(layer.getRasterContrast().getFunction());
assertEquals(CameraFunction.class, layer.getRasterContrast().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterContrast().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).size());
});
}
@@ -493,16 +430,13 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-fade-durationTransitionOptions");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterFadeDurationTransition(options);
assertEquals(layer.getRasterFadeDurationTransition(), options);
}
// Set and Get
TransitionOptions options = new TransitionOptions(300, 100);
layer.setRasterFadeDurationTransition(options);
assertEquals(layer.getRasterFadeDurationTransition(), options);
});
}
@@ -511,15 +445,12 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-fade-duration");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set and Get
layer.setProperties(rasterFadeDuration(0.3f));
assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f);
}
// Set and Get
layer.setProperties(rasterFadeDuration(0.3f));
assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f);
});
}
@@ -528,30 +459,27 @@ public class RasterLayerTest extends BaseActivityTest {
validateTestSetup();
setupLayer();
Timber.i("raster-fade-duration");
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
assertNotNull(layer);
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
// Set
layer.setProperties(
rasterFadeDuration(
zoom(
exponential(
stop(2, rasterFadeDuration(0.3f))
).withBase(0.5f)
)
// Set
layer.setProperties(
rasterFadeDuration(
zoom(
exponential(
stop(2, rasterFadeDuration(0.3f))
).withBase(0.5f)
)
);
)
);
// Verify
assertNotNull(layer.getRasterFadeDuration());
assertNotNull(layer.getRasterFadeDuration().getFunction());
assertEquals(CameraFunction.class, layer.getRasterFadeDuration().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterFadeDuration().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).size());
}
// Verify
assertNotNull(layer.getRasterFadeDuration());
assertNotNull(layer.getRasterFadeDuration().getFunction());
assertEquals(CameraFunction.class, layer.getRasterFadeDuration().getFunction().getClass());
assertEquals(ExponentialStops.class, layer.getRasterFadeDuration().getFunction().getStops().getClass());
assertEquals(0.5f, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).getBase(), 0.001);
assertEquals(1, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).size());
});
}

View File

@@ -8,7 +8,6 @@ import android.support.test.espresso.ViewAction;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
@@ -22,7 +21,6 @@ import com.mapbox.mapboxsdk.style.sources.RasterSource;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.style.sources.VectorSource;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity;
@@ -192,41 +190,38 @@ public class RuntimeStyleTests extends BaseActivityTest {
@Test
public void testAddRemoveSource() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
mapboxMap.removeSource("my-source");
invoke(mapboxMap, (uiController, mapboxMap) -> {
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
mapboxMap.removeSource("my-source");
// Add initial source
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
// Add initial source
mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
// Remove
Source mySource = mapboxMap.removeSource("my-source");
assertNotNull(mySource);
assertNull(mapboxMap.getLayer("my-source"));
// Remove
Source mySource = mapboxMap.removeSource("my-source");
assertNotNull(mySource);
assertNull(mapboxMap.getLayer("my-source"));
// Add
Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source);
// Add
Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source);
// Remove, preserving the reference
mapboxMap.removeSource(source);
// Remove, preserving the reference
mapboxMap.removeSource(source);
// Re-add the reference...
mapboxMap.addSource(source);
// Re-add the reference...
mapboxMap.addSource(source);
// Ensure it's there
Assert.assertNotNull(mapboxMap.getSource(source.getId()));
// Ensure it's there
Assert.assertNotNull(mapboxMap.getSource(source.getId()));
// Test adding a duplicate source
try {
Source source2 = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source2);
fail("Should not have been allowed to add a source with a duplicate id");
} catch (CannotAddSourceException cannotAddSourceException) {
// OK
}
// Test adding a duplicate source
try {
Source source2 = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source2);
fail("Should not have been allowed to add a source with a duplicate id");
} catch (CannotAddSourceException cannotAddSourceException) {
// OK
}
});
@@ -235,45 +230,36 @@ public class RuntimeStyleTests extends BaseActivityTest {
@Test
public void testVectorSourceUrlGetter() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
VectorSource source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source);
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
VectorSource source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source);
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl());
});
}
@Test
public void testRasterSourceUrlGetter() {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
RasterSource source = new RasterSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source);
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl());
}
invoke(mapboxMap, (uiController, mapboxMap) -> {
RasterSource source = new RasterSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
mapboxMap.addSource(source);
assertEquals("mapbox://mapbox.mapbox-terrain-v2", source.getUrl());
});
}
@Test
public void testGeoJsonSourceUrlGetter() throws MalformedURLException {
validateTestSetup();
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
GeoJsonSource source = new GeoJsonSource("my-source");
mapboxMap.addSource(source);
assertNull(source.getUrl());
try {
source.setUrl(new URL("http://mapbox.com/my-file.json"));
} catch (MalformedURLException exception) {
fail();
}
assertEquals("http://mapbox.com/my-file.json", source.getUrl());
invoke(mapboxMap, (uiController, mapboxMap) -> {
GeoJsonSource source = new GeoJsonSource("my-source");
mapboxMap.addSource(source);
assertNull(source.getUrl());
try {
source.setUrl(new URL("http://mapbox.com/my-file.json"));
} catch (MalformedURLException exception) {
fail();
}
assertEquals("http://mapbox.com/my-file.json", source.getUrl());
});
}