-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[annotation-plugin] - add marker plugin
- Loading branch information
Showing
19 changed files
with
2,442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/annotation/BaseActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.mapbox.mapboxsdk.plugins.annotation; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
import android.support.test.espresso.Espresso; | ||
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.maps.MapboxMap; | ||
|
||
import com.mapbox.mapboxsdk.plugins.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; | ||
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 BaseActivityTest { | ||
|
||
@Rule | ||
public ActivityTestRule<Activity> rule = new ActivityTestRule<>(getActivityClass()); | ||
|
||
@Rule | ||
public TestName testName = new TestName(); | ||
|
||
protected MapboxMap mapboxMap; | ||
protected OnMapReadyIdlingResource idlingResource; | ||
|
||
@Before | ||
public void beforeTest() { | ||
try { | ||
Timber.e("@Before %s: register idle resource", testName.getMethodName()); | ||
idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); | ||
IdlingRegistry.getInstance().register(idlingResource); | ||
checkViewIsDisplayed(android.R.id.content); | ||
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 = android.R.id.content or \n" | ||
+ "the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n" | ||
+ "You can resolve this issue by adding the requirements above or\n add " | ||
+ getActivityClass().getSimpleName() + " to the platform/android/scripts/exclude-activity-gen.json to blacklist" | ||
+ " the Activity from being generated.\n"); | ||
} | ||
} | ||
|
||
protected void validateTestSetup() { | ||
Assert.assertTrue("Device is not connected to the Internet.", isConnected(rule.getActivity())); | ||
checkViewIsDisplayed(android.R.id.content); | ||
Assert.assertNotNull(mapboxMap); | ||
} | ||
|
||
protected MapboxMap getMapboxMap() { | ||
return mapboxMap; | ||
} | ||
|
||
protected abstract Class getActivityClass(); | ||
|
||
protected void checkViewIsDisplayed(int id) { | ||
onView(withId(id)).check(matches(isDisplayed())); | ||
} | ||
|
||
protected void waitAction() { | ||
waitAction(500); | ||
} | ||
|
||
protected void waitAction(long waitTime) { | ||
onView(withId(android.R.id.content)).perform(new WaitAction(waitTime)); | ||
} | ||
|
||
static boolean isConnected(Context context) { | ||
ConnectivityManager connectivityManager | ||
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); | ||
return activeNetworkInfo != null && activeNetworkInfo.isConnected(); | ||
} | ||
|
||
protected ViewInteraction onMapView() { | ||
return onView(withId(android.R.id.content)); | ||
} | ||
|
||
protected MapboxMapAction getMapboxMapAction(MapboxMapAction.OnInvokeActionListener onInvokeActionListener) { | ||
return new MapboxMapAction(onInvokeActionListener, mapboxMap); | ||
} | ||
|
||
@After | ||
public void afterTest() { | ||
Timber.e("@After test: unregister idle resource"); | ||
IdlingRegistry.getInstance().unregister(idlingResource); | ||
} | ||
} | ||
|
47 changes: 47 additions & 0 deletions
47
app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/annotation/MapboxMapAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.mapbox.mapboxsdk.plugins.annotation; | ||
|
||
import android.support.test.espresso.UiController; | ||
import android.support.test.espresso.ViewAction; | ||
import android.view.View; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import org.hamcrest.Matcher; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
|
||
public class MapboxMapAction implements ViewAction { | ||
|
||
private OnInvokeActionListener invokeViewAction; | ||
private MapboxMap mapboxMap; | ||
|
||
public MapboxMapAction(OnInvokeActionListener invokeViewAction, MapboxMap mapboxMap) { | ||
this.invokeViewAction = invokeViewAction; | ||
this.mapboxMap = mapboxMap; | ||
} | ||
|
||
@Override | ||
public Matcher<View> getConstraints() { | ||
return isDisplayed(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
public void perform(UiController uiController, View view) { | ||
invokeViewAction.onInvokeAction(uiController, mapboxMap); | ||
} | ||
|
||
public static void invoke(MapboxMap mapboxMap, OnInvokeActionListener invokeViewAction) { | ||
onView(withId(android.R.id.content)).perform(new MapboxMapAction(invokeViewAction, mapboxMap)); | ||
} | ||
|
||
public interface OnInvokeActionListener { | ||
void onInvokeAction(UiController uiController, MapboxMap mapboxMap); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.