Skip to content

Commit

Permalink
adds validation utils class (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Mace authored Oct 25, 2017
1 parent 7d1375f commit 4f872e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;
import com.mapbox.services.android.navigation.v5.snap.Snap;
import com.mapbox.services.android.navigation.v5.snap.SnapToRoute;
import com.mapbox.services.android.navigation.v5.utils.ValidationUtils;
import com.mapbox.services.android.telemetry.MapboxEvent;
import com.mapbox.services.android.telemetry.MapboxTelemetry;
import com.mapbox.services.android.telemetry.location.LocationEngine;
Expand Down Expand Up @@ -353,6 +354,7 @@ public LocationEngine getLocationEngine() {
* @since 0.1.0
*/
public void startNavigation(@NonNull DirectionsRoute directionsRoute) {
ValidationUtils.validDirectionsRoute(directionsRoute, options.defaultMilestonesEnabled());
this.directionsRoute = directionsRoute;
Timber.d("MapboxNavigation startNavigation called.");
if (!isBound) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mapbox.services.android.navigation.v5.utils;

import com.mapbox.directions.v5.models.DirectionsRoute;

import java.util.MissingFormatArgumentException;

public final class ValidationUtils {

private ValidationUtils() {
// Class should not be initialized.
}

public static void validDirectionsRoute(DirectionsRoute directionsRoute,
boolean defaultMilestonesEnabled) {
if (!directionsRoute.routeOptions().voiceInstructions() && defaultMilestonesEnabled) {
throw new MissingFormatArgumentException("Using the default milestone requires the "
+ "directions route to include the voice instructions object.");
}
}
}

0 comments on commit 4f872e2

Please sign in to comment.