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 @@ -255,7 +255,7 @@ private static String formatCoordinates(List<Point> coordinates) {
@Override
protected abstract String baseUrl();

@Nullable
@NonNull
abstract String accessToken();

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mapbox.core.exceptions.ServicesException;
import com.mapbox.geojson.Point;

import org.hamcrest.core.StringStartsWith;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -130,13 +131,23 @@ public void addWaypoint_maxWaypointsAdded() throws Exception {

@Test
public void build_noAccessTokenExceptionThrown() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Missing required properties: accessToken");
MapboxDirections.builder()
.origin(Point.fromLngLat(1.0, 1.0))
.destination(Point.fromLngLat(2.0, 2.0))
.build();
}

@Test
public void build_invalidAccessTokenExceptionThrown() throws ServicesException {
thrown.expect(ServicesException.class);
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
MapboxDirections mapboxDirections = MapboxDirections.builder()
thrown.expectMessage(StringStartsWith.startsWith("Using Mapbox Services requires setting a valid access token"));
MapboxDirections.builder()
.accessToken("")
.origin(Point.fromLngLat(1.0, 1.0))
.destination(Point.fromLngLat(2.0, 2.0))
.build();
mapboxDirections.executeCall();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public Call<List<GeocodingResponse>> cloneBatchCall() {
@NonNull
abstract String mode();

@Nullable
@NonNull
abstract String accessToken();

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,25 @@ public void executeBatchCall_exceptionThrownWhenModeNotSetCorrectly() throws Exc
}

@Test
public void build_accessTokenNotValidException() throws Exception {
public void build_noAccessTokenExceptionThrown() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Missing required properties: accessToken");
MapboxGeocoding.builder()
.query("1600 pennsylvania ave nw")
.baseUrl(mockUrl.toString())
.build();
}

@Test
public void build_invalidAccessTokenExceptionThrown() throws Exception {
thrown.expect(ServicesException.class);
thrown.expectMessage(
startsWith("Using Mapbox Services requires setting a valid access token."));
MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder()
MapboxGeocoding.builder()
.accessToken("")
.query("1600 pennsylvania ave nw")
.baseUrl(mockUrl.toString())
.build();
mapboxGeocoding.executeCall();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private static List<Point> formatCoordinates(String coordinates) {
@Nullable
abstract String clientAppName();

@Nullable
@NonNull
abstract String accessToken();

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,24 @@ public void build_throwsExceptionWhenNotMatchingTimestampsForEachCoord() throws
}

@Test
public void build_throwsExceptionWhenNoValidAccessTokenProvided() throws Exception {
public void build_noAccessTokenExceptionThrown() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Missing required properties: accessToken");
MapboxMapMatching.builder()
.coordinate(Point.fromLngLat(2.0, 2.0))
.coordinate(Point.fromLngLat(2.0, 2.0))
.build();
}

@Test
public void build_invalidAccessTokenExceptionThrown() throws Exception {
thrown.expect(ServicesException.class);
thrown.expectMessage(
startsWith("Using Mapbox Services requires setting a valid access token."));
MapboxMapMatching mapMatching = MapboxMapMatching.builder()
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
MapboxMapMatching.builder()
.accessToken("")
.coordinate(Point.fromLngLat(2.0, 2.0))
.coordinate(Point.fromLngLat(2.0, 2.0))
.baseUrl("https://foobar.com")
.build();
mapMatching.executeCall();
}

@Test
Expand Down Expand Up @@ -213,6 +221,7 @@ public void mapMatchingToDirectionsRoute() throws Exception {
assertNotNull(mapMatching.executeCall().body().matchings().get(0).toDirectionRoute());
}


@Test
public void accessToken_doesGetPlacedInUrlCorrectly() throws Exception {
MapboxMapMatching mapMatching = MapboxMapMatching.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,20 @@ public void testCallSanity() throws ServicesException, IOException {
}

@Test
public void requiredAccessToken() throws ServicesException {
public void build_noAccessTokenExceptionThrown() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Missing required properties: accessToken");
MapboxMatrix.builder()
.baseUrl(mockUrl.toString())
.coordinate(Point.fromLngLat(2.0, 2.0))
.coordinate(Point.fromLngLat(4.0, 4.0))
.build();
}

@Test
public void build_invalidAccessTokenExceptionThrown() throws Exception {
thrown.expect(ServicesException.class);
thrown.expectMessage(startsWith("Using Mapbox Services requires setting a valid access token"));
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
MapboxMatrix.builder()
.accessToken("")
.baseUrl(mockUrl.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected Call<OptimizationResponse> initializeCall() {
@Nullable
abstract String clientAppName();

@Nullable
@NonNull
abstract String accessToken();

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,25 @@ public void build_doesThrowTwoCoordinateMinException() throws Exception {
}

@Test
public void build_doesThrowRequiredAccessTokenException() throws ServicesException {
thrown.expect(ServicesException.class);
thrown.expectMessage(startsWith("Using Mapbox Services requires setting a valid access token"));
public void build_noAccessTokenExceptionThrown() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Missing required properties: accessToken");
MapboxOptimization.builder()
.coordinate(Point.fromLngLat(1.0, 1.0))
.coordinate(Point.fromLngLat(1.0, 1.0))
.build();
}

@Test
public void build_invalidAccessTokenExceptionThrown() throws Exception {
thrown.expect(ServicesException.class);
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
MapboxOptimization.builder()
.accessToken("")
.coordinate(Point.fromLngLat(1.0, 1.0))
.coordinate(Point.fromLngLat(1.0, 1.0))
.build();
}
@Test
public void build_doesThrowTooManyCoordinatesException() throws ServicesException {
int total = 13;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class MapboxStaticMap {
private static final String BEFORE_LAYER = "before_layer";
private static final String CAMERA_AUTO = "auto";

@Nullable
@NonNull
abstract String accessToken();

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ public void build_throwsExceptionWhenStyleIdNotSet() throws Exception {
}

@Test
public void accessToken_exceptionGetsThrownWhenMissing() throws Exception {
thrown.expect(ServicesException.class);
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
public void build_noAccessTokenExceptionThrown() throws Exception {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Missing required properties: accessToken");
MapboxStaticMap.builder().build();
}

@Test
public void build_invalidAccessTokenExceptionThrown() throws Exception {
thrown.expect(ServicesException.class);
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
MapboxStaticMap.builder()
.accessToken("")
.build();
}

@Test
public void baseUrl_settingShowsUpInTheRequestUrl() throws Exception {
MapboxStaticMap staticMap = MapboxStaticMap.builder()
.accessToken(ACCESS_TOKEN)
Expand Down