[android] - throw concrete exception when generated test cases fail to read the Activity members (#6281)
This commit is contained in:
@@ -2,14 +2,15 @@ package com.mapbox.mapboxsdk.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.test.espresso.Espresso;
|
||||
import android.support.test.espresso.IdlingResourceTimeoutException;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource;
|
||||
import com.mapbox.mapboxsdk.utils.ScreenshotUtil;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource;
|
||||
import com.mapbox.mapboxsdk.utils.ScreenshotUtil;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -29,11 +30,19 @@ public abstract class BaseTest {
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
Log.e(MapboxConstants.TAG, "@Before test: register idle resource");
|
||||
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
|
||||
Espresso.registerIdlingResources(idlingResource);
|
||||
checkViewIsDisplayed(R.id.mapView);
|
||||
mapboxMap = idlingResource.getMapboxMap();
|
||||
try {
|
||||
Log.e(MapboxConstants.TAG, "@Before test: register idle resource");
|
||||
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
|
||||
Espresso.registerIdlingResources(idlingResource);
|
||||
checkViewIsDisplayed(R.id.mapView);
|
||||
mapboxMap = idlingResource.getMapboxMap();
|
||||
} catch (IdlingResourceTimeoutException e) {
|
||||
Log.e(MapboxConstants.TAG, "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 be implementing the requirements above or\n add " + getActivityClass().getSimpleName() + " to the excludeActivities array in `generate-test-code.js`.\n");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Class getActivityClass();
|
||||
|
||||
Reference in New Issue
Block a user