Skip to content

Commit

Permalink
add new textSearchQuery method with test
Browse files Browse the repository at this point in the history
  • Loading branch information
danoscarmike committed May 2, 2019
1 parent 8b8e4f5 commit 96a6a56
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/google/maps/PlacesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.maps;

import com.google.maps.model.LatLng;
import com.google.maps.model.PlaceType;

/**
* Performs a text search for places. The Google Places API enables you to get data from the same
Expand Down Expand Up @@ -73,6 +74,19 @@ public static TextSearchRequest textSearchQuery(GeoApiContext context, String qu
return request;
}

/**
* Performs a search for Places using a PlaceType parameter.
*
* @param context The context on which to make Geo API requests.
* @param type Restricts the results to places matching the specified PlaceType.
* @return Returns a TextSearchRequest that can be configured and executed.
*/
public static TextSearchRequest textSearchQuery(GeoApiContext context, PlaceType type) {
TextSearchRequest request = new TextSearchRequest(context);
request.type(type);
return request;
}

/**
* Retrieves the next page of Text Search results. The nextPageToken, returned in a
* PlacesSearchResponse when there are more pages of results, encodes all of the original Text
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/google/maps/PlacesApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,21 @@ public void testTextSearchRequest() throws Exception {
}
}

@Test
public void testTextSearchRequestWithType() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) {
LatLng location = new LatLng(-33.866611, 151.195832);
PlacesSearchResponse results = PlacesApi.textSearchQuery(sc.context, PlaceType.ESTABLISHMENT)
.location(location)
.radius(500)
.await();

sc.assertParamValue(location.toUrlValue(), "location");
sc.assertParamValue(String.valueOf(500), "radius");
sc.assertParamValue(PlaceType.ESTABLISHMENT.toString(), "type");
}
}

@Test(expected = IllegalArgumentException.class)
public void testTextSearchLocationWithoutRadius() throws Exception {
try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) {
Expand Down

0 comments on commit 96a6a56

Please sign in to comment.