blob: c5543222f11621e788056f4334e1d2d0b13bbd79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package com.mapbox.mapboxsdk.activity;
import android.app.Activity;
import android.support.test.espresso.Espresso;
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 org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
public abstract class BaseTest {
@Rule
public ActivityTestRule<Activity> rule = new ActivityTestRule<>(getActivityClass());
protected MapboxMap mapboxMap;
protected OnMapReadyIdlingResource idlingResource;
@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();
}
protected abstract Class getActivityClass();
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);
}
});
}
@After
public void afterTest() {
Log.e(MapboxConstants.TAG, "@After test: unregister idle resource");
Espresso.unregisterIdlingResources(idlingResource);
}
}
|