Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,86 @@ public final class DirectionsCriteria {
@SuppressWarnings("checkstyle:javadocvariable")
public static final int TRAFFIC_TENDENCY_RAPIDLY_DECREASING_CONGESTION = 5;

/*
* Used in Japan for all payments other than transponder such as ETC or ETCX.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_GENERAL = "general";

/*
* A transponder in any country, for any transponder system (e.g. EZ-PASS, Peach Pass).
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_ETC = "etc";

/*
* A transponder only used for several specific roads in Japan.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_ETCX = "etcx";

/*
* Payment can be done in cash (coins or notes) of the locally common currency.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_CASH = "cash";

/*
* Exact cash payment or tokens at a toll structure.
* Tokens are pre-purchased coins used to pay toll.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_EXACT_CASH = "exact_cash";

/*
* Payment can be done by coins.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_COINS = "coins";

/*
* Payment can be done by notes (paper money).
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_NOTES = "notes";

/*
* Payment can be done with common debit cards.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_DEBIT_CARDS = "debit_cards";

/*
* A pre-purchased pass or subscription.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_PASS_CARD = "pass_card";

/*
* Payment can be done with common credit cards.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_CREDIT_CARDS = "credit_cards";

/*
* Automatic monitor of vehicles that enter the toll road without a transponder.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_VIDEO = "video";

/*
* Generic tag for any cryptocurrency.
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_CRYPTOCURRENCIES = "cryptocurrencies";

/*
* Payment possible via phone or other personal device's app
* (e.g. Bluetooth, barcode, CR code, etc.).
*/
@SuppressWarnings("checkstyle:javadocvariable")
public static final String PAYMENT_METHOD_APP = "app";

private DirectionsCriteria() {
//not called
}
Expand Down Expand Up @@ -481,4 +561,27 @@ private DirectionsCriteria() {
})
public @interface TrafficTendencyCriteria {
}

/*
* Supported payment methods. See {@link RouteOptions#paymentMethods()}.
*/
@SuppressWarnings("checkstyle:javadoctype")
@Retention(RetentionPolicy.CLASS)
@StringDef({
PAYMENT_METHOD_GENERAL,
PAYMENT_METHOD_ETC,
PAYMENT_METHOD_ETCX,
PAYMENT_METHOD_CASH,
PAYMENT_METHOD_EXACT_CASH,
PAYMENT_METHOD_COINS,
PAYMENT_METHOD_NOTES,
PAYMENT_METHOD_DEBIT_CARDS,
PAYMENT_METHOD_PASS_CARD,
PAYMENT_METHOD_CREDIT_CARDS,
PAYMENT_METHOD_VIDEO,
PAYMENT_METHOD_CRYPTOCURRENCIES,
PAYMENT_METHOD_APP,
})
public @interface PaymentMethodsCriteria {
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mapbox.api.directions.v5.models;

import androidx.annotation.Nullable;

import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -81,6 +80,16 @@ public static Builder builder() {
@Nullable
public abstract List<String> indications();

/*
* Available payment methods for the lane.
* @return A list of strings where each value
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
*/
@SuppressWarnings("checkstyle:javadocmethod")
@Nullable
@SerializedName("payment_methods")
public abstract List<String> paymentMethods();

/**
* Convert the current {@link IntersectionLanes} to its builder holding the currently assigned
* values. This allows you to modify a single property and then rebuild the object resulting in
Expand Down Expand Up @@ -167,6 +176,14 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
*/
public abstract Builder indications(@Nullable List<String> indications);

/*
* Set available payment methods for the lane.
* @param paymentMethods is a list of strings where each value
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
*/
@SuppressWarnings("checkstyle:javadocmethod")
public abstract Builder paymentMethods(@Nullable List<String> paymentMethods);

/**
* Build a new {@link IntersectionLanes} object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,29 @@ public List<Boolean> snappingIncludeStaticClosuresList() {
@Nullable
public abstract Boolean metadata();

/*
* Enables filtering the route and valid lanes by payment methods. Default is no filtering.
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
* @return a comma separated string where each value
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
*/
@SuppressWarnings("checkstyle:javadocmethod")
@SerializedName("payment_methods")
@Nullable
public abstract String paymentMethods();

/*
* Enables filtering the route and valid lanes by payment methods. Default is no filtering.
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
* @return a list of strings where each value
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
*/
@SuppressWarnings("checkstyle:javadocmethod")
@Nullable
public List<String> paymentMethodsList() {
return ParseUtils.parseToStrings(paymentMethods(), ",");
}

/**
* Gson type adapter for parsing Gson to this class.
*
Expand Down Expand Up @@ -1045,6 +1068,7 @@ public URL toUrl(@NonNull String accessToken) {
appendQueryParameter(sb, "compute_toll_cost", computeTollCost());
appendQueryParameter(sb, "waypoints_per_route", waypointsPerRoute());
appendQueryParameter(sb, "metadata", metadata());
appendQueryParameter(sb, "payment_methods", paymentMethods());

Map<String, SerializableJsonElement> unrecognized = unrecognized();
if (unrecognized != null) {
Expand Down Expand Up @@ -2090,6 +2114,31 @@ public Builder unrecognizedProperties(@Nullable Map<String, String> unrecognized
return unrecognized(null);
}

/*
* Enables filtering the route and valid lanes by payment methods. Default is no filtering.
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
* @param paymentMethods is a comma separated string where each value
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
* @return this builder
*/
@SuppressWarnings("checkstyle:javadocmethod")
@NonNull
public abstract Builder paymentMethods(@Nullable String paymentMethods);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing updates to MapboxDirections that use this new parameter (and corresponding request/response tests).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. But I'm not sure about response tests in the services-directions module. They seem like a duplication of tests from the services-dirctions-model module, as they just check how a JSON test file transforms to model. WDYT?


/*
* Enables filtering the route and valid lanes by payment methods. Default is no filtering.
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
* @param paymentMethods is a list of strings where each value
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
* @return this builder
*/
@SuppressWarnings("checkstyle:javadocmethod")
@NonNull
public Builder paymentMethodsList(@Nullable List<String> paymentMethods) {
String result = FormatUtils.join(",", paymentMethods);
return paymentMethods(result);
}

/**
* Builds the object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import com.mapbox.api.directions.v5.DirectionsCriteria;
import com.mapbox.core.TestUtils;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class IntersectionLanesTest extends TestUtils {

Expand Down Expand Up @@ -71,4 +73,19 @@ public void testFromJson_validIndication() {

assertEquals(intersectionLanes, intersectionLanesFromJson);
}

@Test
public void testFromJson_etcAndGeneralPayment() {
IntersectionLanes intersectionLanes = IntersectionLanes.builder()
.paymentMethods(Arrays.asList(
DirectionsCriteria.PAYMENT_METHOD_GENERAL,
DirectionsCriteria.PAYMENT_METHOD_ETC
))
.build();

String jsonString = "{\"payment_methods\": [\"general\", \"etc\"]}";
IntersectionLanes intersectionLanesFromJson = IntersectionLanes.fromJson(jsonString);

assertEquals(intersectionLanes, intersectionLanesFromJson);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static com.google.gson.JsonParser.parseString;
import static com.mapbox.api.directions.v5.utils.Asserts.assertContains;
import static com.mapbox.api.directions.v5.utils.Asserts.assertContainsExactCount;
import static com.mapbox.api.directions.v5.utils.Asserts.assertDoesNotContain;
import static com.mapbox.api.directions.v5.utils.Asserts.assertNoDuplicatedParameters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -37,7 +38,7 @@ public class RouteOptionsTest extends TestUtils {
*/
private static final String ROUTE_OPTIONS_JSON = "route_options_v5.json";
private static final String ROUTE_OPTIONS_URL =
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&snapping_include_static_closures=true%3B%3Bfalse&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&max_weight=2.9&compute_toll_cost=true&waypoints_per_route=true&metadata=true";
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&snapping_include_static_closures=true%3B%3Bfalse&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&max_weight=2.9&compute_toll_cost=true&waypoints_per_route=true&metadata=true&payment_methods=general";
private static final String ACCESS_TOKEN = "pk.token";

private final String optionsJson = loadJsonFixture(ROUTE_OPTIONS_JSON);
Expand Down Expand Up @@ -1011,6 +1012,45 @@ public void emptyExcludeObjectsCleansUpExcludes() {
assertNull(routeOptions.exclude());
}

@Test
public void etcPaymentMethod() {
RouteOptions routeOptions = routeOptions().toBuilder()
.paymentMethodsList(Arrays.asList(DirectionsCriteria.PAYMENT_METHOD_ETC))
.build();
String query = routeOptions.toUrl("test").getQuery();

assertEquals("etc", routeOptions.paymentMethods());
assertContains(query, "payment_methods=etc");
}

@Test
public void generalAndEtcPaymentsMethod() {
List<String> paymentMethods = Arrays.asList(
DirectionsCriteria.PAYMENT_METHOD_ETC,
DirectionsCriteria.PAYMENT_METHOD_GENERAL
);
RouteOptions routeOptions = routeOptions().toBuilder()
.paymentMethodsList(paymentMethods)
.build();
String query = routeOptions.toUrl("test").getQuery();

assertEquals("etc,general", routeOptions.paymentMethods());
assertEquals(paymentMethods, routeOptions.paymentMethodsList());
assertContains(query, "payment_methods=etc%2Cgeneral");
}

@Test
public void emptyPaymentMethodsList() {
RouteOptions routeOptions = routeOptions().toBuilder()
.paymentMethodsList(Collections.<String>emptyList())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test that checks what happens if you pass null (if it's supported) or don't call the method at all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I just felt confidence in case of null, because it's a default value. I didn't felt confidence in case of an empty list and added the test 🙂
If you think it's important, I will add a test for the null case 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen? Will there be a parameter with an empty string or no parameter at all? Since it's no parameter at all for an empty list I guess it will be the same for null so here I don't think it's necessary. I usually add tests for null and empty as a rule, just to be sure. No pressure tho. :)

.build();
String query = routeOptions.toUrl("test").getQuery();

assertNull(routeOptions.paymentMethods());
assertNull(routeOptions.paymentMethodsList());
assertDoesNotContain(query, "payment_methods");
}

/**
* Fills up all the options using string variants. Values need ot be equal to the ones in {@link #optionsJson}.
*/
Expand Down Expand Up @@ -1061,6 +1101,7 @@ private RouteOptions routeOptions() {
.metadata(true)
.computeTollCost(true)
.waypointsPerRoute(true)
.paymentMethods(DirectionsCriteria.PAYMENT_METHOD_GENERAL)
.build();
}

Expand Down Expand Up @@ -1168,6 +1209,7 @@ private RouteOptions routeOptionsList() {
.metadata(true)
.computeTollCost(true)
.waypointsPerRoute(true)
.paymentMethodsList(Arrays.asList(DirectionsCriteria.PAYMENT_METHOD_GENERAL))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"enable_refresh": true,
"metadata": true,
"waypoints_per_route": true,
"compute_toll_cost": true
"compute_toll_cost": true,
"payment_methods": "general"
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Call<DirectionsResponse> getCall(
@Query("max_weight") Double maxWeight,
@Query("compute_toll_cost") Boolean computeTollCost,
@Query("waypoints_per_route") Boolean waypointsPerRoute,
@Query("metadata") Boolean metadata
@Query("metadata") Boolean metadata,
@Query("payment_methods") String paymentMethods
);

/**
Expand Down Expand Up @@ -191,6 +192,7 @@ Call<DirectionsResponse> postCall(
@Field("max_weight") Double maxWeight,
@Field("compute_toll_cost") Boolean computeTollCost,
@Field("waypoints_per_route") Boolean waypointsPerRoute,
@Field("metadata") Boolean metadata
@Field("metadata") Boolean metadata,
@Field("payment_methods") String paymentMethods
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ private Call<DirectionsResponse> get() {
routeOptions().maxWeight(),
routeOptions().computeTollCost(),
routeOptions().waypointsPerRoute(),
routeOptions().metadata()
routeOptions().metadata(),
routeOptions().paymentMethods()
);
}

Expand Down Expand Up @@ -156,7 +157,8 @@ private Call<DirectionsResponse> post() {
routeOptions().maxWeight(),
routeOptions().computeTollCost(),
routeOptions().waypointsPerRoute(),
routeOptions().metadata()
routeOptions().metadata(),
routeOptions().paymentMethods()
);
}

Expand Down
Loading