|
27 | 27 | import static com.mapbox.api.directions.v5.DirectionsCriteria.APPROACH_CURB; |
28 | 28 | import static org.hamcrest.core.StringStartsWith.startsWith; |
29 | 29 | import static org.junit.Assert.assertEquals; |
| 30 | +import static org.junit.Assert.assertFalse; |
30 | 31 | import static org.junit.Assert.assertNotNull; |
| 32 | +import static org.junit.Assert.assertNull; |
31 | 33 | import static org.junit.Assert.assertTrue; |
32 | 34 |
|
33 | 35 | public class MapboxMatrixTest extends TestUtils { |
@@ -149,7 +151,13 @@ public void validCoordinatesTotal() throws ServicesException { |
149 | 151 | } |
150 | 152 |
|
151 | 153 | thrown.expect(ServicesException.class); |
152 | | - thrown.expectMessage(startsWith("Maximum of 25 coordinates are allowed for this API.")); |
| 154 | + thrown.expectMessage(startsWith( |
| 155 | + "A maximum of 25 coordinates is the default " + |
| 156 | + " allowed for this API. If your Mapbox account has been enabled by the" + |
| 157 | + " Mapbox team to make a request with more than 25 coordinates, please use" + |
| 158 | + " the builder's coordinateListSizeLimit() method and pass through your account" + |
| 159 | + "-specific maximum." |
| 160 | + )); |
153 | 161 | MapboxMatrix.builder() |
154 | 162 | .accessToken(ACCESS_TOKEN) |
155 | 163 | .profile(DirectionsCriteria.PROFILE_DRIVING) |
@@ -222,4 +230,60 @@ public void annotationsAndApproaches() throws ServicesException, IOException { |
222 | 230 | assertEquals(27192.3, response.body().distances().get(0)[2], DELTA); |
223 | 231 | assertEquals("McAllister Street", response.body().destinations().get(0).name()); |
224 | 232 | } |
| 233 | + |
| 234 | + @Test |
| 235 | + public void destinationListSizeLimitCheckThatCallWorks() throws ServicesException, IOException { |
| 236 | + int total = 35; |
| 237 | + ArrayList<Point> positions = new ArrayList<>(); |
| 238 | + for (int i = 0; i < total; i++) { |
| 239 | + positions.add(Point.fromLngLat(0.0, 0.0)); |
| 240 | + } |
| 241 | + |
| 242 | + MapboxMatrix client = MapboxMatrix.builder() |
| 243 | + .accessToken(ACCESS_TOKEN) |
| 244 | + .profile(DirectionsCriteria.PROFILE_DRIVING) |
| 245 | + .coordinateListSizeLimit(50) |
| 246 | + .coordinates(positions) |
| 247 | + .build(); |
| 248 | + |
| 249 | + Response<MatrixResponse> response = client.executeCall(); |
| 250 | + assertFalse(response.isSuccessful()); |
| 251 | + assertNull(response.body()); |
| 252 | + } |
| 253 | + |
| 254 | + @Test |
| 255 | + public void build_invalidCoordinateAndDefaultMaxExceptionThrown() throws Exception { |
| 256 | + int total = 35; |
| 257 | + ArrayList<Point> positions = new ArrayList<>(); |
| 258 | + for (int i = 0; i < total; i++) { |
| 259 | + positions.add(Point.fromLngLat(0.0, 0.0)); |
| 260 | + } |
| 261 | + |
| 262 | + thrown.expect(ServicesException.class); |
| 263 | + thrown.expectMessage("If you're going to use the coordinateListSizeLimit() method," |
| 264 | + + " please pass through a number that's equal to or greater than the size of" |
| 265 | + + " your coordinate list."); |
| 266 | + MapboxMatrix.builder() |
| 267 | + .accessToken(ACCESS_TOKEN) |
| 268 | + .coordinateListSizeLimit(20) |
| 269 | + .coordinates(positions) |
| 270 | + .build(); |
| 271 | + } |
| 272 | + |
| 273 | + @Test |
| 274 | + public void build_invalidLessThanZeroDefaultMaxExceptionThrown() throws Exception { |
| 275 | + int total = 20; |
| 276 | + ArrayList<Point> positions = new ArrayList<>(); |
| 277 | + for (int i = 0; i < total; i++) { |
| 278 | + positions.add(Point.fromLngLat(0.0, 0.0)); |
| 279 | + } |
| 280 | + thrown.expect(ServicesException.class); |
| 281 | + thrown.expectMessage("If you're going to use the coordinateListSizeLimit() method, " + |
| 282 | + "please pass through a number that's greater than zero."); |
| 283 | + MapboxMatrix.builder() |
| 284 | + .accessToken(ACCESS_TOKEN) |
| 285 | + .coordinates(positions) |
| 286 | + .coordinateListSizeLimit(-3) |
| 287 | + .build(); |
| 288 | + } |
225 | 289 | } |
0 commit comments