[android] - move MapboxMapTest to java unit test

This commit is contained in:
tobrun
2018-12-11 16:28:27 +01:00
committed by Tobrun
parent aedbdc21d0
commit b1ae6c9051
3 changed files with 111 additions and 232 deletions

View File

@@ -11,21 +11,13 @@ import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
import com.mapbox.mapboxsdk.testapp.utils.ViewUtils;
import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Test;
import timber.log.Timber;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +25,6 @@ import java.util.List;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.mapbox.mapboxsdk.testapp.utils.TestConstants.LAT_LNG_DELTA;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertEquals;
@@ -45,7 +36,9 @@ import static org.junit.Assert.assertTrue;
* Methods executed on MapboxMap are called from a ViewAction to ensure correct synchronisation
* with the application UI-thread.
* </p>
* @deprecated remove this file when removing deprecated annotations
*/
@Deprecated
public class MapboxMapTest extends BaseActivityTest {
@Override
@@ -59,113 +52,6 @@ public class MapboxMapTest extends BaseActivityTest {
assertNotNull("mapboxMap should not be null", mapboxMap);
}
//
// Style wide transition options
//
@Test
public void testTransitionDuration() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
long transitionDuration = 600;
mapboxMap.getStyle().setTransition(new TransitionOptions(transitionDuration, 0));
assertEquals(
"TransitionDuration should match",
transitionDuration,
mapboxMap.getStyle().getTransition().getDuration(),
0
);
}));
}
@Test
public void testTransitionDelay() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
long transitionDelay = 50;
mapboxMap.getStyle().setTransition(new TransitionOptions(600, transitionDelay));
assertEquals(
"TransitionDelay should match",
transitionDelay,
mapboxMap.getStyle().getTransition().getDelay(),
0
);
}));
}
//
// Camera tests
//
@Test
public void testCameraPositionOnFinish() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
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() {
}
@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((uiController, view) -> {
// set
mapboxMap.setLatLngBoundsForCameraTarget(
new LatLngBounds.Builder().include(new LatLng()).include(new LatLng(1, 1)).build());
// reset
mapboxMap.setLatLngBoundsForCameraTarget(null);
}));
}
//
// MinZoomLevel
//
@Test
public void testMinZoom() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setMinZoomPreference(10);
assertEquals("MinZoom should match", 10, mapboxMap.getMinZoomLevel(), 10);
}));
}
@Test
public void testMaxZoom() {
validateTestSetup();
final double zoom = 10;
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setMaxZoomPreference(zoom);
assertEquals("MaxZoom should match", zoom, mapboxMap.getMaxZoomLevel(), 10);
}));
}
@Test
@Ignore
public void testInitialZoomLevels() {
validateTestSetup();
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);
}));
}
//
// InfoWindow
//
@@ -198,59 +84,6 @@ public class MapboxMapTest extends BaseActivityTest {
}));
}
//
// setters/getters interfaces
//
@Test
public void testFpsListener() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MapboxMap.OnFpsChangedListener fpsChangedListener = fps -> {
};
mapboxMap.setOnFpsChangedListener(fpsChangedListener);
assertEquals("FpsListener should match", fpsChangedListener, mapboxMap.getOnFpsChangedListener());
}));
}
@Test
public void testInfoWindowClickListener() {
validateTestSetup();
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((uiController, view) -> {
MapboxMap.OnInfoWindowCloseListener listener = marker -> {
};
mapboxMap.setOnInfoWindowCloseListener(listener);
assertEquals("InfoWindowCloseListener should match", listener, mapboxMap.getOnInfoWindowCloseListener());
}));
}
@Test
public void testInfoWindowLongClickListener() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
MapboxMap.OnInfoWindowLongClickListener listener = marker -> {
};
mapboxMap.setOnInfoWindowLongClickListener(listener);
assertEquals("InfoWindowLongClickListener should match", listener,
mapboxMap.getOnInfoWindowLongClickListener());
}));
}
//
// Annotations
//
@@ -626,21 +459,6 @@ public class MapboxMapTest extends BaseActivityTest {
}));
}
// Tile pre-fetching
@Test
public void testTilePrefetch() {
validateTestSetup();
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
mapboxMap.setPrefetchesTiles(true);
assertTrue(mapboxMap.getPrefetchesTiles());
mapboxMap.setPrefetchesTiles(false);
assertFalse(mapboxMap.getPrefetchesTiles());
}));
}
//
public class MapboxMapAction implements ViewAction {
private InvokeViewAction invokeViewAction;
@@ -668,4 +486,4 @@ public class MapboxMapTest extends BaseActivityTest {
interface InvokeViewAction {
void onViewAction(UiController uiController, View view);
}
}
}