summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-09-20 14:40:20 +0200
committerTobrun <tobrun@mapbox.com>2018-09-24 10:32:50 +0200
commit515fcf394f1e93d16b0f86e3db4c10e579fd0f1a (patch)
tree33c3aad24356c4d9ee780d912a18361352fd1d72 /platform
parentd92eace224d4c1b6f3d6f0dd3281ec0d995bdc20 (diff)
downloadqtlocation-mapboxgl-515fcf394f1e93d16b0f86e3db4c10e579fd0f1a.tar.gz
[android] - replace reflection setup with a findViewById, improves stability of the instrumentation tests on cCI
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java21
2 files changed, 18 insertions, 18 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
index 3682440aeb..d40b678279 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
+import android.support.test.espresso.Espresso;
import android.support.test.espresso.IdlingRegistry;
import android.support.test.espresso.IdlingResourceTimeoutException;
import android.support.test.espresso.ViewInteraction;
@@ -46,16 +47,14 @@ public abstract class BaseActivityTest {
Timber.e(String.format("%s - %s", testNameRule.getMethodName(), "@Before test: register idle resource"));
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
IdlingRegistry.getInstance().register(idlingResource);
- checkViewIsDisplayed(R.id.mapView);
+ Espresso.onIdle();
mapboxMap = idlingResource.getMapboxMap();
} catch (IdlingResourceTimeoutException idlingResourceTimeoutException) {
- Timber.e("Idling resource timed out. Couldn't not validate if map is ready.");
- throw new RuntimeException("Could not start test for " + getActivityClass().getSimpleName() + ".\n"
- + "The ViewHierarchy doesn't contain a view with resource id = R.id.mapView or \n"
- + "the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n"
- + "You can resolve this issue by adding the requirements above or\n add "
- + getActivityClass().getSimpleName() + " to the platform/android/scripts/exclude-activity-gen.json to blacklist"
- + " the Activity from being generated.\n");
+ throw new RuntimeException(String.format("Could not start %s test for %s.\n Either the ViewHierarchy doesn't "
+ + "contain a view with resource id = R.id.mapView or \n the hosting Activity wasn't in an idle state.",
+ testNameRule.getMethodName(),
+ getActivityClass().getSimpleName())
+ );
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java
index 4e4c69620a..16959ed5b5 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java
@@ -2,29 +2,30 @@ package com.mapbox.mapboxsdk.testapp.utils;
import android.app.Activity;
import android.os.Handler;
+import android.os.Looper;
import android.support.annotation.WorkerThread;
import android.support.test.espresso.IdlingResource;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-
-import java.lang.reflect.Field;
+import com.mapbox.mapboxsdk.testapp.R;
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {
private MapboxMap mapboxMap;
private IdlingResource.ResourceCallback resourceCallback;
+ private final Handler handler = new Handler(Looper.getMainLooper());
@WorkerThread
- public OnMapReadyIdlingResource(Activity activity) {
- new Handler(activity.getMainLooper()).post(() -> {
- try {
- Field field = activity.getClass().getDeclaredField("mapView");
- field.setAccessible(true);
- ((MapView) field.get(activity)).getMapAsync(OnMapReadyIdlingResource.this);
- } catch (Exception err) {
- throw new RuntimeException(err);
+ public OnMapReadyIdlingResource(final Activity activity) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ MapView mapView = (MapView) activity.findViewById(R.id.mapView);
+ if (mapView != null) {
+ mapView.getMapAsync(OnMapReadyIdlingResource.this);
+ }
}
});
}