diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java | 81 |
1 files changed, 41 insertions, 40 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 b00255a6c7..2f51140cd1 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,9 +4,9 @@ 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.constants.MapboxConstants; +import timber.log.Timber; + import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; @@ -23,49 +23,50 @@ import static android.support.test.espresso.matcher.ViewMatchers.withId; public abstract class BaseActivityTest { - @Rule - public ActivityTestRule<Activity> rule = new ActivityTestRule<>(getActivityClass()); - protected MapboxMap mapboxMap; - protected OnMapReadyIdlingResource idlingResource; + @Rule + public ActivityTestRule<Activity> rule = new ActivityTestRule<>(getActivityClass()); + protected MapboxMap mapboxMap; + protected OnMapReadyIdlingResource idlingResource; - @Before - public void beforeTest() { - 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"); - } + @Before + public void beforeTest() { + try { + Timber.e("@Before test: register idle resource"); + idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); + Espresso.registerIdlingResources(idlingResource); + checkViewIsDisplayed(R.id.mapView); + 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 be implementing the requirements above or\n add " + + getActivityClass().getSimpleName() + " to the excludeActivities array in `generate-test-code.js`.\n"); } + } - protected abstract Class getActivityClass(); + protected abstract Class getActivityClass(); - protected void checkViewIsDisplayed(int id) { - onView(withId(id)) - .check(matches(isDisplayed())); - } + protected void checkViewIsDisplayed(int id) { + onView(withId(id)) + .check(matches(isDisplayed())); + } - protected void takeScreenshot(final String name) { - final Activity activity = rule.getActivity(); - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - ScreenshotUtil.take(activity, name); - } - }); - } + protected void takeScreenshot(final String name) { + final Activity activity = rule.getActivity(); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + ScreenshotUtil.take(activity, name); + } + }); + } - @After - public void afterTest() { - Log.e(MapboxConstants.TAG, "@After test: unregister idle resource"); - Espresso.unregisterIdlingResources(idlingResource); - } + @After + public void afterTest() { + Timber.e("@After test: unregister idle resource"); + Espresso.unregisterIdlingResources(idlingResource); + } } |