Skip to content

Commit 56470d3

Browse files
authored
all accesToken fields should be annotated with @nonnull (#875)
1 parent b198e45 commit 56470d3

11 files changed

Lines changed: 85 additions & 25 deletions

File tree

services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private static String formatCoordinates(List<Point> coordinates) {
255255
@Override
256256
protected abstract String baseUrl();
257257

258-
@Nullable
258+
@NonNull
259259
abstract String accessToken();
260260

261261
@Nullable

services-directions/src/test/java/com/mapbox/api/directions/v5/MapboxDirectionsTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.mapbox.core.exceptions.ServicesException;
1313
import com.mapbox.geojson.Point;
1414

15+
import org.hamcrest.core.StringStartsWith;
1516
import org.junit.After;
1617
import org.junit.Assert;
1718
import org.junit.Before;
@@ -130,13 +131,23 @@ public void addWaypoint_maxWaypointsAdded() throws Exception {
130131

131132
@Test
132133
public void build_noAccessTokenExceptionThrown() throws Exception {
134+
thrown.expect(IllegalStateException.class);
135+
thrown.expectMessage("Missing required properties: accessToken");
136+
MapboxDirections.builder()
137+
.origin(Point.fromLngLat(1.0, 1.0))
138+
.destination(Point.fromLngLat(2.0, 2.0))
139+
.build();
140+
}
141+
142+
@Test
143+
public void build_invalidAccessTokenExceptionThrown() throws ServicesException {
133144
thrown.expect(ServicesException.class);
134-
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
135-
MapboxDirections mapboxDirections = MapboxDirections.builder()
145+
thrown.expectMessage(StringStartsWith.startsWith("Using Mapbox Services requires setting a valid access token"));
146+
MapboxDirections.builder()
147+
.accessToken("")
136148
.origin(Point.fromLngLat(1.0, 1.0))
137149
.destination(Point.fromLngLat(2.0, 2.0))
138150
.build();
139-
mapboxDirections.executeCall();
140151
}
141152

142153
@Test

services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public Call<List<GeocodingResponse>> cloneBatchCall() {
177177
@NonNull
178178
abstract String mode();
179179

180-
@Nullable
180+
@NonNull
181181
abstract String accessToken();
182182

183183
@NonNull

services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,25 @@ public void executeBatchCall_exceptionThrownWhenModeNotSetCorrectly() throws Exc
6666
}
6767

6868
@Test
69-
public void build_accessTokenNotValidException() throws Exception {
69+
public void build_noAccessTokenExceptionThrown() throws Exception {
70+
thrown.expect(IllegalStateException.class);
71+
thrown.expectMessage("Missing required properties: accessToken");
72+
MapboxGeocoding.builder()
73+
.query("1600 pennsylvania ave nw")
74+
.baseUrl(mockUrl.toString())
75+
.build();
76+
}
77+
78+
@Test
79+
public void build_invalidAccessTokenExceptionThrown() throws Exception {
7080
thrown.expect(ServicesException.class);
7181
thrown.expectMessage(
7282
startsWith("Using Mapbox Services requires setting a valid access token."));
73-
MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder()
83+
MapboxGeocoding.builder()
84+
.accessToken("")
7485
.query("1600 pennsylvania ave nw")
7586
.baseUrl(mockUrl.toString())
7687
.build();
77-
mapboxGeocoding.executeCall();
7888
}
7989

8090
@Test

services-matching/src/main/java/com/mapbox/api/matching/v5/MapboxMapMatching.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private static List<Point> formatCoordinates(String coordinates) {
247247
@Nullable
248248
abstract String clientAppName();
249249

250-
@Nullable
250+
@NonNull
251251
abstract String accessToken();
252252

253253
@Nullable

services-matching/src/test/java/com/mapbox/api/matching/v5/MapboxMapMatchingTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,24 @@ public void build_throwsExceptionWhenNotMatchingTimestampsForEachCoord() throws
168168
}
169169

170170
@Test
171-
public void build_throwsExceptionWhenNoValidAccessTokenProvided() throws Exception {
171+
public void build_noAccessTokenExceptionThrown() throws Exception {
172+
thrown.expect(IllegalStateException.class);
173+
thrown.expectMessage("Missing required properties: accessToken");
174+
MapboxMapMatching.builder()
175+
.coordinate(Point.fromLngLat(2.0, 2.0))
176+
.coordinate(Point.fromLngLat(2.0, 2.0))
177+
.build();
178+
}
179+
180+
@Test
181+
public void build_invalidAccessTokenExceptionThrown() throws Exception {
172182
thrown.expect(ServicesException.class);
173-
thrown.expectMessage(
174-
startsWith("Using Mapbox Services requires setting a valid access token."));
175-
MapboxMapMatching mapMatching = MapboxMapMatching.builder()
183+
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
184+
MapboxMapMatching.builder()
185+
.accessToken("")
176186
.coordinate(Point.fromLngLat(2.0, 2.0))
177187
.coordinate(Point.fromLngLat(2.0, 2.0))
178-
.baseUrl("https://foobar.com")
179188
.build();
180-
mapMatching.executeCall();
181189
}
182190

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

224+
216225
@Test
217226
public void accessToken_doesGetPlacedInUrlCorrectly() throws Exception {
218227
MapboxMapMatching mapMatching = MapboxMapMatching.builder()

services-matrix/src/test/java/com/mapbox/api/matrix/v1/MapboxMatrixTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,20 @@ public void testCallSanity() throws ServicesException, IOException {
9191
}
9292

9393
@Test
94-
public void requiredAccessToken() throws ServicesException {
94+
public void build_noAccessTokenExceptionThrown() throws Exception {
95+
thrown.expect(IllegalStateException.class);
96+
thrown.expectMessage("Missing required properties: accessToken");
97+
MapboxMatrix.builder()
98+
.baseUrl(mockUrl.toString())
99+
.coordinate(Point.fromLngLat(2.0, 2.0))
100+
.coordinate(Point.fromLngLat(4.0, 4.0))
101+
.build();
102+
}
103+
104+
@Test
105+
public void build_invalidAccessTokenExceptionThrown() throws Exception {
95106
thrown.expect(ServicesException.class);
96-
thrown.expectMessage(startsWith("Using Mapbox Services requires setting a valid access token"));
107+
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
97108
MapboxMatrix.builder()
98109
.accessToken("")
99110
.baseUrl(mockUrl.toString())

services-optimization/src/main/java/com/mapbox/api/optimization/v1/MapboxOptimization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected Call<OptimizationResponse> initializeCall() {
112112
@Nullable
113113
abstract String clientAppName();
114114

115-
@Nullable
115+
@NonNull
116116
abstract String accessToken();
117117

118118
@NonNull

services-optimization/src/test/java/com/mapbox/api/optimization/v1/MapboxOptimizationTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,25 @@ public void build_doesThrowTwoCoordinateMinException() throws Exception {
7979
}
8080

8181
@Test
82-
public void build_doesThrowRequiredAccessTokenException() throws ServicesException {
83-
thrown.expect(ServicesException.class);
84-
thrown.expectMessage(startsWith("Using Mapbox Services requires setting a valid access token"));
82+
public void build_noAccessTokenExceptionThrown() throws Exception {
83+
thrown.expect(IllegalStateException.class);
84+
thrown.expectMessage("Missing required properties: accessToken");
8585
MapboxOptimization.builder()
8686
.coordinate(Point.fromLngLat(1.0, 1.0))
8787
.coordinate(Point.fromLngLat(1.0, 1.0))
8888
.build();
8989
}
9090

91+
@Test
92+
public void build_invalidAccessTokenExceptionThrown() throws Exception {
93+
thrown.expect(ServicesException.class);
94+
thrown.expectMessage("Using Mapbox Services requires setting a valid access token.");
95+
MapboxOptimization.builder()
96+
.accessToken("")
97+
.coordinate(Point.fromLngLat(1.0, 1.0))
98+
.coordinate(Point.fromLngLat(1.0, 1.0))
99+
.build();
100+
}
91101
@Test
92102
public void build_doesThrowTooManyCoordinatesException() throws ServicesException {
93103
int total = 13;

services-staticmap/src/main/java/com/mapbox/api/staticmap/v1/MapboxStaticMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class MapboxStaticMap {
3838
private static final String BEFORE_LAYER = "before_layer";
3939
private static final String CAMERA_AUTO = "auto";
4040

41-
@Nullable
41+
@NonNull
4242
abstract String accessToken();
4343

4444
@NonNull

0 commit comments

Comments
 (0)