Skip to content

Commit

Permalink
Update tests and cleanup route profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Apr 11, 2018
1 parent 0ece1ba commit 307bcf5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.METERS_REMAINING_TILL_ARRIVAL;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_TYPE_ARRIVE;
Expand All @@ -21,6 +23,14 @@ public final class RouteUtils {

private static final String FORCED_LOCATION = "Forced Location";
private static final int FIRST_COORDINATE = 0;
private static final Set<String> VALID_PROFILES = new HashSet<String>() {
{
add(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC);
add(DirectionsCriteria.PROFILE_DRIVING);
add(DirectionsCriteria.PROFILE_CYCLING);
add(DirectionsCriteria.PROFILE_WALKING);
}
};

private RouteUtils() {
// Utils class therefore, shouldn't be initialized.
Expand Down Expand Up @@ -137,11 +147,7 @@ public static Location createFirstLocationFromRoute(DirectionsRoute route) {
* @since 0.13.0
*/
public static boolean isValidRouteProfile(String routeProfile) {
return !TextUtils.isEmpty(routeProfile)
&& routeProfile.contentEquals(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
|| routeProfile.contentEquals(DirectionsCriteria.PROFILE_DRIVING)
|| routeProfile.contentEquals(DirectionsCriteria.PROFILE_CYCLING)
|| routeProfile.contentEquals(DirectionsCriteria.PROFILE_WALKING);
return !TextUtils.isEmpty(routeProfile) && VALID_PROFILES.contains(routeProfile);
}

private static boolean upcomingStepIsArrival(@NonNull RouteProgress routeProgress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,41 @@ public void isArrivalEvent_returnsFalseWhenManeuverTypeIsNotArrival_andIsNotVali
}

@Test
public void isValidRouteProfile_returnsTrueWithValidProfile() throws Exception {
public void isValidRouteProfile_returnsTrueWithDrivingTrafficProfile() throws Exception {
String routeProfile = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC;

boolean isValidProfile = RouteUtils.isValidRouteProfile(routeProfile);

assertTrue(isValidProfile);
}

@Test
public void isValidRouteProfile_returnsTrueWithDrivingProfile() throws Exception {
String routeProfile = DirectionsCriteria.PROFILE_DRIVING;

boolean isValidProfile = RouteUtils.isValidRouteProfile(routeProfile);

assertTrue(isValidProfile);
}

@Test
public void isValidRouteProfile_returnsTrueWithCyclingProfile() throws Exception {
String routeProfile = DirectionsCriteria.PROFILE_CYCLING;

boolean isValidProfile = RouteUtils.isValidRouteProfile(routeProfile);

assertTrue(isValidProfile);
}

@Test
public void isValidRouteProfile_returnsTrueWithWalkingProfile() throws Exception {
String routeProfile = DirectionsCriteria.PROFILE_WALKING;

boolean isValidProfile = RouteUtils.isValidRouteProfile(routeProfile);

assertTrue(isValidProfile);
}

@Test
public void isValidRouteProfile_returnsFalseWithInvalidProfile() throws Exception {
String routeProfile = "invalid_profile";
Expand All @@ -131,6 +158,15 @@ public void isValidRouteProfile_returnsFalseWithInvalidProfile() throws Exceptio
assertFalse(isValidProfile);
}

@Test
public void isValidRouteProfile_returnsFalseWithNullProfile() throws Exception {
String routeProfile = null;

boolean isValidProfile = RouteUtils.isValidRouteProfile(routeProfile);

assertFalse(isValidProfile);
}

private int obtainLastStepIndex(DirectionsRoute route) throws IOException {
RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
int lastStepIndex = lastLeg.steps().indexOf(lastLeg.steps().get(lastLeg.steps().size() - 1));
Expand Down

0 comments on commit 307bcf5

Please sign in to comment.