Skip to content

Commit

Permalink
all accesToken fields should be annotated with @nonnull (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
osana committed Aug 27, 2018
1 parent b198e45 commit 56470d3
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 25 deletions.
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
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
Expand Up @@ -177,7 +177,7 @@ public Call<List<GeocodingResponse>> cloneBatchCall() {
@NonNull
abstract String mode();

@Nullable
@NonNull
abstract String accessToken();

@NonNull
Expand Down
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
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
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
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
Expand Up @@ -112,7 +112,7 @@ protected Call<OptimizationResponse> initializeCall() {
@Nullable
abstract String clientAppName();

@Nullable
@NonNull
abstract String accessToken();

@NonNull
Expand Down
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
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
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

0 comments on commit 56470d3

Please sign in to comment.