-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cameron Mace
committed
Jul 13, 2017
1 parent
9572d25
commit 93880b6
Showing
47 changed files
with
2,278 additions
and
34 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
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
46 changes: 46 additions & 0 deletions
46
...ndroidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginAction.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,46 @@ | ||
package com.mapbox.mapboxsdk.plugins.locationlayer; | ||
|
||
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.matcher.ViewMatchers.isDisplayed; | ||
|
||
class LocationLayerPluginAction implements ViewAction { | ||
|
||
private MapboxMap mapboxMap; | ||
private LocationLayerPlugin locationLayerPlugin; | ||
private onPerformLocationLayerAction onPerformLocationLayerAction; | ||
|
||
LocationLayerPluginAction(MapboxMap mapboxMap, LocationLayerPlugin locationLayerPlugin, | ||
onPerformLocationLayerAction onPerformLocationLayerAction) { | ||
this.locationLayerPlugin = locationLayerPlugin; | ||
this.mapboxMap = mapboxMap; | ||
this.onPerformLocationLayerAction = onPerformLocationLayerAction; | ||
} | ||
|
||
@Override | ||
public Matcher<View> getConstraints() { | ||
return isDisplayed(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
public void perform(UiController uiController, View view) { | ||
if (onPerformLocationLayerAction != null) { | ||
onPerformLocationLayerAction.onLocationLayerAction(locationLayerPlugin, mapboxMap, uiController); | ||
} | ||
} | ||
|
||
interface onPerformLocationLayerAction { | ||
void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController); | ||
} | ||
} |
174 changes: 174 additions & 0 deletions
174
.../androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPluginTest.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,174 @@ | ||
package com.mapbox.mapboxsdk.plugins.locationlayer; | ||
|
||
import android.support.test.espresso.Espresso; | ||
import android.support.test.espresso.IdlingResourceTimeoutException; | ||
import android.support.test.espresso.UiController; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.mapbox.mapboxsdk.constants.Style; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.plugins.testapp.activity.location.LocationLayerModesActivity; | ||
import com.mapbox.mapboxsdk.style.layers.Property; | ||
import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
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; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SuppressWarnings( {"MissingPermission"}) | ||
public class LocationLayerPluginTest { | ||
|
||
private static final double DELTA = 1E-10; | ||
|
||
@Rule | ||
public ActivityTestRule<LocationLayerModesActivity> rule = new ActivityTestRule<>(LocationLayerModesActivity.class); | ||
|
||
private OnMapReadyIdlingResource idlingResource; | ||
private MapboxMap mapboxMap; | ||
private LocationLayerPlugin locationLayerPlugin; | ||
|
||
@Before | ||
public void beforeTest() { | ||
try { | ||
Timber.e("@Before: register idle resource"); | ||
idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); | ||
Espresso.registerIdlingResources(idlingResource); | ||
onView(withId(android.R.id.content)).check(matches(isDisplayed())); | ||
mapboxMap = idlingResource.getMapboxMap(); | ||
locationLayerPlugin = rule.getActivity().getLocationLayerPlugin(); | ||
} catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { | ||
Timber.e("Idling resource timed out. Couldn't not validate if map is ready."); | ||
throw new RuntimeException("Could not start executeLocationLayerTest for " | ||
+ this.getClass().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"); | ||
} | ||
} | ||
|
||
@Test | ||
public void sanity() throws Exception { | ||
assertTrue(mapboxMap != null); | ||
assertTrue(locationLayerPlugin != null); | ||
} | ||
|
||
@Test | ||
public void locationSourceAdded() throws Exception { | ||
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() { | ||
@Override | ||
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, | ||
UiController uiController) { | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); | ||
assertTrue(mapboxMap.getSource(LocationLayerConstants.LOCATION_SOURCE) != null); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void locationAccuracySourceAdded() throws Exception { | ||
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() { | ||
@Override | ||
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, | ||
UiController uiController) { | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); | ||
assertTrue(mapboxMap.getSource(LocationLayerConstants.LOCATION_ACCURACY_SOURCE) != null); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void locationTrackingLayersAdded() throws Exception { | ||
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() { | ||
@Override | ||
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, | ||
UiController uiController) { | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_ACCURACY_LAYER) != null); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_BACKGROUND_LAYER) != null); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void locationBearingLayersAdded() throws Exception { | ||
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() { | ||
@Override | ||
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, | ||
UiController uiController) { | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_ACCURACY_LAYER) != null); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_BACKGROUND_LAYER) != null); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_BEARING_LAYER) != null); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void locationNavigationLayersAdded() throws Exception { | ||
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() { | ||
@Override | ||
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, | ||
UiController uiController) { | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.COMPASS); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_NAVIGATION_LAYER) != null); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void locationLayerModeCorrectlySetToNone() throws Exception { | ||
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() { | ||
@Override | ||
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, | ||
UiController uiController) { | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null); | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NONE); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER).getVisibility().getValue() | ||
.equals(Property.NONE)); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void onMapChangeLocationLayerRedrawn() throws Exception { | ||
executeLocationLayerTest(new LocationLayerPluginAction.onPerformLocationLayerAction() { | ||
@Override | ||
public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, | ||
UiController uiController) { | ||
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null); | ||
mapboxMap.setStyleUrl(Style.SATELLITE); | ||
uiController.loopMainThreadForAtLeast(500); | ||
assertEquals(locationLayerPlugin.getLocationLayerMode(), LocationLayerMode.TRACKING); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER) != null); | ||
assertTrue(mapboxMap.getLayer(LocationLayerConstants.LOCATION_LAYER).getVisibility().getValue() | ||
.equals(Property.VISIBLE)); | ||
} | ||
}); | ||
} | ||
|
||
@After | ||
public void afterTest() { | ||
Timber.e("@After: unregister idle resource"); | ||
Espresso.unregisterIdlingResources(idlingResource); | ||
} | ||
|
||
public void executeLocationLayerTest(LocationLayerPluginAction.onPerformLocationLayerAction listener) { | ||
onView(withId(android.R.id.content)).perform(new LocationLayerPluginAction(mapboxMap, locationLayerPlugin, | ||
listener)); | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
plugins/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/Utils.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,60 @@ | ||
package com.mapbox.mapboxsdk.plugins.testapp; | ||
|
||
import android.location.Location; | ||
|
||
import com.mapbox.mapboxsdk.constants.Style; | ||
|
||
import java.util.Random; | ||
|
||
import timber.log.Timber; | ||
|
||
/** | ||
* Useful utilities used throughout the testapp. | ||
*/ | ||
public class Utils { | ||
|
||
private static final String[] STYLES = new String[] { | ||
Style.MAPBOX_STREETS, | ||
Style.OUTDOORS, | ||
Style.LIGHT, | ||
Style.DARK, | ||
Style.SATELLITE_STREETS, | ||
Style.TRAFFIC_DAY, | ||
Style.TRAFFIC_NIGHT | ||
}; | ||
|
||
private static int index; | ||
|
||
/** | ||
* Utility to cycle through map styles. Useful to test if runtime styling source and layers transfer over to new | ||
* style. | ||
* | ||
* @return a string ID representing the map style | ||
*/ | ||
public static String getNextStyle() { | ||
index++; | ||
if (index == STYLES.length) { | ||
index = 0; | ||
} | ||
return STYLES[index]; | ||
} | ||
|
||
/** | ||
* Utility for getting a random coordinate inside a provided bounding box and creates a {@link Location} from it. | ||
* | ||
* @param bbox double array forming the bounding box in the order of {@code [minx, miny, maxx, maxy]} | ||
* @return a {@link Location} object using the random coordinate | ||
*/ | ||
public static Location getRandomLocation(double[] bbox) { | ||
Random random = new Random(); | ||
|
||
double randomLat = bbox[1] + (bbox[3] - bbox[1]) * random.nextDouble(); | ||
double randomLon = bbox[0] + (bbox[2] - bbox[0]) * random.nextDouble(); | ||
|
||
Location location = new Location("random-loc"); | ||
location.setLongitude(randomLon); | ||
location.setLatitude(randomLat); | ||
Timber.d("getRandomLatLng: %s", location.toString()); | ||
return location; | ||
} | ||
} |
Oops, something went wrong.