[android] deliver onMapReady only if mapboxMap is not null
This commit is contained in:
committed by
Łukasz Paczos
parent
3b9618e025
commit
a282b195d5
@@ -6,17 +6,21 @@ import android.support.test.espresso.IdlingRegistry;
|
||||
import android.support.test.espresso.IdlingResourceTimeoutException;
|
||||
import android.support.test.espresso.ViewInteraction;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.action.WaitAction;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
@@ -38,7 +42,12 @@ public abstract class BaseActivityTest {
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
try {
|
||||
Timber.e(String.format("%s - %s", testNameRule.getMethodName(), "@Before test: register idle resource"));
|
||||
Timber.e(String.format(
|
||||
"%s - %s - %s",
|
||||
getClass().getSimpleName(),
|
||||
testNameRule.getMethodName(),
|
||||
"@Before test: register idle resource"
|
||||
));
|
||||
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
|
||||
IdlingRegistry.getInstance().register(idlingResource);
|
||||
Espresso.onIdle();
|
||||
|
||||
@@ -11,21 +11,20 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
private IdlingResource.ResourceCallback resourceCallback;
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@WorkerThread
|
||||
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);
|
||||
}
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(() -> {
|
||||
MapView mapView = activity.findViewById(R.id.mapView);
|
||||
if (mapView != null) {
|
||||
mapView.getMapAsync(OnMapReadyIdlingResource.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -51,6 +50,7 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
Assert.assertNotNull("MapboxMap should not be null", mapboxMap);
|
||||
this.mapboxMap = mapboxMap;
|
||||
if (resourceCallback != null) {
|
||||
resourceCallback.onTransitionToIdle();
|
||||
|
||||
Reference in New Issue
Block a user