Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit c9c2e96

Browse files
committed
[android] speed up ui tests
- Make the idling resource use a push model instead of polling for the ready state.
1 parent f6c6d45 commit c9c2e96

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java

+21-22
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@
33
import android.app.Activity;
44
import android.support.test.espresso.IdlingResource;
55

6-
import timber.log.Timber;
7-
6+
import com.mapbox.mapboxsdk.maps.MapView;
87
import com.mapbox.mapboxsdk.maps.MapboxMap;
8+
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
99

1010
import java.lang.reflect.Field;
1111

12-
public class OnMapReadyIdlingResource implements IdlingResource {
12+
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {
1313

14-
private final Activity activity;
1514
private MapboxMap mapboxMap;
1615
private IdlingResource.ResourceCallback resourceCallback;
16+
private Activity activity;
1717

1818
public OnMapReadyIdlingResource(Activity activity) {
1919
this.activity = activity;
20+
try {
21+
Field field = activity.getClass().getDeclaredField("mapView");
22+
field.setAccessible(true);
23+
((MapView) field.get(activity)).getMapAsync(this);
24+
} catch (Exception err) {
25+
throw new RuntimeException(err);
26+
}
27+
2028
}
2129

2230
@Override
@@ -26,32 +34,23 @@ public String getName() {
2634

2735
@Override
2836
public boolean isIdleNow() {
29-
boolean idle = isMapboxMapReady();
30-
if (idle && resourceCallback != null) {
31-
resourceCallback.onTransitionToIdle();
32-
}
33-
return idle;
37+
return mapboxMap != null;
3438
}
3539

3640
@Override
3741
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
3842
this.resourceCallback = resourceCallback;
3943
}
4044

41-
private boolean isMapboxMapReady() {
42-
try {
43-
Field field = activity.getClass().getDeclaredField("mapboxMap");
44-
field.setAccessible(true);
45-
mapboxMap = (MapboxMap) field.get(activity);
46-
Timber.e("isMapboxReady called with value %s", (mapboxMap != null));
47-
return mapboxMap != null;
48-
} catch (Exception exception) {
49-
Timber.e(exception, "could not reflect");
50-
return false;
51-
}
52-
}
53-
5445
public MapboxMap getMapboxMap() {
5546
return mapboxMap;
5647
}
48+
49+
@Override
50+
public void onMapReady(MapboxMap mapboxMap) {
51+
this.mapboxMap = mapboxMap;
52+
if (resourceCallback != null) {
53+
resourceCallback.onTransitionToIdle();
54+
}
55+
}
5756
}

0 commit comments

Comments
 (0)