2323import static org .junit .Assert .assertNotNull ;
2424import static org .junit .Assert .fail ;
2525
26+ import com .google .maps .internal .HttpHeaders ;
2627import com .google .maps .model .AddressComponentType ;
2728import com .google .maps .model .AddressType ;
2829import com .google .maps .model .ComponentFilter ;
3233import java .util .ArrayList ;
3334import java .util .Arrays ;
3435import java .util .List ;
36+ import java .util .UUID ;
37+ import okhttp3 .Headers ;
3538import org .junit .Test ;
3639import org .junit .experimental .categories .Category ;
3740
@@ -93,6 +96,68 @@ public void testPlaceGeocode() throws Exception {
9396 }
9497 }
9598
99+ private void testExperienceIdSample () {
100+ // [START maps_experience_id]
101+ final String experienceId = UUID .randomUUID ().toString ();
102+
103+ // instantiate context
104+ final GeoApiContext context =
105+ new GeoApiContext .Builder ().apiKey ("AIza-Maps-API-Key" ).build ();
106+
107+ // set the experience id on a request
108+ final GeocodingApiRequest request =
109+ GeocodingApi .newRequest (context ).experienceIds (experienceId );
110+
111+ // set a new experience id on another request
112+ final String otherExperienceId = UUID .randomUUID ().toString ();
113+ final GeocodingApiRequest request2 =
114+ GeocodingApi .newRequest (context ).experienceIds (otherExperienceId );
115+
116+ // make API request, the client will set the header
117+ // X-GOOG-MAPS-EXPERIENCE-ID: experienceId,otherExperienceId
118+ // [END maps_experience_id]
119+ }
120+
121+ @ Test
122+ public void testNoExperienceId () throws Exception {
123+ try (LocalTestServerContext sc = new LocalTestServerContext (placeGeocodeResponse )) {
124+ String placeID = "ChIJP3Sa8ziYEmsRUKgyFmh9AQM" ;
125+ GeocodingResult [] results = GeocodingApi .newRequest (sc .context ).place (placeID ).await ();
126+ final Headers headers = sc .headers ();
127+ final List <String > experienceIds = headers .values (HttpHeaders .X_GOOG_MAPS_EXPERIENCE_ID );
128+ assertEquals (0 , experienceIds .size ());
129+ }
130+ }
131+
132+ @ Test
133+ public void testExperienceId () throws Exception {
134+ try (LocalTestServerContext sc = new LocalTestServerContext (placeGeocodeResponse )) {
135+ String placeID = "ChIJP3Sa8ziYEmsRUKgyFmh9AQM" ;
136+ String expId = "experienceId" ;
137+ GeocodingApi .newRequest (sc .context ).experienceIds (expId )
138+ .place (placeID ).await ();
139+ final Headers headers = sc .headers ();
140+ final List <String > experienceIds = headers .values (HttpHeaders .X_GOOG_MAPS_EXPERIENCE_ID );
141+ assertEquals (1 , experienceIds .size ());
142+ assertEquals (expId , experienceIds .get (0 ));
143+ }
144+ }
145+
146+ @ Test
147+ public void testExperienceIds () throws Exception {
148+ try (LocalTestServerContext sc = new LocalTestServerContext (placeGeocodeResponse )) {
149+ String placeID = "ChIJP3Sa8ziYEmsRUKgyFmh9AQM" ;
150+ String expId = "experienceId" ;
151+ String expId2 = "experienceId2" ;
152+ GeocodingResult [] results = GeocodingApi .newRequest (sc .context ).experienceIds (expId , expId2 )
153+ .place (placeID ).await ();
154+ final Headers headers = sc .headers ();
155+ final List <String > experienceIds = headers .values (HttpHeaders .X_GOOG_MAPS_EXPERIENCE_ID );
156+ assertEquals (1 , experienceIds .size ());
157+ assertEquals (expId + "," + expId2 , experienceIds .get (0 ));
158+ }
159+ }
160+
96161 @ Test
97162 public void testAsync () throws Exception {
98163 try (LocalTestServerContext sc = new LocalTestServerContext (simpleGeocodeResponse )) {
@@ -148,8 +213,7 @@ public void testReverseGeocode() throws Exception {
148213 }
149214
150215 /**
151- * Simple geocode sample: <a
152- * href="https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA">
216+ * Simple geocode sample: <a href="https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA">
153217 * Address Geocode for "1600 Amphitheatre Parkway, Mountain View, CA"</a>.
154218 */
155219 @ Test
@@ -249,8 +313,7 @@ public void testGeocodeTheGoogleplex() throws Exception {
249313 }
250314
251315 /**
252- * Address geocode with bounds: <a
253- * href="https://maps.googleapis.com/maps/api/geocode/json?address=Winnetka&bounds=34.172684,-118.604794|34.236144,-118.500938">
316+ * Address geocode with bounds: <a href="https://maps.googleapis.com/maps/api/geocode/json?address=Winnetka&bounds=34.172684,-118.604794|34.236144,-118.500938">
254317 * Winnetka within (34.172684,-118.604794) - (34.236144,-118.500938)</a>.
255318 */
256319 @ Test
@@ -339,9 +402,8 @@ public void testGeocodeWithBounds() throws Exception {
339402 }
340403
341404 /**
342- * Geocode with region biasing: <a
343- * href="https://maps.googleapis.com/maps/api/geocode/json?address=Toledo®ion=es">Geocode for
344- * Toledo in Spain</a>.
405+ * Geocode with region biasing: <a href="https://maps.googleapis.com/maps/api/geocode/json?address=Toledo®ion=es">Geocode
406+ * for Toledo in Spain</a>.
345407 */
346408 @ Test
347409 public void testGeocodeWithRegionBiasing () throws Exception {
@@ -423,8 +485,7 @@ public void testGeocodeWithRegionBiasing() throws Exception {
423485 }
424486
425487 /**
426- * Geocode with component filtering: <a
427- * href="https://maps.googleapis.com/maps/api/geocode/json?address=santa+cruz&components=country:ES">
488+ * Geocode with component filtering: <a href="https://maps.googleapis.com/maps/api/geocode/json?address=santa+cruz&components=country:ES">
428489 * Geocoding "santa cruz" with country set to ES</a>.
429490 */
430491 @ Test
@@ -508,8 +569,7 @@ public void testGeocodeWithComponentFilter() throws Exception {
508569 }
509570
510571 /**
511- * Geocode with multiple component filters: <a
512- * href="https://maps.googleapis.com/maps/api/geocode/json?address=Torun&components=administrative_area:TX|country:US">
572+ * Geocode with multiple component filters: <a href="https://maps.googleapis.com/maps/api/geocode/json?address=Torun&components=administrative_area:TX|country:US">
513573 * Geocoding Torun, with administrative area of "TX" and country of "US"</a>.
514574 */
515575 @ Test
@@ -595,8 +655,7 @@ public void testGeocodeWithMultipleComponentFilters() throws Exception {
595655 }
596656
597657 /**
598- * Making a request using just components filter: <a
599- * href="https://maps.googleapis.com/maps/api/geocode/json?components=route:Annegatan|administrative_area:Helsinki|country:Finland">
658+ * Making a request using just components filter: <a href="https://maps.googleapis.com/maps/api/geocode/json?components=route:Annegatan|administrative_area:Helsinki|country:Finland">
600659 * Searching for a route of Annegatan, in the administrative area of Helsinki, and the country of
601660 * Finland </a>.
602661 */
@@ -683,8 +742,7 @@ public void testGeocodeWithJustComponents() throws Exception {
683742 }
684743
685744 /**
686- * Simple reverse geocoding. <a
687- * href="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452">Reverse
745+ * Simple reverse geocoding. <a href="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452">Reverse
688746 * geocode (40.714224,-73.961452)</a>.
689747 */
690748 @ Test
@@ -706,8 +764,7 @@ public void testSimpleReverseGeocode() throws Exception {
706764 }
707765
708766 /**
709- * Reverse geocode restricted by type: <a
710- * href="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&location_type=ROOFTOP&result_type=street_address">
767+ * Reverse geocode restricted by type: <a href="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&location_type=ROOFTOP&result_type=street_address">
711768 * Reverse Geocode (40.714224,-73.961452) with location type of ROOFTOP and result type of
712769 * street_address</a>.
713770 */
@@ -805,7 +862,9 @@ public void testReverseGeocodeRestrictedByType() throws Exception {
805862 }
806863 }
807864
808- /** Testing UTF8 result parsing. */
865+ /**
866+ * Testing UTF8 result parsing.
867+ */
809868 @ Test
810869 public void testUtfResult () throws Exception {
811870 try (LocalTestServerContext sc = new LocalTestServerContext (utfResultGeocodeResponse )) {
@@ -924,7 +983,9 @@ public void testCustomParameterPassThrough() throws Exception {
924983 }
925984 }
926985
927- /** Testing Kita Ward reverse geocode. */
986+ /**
987+ * Testing Kita Ward reverse geocode.
988+ */
928989 @ Test
929990 public void testReverseGeocodeWithKitaWard () throws Exception {
930991 try (LocalTestServerContext sc =
@@ -947,7 +1008,9 @@ public void testReverseGeocodeWithKitaWard() throws Exception {
9471008 }
9481009 }
9491010
950- /** Testing supported Address Types for Geocoding. */
1011+ /**
1012+ * Testing supported Address Types for Geocoding.
1013+ */
9511014 @ Test
9521015 public void testSupportedAddressTypesFood () throws Exception {
9531016 try (LocalTestServerContext sc =
@@ -1038,7 +1101,9 @@ public void testSupportedAddressTypesFood() throws Exception {
10381101 }
10391102 }
10401103
1041- /** Testing supported Address Types for Geocoding - Synagogue. */
1104+ /**
1105+ * Testing supported Address Types for Geocoding - Synagogue.
1106+ */
10421107 @ Test
10431108 public void testSupportedAddressTypesSynagogue () throws Exception {
10441109 try (LocalTestServerContext sc =
0 commit comments