summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java106
1 files changed, 49 insertions, 57 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java
index f1e2a6c418..bf8bcb9f66 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RuntimeStyleTests.java
@@ -8,6 +8,7 @@ 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;
@@ -21,6 +22,7 @@ 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;
@@ -40,6 +42,7 @@ 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;
+import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -189,63 +192,88 @@ public class RuntimeStyleTests extends BaseActivityTest {
@Test
public void testAddRemoveSource() {
validateTestSetup();
- mapboxMap.addSource(new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2"));
- mapboxMap.removeSource("my-source");
+ 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");
+
+ // 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"));
+
+ // Add
+ Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
+ mapboxMap.addSource(source);
+
+ // Remove, preserving the reference
+ mapboxMap.removeSource(source);
+
+ // Re-add the reference...
+ mapboxMap.addSource(source);
+
+ // 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
+ }
+ }
+ });
- onView(withId(R.id.mapView)).perform(new AddRemoveSourceAction());
}
@Test
public void testVectorSourceUrlGetter() {
validateTestSetup();
-
- onView(withId(R.id.mapView)).perform(new BaseViewAction() {
-
+ invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
- public void perform(UiController uiController, View view) {
+ 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());
}
-
});
}
@Test
public void testRasterSourceUrlGetter() {
validateTestSetup();
-
- onView(withId(R.id.mapView)).perform(new BaseViewAction() {
-
+ invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
- public void perform(UiController uiController, View view) {
+ 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());
}
-
});
}
@Test
- public void testGeoJsonSourceUrlGetter() {
+ public void testGeoJsonSourceUrlGetter() throws MalformedURLException {
validateTestSetup();
-
- onView(withId(R.id.mapView)).perform(new BaseViewAction() {
-
+ invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
@Override
- public void perform(UiController uiController, View view) {
+ 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 err) {
- assertTrue(err.getMessage(), false);
+ } catch (MalformedURLException exception) {
+ fail();
}
assertEquals("http://mapbox.com/my-file.json", source.getUrl());
}
-
});
}
@@ -329,42 +357,6 @@ public class RuntimeStyleTests extends BaseActivityTest {
}
}
- private class AddRemoveSourceAction extends BaseViewAction {
-
- @Override
- public void perform(UiController uiController, View view) {
- // 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"));
-
- // Add
- Source source = new VectorSource("my-source", "mapbox://mapbox.mapbox-terrain-v2");
- mapboxMap.addSource(source);
-
- // Remove, preserving the reference
- mapboxMap.removeSource(source);
-
- // Re-add the reference...
- mapboxMap.addSource(source);
-
- // 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
- }
- }
- }
-
@After
public void unregisterIntentServiceIdlingResource() {
Espresso.unregisterIdlingResources(idlingResource);