11package com .mapbox .api .geocoding .v5 ;
22
33import com .mapbox .api .geocoding .v5 .models .GeocodingResponse ;
4- import com .mapbox .core .TestUtils ;
54import com .mapbox .core .exceptions .ServicesException ;
65import com .mapbox .geojson .BoundingBox ;
76import com .mapbox .geojson .Point ;
87
9- import org .hamcrest .junit .ExpectedException ;
10- import org .junit .After ;
11- import org .junit .Before ;
12- import org .junit .Rule ;
138import org .junit .Test ;
149
1510import java .io .IOException ;
1611import java .util .List ;
1712import java .util .Locale ;
1813
19- import okhttp3 .HttpUrl ;
20- import okhttp3 .mockwebserver .MockResponse ;
21- import okhttp3 .mockwebserver .MockWebServer ;
22- import okhttp3 .mockwebserver .RecordedRequest ;
2314import retrofit2 .Response ;
2415
2516import static org .hamcrest .Matchers .startsWith ;
@@ -67,7 +58,7 @@ public void executeBatchCall_exceptionThrownWhenModeNotSetCorrectly() throws Exc
6758 }
6859
6960 @ Test
70- public void build_noAccessTokenExceptionThrown () throws Exception {
61+ public void build_noAccessTokenExceptionThrown () {
7162 thrown .expect (IllegalStateException .class );
7263 thrown .expectMessage ("Missing required properties: accessToken" );
7364 MapboxGeocoding .builder ()
@@ -77,7 +68,7 @@ public void build_noAccessTokenExceptionThrown() throws Exception {
7768 }
7869
7970 @ Test
80- public void build_invalidAccessTokenExceptionThrown () throws Exception {
71+ public void build_invalidAccessTokenExceptionThrown () {
8172 thrown .expect (ServicesException .class );
8273 thrown .expectMessage (
8374 startsWith ("Using Mapbox Services requires setting a valid access token." ));
@@ -113,7 +104,7 @@ public void query_acceptsPointsCorrectly() throws Exception {
113104 }
114105
115106 @ Test
116- public void baseUrl_doesChangeTheRequestUrl () throws Exception {
107+ public void baseUrl_doesChangeTheRequestUrl () {
117108 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
118109 .accessToken (ACCESS_TOKEN )
119110 .baseUrl ("https://foobar.com" )
@@ -124,7 +115,7 @@ public void baseUrl_doesChangeTheRequestUrl() throws Exception {
124115 }
125116
126117 @ Test
127- public void country_localeCountryConvertsCorrectly () throws Exception {
118+ public void country_localeCountryConvertsCorrectly () {
128119 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
129120 .accessToken (ACCESS_TOKEN )
130121 .baseUrl (mockUrl .toString ())
@@ -135,7 +126,7 @@ public void country_localeCountryConvertsCorrectly() throws Exception {
135126 }
136127
137128 @ Test
138- public void country_localeCountryHandlesMultipleCountriesCorrectly () throws Exception {
129+ public void country_localeCountryHandlesMultipleCountriesCorrectly () {
139130 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
140131 .accessToken (ACCESS_TOKEN )
141132 .baseUrl (mockUrl .toString ())
@@ -148,7 +139,7 @@ public void country_localeCountryHandlesMultipleCountriesCorrectly() throws Exce
148139 }
149140
150141 @ Test
151- public void proximity_doesGetAddedToUrlCorrectly () throws Exception {
142+ public void proximity_doesGetAddedToUrlCorrectly () {
152143 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
153144 .accessToken (ACCESS_TOKEN )
154145 .baseUrl (mockUrl .toString ())
@@ -160,7 +151,7 @@ public void proximity_doesGetAddedToUrlCorrectly() throws Exception {
160151 }
161152
162153 @ Test
163- public void geocodingTypes_getsAddedToUrlCorrectly () throws Exception {
154+ public void geocodingTypes_getsAddedToUrlCorrectly () {
164155 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
165156 .accessToken (ACCESS_TOKEN )
166157 .baseUrl (mockUrl .toString ())
@@ -172,7 +163,7 @@ public void geocodingTypes_getsAddedToUrlCorrectly() throws Exception {
172163 }
173164
174165 @ Test
175- public void autocomplete_getsAddedToUrlCorrectly () throws Exception {
166+ public void autocomplete_getsAddedToUrlCorrectly () {
176167 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
177168 .accessToken (ACCESS_TOKEN )
178169 .baseUrl (mockUrl .toString ())
@@ -184,7 +175,7 @@ public void autocomplete_getsAddedToUrlCorrectly() throws Exception {
184175 }
185176
186177 @ Test
187- public void bbox_getsFormattedCorrectlyForUrl () throws Exception {
178+ public void bbox_getsFormattedCorrectlyForUrl () {
188179 BoundingBox bbox = BoundingBox .fromLngLats (
189180 -77.083056 , 38.908611 , -76.997778 , 38.959167 );
190181 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
@@ -198,7 +189,7 @@ public void bbox_getsFormattedCorrectlyForUrl() throws Exception {
198189 }
199190
200191 @ Test
201- public void bbox_asPoints_getsFormattedCorrectlyForUrl () throws Exception {
192+ public void bbox_asPoints_getsFormattedCorrectlyForUrl () {
202193 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
203194 .accessToken (ACCESS_TOKEN )
204195 .baseUrl (mockUrl .toString ())
@@ -213,7 +204,7 @@ public void bbox_asPoints_getsFormattedCorrectlyForUrl() throws Exception {
213204 }
214205
215206 @ Test
216- public void limit_getsAddedToUrlCorrectly () throws Exception {
207+ public void limit_getsAddedToUrlCorrectly () {
217208 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
218209 .accessToken (ACCESS_TOKEN )
219210 .baseUrl (mockUrl .toString ())
@@ -225,7 +216,7 @@ public void limit_getsAddedToUrlCorrectly() throws Exception {
225216 }
226217
227218 @ Test
228- public void language_getsConvertedToUrlCorrectly () throws Exception {
219+ public void language_getsConvertedToUrlCorrectly () {
229220 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
230221 .accessToken (ACCESS_TOKEN )
231222 .baseUrl (mockUrl .toString ())
@@ -237,7 +228,7 @@ public void language_getsConvertedToUrlCorrectly() throws Exception {
237228 }
238229
239230 @ Test
240- public void clientAppName_hasAppInString () throws Exception {
231+ public void clientAppName_hasAppInString () {
241232 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
242233 .accessToken (ACCESS_TOKEN )
243234 .baseUrl (mockUrl .toString ())
@@ -249,7 +240,7 @@ public void clientAppName_hasAppInString() throws Exception {
249240 }
250241
251242 @ Test
252- public void reverseMode_getsAddedToUrlCorrectly () throws Exception {
243+ public void reverseMode_getsAddedToUrlCorrectly () {
253244 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
254245 .accessToken (ACCESS_TOKEN )
255246 .baseUrl ("https://foobar.com" )
@@ -270,7 +261,7 @@ public void reverseMode_getsAddedToUrlCorrectly() throws Exception {
270261 }
271262
272263 @ Test
273- public void reverseMode_onlyLimit1_Allowed () throws Exception {
264+ public void reverseMode_onlyLimit1_Allowed () {
274265 thrown .expect (ServicesException .class );
275266 thrown .expectMessage (startsWith ("Limit must be combined with a single type" ));
276267 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
@@ -296,7 +287,7 @@ public void fuzzyMatchSanity() throws Exception {
296287 }
297288
298289 @ Test
299- public void fuzzyMatch_getsAddedToUrlCorrectly () throws Exception {
290+ public void fuzzyMatch_getsAddedToUrlCorrectly () {
300291 MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
301292 .accessToken (ACCESS_TOKEN )
302293 .query ("wahsington" )
@@ -307,4 +298,86 @@ public void fuzzyMatch_getsAddedToUrlCorrectly() throws Exception {
307298 assertTrue (mapboxGeocoding .cloneCall ().request ().url ().toString ()
308299 .contains ("fuzzyMatch=true" ));
309300 }
301+
302+ @ Test
303+ public void intersectionSearchSanity () throws IOException {
304+ MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
305+ .accessToken (ACCESS_TOKEN )
306+ .intersectionStreets ("Market Street" , "Fremont Street" )
307+ .proximity ("-122.39738575285674,37.792514711136945" )
308+ .geocodingTypes (GeocodingCriteria .TYPE_ADDRESS )
309+ .baseUrl (mockUrl .toString ())
310+ .build ();
311+ assertNotNull (mapboxGeocoding );
312+ Response <GeocodingResponse > response = mapboxGeocoding .executeCall ();
313+ assertEquals (200 , response .code ());
314+ }
315+
316+ @ Test
317+ public void intersectionSearchAndAddedCorrectly () {
318+ MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
319+ .accessToken (ACCESS_TOKEN )
320+ .intersectionStreets ("Street one" , "Street two" )
321+ .proximity ("-122.39738575285674,37.792514711136945" )
322+ .geocodingTypes (GeocodingCriteria .TYPE_ADDRESS )
323+ .baseUrl (mockUrl .toString ())
324+ .build ();
325+ assertNotNull (mapboxGeocoding );
326+ assertTrue (mapboxGeocoding .cloneCall ().request ().url ().toString ().contains ("and" ));
327+ }
328+
329+ @ Test
330+ public void intersectionSearch_AddIntersectionToQuery () {
331+ MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
332+ .accessToken (ACCESS_TOKEN )
333+ .intersectionStreets ("Market Street" , "Fremont Street" )
334+ .proximity ("-122.39738575285674,37.792514711136945" )
335+ .geocodingTypes (GeocodingCriteria .TYPE_ADDRESS )
336+ .baseUrl (mockUrl .toString ())
337+ .build ();
338+ assertNotNull (mapboxGeocoding );
339+ assertTrue (mapboxGeocoding .cloneCall ().request ().url ().toString ()
340+ .contains ("Market%20Street%20and%20Fremont%20Street" ));
341+ }
342+
343+ @ Test
344+ public void intersectionSearch_WrongMode () {
345+ thrown .expect (ServicesException .class );
346+ thrown .expectMessage (
347+ startsWith ("Geocoding mode must be GeocodingCriteria.MODE_PLACES or GeocodingCriteria.MODE_PLACES_PERMANENT for intersection search." ));
348+ MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
349+ .accessToken (ACCESS_TOKEN )
350+ .mode ("RandomMode" )
351+ .intersectionStreets ("Market Street" , "Fremont Street" )
352+ .proximity ("-122.39738575285674,37.792514711136945" )
353+ .geocodingTypes (GeocodingCriteria .TYPE_ADDRESS )
354+ .baseUrl (mockUrl .toString ())
355+ .build ();
356+ }
357+
358+ @ Test
359+ public void intersectionSearch_AutoSetGeocodingType () {
360+ MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
361+ .accessToken (ACCESS_TOKEN )
362+ .intersectionStreets ("Market Street" , "Fremont Street" )
363+ .proximity ("-122.39738575285674,37.792514711136945" )
364+ .baseUrl (mockUrl .toString ())
365+ .build ();
366+ assertNotNull (mapboxGeocoding );
367+ assertTrue (mapboxGeocoding .cloneCall ().request ().url ().toString ()
368+ .contains ("types=address" ));
369+ }
370+
371+ @ Test
372+ public void intersectionSearch_EmptyPromixity () {
373+ thrown .expect (ServicesException .class );
374+ thrown .expectMessage (
375+ startsWith ("Geocoding proximity must be set for intersection search." ));
376+ MapboxGeocoding mapboxGeocoding = MapboxGeocoding .builder ()
377+ .accessToken (ACCESS_TOKEN )
378+ .intersectionStreets ("Market Street" , "Fremont Street" )
379+ .geocodingTypes (GeocodingCriteria .TYPE_ADDRESS )
380+ .baseUrl (mockUrl .toString ())
381+ .build ();
382+ }
310383}
0 commit comments