diff --git a/CONTRIBUTORS b/CONTRIBUTORS index acdc8c5dd..ab7b0c88a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -16,6 +16,7 @@ Malcolm Windsor @mwindsor-beoped Mark McDonald @markmcd Nicolas Poirier @NicolasPoirier Pulkit Bhuwalka @nutsiepully +Pavel Smagin @psmagin Romain Sertelon @rsertelon Sam Lukes @slukes Sipos Tamas @onlyonce diff --git a/README.md b/README.md index b4eec34cf..8703f3b16 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ The `GeoApiContext` is designed to be a [Singleton](https://en.wikipedia.org/wik in your application. Please instantiate one on application startup, and continue to use it for the life of your application. This will enable proper QPS enforcement across all of your requests. -For more usage examples, check out [the tests](src/test/java/com/google/maps/). +For more usage examples, check out [the tests](src/test/java/com/google/maps). ## Features diff --git a/build.gradle b/build.gradle index c069a725f..bfcf6c1f5 100644 --- a/build.gradle +++ b/build.gradle @@ -5,12 +5,13 @@ buildscript { mavenCentral() } dependencies { - classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.0' + classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2' } } plugins { - id 'com.github.sherter.google-java-format' version '0.6' + id 'com.github.sherter.google-java-format' version '0.7.1' + id 'com.github.ben-manes.versions' version '0.20.0' } apply plugin: 'java' @@ -43,18 +44,18 @@ artifacts { } dependencies { - compile 'com.google.code.gson:gson:2.8.1' - compile 'com.squareup.okhttp3:okhttp:3.8.1' - compile 'joda-time:joda-time:2.9.9' - compileOnly 'com.google.appengine:appengine-api-1.0-sdk:1.9.54' + compileOnly 'com.google.appengine:appengine-api-1.0-sdk:1.9.64' + compile 'com.google.code.gson:gson:2.8.5' + compile 'com.squareup.okhttp3:okhttp:3.10.0' + compile 'joda-time:joda-time:2.10' compile 'org.slf4j:slf4j-api:1.7.25' testCompile 'junit:junit:4.12' - testCompile 'org.mockito:mockito-core:1.10.19' - testCompile 'com.squareup.okhttp3:mockwebserver:3.8.1' - testCompile 'org.apache.httpcomponents:httpclient:4.5.3' + testCompile 'org.mockito:mockito-core:2.19.0' + testCompile 'com.squareup.okhttp3:mockwebserver:3.10.0' + testCompile 'org.apache.httpcomponents:httpclient:4.5.5' testCompile 'org.slf4j:slf4j-simple:1.7.25' testCompile 'commons-lang:commons-lang:2.6' - testCompile 'org.json:json:20170516' + testCompile 'org.json:json:20180130' } task updateVersion(type: Copy) { diff --git a/gradle.properties b/gradle.properties index b1833b789..22ae759d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=0.2.8 +version=0.2.9 # variables required to allow build.gradle to parse, # override in ~/.gradle/gradle.properties diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c8989c4c1..3cae844ba 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip diff --git a/src/main/java/com/google/maps/DirectionsApi.java b/src/main/java/com/google/maps/DirectionsApi.java index 8b4b1677c..fe1eb48e9 100644 --- a/src/main/java/com/google/maps/DirectionsApi.java +++ b/src/main/java/com/google/maps/DirectionsApi.java @@ -38,10 +38,26 @@ public class DirectionsApi { private DirectionsApi() {} + /** + * Creates a new DirectionsApiRequest using the given context, with all attributes at their + * default values. + * + * @param context Context that the DirectionsApiRequest will be executed against + * @return A newly constructed DirectionsApiRequest between the given points. + */ public static DirectionsApiRequest newRequest(GeoApiContext context) { return new DirectionsApiRequest(context); } + /** + * Creates a new DirectionsApiRequest between the given origin and destination, using the defaults + * for all other options. + * + * @param context Context that the DirectionsApiRequest will be executed against + * @param origin Origin address as text + * @param destination Destination address as text + * @return A newly constructed DirectionsApiRequest between the given points. + */ public static DirectionsApiRequest getDirections( GeoApiContext context, String origin, String destination) { return new DirectionsApiRequest(context).origin(origin).destination(destination); diff --git a/src/main/java/com/google/maps/GaeRequestHandler.java b/src/main/java/com/google/maps/GaeRequestHandler.java index 3c28cda25..3ec75c63e 100644 --- a/src/main/java/com/google/maps/GaeRequestHandler.java +++ b/src/main/java/com/google/maps/GaeRequestHandler.java @@ -63,7 +63,7 @@ public > PendingResult handle( throw (new RuntimeException(e)); } - return new GaePendingResult( + return new GaePendingResult<>( req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry); } @@ -89,13 +89,13 @@ public > PendingResult handlePost( throw (new RuntimeException(e)); } - return new GaePendingResult( + return new GaePendingResult<>( req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry); } @Override public void shutdown() { - //do nothing + // do nothing } /** Builder strategy for constructing {@code GaeRequestHandler}. */ diff --git a/src/main/java/com/google/maps/GeoApiContext.java b/src/main/java/com/google/maps/GeoApiContext.java index 5482e107f..a5d1bd4a9 100644 --- a/src/main/java/com/google/maps/GeoApiContext.java +++ b/src/main/java/com/google/maps/GeoApiContext.java @@ -36,6 +36,15 @@ * The entry point for making requests against the Google Geo APIs. * *

Construct this object by using the enclosed {@link GeoApiContext.Builder}. + * + *

GeoApiContexts should be shared

+ * + * GeoApiContext works best when you create a single GeoApiContext instance, or one per API key, and + * reuse it for all your Google Geo API queries. This is because each GeoApiContext manages its own + * thread pool, back-end client, and other resources. + * + *

When you are finished with a GeoApiContext object, you must call {@link #shutdown()} on it to + * release its resources. */ public class GeoApiContext { @@ -127,6 +136,10 @@ interface Builder { } } + /** + * Shut down this GeoApiContext instance, reclaiming resources. After shutdown() has been called, + * no further queries may be done against this instance. + */ public void shutdown() { requestHandler.shutdown(); } diff --git a/src/main/java/com/google/maps/GeolocationApiRequest.java b/src/main/java/com/google/maps/GeolocationApiRequest.java index 64fdac2e4..ae84d45bb 100644 --- a/src/main/java/com/google/maps/GeolocationApiRequest.java +++ b/src/main/java/com/google/maps/GeolocationApiRequest.java @@ -37,7 +37,7 @@ public class GeolocationApiRequest @Override protected void validateRequest() { if (this.payload.considerIp != null - && this.payload.considerIp == false + && !this.payload.considerIp && this.payload.wifiAccessPoints != null && this.payload.wifiAccessPoints.length < 2) { throw new IllegalArgumentException("Request must contain two or more 'Wifi Access Points'"); diff --git a/src/main/java/com/google/maps/NearbySearchRequest.java b/src/main/java/com/google/maps/NearbySearchRequest.java index 642073b03..406d060f9 100644 --- a/src/main/java/com/google/maps/NearbySearchRequest.java +++ b/src/main/java/com/google/maps/NearbySearchRequest.java @@ -162,9 +162,11 @@ public NearbySearchRequest type(PlaceType type) { * Restricts the results to places matching the specified type. Provides support for multiple * types. * + * @deprecated Multiple search types are ignored by the Places API. * @param types The {@link PlaceType}s to restrict results to. * @return Returns this {@code NearbyApiRequest} for call chaining. */ + @Deprecated public NearbySearchRequest type(PlaceType... types) { return param("type", join('|', types)); } diff --git a/src/main/java/com/google/maps/OkHttpRequestHandler.java b/src/main/java/com/google/maps/OkHttpRequestHandler.java index 240ca86c4..f223970b7 100644 --- a/src/main/java/com/google/maps/OkHttpRequestHandler.java +++ b/src/main/java/com/google/maps/OkHttpRequestHandler.java @@ -63,7 +63,7 @@ public > PendingResult handle( Request req = new Request.Builder().get().header("User-Agent", userAgent).url(hostName + url).build(); - return new OkHttpPendingResult( + return new OkHttpPendingResult<>( req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry); } @@ -86,12 +86,13 @@ public > PendingResult handlePost( .url(hostName + url) .build(); - return new OkHttpPendingResult( + return new OkHttpPendingResult<>( req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry); } public void shutdown() { executorService.shutdown(); + client.connectionPool().evictAll(); } /** Builder strategy for constructing an {@code OkHTTPRequestHandler}. */ @@ -153,6 +154,18 @@ public Request authenticate(Route route, Response response) throws IOException { }); } + /** + * Gets a reference to the OkHttpClient.Builder used to build the OkHttpRequestHandler's + * internal OkHttpClient. This allows you to fully customize the OkHttpClient that the resulting + * OkHttpRequestHandler will make HTTP requests through. + * + * @return OkHttpClient.Builder that will produce the OkHttpClient used by the + * OkHttpRequestHandler built by this. + */ + public OkHttpClient.Builder okHttpClientBuilder() { + return builder; + } + @Override public RequestHandler build() { OkHttpClient client = builder.build(); diff --git a/src/main/java/com/google/maps/StaticMapsRequest.java b/src/main/java/com/google/maps/StaticMapsRequest.java index f4c572837..5246f271b 100644 --- a/src/main/java/com/google/maps/StaticMapsRequest.java +++ b/src/main/java/com/google/maps/StaticMapsRequest.java @@ -167,7 +167,7 @@ public StaticMapsRequest region(String region) { public static class Markers implements UrlValue { - public static enum MarkersSize implements UrlValue { + public enum MarkersSize implements UrlValue { tiny, mid, small, @@ -179,7 +179,7 @@ public String toUrlValue() { } } - public static enum CustomIconAnchor implements UrlValue { + public enum CustomIconAnchor implements UrlValue { top, bottom, left, diff --git a/src/main/java/com/google/maps/internal/GaePendingResult.java b/src/main/java/com/google/maps/internal/GaePendingResult.java index c0b8eef85..fd3f0ab66 100644 --- a/src/main/java/com/google/maps/internal/GaePendingResult.java +++ b/src/main/java/com/google/maps/internal/GaePendingResult.java @@ -172,16 +172,11 @@ private T parseResponse(GaePendingResult request, HTTPResponse response) .registerTypeAdapter(Fare.class, new FareAdapter()) .registerTypeAdapter(LatLng.class, new LatLngAdapter()) .registerTypeAdapter( - AddressComponentType.class, - new SafeEnumAdapter(AddressComponentType.UNKNOWN)) - .registerTypeAdapter( - AddressType.class, new SafeEnumAdapter(AddressType.UNKNOWN)) - .registerTypeAdapter( - TravelMode.class, new SafeEnumAdapter(TravelMode.UNKNOWN)) - .registerTypeAdapter( - LocationType.class, new SafeEnumAdapter(LocationType.UNKNOWN)) - .registerTypeAdapter( - RatingType.class, new SafeEnumAdapter(RatingType.UNKNOWN)) + AddressComponentType.class, new SafeEnumAdapter<>(AddressComponentType.UNKNOWN)) + .registerTypeAdapter(AddressType.class, new SafeEnumAdapter<>(AddressType.UNKNOWN)) + .registerTypeAdapter(TravelMode.class, new SafeEnumAdapter<>(TravelMode.UNKNOWN)) + .registerTypeAdapter(LocationType.class, new SafeEnumAdapter<>(LocationType.UNKNOWN)) + .registerTypeAdapter(RatingType.class, new SafeEnumAdapter<>(RatingType.UNKNOWN)) .registerTypeAdapter(DayOfWeek.class, new DayOfWeekAdapter()) .registerTypeAdapter(PriceLevel.class, new PriceLevelAdapter()) .registerTypeAdapter(Instant.class, new InstantAdapter()) diff --git a/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java b/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java index 1e4cb19fa..5102a4c0d 100644 --- a/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java +++ b/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java @@ -74,8 +74,8 @@ public GeolocationApi.Response read(JsonReader reader) throws IOException { reader.beginObject(); // opening { while (reader.hasNext()) { String name = reader.nextName(); - // two different objects could be returned a success object containing "location" and "accuracy" - // keys or an error object containing an "error" key + // two different objects could be returned a success object containing "location" and + // "accuracy" keys or an error object containing an "error" key if (name.equals("location")) { // we already have a parser for the LatLng object so lets use that response.location = latLngAdapter.read(reader); @@ -96,7 +96,8 @@ public GeolocationApi.Response read(JsonReader reader) throws IOException { reader.beginObject(); // ...and each error array element is an object... while (reader.hasNext()) { errName = reader.nextName(); - // ...with keys "reason", "domain", "debugInfo", "location", "locationType", and "message" (again) + // ...with keys "reason", "domain", "debugInfo", "location", "locationType", and + // "message" (again) if (errName.equals("reason")) { response.reason = reader.nextString(); } else if (errName.equals("domain")) { diff --git a/src/main/java/com/google/maps/internal/OkHttpPendingResult.java b/src/main/java/com/google/maps/internal/OkHttpPendingResult.java index cd7fb1690..ea4d9f1c3 100644 --- a/src/main/java/com/google/maps/internal/OkHttpPendingResult.java +++ b/src/main/java/com/google/maps/internal/OkHttpPendingResult.java @@ -153,7 +153,7 @@ public T await() throws ApiException, IOException, InterruptedException { } } - final BlockingQueue waiter = new ArrayBlockingQueue(1); + final BlockingQueue waiter = new ArrayBlockingQueue<>(1); final OkHttpPendingResult parent = this; // This callback will be called on another thread, handled by the RateLimitExecutorService. diff --git a/src/main/java/com/google/maps/internal/PolylineEncoding.java b/src/main/java/com/google/maps/internal/PolylineEncoding.java index d53308dd0..a71ae8e91 100644 --- a/src/main/java/com/google/maps/internal/PolylineEncoding.java +++ b/src/main/java/com/google/maps/internal/PolylineEncoding.java @@ -23,8 +23,9 @@ /** * Utility class that encodes and decodes Polylines. * - *

See {@url https://developers.google.com/maps/documentation/utilities/polylinealgorithm} for - * detailed description of this format. + *

See + * https://developers.google.com/maps/documentation/utilities/polylinealgorithm for detailed + * description of this format. */ public class PolylineEncoding { /** Decodes an encoded path string into a sequence of LatLngs. */ @@ -32,7 +33,7 @@ public static List decode(final String encodedPath) { int len = encodedPath.length(); - final List path = new ArrayList(len / 2); + final List path = new ArrayList<>(len / 2); int index = 0; int lat = 0; int lng = 0; diff --git a/src/main/java/com/google/maps/internal/RateLimitExecutorService.java b/src/main/java/com/google/maps/internal/RateLimitExecutorService.java index 0c24708d6..1c94b0b33 100644 --- a/src/main/java/com/google/maps/internal/RateLimitExecutorService.java +++ b/src/main/java/com/google/maps/internal/RateLimitExecutorService.java @@ -51,7 +51,7 @@ public class RateLimitExecutorService implements ExecutorService, Runnable { new SynchronousQueue(), threadFactory("Rate Limited Dispatcher", true)); - private final BlockingQueue queue = new LinkedBlockingQueue(); + private final BlockingQueue queue = new LinkedBlockingQueue<>(); private final RateLimiter rateLimiter = RateLimiter.create(DEFAULT_QUERIES_PER_SECOND, 1, TimeUnit.SECONDS); @@ -104,12 +104,12 @@ public void execute(Runnable runnable) { @Override public void shutdown() { delegate.shutdown(); - //we need this to break out of queue.take() + // we need this to break out of queue.take() execute( new Runnable() { @Override public void run() { - //do nothing + // do nothing } }); } @@ -119,12 +119,12 @@ public void run() { @Override public List shutdownNow() { List tasks = delegate.shutdownNow(); - //we need this to break out of queue.take() + // we need this to break out of queue.take() execute( new Runnable() { @Override public void run() { - //do nothing + // do nothing } }); return tasks; diff --git a/src/main/java/com/google/maps/internal/StringJoin.java b/src/main/java/com/google/maps/internal/StringJoin.java index c18e70021..9af4e0b10 100644 --- a/src/main/java/com/google/maps/internal/StringJoin.java +++ b/src/main/java/com/google/maps/internal/StringJoin.java @@ -15,6 +15,8 @@ package com.google.maps.internal; +import java.util.Objects; + /** Utility class to join strings. */ public class StringJoin { @@ -30,6 +32,10 @@ public interface UrlValue { private StringJoin() {} public static String join(char delim, String... parts) { + return join(new String(new char[] {delim}), parts); + } + + public static String join(CharSequence delim, String... parts) { StringBuilder result = new StringBuilder(); for (int i = 0; i < parts.length; i++) { if (i != 0) { @@ -40,6 +46,21 @@ public static String join(char delim, String... parts) { return result.toString(); } + public static String join(char delim, Object... parts) { + return join(new String(new char[] {delim}), parts); + } + + public static String join(CharSequence delim, Object... parts) { + StringBuilder result = new StringBuilder(); + for (int i = 0; i < parts.length; i++) { + if (i != 0) { + result.append(delim); + } + result.append(Objects.toString(parts[i])); + } + return result.toString(); + } + public static String join(char delim, UrlValue... parts) { String[] strings = new String[parts.length]; int i = 0; diff --git a/src/main/java/com/google/maps/internal/ratelimiter/RateLimiter.java b/src/main/java/com/google/maps/internal/ratelimiter/RateLimiter.java index 4e9e540ce..078c92b74 100644 --- a/src/main/java/com/google/maps/internal/ratelimiter/RateLimiter.java +++ b/src/main/java/com/google/maps/internal/ratelimiter/RateLimiter.java @@ -408,7 +408,7 @@ protected SleepingStopwatch() {} protected abstract void sleepMicrosUninterruptibly(long micros); - public static final SleepingStopwatch createFromSystemTimer() { + public static SleepingStopwatch createFromSystemTimer() { return new SleepingStopwatch() { final Stopwatch stopwatch = Stopwatch.createStarted(); diff --git a/src/main/java/com/google/maps/internal/ratelimiter/SmoothRateLimiter.java b/src/main/java/com/google/maps/internal/ratelimiter/SmoothRateLimiter.java index e909c2f88..178555bc1 100644 --- a/src/main/java/com/google/maps/internal/ratelimiter/SmoothRateLimiter.java +++ b/src/main/java/com/google/maps/internal/ratelimiter/SmoothRateLimiter.java @@ -203,7 +203,6 @@ abstract class SmoothRateLimiter extends RateLimiter { *

* thresholdPermits = 0.5 * warmupPeriod / stableInterval *
- * *
  • The time to go from maxPermits to thresholdPermits is equal to the integral of the * function between thresholdPermits and maxPermits. This is the area of the pictured * trapezoid, and it is equal to 0.5 * (stableInterval + coldInterval) * (maxPermits - @@ -211,7 +210,6 @@ abstract class SmoothRateLimiter extends RateLimiter { *
    * maxPermits = thresholdPermits + 2 * warmupPeriod / (stableInterval + coldInterval) *
    - * * */ static final class SmoothWarmingUp extends SmoothRateLimiter { diff --git a/src/main/java/com/google/maps/model/AddressComponent.java b/src/main/java/com/google/maps/model/AddressComponent.java index fd3c6ee30..8e847cf07 100644 --- a/src/main/java/com/google/maps/model/AddressComponent.java +++ b/src/main/java/com/google/maps/model/AddressComponent.java @@ -15,7 +15,10 @@ package com.google.maps.model; +import static com.google.maps.internal.StringJoin.join; + import java.io.Serializable; + /** * The parts of an address. * @@ -40,4 +43,15 @@ public class AddressComponent implements Serializable { /** Indicates the type of each part of the address. Examples include street number or country. */ public AddressComponentType[] types; + + public String toString() { + StringBuilder sb = new StringBuilder("[AddressComponent: "); + sb.append("\"").append(longName).append("\""); + if (shortName != null) { + sb.append(" (\"").append(shortName).append("\")"); + } + sb.append(" (").append(join(", ", (Object[]) types)).append(")"); + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/AddressComponentType.java b/src/main/java/com/google/maps/model/AddressComponentType.java index 71304946e..4fcb08d49 100644 --- a/src/main/java/com/google/maps/model/AddressComponentType.java +++ b/src/main/java/com/google/maps/model/AddressComponentType.java @@ -31,6 +31,9 @@ public enum AddressComponentType { /** A major intersection, usually of two major roads. */ INTERSECTION("intersection"), + /** A continent. */ + CONTINENT("continent"), + /** A political entity. Usually, this type indicates a polygon of some civil administration. */ POLITICAL("political"), @@ -166,6 +169,84 @@ public enum AddressComponentType { /** The location of a light rail station. */ LIGHT_RAIL_STATION("light_rail_station"), + /** A general contractor. */ + GENERAL_CONTRACTOR("general_contractor"), + + /** A food service establishment. */ + FOOD("food"), + + /** A real-estate agency. */ + REAL_ESTATE_AGENCY("real_estate_agency"), + + /** A car-rental establishment. */ + CAR_RENTAL("car_rental"), + + /** A travel agency. */ + TRAVEL_AGENCY("travel_agency"), + + /** An electronics store. */ + ELECTRONICS_STORE("electronics_store"), + + /** A home goods store. */ + HOME_GOODS_STORE("home_goods_store"), + + /** A school. */ + SCHOOL("school"), + + /** A store. */ + STORE("store"), + + /** A shopping mall. */ + SHOPPING_MALL("shopping_mall"), + + /** A lodging establishment. */ + LODGING("lodging"), + + /** An art gallery. */ + ART_GALLERY("art_gallery"), + + /** A lawyer. */ + LAWYER("lawyer"), + + /** A restaurant. */ + RESTAURANT("restaurant"), + + /** A bar. */ + BAR("bar"), + + /** A take-away meal establishment. */ + MEAL_TAKEAWAY("meal_takeaway"), + + /** A clothing store. */ + CLOTHING_STORE("clothing_store"), + + /** A local government office. */ + LOCAL_GOVERNMENT_OFFICE("local_government_office"), + + /** A finance establishment. */ + FINANCE("finance"), + + /** A moving company. */ + MOVING_COMPANY("moving_company"), + + /** A storage establishment. */ + STORAGE("storage"), + + /** A cafe. */ + CAFE("cafe"), + + /** A car repair establishment. */ + CAR_REPAIR("car_repair"), + + /** A health service provider. */ + HEALTH("health"), + + /** An insurance agency. */ + INSURANCE_AGENCY("insurance_agency"), + + /** A painter. */ + PAINTER("painter"), + /** * Indicates an unknown address component type returned by the server. The Java Client for Google * Maps Services should be updated to support the new value. diff --git a/src/main/java/com/google/maps/model/AddressType.java b/src/main/java/com/google/maps/model/AddressType.java index 96f45d042..9aa90a75d 100644 --- a/src/main/java/com/google/maps/model/AddressType.java +++ b/src/main/java/com/google/maps/model/AddressType.java @@ -47,6 +47,9 @@ public enum AddressType implements UrlValue { /** A major intersection, usually of two major roads. */ INTERSECTION("intersection"), + /** A continent. */ + CONTINENT("continent"), + /** A political entity. Usually, this type indicates a polygon of some civil administration. */ POLITICAL("political"), @@ -380,6 +383,9 @@ public enum AddressType implements UrlValue { /** Currently not a documented return type. */ FUNERAL_HOME("funeral_home"), + /** Currently not a documented return type. */ + GENERAL_CONTRACTOR("general_contractor"), + /** Currently not a documented return type. */ HINDU_TEMPLE("hindu_temple"), diff --git a/src/main/java/com/google/maps/model/AutocompletePrediction.java b/src/main/java/com/google/maps/model/AutocompletePrediction.java index e7a5f79cf..e4c33c1c4 100644 --- a/src/main/java/com/google/maps/model/AutocompletePrediction.java +++ b/src/main/java/com/google/maps/model/AutocompletePrediction.java @@ -16,6 +16,8 @@ package com.google.maps.model; import java.io.Serializable; +import java.util.Arrays; +import java.util.Objects; /** * Represents a single Autocomplete result returned from the Google Places API Web Service. @@ -61,6 +63,10 @@ public static class MatchedSubstring { /** The start position of the matched substring, measured in Unicode characters. */ public int offset; + + public String toString() { + return String.format("(offset=%d, length=%d)", offset, length); + } } /** @@ -83,5 +89,21 @@ public static class Term { /** The text of the matched term. */ public String value; + + public String toString() { + return String.format("(offset=%d, value=%s)", offset, value); + } + } + + public String toString() { + return String.format( + "[AutocompletePrediction: \"%s\", placeId=%s, types=%s, terms=%s, " + + "matchedSubstrings=%s, structuredFormatting=%s]", + description, + placeId, + Arrays.toString(types), + Arrays.toString(terms), + Arrays.toString(matchedSubstrings), + Objects.toString(structuredFormatting)); } } diff --git a/src/main/java/com/google/maps/model/AutocompleteStructuredFormatting.java b/src/main/java/com/google/maps/model/AutocompleteStructuredFormatting.java index 14be7a2d6..ee3fdc6b1 100644 --- a/src/main/java/com/google/maps/model/AutocompleteStructuredFormatting.java +++ b/src/main/java/com/google/maps/model/AutocompleteStructuredFormatting.java @@ -16,6 +16,7 @@ package com.google.maps.model; import java.io.Serializable; +import java.util.Arrays; /** The structured formatting info for a {@link com.google.maps.model.AutocompletePrediction}. */ public class AutocompleteStructuredFormatting implements Serializable { @@ -30,4 +31,15 @@ public class AutocompleteStructuredFormatting implements Serializable { /** The secondary text of a prediction, usually the location of the place. */ public String secondaryText; + + public String toString() { + StringBuilder sb = new StringBuilder("("); + sb.append("\"").append(mainText).append("\""); + sb.append(" at ").append(Arrays.toString(mainTextMatchedSubstrings)); + if (secondaryText != null) { + sb.append(", secondaryText=\"").append(secondaryText).append("\""); + } + sb.append(")"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/Bounds.java b/src/main/java/com/google/maps/model/Bounds.java index 7dba93a21..5e2086713 100644 --- a/src/main/java/com/google/maps/model/Bounds.java +++ b/src/main/java/com/google/maps/model/Bounds.java @@ -25,4 +25,8 @@ public class Bounds implements Serializable { public LatLng northeast; /** The southwest corner of the bounding box. */ public LatLng southwest; + + public String toString() { + return String.format("[%s, %s]", northeast, southwest); + } } diff --git a/src/main/java/com/google/maps/model/CellTower.java b/src/main/java/com/google/maps/model/CellTower.java index 5b8085f92..5be8e0baf 100644 --- a/src/main/java/com/google/maps/model/CellTower.java +++ b/src/main/java/com/google/maps/model/CellTower.java @@ -79,6 +79,19 @@ private CellTower( /** The timing advance value. */ public Integer timingAdvance = null; + public String toString() { + return String.format( + "[CellTower: cellId=%s, locationAreaCode=%s, mobileCountryCode=%s, " + + "mobileNetworkCode=%s, age=%s, signalStrength=%s, timingAdvance=%s]", + cellId, + locationAreaCode, + mobileCountryCode, + mobileNetworkCode, + age, + signalStrength, + timingAdvance); + } + public static class CellTowerBuilder { private Integer _cellId = null; private Integer _locationAreaCode = null; @@ -101,37 +114,37 @@ public CellTower createCellTower() { } public CellTowerBuilder CellId(int newCellId) { - this._cellId = new Integer(newCellId); + this._cellId = newCellId; return this; } public CellTowerBuilder LocationAreaCode(int newLocationAreaCode) { - this._locationAreaCode = new Integer(newLocationAreaCode); + this._locationAreaCode = newLocationAreaCode; return this; } public CellTowerBuilder MobileCountryCode(int newMobileCountryCode) { - this._mobileCountryCode = new Integer(newMobileCountryCode); + this._mobileCountryCode = newMobileCountryCode; return this; } public CellTowerBuilder MobileNetworkCode(int newMobileNetworkCode) { - this._mobileNetworkCode = new Integer(newMobileNetworkCode); + this._mobileNetworkCode = newMobileNetworkCode; return this; } public CellTowerBuilder Age(int newAge) { - this._age = new Integer(newAge); + this._age = newAge; return this; } public CellTowerBuilder SignalStrength(int newSignalStrength) { - this._signalStrength = new Integer(newSignalStrength); + this._signalStrength = newSignalStrength; return this; } public CellTowerBuilder TimingAdvance(int newTimingAdvance) { - this._timingAdvance = new Integer(newTimingAdvance); + this._timingAdvance = newTimingAdvance; return this; } } diff --git a/src/main/java/com/google/maps/model/DirectionsLeg.java b/src/main/java/com/google/maps/model/DirectionsLeg.java index f88bfdeb4..826bda7da 100644 --- a/src/main/java/com/google/maps/model/DirectionsLeg.java +++ b/src/main/java/com/google/maps/model/DirectionsLeg.java @@ -93,4 +93,25 @@ public class DirectionsLeg implements Serializable { * leg. */ public String endAddress; + + public String toString() { + StringBuilder sb = + new StringBuilder( + String.format( + "[DirectionsLeg: \"%s\" -> \"%s\" (%s -> %s)", + startAddress, endAddress, startLocation, endLocation)); + if (departureTime != null) { + sb.append(", departureTime=").append(departureTime); + } + if (arrivalTime != null) { + sb.append(", arrivalTime=").append(arrivalTime); + } + if (durationInTraffic != null) { + sb.append(", durationInTraffic=").append(durationInTraffic); + } + sb.append(", duration=").append(duration); + sb.append(", distance=").append(distance); + sb.append(": ").append(steps.length).append(" steps]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/DirectionsRoute.java b/src/main/java/com/google/maps/model/DirectionsRoute.java index 55feb38d0..c189a76b7 100644 --- a/src/main/java/com/google/maps/model/DirectionsRoute.java +++ b/src/main/java/com/google/maps/model/DirectionsRoute.java @@ -16,6 +16,7 @@ package com.google.maps.model; import java.io.Serializable; +import java.util.Arrays; /** * A Directions API result. When the Directions API returns results, it places them within a routes @@ -71,4 +72,19 @@ public class DirectionsRoute implements Serializable { * warnings yourself. */ public String[] warnings; + + public String toString() { + String str = + String.format( + "[DirectionsRoute: \"%s\", %d legs, waypointOrder=%s, bounds=%s", + summary, legs.length, Arrays.toString(waypointOrder), bounds); + if (fare != null) { + str = str + ", fare=" + fare; + } + if (warnings != null && warnings.length > 0) { + str = str + ", " + warnings.length + " warnings"; + } + str = str + "]"; + return str; + } } diff --git a/src/main/java/com/google/maps/model/DirectionsStep.java b/src/main/java/com/google/maps/model/DirectionsStep.java index 450db03b5..0f9bdd5ac 100644 --- a/src/main/java/com/google/maps/model/DirectionsStep.java +++ b/src/main/java/com/google/maps/model/DirectionsStep.java @@ -84,4 +84,19 @@ public class DirectionsStep implements Serializable { * Details for more detail. */ public TransitDetails transitDetails; + + public String toString() { + StringBuilder sb = new StringBuilder("[DirectionsStep: "); + sb.append("\"").append(htmlInstructions).append("\""); + sb.append(String.format(" (%s -> %s", startLocation, endLocation)).append(")"); + sb.append(" ").append(travelMode); + sb.append(", duration=").append(duration); + sb.append(", distance=").append(distance); + sb.append(", ").append(steps.length).append(" steps"); + if (transitDetails != null) { + sb.append(", transitDetails=").append(transitDetails); + } + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/DistanceMatrix.java b/src/main/java/com/google/maps/model/DistanceMatrix.java index b2b9dd594..1bab5f7ba 100644 --- a/src/main/java/com/google/maps/model/DistanceMatrix.java +++ b/src/main/java/com/google/maps/model/DistanceMatrix.java @@ -51,4 +51,10 @@ public DistanceMatrix( this.destinationAddresses = destinationAddresses; this.rows = rows; } + + public String toString() { + return String.format( + "DistanceMatrix: %d origins x %d destinations, %d rows", + originAddresses.length, destinationAddresses.length, rows.length); + } } diff --git a/src/main/java/com/google/maps/model/DistanceMatrixElement.java b/src/main/java/com/google/maps/model/DistanceMatrixElement.java index 2fb7c74ae..986a826f3 100644 --- a/src/main/java/com/google/maps/model/DistanceMatrixElement.java +++ b/src/main/java/com/google/maps/model/DistanceMatrixElement.java @@ -56,4 +56,18 @@ public class DistanceMatrixElement implements Serializable { /** {@code fare} contains information about the fare (that is, the ticket costs) on this route. */ public Fare fare; + + public String toString() { + String str = + String.format( + "[DistanceMatrixElement %s distance=%s, duration=%s", status, distance, duration); + if (durationInTraffic != null) { + str = str + ", durationInTraffic=" + durationInTraffic; + } + if (fare != null) { + str = str + ", fare=" + fare; + } + str = str + "]"; + return str; + } } diff --git a/src/main/java/com/google/maps/model/DistanceMatrixRow.java b/src/main/java/com/google/maps/model/DistanceMatrixRow.java index 11d0b4eae..7792c9acb 100644 --- a/src/main/java/com/google/maps/model/DistanceMatrixRow.java +++ b/src/main/java/com/google/maps/model/DistanceMatrixRow.java @@ -27,4 +27,8 @@ public class DistanceMatrixRow implements Serializable { /** The results for this row, or individual origin. */ public DistanceMatrixElement[] elements; + + public String toString() { + return String.format("[DistanceMatrixRow %d elements]", elements.length); + } } diff --git a/src/main/java/com/google/maps/model/ElevationResult.java b/src/main/java/com/google/maps/model/ElevationResult.java index e1406644e..9d57cdd5a 100644 --- a/src/main/java/com/google/maps/model/ElevationResult.java +++ b/src/main/java/com/google/maps/model/ElevationResult.java @@ -17,12 +17,23 @@ import java.io.Serializable; -/** An Elevation API result. */ +/** + * An Elevation API result. + * + *

    Units are in meters, per https://developers.google.com/maps/documentation/elevation/start. + */ public class ElevationResult implements Serializable { private static final long serialVersionUID = 1L; + /** Elevation in meters. */ public double elevation; + /** Location of the elevation data. */ public LatLng location; + /** Maximum distance between data points from which the elevation was interpolated, in meters. */ public double resolution; + + public String toString() { + return String.format("(%s, %f m, resolution=%f m)", location, elevation, resolution); + } } diff --git a/src/main/java/com/google/maps/model/EncodedPolyline.java b/src/main/java/com/google/maps/model/EncodedPolyline.java index 853bb9835..d714abc16 100644 --- a/src/main/java/com/google/maps/model/EncodedPolyline.java +++ b/src/main/java/com/google/maps/model/EncodedPolyline.java @@ -50,4 +50,10 @@ public String getEncodedPath() { public List decodePath() { return PolylineEncoding.decode(points); } + + // Use the encoded point representation; decoding to get an alternate representation for + // individual points would be expensive. + public String toString() { + return String.format("[EncodedPolyline: %s]", points); + } } diff --git a/src/main/java/com/google/maps/model/Fare.java b/src/main/java/com/google/maps/model/Fare.java index 22df2e45b..1781b33dc 100644 --- a/src/main/java/com/google/maps/model/Fare.java +++ b/src/main/java/com/google/maps/model/Fare.java @@ -34,4 +34,8 @@ public class Fare implements Serializable { /** The total fare amount, in the currency specified in {@link #currency}. */ public BigDecimal value; + + public String toString() { + return String.format("%s %s", value, currency); + } } diff --git a/src/main/java/com/google/maps/model/FindPlaceFromText.java b/src/main/java/com/google/maps/model/FindPlaceFromText.java index 77fb1f1df..c9381e1e5 100644 --- a/src/main/java/com/google/maps/model/FindPlaceFromText.java +++ b/src/main/java/com/google/maps/model/FindPlaceFromText.java @@ -22,4 +22,8 @@ public class FindPlaceFromText implements Serializable { private static final long serialVersionUID = 1L; public PlacesSearchResult candidates[]; + + public String toString() { + return String.format("[FindPlaceFromText %d candidates]", candidates.length); + } } diff --git a/src/main/java/com/google/maps/model/GeocodedWaypoint.java b/src/main/java/com/google/maps/model/GeocodedWaypoint.java index 3544a4190..9edbb2b50 100644 --- a/src/main/java/com/google/maps/model/GeocodedWaypoint.java +++ b/src/main/java/com/google/maps/model/GeocodedWaypoint.java @@ -16,6 +16,7 @@ package com.google.maps.model; import java.io.Serializable; +import java.util.Arrays; /** * A point in a Directions API response; either the origin, one of the requested waypoints, or the @@ -26,6 +27,7 @@ public class GeocodedWaypoint implements Serializable { private static final long serialVersionUID = 1L; + /** The status code resulting from the geocoding operation for this waypoint. */ public GeocodedWaypointStatus geocoderStatus; @@ -40,4 +42,15 @@ public class GeocodedWaypoint implements Serializable { /** The address types of the geocoding result used for calculating directions. */ public AddressType types[]; + + public String toString() { + StringBuilder sb = new StringBuilder("[GeocodedWaypoint"); + sb.append(" ").append(geocoderStatus); + if (partialMatch) { + sb.append(" ").append("PARTIAL MATCH"); + } + sb.append(" placeId=").append(placeId); + sb.append(", types=").append(Arrays.toString(types)); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/GeocodingResult.java b/src/main/java/com/google/maps/model/GeocodingResult.java index ae0cd73fa..d30dd9a77 100644 --- a/src/main/java/com/google/maps/model/GeocodingResult.java +++ b/src/main/java/com/google/maps/model/GeocodingResult.java @@ -16,6 +16,7 @@ package com.google.maps.model; import java.io.Serializable; +import java.util.Arrays; /** A result from a Geocoding API call. */ public class GeocodingResult implements Serializable { @@ -71,4 +72,24 @@ public class GeocodingResult implements Serializable { /** A unique identifier for this place. */ public String placeId; + + /** The Plus Code identifier for this place. */ + public PlusCode plusCode; + + public String toString() { + StringBuilder sb = new StringBuilder("[GeocodingResult"); + if (partialMatch) { + sb.append(" PARTIAL MATCH"); + } + sb.append(" placeId=").append(placeId); + sb.append(" ").append(geometry); + sb.append(", formattedAddress=").append(formattedAddress); + sb.append(", types=").append(Arrays.toString(types)); + sb.append(", addressComponents=").append(Arrays.toString(addressComponents)); + if (postcodeLocalities != null && postcodeLocalities.length > 0) { + sb.append(", postcodeLocalities=").append(Arrays.toString(postcodeLocalities)); + } + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/GeolocationPayload.java b/src/main/java/com/google/maps/model/GeolocationPayload.java index ebfcf0cbc..ba7cbe87c 100644 --- a/src/main/java/com/google/maps/model/GeolocationPayload.java +++ b/src/main/java/com/google/maps/model/GeolocationPayload.java @@ -15,8 +15,11 @@ package com.google.maps.model; +import static com.google.maps.internal.StringJoin.join; + import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -76,6 +79,33 @@ private GeolocationPayload( /** An array of WiFi access point objects. See {@link com.google.maps.model.WifiAccessPoint}. */ public WifiAccessPoint[] wifiAccessPoints; + public String toString() { + StringBuilder sb = new StringBuilder("[GeolocationPayload"); + List elements = new ArrayList<>(); + if (homeMobileCountryCode != null) { + elements.add("homeMobileCountryCode=" + homeMobileCountryCode); + } + if (homeMobileNetworkCode != null) { + elements.add("homeMobileNetworkCode=" + homeMobileNetworkCode); + } + if (radioType != null) { + elements.add("radioType=" + radioType); + } + if (carrier != null) { + elements.add("carrier=" + carrier); + } + elements.add("considerIp=" + considerIp); + if (cellTowers != null && cellTowers.length > 0) { + elements.add("cellTowers=" + Arrays.toString(cellTowers)); + } + if (wifiAccessPoints != null && wifiAccessPoints.length > 0) { + elements.add("wifiAccessPoints=" + Arrays.toString(wifiAccessPoints)); + } + sb.append(join(", ", elements)); + sb.append("]"); + return sb.toString(); + } + public static class GeolocationPayloadBuilder { private Integer _homeMobileCountryCode = null; private Integer _homeMobileNetworkCode = null; @@ -83,9 +113,9 @@ public static class GeolocationPayloadBuilder { private String _carrier = null; private Boolean _considerIp = null; private CellTower[] _cellTowers = null; - private List _addedCellTowers = new ArrayList(); + private List _addedCellTowers = new ArrayList<>(); private WifiAccessPoint[] _wifiAccessPoints = null; - private List _addedWifiAccessPoints = new ArrayList(); + private List _addedWifiAccessPoints = new ArrayList<>(); public GeolocationPayload createGeolocationPayload() { // if wifi access points have been added individually... @@ -110,12 +140,12 @@ public GeolocationPayload createGeolocationPayload() { } public GeolocationPayloadBuilder HomeMobileCountryCode(int newHomeMobileCountryCode) { - this._homeMobileCountryCode = new Integer(newHomeMobileCountryCode); + this._homeMobileCountryCode = newHomeMobileCountryCode; return this; } public GeolocationPayloadBuilder HomeMobileNetworkCode(int newHomeMobileNetworkCode) { - this._homeMobileNetworkCode = new Integer(newHomeMobileNetworkCode); + this._homeMobileNetworkCode = newHomeMobileNetworkCode; return this; } @@ -130,7 +160,7 @@ public GeolocationPayloadBuilder Carrier(String newCarrier) { } public GeolocationPayloadBuilder ConsiderIp(boolean newConsiderIp) { - this._considerIp = new Boolean(newConsiderIp); + this._considerIp = newConsiderIp; return this; } diff --git a/src/main/java/com/google/maps/model/GeolocationResult.java b/src/main/java/com/google/maps/model/GeolocationResult.java index fa3a69e8d..06927db75 100644 --- a/src/main/java/com/google/maps/model/GeolocationResult.java +++ b/src/main/java/com/google/maps/model/GeolocationResult.java @@ -36,4 +36,8 @@ public class GeolocationResult implements Serializable { * around the returned {@code location}. */ public double accuracy; + + public String toString() { + return String.format("%s, accuracy=%s m", location, accuracy); + } } diff --git a/src/main/java/com/google/maps/model/Geometry.java b/src/main/java/com/google/maps/model/Geometry.java index 6289ac0ea..5f93c1ea1 100644 --- a/src/main/java/com/google/maps/model/Geometry.java +++ b/src/main/java/com/google/maps/model/Geometry.java @@ -43,4 +43,9 @@ public class Geometry implements Serializable { * frame a result when displaying it to a user. */ public Bounds viewport; + + public String toString() { + return String.format( + "[Geometry: %s (%s) bounds=%s, viewport=%s]", location, locationType, bounds, viewport); + } } diff --git a/src/main/java/com/google/maps/model/OpeningHours.java b/src/main/java/com/google/maps/model/OpeningHours.java index e4e5ab686..58d124208 100644 --- a/src/main/java/com/google/maps/model/OpeningHours.java +++ b/src/main/java/com/google/maps/model/OpeningHours.java @@ -16,6 +16,7 @@ package com.google.maps.model; import java.io.Serializable; +import java.util.Arrays; import org.joda.time.LocalTime; /** @@ -43,19 +44,29 @@ public static class OpenClose implements Serializable { private static final long serialVersionUID = 1L; public enum DayOfWeek { - SUNDAY, - MONDAY, - TUESDAY, - WEDNESDAY, - THURSDAY, - FRIDAY, - SATURDAY, + SUNDAY("Sunday"), + MONDAY("Monday"), + TUESDAY("Tuesday"), + WEDNESDAY("Wednesday"), + THURSDAY("Thursday"), + FRIDAY("Friday"), + SATURDAY("Saturday"), /** * Indicates an unknown day of week type returned by the server. The Java Client for Google * Maps Services should be updated to support the new value. */ - UNKNOWN + UNKNOWN("Unknown"); + + private DayOfWeek(String name) { + this.name = name; + } + + private final String name; + + public String getName() { + return name; + } } /** Day that this Open/Close pair is for. */ @@ -63,6 +74,10 @@ public enum DayOfWeek { /** Time that this Open or Close happens at. */ public LocalTime time; + + public String toString() { + return String.format("%s %s", day, time); + } } /** When the Place opens. */ @@ -70,6 +85,10 @@ public enum DayOfWeek { /** When the Place closes. */ public Period.OpenClose close; + + public String toString() { + return String.format("%s - %s", open, close); + } } /** Opening periods covering seven days, starting from Sunday, in chronological order. */ @@ -87,4 +106,16 @@ public enum DayOfWeek { *

    Note: this field will be null if it isn't present in the response. */ public Boolean permanentlyClosed; + + public String toString() { + StringBuilder sb = new StringBuilder("[OpeningHours:"); + if (permanentlyClosed != null && permanentlyClosed) { + sb.append(" permanentlyClosed"); + } + if (openNow != null && openNow) { + sb.append(" openNow"); + } + sb.append(" ").append(Arrays.toString(periods)); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/Photo.java b/src/main/java/com/google/maps/model/Photo.java index c85c08be2..354d33400 100644 --- a/src/main/java/com/google/maps/model/Photo.java +++ b/src/main/java/com/google/maps/model/Photo.java @@ -37,4 +37,13 @@ public class Photo implements Serializable { /** Attributions about this listing which must be displayed to the user. */ public String[] htmlAttributions; + + public String toString() { + String str = String.format("[Photo %s (%d x %d)", photoReference, width, height); + if (htmlAttributions != null && htmlAttributions.length > 0) { + str = str + " " + htmlAttributions.length + " attributions"; + } + str = str + "]"; + return str; + } } diff --git a/src/main/java/com/google/maps/model/PlaceDetails.java b/src/main/java/com/google/maps/model/PlaceDetails.java index d27b4293d..88cfa772b 100644 --- a/src/main/java/com/google/maps/model/PlaceDetails.java +++ b/src/main/java/com/google/maps/model/PlaceDetails.java @@ -17,6 +17,7 @@ import java.io.Serializable; import java.net.URL; +import java.util.Arrays; import org.joda.time.Instant; /** @@ -70,6 +71,9 @@ public class PlaceDetails implements Serializable { /** The scope of the placeId. */ public PlaceIdScope scope; + /** The Plus Code location identifier for this place. */ + public PlusCode plusCode; + /** Whether the place has permanently closed. */ public boolean permanentlyClosed; @@ -89,6 +93,10 @@ public static class AlternatePlaceIds implements Serializable { * place ID is recognised by your application only. */ public PlaceIdScope scope; + + public String toString() { + return String.format("%s (%s)", placeId, scope); + } } /** @@ -160,9 +168,15 @@ public enum RatingType { /** An IETF language code indicating the language used in the user's review. */ public String language; + /** The URL of the user's Google+ profile photo, if available. */ + public String profilePhotoUrl; + /** The user's overall rating for this place. This is a whole number, ranging from 1 to 5. */ public int rating; + /** The relative time that the review was submitted. */ + public String relativeTimeDescription; + /** * The user's review. When reviewing a location with Google Places, text reviews are considered * optional. @@ -180,7 +194,7 @@ public enum RatingType { public Review[] reviews; /** Feature types describing the given result. */ - public String[] types; + public AddressType[] types; /** * The URL of the official Google page for this place. This will be the establishment's Google+ @@ -204,4 +218,58 @@ public enum RatingType { /** Attributions about this listing which must be displayed to the user. */ public String[] htmlAttributions; + + public String toString() { + StringBuilder sb = new StringBuilder("[PlaceDetails: "); + sb.append("\"").append(name).append("\""); + sb.append(" ").append(placeId).append(" (").append(scope).append(")"); + sb.append(" address=\"").append(formattedAddress).append("\""); + sb.append(" geometry=").append(geometry); + if (vicinity != null) { + sb.append(", vicinity=").append(vicinity); + } + if (types != null && types.length > 0) { + sb.append(", types=").append(Arrays.toString(types)); + } + if (altIds != null && altIds.length > 0) { + sb.append(", altIds=").append(Arrays.toString(altIds)); + } + if (formattedPhoneNumber != null) { + sb.append(", phone=").append(formattedPhoneNumber); + } + if (internationalPhoneNumber != null) { + sb.append(", internationalPhoneNumber=").append(internationalPhoneNumber); + } + if (url != null) { + sb.append(", url=").append(url); + } + if (website != null) { + sb.append(", website=").append(website); + } + if (icon != null) { + sb.append(", icon"); + } + if (openingHours != null) { + sb.append(", openingHours"); + sb.append(", utcOffset=").append(utcOffset); + } + if (priceLevel != null) { + sb.append(", priceLevel=").append(priceLevel); + } + sb.append(", rating=").append(rating); + if (permanentlyClosed) { + sb.append(", permanentlyClosed"); + } + if (photos != null && photos.length > 0) { + sb.append(", ").append(photos.length).append(" photos"); + } + if (reviews != null && reviews.length > 0) { + sb.append(", ").append(reviews.length).append(" reviews"); + } + if (htmlAttributions != null && htmlAttributions.length > 0) { + sb.append(", ").append(htmlAttributions.length).append(" htmlAttributions"); + } + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/PlacesSearchResponse.java b/src/main/java/com/google/maps/model/PlacesSearchResponse.java index f4d9afdbe..16cb3f6ed 100644 --- a/src/main/java/com/google/maps/model/PlacesSearchResponse.java +++ b/src/main/java/com/google/maps/model/PlacesSearchResponse.java @@ -42,4 +42,17 @@ public class PlacesSearchResponse implements Serializable { * will become valid to execute. */ public String nextPageToken; + + public String toString() { + StringBuilder sb = new StringBuilder("[PlacesSearchResponse: "); + sb.append(results.length).append(" results"); + if (nextPageToken != null) { + sb.append(", nextPageToken=").append(nextPageToken); + } + if (htmlAttributions != null && htmlAttributions.length > 0) { + sb.append(", ").append(htmlAttributions.length).append(" htmlAttributions"); + } + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/PlacesSearchResult.java b/src/main/java/com/google/maps/model/PlacesSearchResult.java index 65b7206f1..b48142eb1 100644 --- a/src/main/java/com/google/maps/model/PlacesSearchResult.java +++ b/src/main/java/com/google/maps/model/PlacesSearchResult.java @@ -17,6 +17,7 @@ import java.io.Serializable; import java.net.URL; +import java.util.Arrays; /** * A single result in the search results returned from the Google Places API Web Service. @@ -52,7 +53,7 @@ public class PlacesSearchResult implements Serializable { /** A textual identifier that uniquely identifies a place. */ public String placeId; - /** sThe scope of the placeId. */ + /** The scope of the placeId. */ public PlaceIdScope scope; /** The place's rating, from 1.0 to 5.0, based on aggregated user reviews. */ @@ -72,4 +73,34 @@ public class PlacesSearchResult implements Serializable { /** Indicates that the place has permanently shut down. */ public boolean permanentlyClosed; + + public String toString() { + StringBuilder sb = new StringBuilder("[PlacesSearchResult: "); + sb.append("\"").append(name).append("\""); + sb.append(", \"").append(formattedAddress).append("\""); + sb.append(", geometry=").append(geometry); + sb.append(", placeId=").append(placeId).append(" (").append(scope).append(" )"); + if (vicinity != null) { + sb.append(", vicinity=").append(vicinity); + } + if (types != null && types.length > 0) { + sb.append(", types=").append(Arrays.toString(types)); + } + sb.append(", rating=").append(rating); + if (icon != null) { + sb.append(", icon"); + } + if (openingHours != null) { + sb.append(", openingHours"); + } + if (photos != null && photos.length > 0) { + sb.append(", ").append(photos.length).append(" photos"); + } + if (permanentlyClosed) { + sb.append(", permanentlyClosed"); + } + + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/PlusCode.java b/src/main/java/com/google/maps/model/PlusCode.java new file mode 100644 index 000000000..74f6fc6f1 --- /dev/null +++ b/src/main/java/com/google/maps/model/PlusCode.java @@ -0,0 +1,35 @@ +/* + * Copyright 2018 Google Inc. All rights reserved. + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF + * ANY KIND, either express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.google.maps.model; + +/** A Plus Code encoded location reference. */ +public class PlusCode { + /** The global Plus Code identifier. */ + public String globalCode; + + /** The compound Plus Code identifier. May be null for locations in remote areas. */ + public String compoundCode; + + public String toString() { + StringBuilder sb = new StringBuilder("[PlusCode: "); + sb.append(globalCode); + if (compoundCode != null) { + sb.append(", compoundCode=").append(compoundCode); + } + sb.append("]"); + return sb.toString(); + } +} diff --git a/src/main/java/com/google/maps/model/SnappedPoint.java b/src/main/java/com/google/maps/model/SnappedPoint.java index b73367a62..6a4d49263 100644 --- a/src/main/java/com/google/maps/model/SnappedPoint.java +++ b/src/main/java/com/google/maps/model/SnappedPoint.java @@ -42,4 +42,8 @@ public class SnappedPoint implements Serializable { * that road segment. */ public String placeId; + + public String toString() { + return String.format("[%s, placeId=%s, originalIndex=%s]", location, placeId, originalIndex); + } } diff --git a/src/main/java/com/google/maps/model/SnappedSpeedLimitResponse.java b/src/main/java/com/google/maps/model/SnappedSpeedLimitResponse.java index 4b9a7f1a3..a367d1ba9 100644 --- a/src/main/java/com/google/maps/model/SnappedSpeedLimitResponse.java +++ b/src/main/java/com/google/maps/model/SnappedSpeedLimitResponse.java @@ -27,4 +27,16 @@ public class SnappedSpeedLimitResponse implements Serializable { /** Snap-to-road results. */ public SnappedPoint[] snappedPoints; + + public String toString() { + StringBuilder sb = new StringBuilder("[SnappedSpeedLimitResponse:"); + if (speedLimits != null && speedLimits.length > 0) { + sb.append(" ").append(speedLimits.length).append(" speedLimits"); + } + if (snappedPoints != null && snappedPoints.length > 0) { + sb.append(" ").append(snappedPoints.length).append(" speedLimits"); + } + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/SpeedLimit.java b/src/main/java/com/google/maps/model/SpeedLimit.java index 5775cd81d..d58df3e5b 100644 --- a/src/main/java/com/google/maps/model/SpeedLimit.java +++ b/src/main/java/com/google/maps/model/SpeedLimit.java @@ -38,4 +38,8 @@ public class SpeedLimit implements Serializable { public long speedLimitMph() { return Math.round(speedLimit * 0.621371); } + + public String toString() { + return String.format("[%.0f km/h, placeId=%s]", speedLimit, placeId); + } } diff --git a/src/main/java/com/google/maps/model/StopDetails.java b/src/main/java/com/google/maps/model/StopDetails.java index 069c59cf2..592467d79 100644 --- a/src/main/java/com/google/maps/model/StopDetails.java +++ b/src/main/java/com/google/maps/model/StopDetails.java @@ -33,4 +33,8 @@ public class StopDetails implements Serializable { /** The location of the transit station/stop. */ public LatLng location; + + public String toString() { + return String.format("%s (%s)", name, location); + } } diff --git a/src/main/java/com/google/maps/model/TransitAgency.java b/src/main/java/com/google/maps/model/TransitAgency.java index 4a6000310..97b82c8a1 100644 --- a/src/main/java/com/google/maps/model/TransitAgency.java +++ b/src/main/java/com/google/maps/model/TransitAgency.java @@ -36,4 +36,17 @@ public class TransitAgency implements Serializable { /** The phone number of the transit agency. */ public String phone; + + public String toString() { + StringBuilder sb = new StringBuilder("[TransitAgency: "); + sb.append(name); + if (url != null) { + sb.append(", url=").append(url); + } + if (phone != null) { + sb.append(", phone=").append(phone); + } + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/TransitDetails.java b/src/main/java/com/google/maps/model/TransitDetails.java index bf83d830b..0b54751c4 100644 --- a/src/main/java/com/google/maps/model/TransitDetails.java +++ b/src/main/java/com/google/maps/model/TransitDetails.java @@ -62,4 +62,21 @@ public class TransitDetails implements Serializable { /** Information about the transit line used in this step. */ public TransitLine line; + + public String toString() { + StringBuilder sb = new StringBuilder("["); + sb.append(departureStop).append(" at ").append(departureTime); + sb.append(" -> "); + sb.append(arrivalStop).append(" at ").append(arrivalTime); + if (headsign != null) { + sb.append(" (").append(headsign).append(" )"); + } + if (line != null) { + sb.append(" on ").append(line); + } + sb.append(", ").append(numStops).append(" stops"); + sb.append(", headway=").append(headway).append(" s"); + sb.append("]"); + return sb.toString(); + } } diff --git a/src/main/java/com/google/maps/model/TransitLine.java b/src/main/java/com/google/maps/model/TransitLine.java index b417e8dc8..d2baa3e22 100644 --- a/src/main/java/com/google/maps/model/TransitLine.java +++ b/src/main/java/com/google/maps/model/TransitLine.java @@ -60,4 +60,8 @@ public class TransitLine implements Serializable { /** The type of vehicle used on this transit line. */ public Vehicle vehicle; + + public String toString() { + return String.format("%s \"%s\"", shortName, name); + } } diff --git a/src/main/java/com/google/maps/model/Vehicle.java b/src/main/java/com/google/maps/model/Vehicle.java index cbc99ee4e..2b25ae515 100644 --- a/src/main/java/com/google/maps/model/Vehicle.java +++ b/src/main/java/com/google/maps/model/Vehicle.java @@ -42,4 +42,8 @@ public class Vehicle implements Serializable { /** The URL for an icon based on the local transport signage. */ public String localIcon; + + public String toString() { + return String.format("%s (%s)", name, type); + } } diff --git a/src/main/java/com/google/maps/model/WifiAccessPoint.java b/src/main/java/com/google/maps/model/WifiAccessPoint.java index 5bbe19782..d683a460c 100644 --- a/src/main/java/com/google/maps/model/WifiAccessPoint.java +++ b/src/main/java/com/google/maps/model/WifiAccessPoint.java @@ -61,6 +61,27 @@ private WifiAccessPoint( /** The current signal to noise ratio measured in dB. */ public Integer signalToNoiseRatio = null; + public String toString() { + StringBuilder sb = new StringBuilder("[WifiAccessPoint:"); + if (macAddress != null) { + sb.append(" macAddress=").append(macAddress); + } + if (signalStrength != null) { + sb.append(" signalStrength=").append(signalStrength); + } + if (age != null) { + sb.append(" age=").append(age); + } + if (channel != null) { + sb.append(" channel=").append(channel); + } + if (signalToNoiseRatio != null) { + sb.append(" signalToNoiseRatio=").append(signalToNoiseRatio); + } + sb.append("]"); + return sb.toString(); + } + public static class WifiAccessPointBuilder { private String _macAddress = null; private Integer _signalStrength = null; @@ -79,22 +100,22 @@ public WifiAccessPointBuilder MacAddress(String newMacAddress) { } public WifiAccessPointBuilder SignalStrength(int newSignalStrength) { - this._signalStrength = new Integer(newSignalStrength); + this._signalStrength = newSignalStrength; return this; } public WifiAccessPointBuilder Age(int newAge) { - this._age = new Integer(newAge); + this._age = newAge; return this; } public WifiAccessPointBuilder Channel(int newChannel) { - this._channel = new Integer(newChannel); + this._channel = newChannel; return this; } public WifiAccessPointBuilder SignalToNoiseRatio(int newSignalToNoiseRatio) { - this._signalToNoiseRatio = new Integer(newSignalToNoiseRatio); + this._signalToNoiseRatio = newSignalToNoiseRatio; return this; } } diff --git a/src/test/java/com/google/maps/DirectionsApiTest.java b/src/test/java/com/google/maps/DirectionsApiTest.java index b51cf4e56..186726b7a 100644 --- a/src/test/java/com/google/maps/DirectionsApiTest.java +++ b/src/test/java/com/google/maps/DirectionsApiTest.java @@ -33,6 +33,7 @@ import com.google.maps.model.TravelMode; import com.google.maps.model.Unit; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.joda.time.DateTime; import org.joda.time.Duration; @@ -62,11 +63,14 @@ public void testGetDirections() throws Exception { DirectionsApi.getDirections(sc.context, "Sydney, AU", "Melbourne, AU").await(); assertNotNull(result); + assertNotNull(result.toString(), "result.toString() succeeded"); assertNotNull(result.geocodedWaypoints); + assertNotNull(Arrays.toString(result.geocodedWaypoints)); assertEquals(2, result.geocodedWaypoints.length); assertEquals("ChIJP3Sa8ziYEmsRUKgyFmh9AQM", result.geocodedWaypoints[0].placeId); assertEquals("ChIJ90260rVG1moRkM2MIXVWBAQ", result.geocodedWaypoints[1].placeId); assertNotNull(result.routes); + assertNotNull(Arrays.toString(result.routes)); assertEquals(1, result.routes.length); assertNotNull(result.routes[0]); assertEquals("M31 and National Highway M31", result.routes[0].summary); @@ -290,7 +294,7 @@ public void testLanguageParameter() throws Exception { @Test public void testTrafficModel() throws Exception { try (LocalTestServerContext sc = - new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}"); ) { + new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { DirectionsApi.newRequest(sc.context) .origin("48 Pirrama Road, Pyrmont NSW 2009") .destination("182 Church St, Parramatta NSW 2150") @@ -349,7 +353,7 @@ public void testTransitParams() throws Exception { @Test public void testTravelModeWalking() throws Exception { try (LocalTestServerContext sc = - new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}"); ) { + new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { DirectionsResult result = DirectionsApi.newRequest(sc.context) .mode(TravelMode.WALKING) @@ -357,6 +361,7 @@ public void testTravelModeWalking() throws Exception { .destination("182 Church St, Parramatta NSW 2150, Australia") .await(); + assertNotNull(result.toString()); assertNotNull(result.routes); assertNotNull(result.routes[0]); @@ -411,6 +416,7 @@ public void testGeocodedWaypoints() throws Exception { .mode(TravelMode.DRIVING) .await(); + assertNotNull(result.toString()); assertNotNull(result.geocodedWaypoints); assertEquals(2, result.geocodedWaypoints.length); assertEquals(GeocodedWaypointStatus.OK, result.geocodedWaypoints[0].geocoderStatus); @@ -483,7 +489,7 @@ public void testOptimizeWaypointsAfterWaypoints() throws Exception { /** Coordinates in Mexico City. */ private List getOptimizationWaypoints() { - List waypoints = new ArrayList(); + List waypoints = new ArrayList<>(); waypoints.add(new LatLng(19.431676, -99.133999)); waypoints.add(new LatLng(19.427915, -99.138939)); waypoints.add(new LatLng(19.435436, -99.139145)); diff --git a/src/test/java/com/google/maps/DistanceMatrixApiTest.java b/src/test/java/com/google/maps/DistanceMatrixApiTest.java index 49f1358af..66819f9be 100644 --- a/src/test/java/com/google/maps/DistanceMatrixApiTest.java +++ b/src/test/java/com/google/maps/DistanceMatrixApiTest.java @@ -17,6 +17,7 @@ import static com.google.maps.TestUtils.retrieveBody; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import com.google.maps.DirectionsApi.RouteRestriction; import com.google.maps.model.DistanceMatrix; @@ -25,6 +26,7 @@ import com.google.maps.model.TrafficModel; import com.google.maps.model.TravelMode; import com.google.maps.model.Unit; +import java.util.Arrays; import org.apache.commons.lang.StringUtils; import org.joda.time.DateTime; import org.junit.Test; @@ -74,7 +76,11 @@ public void testGetDistanceMatrixWithBasicStringParams() throws Exception { DistanceMatrix matrix = DistanceMatrixApi.getDistanceMatrix(sc.context, origins, destinations).await(); - // Rows length will match the number of origin elements, regardless of whether they're routable. + assertNotNull(matrix.toString()); + assertNotNull(Arrays.toString(matrix.rows)); + + // Rows length will match the number of origin elements, regardless of whether they're + // routable. assertEquals(8, matrix.rows.length); assertEquals(5, matrix.rows[0].elements.length); assertEquals(DistanceMatrixElementStatus.OK, matrix.rows[0].elements[0].status); diff --git a/src/test/java/com/google/maps/ElevationApiTest.java b/src/test/java/com/google/maps/ElevationApiTest.java index 6332848c4..968e40522 100644 --- a/src/test/java/com/google/maps/ElevationApiTest.java +++ b/src/test/java/com/google/maps/ElevationApiTest.java @@ -113,6 +113,7 @@ public void testGetPoint() throws Exception { ElevationResult result = ElevationApi.getByPoint(sc.context, SYDNEY).await(); assertNotNull(result); + assertNotNull(result.toString()); assertEquals(SYDNEY_POINT_ELEVATION, result.elevation, EPSILON); sc.assertParamValue(SYDNEY.toUrlValue(), "locations"); diff --git a/src/test/java/com/google/maps/GeoApiContextTest.java b/src/test/java/com/google/maps/GeoApiContextTest.java index c0abf0a3b..062513552 100644 --- a/src/test/java/com/google/maps/GeoApiContextTest.java +++ b/src/test/java/com/google/maps/GeoApiContextTest.java @@ -269,8 +269,8 @@ public void testQueryParamsHaveOrderPreserved() throws Exception { @Test public void testToggleIfExceptionIsAllowedToRetry() throws Exception { - // Enqueue some error responses, although only the first should be used because the response's exception is not - // allowed to be retried. + // Enqueue some error responses, although only the first should be used because the response's + // exception is not allowed to be retried. MockResponse overQueryLimitResponse = new MockResponse(); overQueryLimitResponse.setStatus("HTTP/1.1 400 Internal server error"); overQueryLimitResponse.setBody(TestUtils.retrieveBody("OverQueryLimitResponse.json")); @@ -307,7 +307,7 @@ public void testShutdown() throws InterruptedException { assertTrue( "Delay thread should start in constructor of RateLimitExecutorService", delayThread.isAlive()); - //this is needed to make sure that delay thread has reached queue.take() + // this is needed to make sure that delay thread has reached queue.take() delayThread.join(10); context.shutdown(); delayThread.join(10); diff --git a/src/test/java/com/google/maps/GeocodingApiTest.java b/src/test/java/com/google/maps/GeocodingApiTest.java index f07e7346d..3f03f6f40 100644 --- a/src/test/java/com/google/maps/GeocodingApiTest.java +++ b/src/test/java/com/google/maps/GeocodingApiTest.java @@ -30,6 +30,7 @@ import com.google.maps.model.LatLng; import com.google.maps.model.LocationType; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -60,11 +61,13 @@ public GeocodingApiTest() { public void testGeocodeLibraryType() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(geocodeLibraryType)) { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).address("80 FR").await(); + assertEquals(1, results.length); assertEquals(3, results[0].types.length); assertEquals(AddressType.ESTABLISHMENT, results[0].types[0]); assertEquals(AddressType.LIBRARY, results[0].types[1]); assertEquals(AddressType.POINT_OF_INTEREST, results[0].types[2]); + assertNotNull(Arrays.toString(results)); } } @@ -73,6 +76,7 @@ public void testSimpleGeocode() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(simpleGeocodeResponse)) { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).address("Sydney").await(); checkSydneyResult(results); + assertNotNull(Arrays.toString(results)); sc.assertParamValue("Sydney", "address"); } @@ -92,7 +96,7 @@ public void testPlaceGeocode() throws Exception { @Test public void testAsync() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(simpleGeocodeResponse)) { - final List resps = new ArrayList(); + final List resps = new ArrayList<>(); PendingResult.Callback callback = new PendingResult.Callback() { @@ -236,6 +240,7 @@ public void testGeocodeTheGoogleplex() throws Exception { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).address(address).await(); assertNotNull(results); + assertNotNull(Arrays.toString(results)); assertEquals( "Google Bldg 41, 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", results[0].formattedAddress); @@ -323,6 +328,8 @@ public void testGeocodeWithBounds() throws Exception { .bounds(new LatLng(34.172684, -118.604794), new LatLng(34.236144, -118.500938)) .await(); + assertNotNull(Arrays.toString(results)); + assertEquals("Winnetka, Los Angeles, CA, USA", results[0].formattedAddress); assertEquals("ChIJ0fd4S_KbwoAR2hRDrsr3HmQ", results[0].placeId); @@ -403,6 +410,8 @@ public void testGeocodeWithRegionBiasing() throws Exception { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).address("Toledo").region("es").await(); + assertNotNull(Arrays.toString(results)); + assertNotNull(results); assertEquals("Toledo, Spain", results[0].formattedAddress); assertEquals(AddressType.LOCALITY, results[0].types[0]); @@ -488,6 +497,8 @@ public void testGeocodeWithComponentFilter() throws Exception { .components(ComponentFilter.country("ES")) .await(); + assertNotNull(Arrays.toString(results)); + assertEquals("Santa Cruz de Tenerife, Spain", results[0].formattedAddress); assertEquals("ChIJcUElzOzMQQwRLuV30nMUEUM", results[0].placeId); @@ -572,6 +583,8 @@ public void testGeocodeWithMultipleComponentFilters() throws Exception { .components(administrativeArea("TX"), country("US")) .await(); + assertNotNull(Arrays.toString(results)); + assertEquals("Texas, USA", results[0].formattedAddress); assertEquals(true, results[0].partialMatch); assertEquals("ChIJSTKCCzZwQIYRPN4IGI8c6xY", results[0].placeId); @@ -660,6 +673,7 @@ public void testGeocodeWithJustComponents() throws Exception { .await(); assertNotNull(results); + assertNotNull(Arrays.toString(results)); assertEquals("Annankatu, 00101 Helsinki, Finland", results[0].formattedAddress); assertEquals("EiBBbm5hbmthdHUsIDAwMTAxIEhlbHNpbmtpLCBTdW9taQ", results[0].placeId); @@ -680,6 +694,7 @@ public void testSimpleReverseGeocode() throws Exception { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).latlng(latlng).await(); assertNotNull(results); + assertNotNull(Arrays.toString(results)); assertEquals("277 Bedford Ave, Brooklyn, NY 11211, USA", results[0].formattedAddress); assertEquals("277", results[0].addressComponents[0].longName); assertEquals("277", results[0].addressComponents[0].shortName); @@ -779,6 +794,7 @@ public void testReverseGeocodeRestrictedByType() throws Exception { .await(); assertNotNull(results); + assertNotNull(Arrays.toString(results)); assertEquals("277 Bedford Ave, Brooklyn, NY 11211, USA", results[0].formattedAddress); assertEquals(LocationType.ROOFTOP, results[0].geometry.locationType); assertEquals("ChIJd8BlQ2BZwokRAFUEcm_qrcA", results[0].placeId); @@ -898,6 +914,7 @@ public void testCustomParameterPassThrough() throws Exception { .custom("new_forward_geocoder", "true") .await(); + assertNotNull(Arrays.toString(results)); assertEquals( "Google Bldg 41, 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", results[0].formattedAddress); @@ -916,6 +933,7 @@ public void testReverseGeocodeWithKitaWard() throws Exception { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).latlng(location).await(); assertNotNull(results); + assertNotNull(Arrays.toString(results)); assertEquals( "Japan, 〒603-8361 Kyōto-fu, Kyōto-shi, Kita-ku, Kinkakujichō, 1 北山鹿苑寺金閣寺", results[0].formattedAddress); @@ -1009,6 +1027,7 @@ public void testSupportedAddressTypesFood() throws Exception { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).address(address).await(); assertNotNull(results); + assertNotNull(Arrays.toString(results)); assertEquals(AddressType.ESTABLISHMENT, results[0].types[0]); assertEquals(AddressType.FOOD, results[0].types[1]); assertEquals(AddressType.GROCERY_OR_SUPERMARKET, results[0].types[2]); @@ -1093,6 +1112,7 @@ public void testSupportedAddressTypesSynagogue() throws Exception { GeocodingResult[] results = GeocodingApi.newRequest(sc.context).address(address).await(); assertNotNull(results); + assertNotNull(Arrays.toString(results)); assertEquals(AddressType.ESTABLISHMENT, results[0].types[0]); assertEquals(AddressType.PLACE_OF_WORSHIP, results[0].types[1]); assertEquals(AddressType.POINT_OF_INTEREST, results[0].types[2]); diff --git a/src/test/java/com/google/maps/GeolocationApiTest.java b/src/test/java/com/google/maps/GeolocationApiTest.java index 20b47da47..8388e17c0 100644 --- a/src/test/java/com/google/maps/GeolocationApiTest.java +++ b/src/test/java/com/google/maps/GeolocationApiTest.java @@ -88,6 +88,8 @@ public void testDocSampleGeolocation() throws Exception { .CreatePayload() .await(); + assertNotNull(result.toString()); + JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); assertEquals(310, body.get("homeMobileCountryCode")); @@ -117,6 +119,8 @@ public void testMinimumWifiGeolocation() throws Exception { .CreatePayload() .await(); + assertNotNull(result.toString()); + JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); JSONArray wifiAccessPoints = body.getJSONArray("wifiAccessPoints"); @@ -149,6 +153,8 @@ public void testBasicGeolocation() throws Exception { .CreatePayload() .await(); + assertNotNull(result.toString()); + JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); JSONArray wifiAccessPoints = body.getJSONArray("wifiAccessPoints"); @@ -186,6 +192,8 @@ public void testAlternateWifiSetterGeolocation() throws Exception { .CreatePayload() .await(); + assertNotNull(result.toString()); + JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); JSONArray wifiAccessPointsResponse = body.getJSONArray("wifiAccessPoints"); @@ -228,6 +236,8 @@ public void testMaximumWifiGeolocation() throws Exception { .CreatePayload() .await(); + assertNotNull(result.toString()); + JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); assertEquals(310, body.get("homeMobileCountryCode")); @@ -269,6 +279,8 @@ public void testMinimumCellTowerGeolocation() throws Exception { .CreatePayload() .await(); + assertNotNull(result.toString()); + JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); JSONObject cellTower = body.getJSONArray("cellTowers").getJSONObject(0); @@ -299,6 +311,7 @@ public void testAlternatePayloadBuilderGeolocation() throws Exception { .createGeolocationPayload(); GeolocationResult result = GeolocationApi.geolocate(sc.context, payload).await(); + assertNotNull(result.toString()); JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); JSONObject cellTower = body.getJSONArray("cellTowers").getJSONObject(0); @@ -335,6 +348,8 @@ public void testMaximumCellTowerGeolocation() throws Exception { .CreatePayload() .await(); + assertNotNull(result.toString()); + JSONObject body = sc.requestBody(); assertEquals(false, body.get("considerIp")); assertEquals(310, body.get("homeMobileCountryCode")); @@ -363,6 +378,7 @@ public void testNoPayloadGeolocation0() throws Exception { GeolocationResult result = GeolocationApi.geolocate(sc.context, payload).await(); assertNotNull(result); + assertNotNull(result.toString()); assertNotNull(result.location); } } @@ -373,6 +389,7 @@ public void testNoPayloadGeolocation1() throws Exception { GeolocationResult result = GeolocationApi.newRequest(sc.context).CreatePayload().await(); assertNotNull(result); + assertNotNull(result.toString()); assertNotNull(result.location); } } diff --git a/src/test/java/com/google/maps/LocalTestServerContext.java b/src/test/java/com/google/maps/LocalTestServerContext.java index 0879b3afb..fad6c5996 100644 --- a/src/test/java/com/google/maps/LocalTestServerContext.java +++ b/src/test/java/com/google/maps/LocalTestServerContext.java @@ -102,7 +102,7 @@ public String path() throws InterruptedException { return request.getPath().split("\\?")[0]; } - void assertParamValue(String expectedValue, String paramName) + void assertParamValue(String expected, String paramName) throws URISyntaxException, InterruptedException { if (this.params == null) { this.params = this.actualParams(); @@ -111,13 +111,13 @@ void assertParamValue(String expectedValue, String paramName) for (NameValuePair pair : params) { if (pair.getName().equals(paramName)) { paramFound = true; - assertEquals(expectedValue, pair.getValue()); + assertEquals(expected, pair.getValue()); } } assertTrue(paramFound); } - void assertParamValues(List expectedValues, String paramName) + void assertParamValues(List expecteds, String paramName) throws URISyntaxException, InterruptedException { if (this.params == null) { this.params = this.actualParams(); @@ -125,11 +125,11 @@ void assertParamValues(List expectedValues, String paramName) int paramsFound = 0; for (NameValuePair pair : params) { if (pair.getName().equals(paramName)) { - assertEquals(expectedValues.get(paramsFound), pair.getValue()); + assertEquals(expecteds.get(paramsFound), pair.getValue()); paramsFound++; } } - assertEquals(paramsFound, expectedValues.size()); + assertEquals(paramsFound, expecteds.size()); } @Override diff --git a/src/test/java/com/google/maps/PlacesApiTest.java b/src/test/java/com/google/maps/PlacesApiTest.java index 01b0861df..a667209b4 100644 --- a/src/test/java/com/google/maps/PlacesApiTest.java +++ b/src/test/java/com/google/maps/PlacesApiTest.java @@ -28,6 +28,7 @@ import com.google.maps.FindPlaceFromTextRequest.LocationBiasRectangular; import com.google.maps.PlaceAutocompleteRequest.SessionToken; import com.google.maps.model.AddressComponentType; +import com.google.maps.model.AddressType; import com.google.maps.model.AutocompletePrediction; import com.google.maps.model.AutocompletePrediction.MatchedSubstring; import com.google.maps.model.AutocompleteStructuredFormatting; @@ -137,6 +138,7 @@ public void testAutocompletePredictionStructuredFormatting() throws Exception { PlacesApi.placeAutocomplete(sc.context, "1", session).await(); assertNotNull(predictions); + assertNotNull(Arrays.toString(predictions)); assertEquals(1, predictions.length); final AutocompletePrediction prediction = predictions[0]; assertNotNull(prediction); @@ -168,6 +170,7 @@ public void testPlaceDetailsLookupGoogleSydney() throws Exception { sc.assertParamValue("place_id,name,types", "fields"); assertNotNull(placeDetails); + assertNotNull(placeDetails.toString()); // Address assertNotNull(placeDetails.addressComponents); @@ -299,8 +302,12 @@ public void testPlaceDetailsLookupGoogleSydney() throws Exception { assertNotNull(review.authorUrl); assertEquals( new URI("https://plus.google.com/118257578392162991040"), review.authorUrl.toURI()); + assertNotNull(review.profilePhotoUrl); + assertEquals("https://lh5.googleusercontent.com/photo.jpg", review.profilePhotoUrl); assertNotNull(review.language); assertEquals("en", review.language); + assertNotNull(review.relativeTimeDescription); + assertEquals("a month ago", review.relativeTimeDescription); assertEquals(5, review.rating); assertNotNull(review.text); assertTrue(review.text.startsWith("As someone who works in the theatre,")); @@ -321,7 +328,7 @@ public void testPlaceDetailsLookupGoogleSydney() throws Exception { assertNotNull(placeDetails.scope); assertEquals(placeDetails.scope, PlaceIdScope.GOOGLE); assertNotNull(placeDetails.types); - assertEquals(placeDetails.types[0], "establishment"); + assertEquals(placeDetails.types[0], AddressType.ESTABLISHMENT); assertEquals(placeDetails.rating, 4.4, 0.1); // Permanently closed: @@ -336,6 +343,7 @@ public void testPlaceDetailsLookupPermanentlyClosedPlace() throws Exception { PlaceDetails placeDetails = PlacesApi.placeDetails(sc.context, PERMANENTLY_CLOSED_PLACE_ID).await(); assertNotNull(placeDetails); + assertNotNull(placeDetails.toString()); assertTrue(placeDetails.permanentlyClosed); } } @@ -345,6 +353,7 @@ public void testPlaceDetailsLookupQuay() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(quayResponseBody)) { PlaceDetails placeDetails = PlacesApi.placeDetails(sc.context, QUAY_PLACE_ID).await(); assertNotNull(placeDetails); + assertNotNull(placeDetails.toString()); assertNotNull(placeDetails.priceLevel); assertEquals(PriceLevel.VERY_EXPENSIVE, placeDetails.priceLevel); assertNotNull(placeDetails.photos); @@ -387,6 +396,7 @@ public void testQueryAutocompletePizzaNearPar() throws Exception { assertNotNull(predictions); assertEquals(predictions.length, 5); + assertNotNull(Arrays.toString(predictions)); AutocompletePrediction prediction = predictions[0]; assertNotNull(prediction); @@ -414,6 +424,7 @@ public void testQueryAutocompleteWithPlaceId() throws Exception { assertNotNull(predictions); assertEquals(predictions.length, 1); + assertNotNull(Arrays.toString(predictions)); AutocompletePrediction prediction = predictions[0]; assertNotNull(prediction); @@ -479,6 +490,7 @@ public void testTextSearchResponse() throws Exception { assertNotNull(results); assertNotNull(results.results); assertEquals(1, results.results.length); + assertNotNull(results.toString()); PlacesSearchResult result = results.results[0]; assertNotNull(result.formattedAddress); @@ -527,6 +539,7 @@ public void testTextSearchNYC() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(textSearchPizzaInNYCbody)) { PlacesSearchResponse results = PlacesApi.textSearchQuery(sc.context, "Pizza in New York").await(); + assertNotNull(results.toString()); assertNotNull(results.nextPageToken); assertEquals( "CuQB1wAAANI17eHXt1HpqbLjkj7T5Ti69DEAClo02Qampg7Q6W_O_krFbge7hnTtDR7oVF3asex" @@ -588,6 +601,7 @@ public void testNearbySearchRequest() throws Exception { } @Test + @SuppressWarnings("deprecation") // Testing a deprecated method public void testNearbySearchRequestWithMultipleType() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) { LatLng location = new LatLng(10, 20); @@ -686,6 +700,7 @@ public void testTextSearch() throws Exception { sc.assertParamValue("Google Sydney", "query"); + assertNotNull(response.toString()); assertEquals(1, response.results.length); PlacesSearchResult result = response.results[0]; assertEquals("5, 48 Pirrama Rd, Pyrmont NSW 2009, Australia", result.formattedAddress); @@ -700,6 +715,7 @@ public void testPhoto() throws Exception { sc.assertParamValue("ChIJN1t_tDeuEmsRUsoyG83frY4", "placeid"); + assertNotNull(placeDetails.toString()); assertEquals(10, placeDetails.photos.length); assertEquals( "CmRaAAAA-N3w5YTMXWautuDW7IZgX9knz_2fNyyUpCWpvYdVEVb8RurBiisMKvr7AFxMW8dsu2yakYoqjW-IYSFk2cylXVM_c50cCxfm7MlgjPErFxumlcW1bLNOe--SwLYmWlvkEhDxjz75xRqim-CkVlwFyp7sGhTs1fE02MZ6GQcc-TugrepSaeWapA", @@ -717,6 +733,7 @@ public void testPizzaInNewYorkPagination() throws Exception { sc.assertParamValue("Pizza in New York", "query"); + assertNotNull(response.toString()); assertEquals(20, response.results.length); assertEquals( "CvQB6AAAAPQLwX6KjvGbOw81Y7aYVhXRlHR8M60aCRXFDM9eyflac4BjE5MaNxTj_1T429x3H2kzBd-ztTFXCSu1CPh3kY44Gu0gmL-xfnArnPE9-BgfqXTpgzGPZNeCltB7m341y4LnU-NE2omFPoDWIrOPIyHnyi05Qol9eP2wKW7XPUhMlHvyl9MeVgZ8COBZKvCdENHbhBD1MN1lWlada6A9GPFj06cCp1aqRGW6v98-IHcIcM9RcfMcS4dLAFm6TsgLq4tpeU6E1kSzhrvDiLMBXdJYFlI0qJmytd2wS3vD0t3zKgU6Im_mY-IJL7AwAqhugBIQ8k0X_n6TnacL9BExELBaixoUo8nPOwWm0Nx02haufF2dY0VL-tg", @@ -733,6 +750,7 @@ public void testPlaceDetailsInFrench() throws Exception { sc.assertParamValue("ChIJ442GNENu5kcRGYUrvgqHw88", "placeid"); sc.assertParamValue("fr", "language"); + assertNotNull(details.toString()); assertEquals("ChIJ442GNENu5kcRGYUrvgqHw88", details.placeId); assertEquals( "35 Rue du Chevalier de la Barre, 75018 Paris, France", details.formattedAddress); @@ -870,6 +888,7 @@ public void testPlaceAutocompleteWithType() throws Exception { sc.assertParamValue("(regions)", "types"); sc.assertParamValue(session.toUrlValue(), "sessiontoken"); + assertNotNull(Arrays.toString(predictions)); assertEquals(5, predictions.length); for (AutocompletePrediction prediction : predictions) { for (int j = 0; j < prediction.types.length; j++) { @@ -964,17 +983,16 @@ public void testFindPlaceFromTextPoint() throws Exception { String input = "Museum of Contemporary Art Australia"; - FindPlaceFromText response = - PlacesApi.findPlaceFromText(sc.context, input, InputType.TEXT_QUERY) - .fields( - FindPlaceFromTextRequest.FieldMask.PHOTOS, - FindPlaceFromTextRequest.FieldMask.FORMATTED_ADDRESS, - FindPlaceFromTextRequest.FieldMask.NAME, - FindPlaceFromTextRequest.FieldMask.RATING, - FindPlaceFromTextRequest.FieldMask.OPENING_HOURS, - FindPlaceFromTextRequest.FieldMask.GEOMETRY) - .locationBias(new LocationBiasPoint(new LatLng(1, 2))) - .await(); + PlacesApi.findPlaceFromText(sc.context, input, InputType.TEXT_QUERY) + .fields( + FindPlaceFromTextRequest.FieldMask.PHOTOS, + FindPlaceFromTextRequest.FieldMask.FORMATTED_ADDRESS, + FindPlaceFromTextRequest.FieldMask.NAME, + FindPlaceFromTextRequest.FieldMask.RATING, + FindPlaceFromTextRequest.FieldMask.OPENING_HOURS, + FindPlaceFromTextRequest.FieldMask.GEOMETRY) + .locationBias(new LocationBiasPoint(new LatLng(1, 2))) + .await(); sc.assertParamValue(input, "input"); sc.assertParamValue("textquery", "inputtype"); @@ -990,17 +1008,16 @@ public void testFindPlaceFromTextCircular() throws Exception { String input = "Museum of Contemporary Art Australia"; - FindPlaceFromText response = - PlacesApi.findPlaceFromText(sc.context, input, InputType.TEXT_QUERY) - .fields( - FindPlaceFromTextRequest.FieldMask.PHOTOS, - FindPlaceFromTextRequest.FieldMask.FORMATTED_ADDRESS, - FindPlaceFromTextRequest.FieldMask.NAME, - FindPlaceFromTextRequest.FieldMask.RATING, - FindPlaceFromTextRequest.FieldMask.OPENING_HOURS, - FindPlaceFromTextRequest.FieldMask.GEOMETRY) - .locationBias(new LocationBiasCircular(new LatLng(1, 2), 3000)) - .await(); + PlacesApi.findPlaceFromText(sc.context, input, InputType.TEXT_QUERY) + .fields( + FindPlaceFromTextRequest.FieldMask.PHOTOS, + FindPlaceFromTextRequest.FieldMask.FORMATTED_ADDRESS, + FindPlaceFromTextRequest.FieldMask.NAME, + FindPlaceFromTextRequest.FieldMask.RATING, + FindPlaceFromTextRequest.FieldMask.OPENING_HOURS, + FindPlaceFromTextRequest.FieldMask.GEOMETRY) + .locationBias(new LocationBiasCircular(new LatLng(1, 2), 3000)) + .await(); sc.assertParamValue(input, "input"); sc.assertParamValue("textquery", "inputtype"); @@ -1016,17 +1033,16 @@ public void testFindPlaceFromTextRectangular() throws Exception { String input = "Museum of Contemporary Art Australia"; - FindPlaceFromText response = - PlacesApi.findPlaceFromText(sc.context, input, InputType.TEXT_QUERY) - .fields( - FindPlaceFromTextRequest.FieldMask.PHOTOS, - FindPlaceFromTextRequest.FieldMask.FORMATTED_ADDRESS, - FindPlaceFromTextRequest.FieldMask.NAME, - FindPlaceFromTextRequest.FieldMask.RATING, - FindPlaceFromTextRequest.FieldMask.OPENING_HOURS, - FindPlaceFromTextRequest.FieldMask.GEOMETRY) - .locationBias(new LocationBiasRectangular(new LatLng(1, 2), new LatLng(3, 4))) - .await(); + PlacesApi.findPlaceFromText(sc.context, input, InputType.TEXT_QUERY) + .fields( + FindPlaceFromTextRequest.FieldMask.PHOTOS, + FindPlaceFromTextRequest.FieldMask.FORMATTED_ADDRESS, + FindPlaceFromTextRequest.FieldMask.NAME, + FindPlaceFromTextRequest.FieldMask.RATING, + FindPlaceFromTextRequest.FieldMask.OPENING_HOURS, + FindPlaceFromTextRequest.FieldMask.GEOMETRY) + .locationBias(new LocationBiasRectangular(new LatLng(1, 2), new LatLng(3, 4))) + .await(); sc.assertParamValue(input, "input"); sc.assertParamValue("textquery", "inputtype"); diff --git a/src/test/java/com/google/maps/RoadsApiIntegrationTest.java b/src/test/java/com/google/maps/RoadsApiIntegrationTest.java index 1a8512b25..d30ac7b4d 100644 --- a/src/test/java/com/google/maps/RoadsApiIntegrationTest.java +++ b/src/test/java/com/google/maps/RoadsApiIntegrationTest.java @@ -25,6 +25,7 @@ import com.google.maps.model.SnappedPoint; import com.google.maps.model.SnappedSpeedLimitResponse; import com.google.maps.model.SpeedLimit; +import java.util.Arrays; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -62,6 +63,7 @@ public void testSnapToRoad() throws Exception { }; SnappedPoint[] points = RoadsApi.snapToRoads(sc.context, false, path).await(); + assertNotNull(Arrays.toString(points)); sc.assertParamValue(join('|', path), "path"); sc.assertParamValue("false", "interpolate"); assertEquals(7, points.length); @@ -86,6 +88,7 @@ public void testSpeedLimitsWithLatLngs() throws Exception { }; SpeedLimit[] speeds = RoadsApi.speedLimits(sc.context, path).await(); + assertNotNull(Arrays.toString(speeds)); assertEquals("/v1/speedLimits", sc.path()); sc.assertParamValue(join('|', path), "path"); assertEquals(7, speeds.length); @@ -112,6 +115,7 @@ public void testSpeedLimitsWithUsaLatLngs() throws Exception { }; SpeedLimit[] speeds = RoadsApi.speedLimits(sc.context, path).await(); + assertNotNull(Arrays.toString(speeds)); assertEquals("/v1/speedLimits", sc.path()); sc.assertParamValue(join('|', path), "path"); assertEquals(7, speeds.length); @@ -134,6 +138,7 @@ public void testSpeedLimitsWithPlaceIds() throws Exception { }; SpeedLimit[] speeds = RoadsApi.speedLimits(sc.context, placeIds).await(); + assertNotNull(Arrays.toString(speeds)); assertEquals("/v1/speedLimits", sc.path()); assertEquals(3, speeds.length); assertEquals("ChIJc0BrC2EE9YgR71DvaFzNgrA", speeds[2].placeId); @@ -159,6 +164,7 @@ public void testSnappedSpeedLimitRequest() throws Exception { }; SnappedSpeedLimitResponse response = RoadsApi.snappedSpeedLimits(sc.context, path).await(); + assertNotNull(response.toString()); assertEquals("/v1/speedLimits", sc.path()); sc.assertParamValue(join('|', path), "path"); assertEquals(path.length, response.snappedPoints.length); @@ -181,6 +187,7 @@ public void testNearestRoads() throws Exception { }; SnappedPoint[] points = RoadsApi.nearestRoads(sc.context, path).await(); + assertNotNull(Arrays.toString(points)); assertEquals("/v1/nearestRoads", sc.path()); sc.assertParamValue(join('|', path), "points"); assertEquals(13, points.length); diff --git a/src/test/java/com/google/maps/internal/RateLimitExecutorServiceTest.java b/src/test/java/com/google/maps/internal/RateLimitExecutorServiceTest.java index b12e311b8..cf6f5cb47 100644 --- a/src/test/java/com/google/maps/internal/RateLimitExecutorServiceTest.java +++ b/src/test/java/com/google/maps/internal/RateLimitExecutorServiceTest.java @@ -40,8 +40,7 @@ public void testRateLimitDoesNotExceedSuppliedQps() throws Exception { int qps = 10; RateLimitExecutorService service = new RateLimitExecutorService(); service.setQueriesPerSecond(qps); - final ConcurrentHashMap executedTimestamps = - new ConcurrentHashMap(); + final ConcurrentHashMap executedTimestamps = new ConcurrentHashMap<>(); for (int i = 0; i < 100; i++) { Runnable emptyTask = @@ -80,7 +79,7 @@ public void run() { } // Check that we executed every request // TODO(brettmorgan): figure out where we are losing requests - //assertEquals(100, countTotalRequests(executedTimestamps)); + // assertEquals(100, countTotalRequests(executedTimestamps)); service.shutdown(); } @@ -102,7 +101,7 @@ public void testDelayThreadIsStoppedAfterShutdownIsCalled() throws InterruptedEx assertTrue( "Delay thread should start in constructor of RateLimitExecutorService", delayThread.isAlive()); - //this is needed to make sure that delay thread has reached queue.take() + // this is needed to make sure that delay thread has reached queue.take() delayThread.join(10); service.shutdown(); delayThread.join(10); diff --git a/src/test/java/com/google/maps/model/EnumsTest.java b/src/test/java/com/google/maps/model/EnumsTest.java index 04599f311..c26f0362b 100644 --- a/src/test/java/com/google/maps/model/EnumsTest.java +++ b/src/test/java/com/google/maps/model/EnumsTest.java @@ -21,7 +21,11 @@ import static org.junit.Assert.fail; import com.google.maps.SmallTests; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -40,116 +44,230 @@ public void testUnknown() throws Exception { @Test public void testCanonicalLiteralsForAddressType() { Map addressTypeToLiteralMap = new HashMap(); - addressTypeToLiteralMap.put(AddressType.STREET_ADDRESS, "street_address"); - addressTypeToLiteralMap.put(AddressType.ROUTE, "route"); - addressTypeToLiteralMap.put(AddressType.INTERSECTION, "intersection"); - addressTypeToLiteralMap.put(AddressType.POLITICAL, "political"); - addressTypeToLiteralMap.put(AddressType.COUNTRY, "country"); - addressTypeToLiteralMap.put( - AddressType.ADMINISTRATIVE_AREA_LEVEL_1, "administrative_area_level_1"); - addressTypeToLiteralMap.put( - AddressType.ADMINISTRATIVE_AREA_LEVEL_2, "administrative_area_level_2"); - addressTypeToLiteralMap.put( - AddressType.ADMINISTRATIVE_AREA_LEVEL_3, "administrative_area_level_3"); - addressTypeToLiteralMap.put( - AddressType.ADMINISTRATIVE_AREA_LEVEL_4, "administrative_area_level_4"); - addressTypeToLiteralMap.put( - AddressType.ADMINISTRATIVE_AREA_LEVEL_5, "administrative_area_level_5"); - addressTypeToLiteralMap.put(AddressType.COLLOQUIAL_AREA, "colloquial_area"); - addressTypeToLiteralMap.put(AddressType.LOCALITY, "locality"); - addressTypeToLiteralMap.put(AddressType.WARD, "ward"); - addressTypeToLiteralMap.put(AddressType.SUBLOCALITY, "sublocality"); - addressTypeToLiteralMap.put(AddressType.SUBLOCALITY_LEVEL_1, "sublocality_level_1"); - addressTypeToLiteralMap.put(AddressType.SUBLOCALITY_LEVEL_2, "sublocality_level_2"); - addressTypeToLiteralMap.put(AddressType.SUBLOCALITY_LEVEL_3, "sublocality_level_3"); - addressTypeToLiteralMap.put(AddressType.SUBLOCALITY_LEVEL_4, "sublocality_level_4"); - addressTypeToLiteralMap.put(AddressType.SUBLOCALITY_LEVEL_5, "sublocality_level_5"); - addressTypeToLiteralMap.put(AddressType.NEIGHBORHOOD, "neighborhood"); - addressTypeToLiteralMap.put(AddressType.PREMISE, "premise"); - addressTypeToLiteralMap.put(AddressType.SUBPREMISE, "subpremise"); - addressTypeToLiteralMap.put(AddressType.POSTAL_CODE, "postal_code"); - addressTypeToLiteralMap.put(AddressType.NATURAL_FEATURE, "natural_feature"); - addressTypeToLiteralMap.put(AddressType.AIRPORT, "airport"); - addressTypeToLiteralMap.put(AddressType.PARK, "park"); - addressTypeToLiteralMap.put(AddressType.POINT_OF_INTEREST, "point_of_interest"); - addressTypeToLiteralMap.put(AddressType.POST_OFFICE, "post_office"); - addressTypeToLiteralMap.put(AddressType.PLACE_OF_WORSHIP, "place_of_worship"); - addressTypeToLiteralMap.put(AddressType.BUS_STATION, "bus_station"); - addressTypeToLiteralMap.put(AddressType.TRAIN_STATION, "train_station"); - addressTypeToLiteralMap.put(AddressType.SUBWAY_STATION, "subway_station"); - addressTypeToLiteralMap.put(AddressType.TRANSIT_STATION, "transit_station"); - addressTypeToLiteralMap.put(AddressType.CHURCH, "church"); - addressTypeToLiteralMap.put(AddressType.FINANCE, "finance"); - addressTypeToLiteralMap.put(AddressType.ESTABLISHMENT, "establishment"); - addressTypeToLiteralMap.put(AddressType.POSTAL_TOWN, "postal_town"); - addressTypeToLiteralMap.put(AddressType.UNIVERSITY, "university"); + // Short alias just to avoid line wrapping in the below code + Map m = addressTypeToLiteralMap; + m.put(AddressType.STREET_ADDRESS, "street_address"); + m.put(AddressType.ROUTE, "route"); + m.put(AddressType.INTERSECTION, "intersection"); + m.put(AddressType.POLITICAL, "political"); + m.put(AddressType.COUNTRY, "country"); + m.put(AddressType.CONTINENT, "continent"); + m.put(AddressType.ADMINISTRATIVE_AREA_LEVEL_1, "administrative_area_level_1"); + m.put(AddressType.ADMINISTRATIVE_AREA_LEVEL_2, "administrative_area_level_2"); + m.put(AddressType.ADMINISTRATIVE_AREA_LEVEL_3, "administrative_area_level_3"); + m.put(AddressType.ADMINISTRATIVE_AREA_LEVEL_4, "administrative_area_level_4"); + m.put(AddressType.ADMINISTRATIVE_AREA_LEVEL_5, "administrative_area_level_5"); + m.put(AddressType.COLLOQUIAL_AREA, "colloquial_area"); + m.put(AddressType.LOCALITY, "locality"); + m.put(AddressType.WARD, "ward"); + m.put(AddressType.SUBLOCALITY, "sublocality"); + m.put(AddressType.SUBLOCALITY_LEVEL_1, "sublocality_level_1"); + m.put(AddressType.SUBLOCALITY_LEVEL_2, "sublocality_level_2"); + m.put(AddressType.SUBLOCALITY_LEVEL_3, "sublocality_level_3"); + m.put(AddressType.SUBLOCALITY_LEVEL_4, "sublocality_level_4"); + m.put(AddressType.SUBLOCALITY_LEVEL_5, "sublocality_level_5"); + m.put(AddressType.NEIGHBORHOOD, "neighborhood"); + m.put(AddressType.PREMISE, "premise"); + m.put(AddressType.SUBPREMISE, "subpremise"); + m.put(AddressType.POSTAL_CODE, "postal_code"); + m.put(AddressType.NATURAL_FEATURE, "natural_feature"); + m.put(AddressType.AIRPORT, "airport"); + m.put(AddressType.PARK, "park"); + m.put(AddressType.POINT_OF_INTEREST, "point_of_interest"); + m.put(AddressType.POST_OFFICE, "post_office"); + m.put(AddressType.PLACE_OF_WORSHIP, "place_of_worship"); + m.put(AddressType.BUS_STATION, "bus_station"); + m.put(AddressType.TRAIN_STATION, "train_station"); + m.put(AddressType.SUBWAY_STATION, "subway_station"); + m.put(AddressType.TRANSIT_STATION, "transit_station"); + m.put(AddressType.CHURCH, "church"); + m.put(AddressType.FINANCE, "finance"); + m.put(AddressType.ESTABLISHMENT, "establishment"); + m.put(AddressType.POSTAL_TOWN, "postal_town"); + m.put(AddressType.UNIVERSITY, "university"); + m.put(AddressType.STREET_NUMBER, "street_number"); + m.put(AddressType.FLOOR, "floor"); + m.put(AddressType.ROOM, "room"); + m.put(AddressType.POST_BOX, "post_box"); + m.put(AddressType.POSTAL_CODE_PREFIX, "postal_code_prefix"); + m.put(AddressType.POSTAL_CODE_SUFFIX, "postal_code_suffix"); + m.put(AddressType.MUSEUM, "museum"); + m.put(AddressType.LIGHT_RAIL_STATION, "light_rail_station"); + m.put(AddressType.SYNAGOGUE, "synagogue"); + m.put(AddressType.FOOD, "food"); + m.put(AddressType.GROCERY_OR_SUPERMARKET, "grocery_or_supermarket"); + m.put(AddressType.STORE, "store"); + m.put(AddressType.LAWYER, "lawyer"); + m.put(AddressType.HEALTH, "health"); + m.put(AddressType.INSURANCE_AGENCY, "insurance_agency"); + m.put(AddressType.GAS_STATION, "gas_station"); + m.put(AddressType.CAR_DEALER, "car_dealer"); + m.put(AddressType.CAR_REPAIR, "car_repair"); + m.put(AddressType.MEAL_TAKEAWAY, "meal_takeaway"); + m.put(AddressType.FURNITURE_STORE, "furniture_store"); + m.put(AddressType.HOME_GOODS_STORE, "home_goods_store"); + m.put(AddressType.SHOPPING_MALL, "shopping_mall"); + m.put(AddressType.GYM, "gym"); + m.put(AddressType.ACCOUNTING, "accounting"); + m.put(AddressType.MOVING_COMPANY, "moving_company"); + m.put(AddressType.LODGING, "lodging"); + m.put(AddressType.STORAGE, "storage"); + m.put(AddressType.CASINO, "casino"); + m.put(AddressType.PARKING, "parking"); + m.put(AddressType.STADIUM, "stadium"); + m.put(AddressType.TRAVEL_AGENCY, "travel_agency"); + m.put(AddressType.NIGHT_CLUB, "night_club"); + m.put(AddressType.BEAUTY_SALON, "beauty_salon"); + m.put(AddressType.HAIR_CARE, "hair_care"); + m.put(AddressType.SPA, "spa"); + m.put(AddressType.SHOE_STORE, "shoe_store"); + m.put(AddressType.BAKERY, "bakery"); + m.put(AddressType.PHARMACY, "pharmacy"); + m.put(AddressType.SCHOOL, "school"); + m.put(AddressType.BOOK_STORE, "book_store"); + m.put(AddressType.DEPARTMENT_STORE, "department_store"); + m.put(AddressType.RESTAURANT, "restaurant"); + m.put(AddressType.REAL_ESTATE_AGENCY, "real_estate_agency"); + m.put(AddressType.BAR, "bar"); + m.put(AddressType.DOCTOR, "doctor"); + m.put(AddressType.HOSPITAL, "hospital"); + m.put(AddressType.FIRE_STATION, "fire_station"); + m.put(AddressType.SUPERMARKET, "supermarket"); + m.put(AddressType.CITY_HALL, "city_hall"); + m.put(AddressType.LOCAL_GOVERNMENT_OFFICE, "local_government_office"); + m.put(AddressType.ATM, "atm"); + m.put(AddressType.BANK, "bank"); + m.put(AddressType.LIBRARY, "library"); + m.put(AddressType.CAR_WASH, "car_wash"); + m.put(AddressType.HARDWARE_STORE, "hardware_store"); + m.put(AddressType.AMUSEMENT_PARK, "amusement_park"); + m.put(AddressType.AQUARIUM, "aquarium"); + m.put(AddressType.ART_GALLERY, "art_gallery"); + m.put(AddressType.BICYCLE_STORE, "bicycle_store"); + m.put(AddressType.BOWLING_ALLEY, "bowling_alley"); + m.put(AddressType.CAFE, "cafe"); + m.put(AddressType.CAMPGROUND, "campground"); + m.put(AddressType.CAR_RENTAL, "car_rental"); + m.put(AddressType.CEMETERY, "cemetery"); + m.put(AddressType.CLOTHING_STORE, "clothing_store"); + m.put(AddressType.CONVENIENCE_STORE, "convenience_store"); + m.put(AddressType.COURTHOUSE, "courthouse"); + m.put(AddressType.DENTIST, "dentist"); + m.put(AddressType.ELECTRICIAN, "electrician"); + m.put(AddressType.ELECTRONICS_STORE, "electronics_store"); + m.put(AddressType.EMBASSY, "embassy"); + m.put(AddressType.FLORIST, "florist"); + m.put(AddressType.FUNERAL_HOME, "funeral_home"); + m.put(AddressType.GENERAL_CONTRACTOR, "general_contractor"); + m.put(AddressType.HINDU_TEMPLE, "hindu_temple"); + m.put(AddressType.JEWELRY_STORE, "jewelry_store"); + m.put(AddressType.LAUNDRY, "laundry"); + m.put(AddressType.LIQUOR_STORE, "liquor_store"); + m.put(AddressType.LOCKSMITH, "locksmith"); + m.put(AddressType.MEAL_DELIVERY, "meal_delivery"); + m.put(AddressType.MOSQUE, "mosque"); + m.put(AddressType.MOVIE_RENTAL, "movie_rental"); + m.put(AddressType.MOVIE_THEATER, "movie_theater"); + m.put(AddressType.PAINTER, "painter"); + m.put(AddressType.PET_STORE, "pet_store"); + m.put(AddressType.PHYSIOTHERAPIST, "physiotherapist"); + m.put(AddressType.PLUMBER, "plumber"); + m.put(AddressType.POLICE, "police"); + m.put(AddressType.ROOFING_CONTRACTOR, "roofing_contractor"); + m.put(AddressType.RV_PARK, "rv_park"); + m.put(AddressType.TAXI_STAND, "taxi_stand"); + m.put(AddressType.VETERINARY_CARE, "veterinary_care"); + m.put(AddressType.ZOO, "zoo"); for (Map.Entry addressTypeLiteralPair : addressTypeToLiteralMap.entrySet()) { assertEquals( addressTypeLiteralPair.getValue(), addressTypeLiteralPair.getKey().toCanonicalLiteral()); } + List enumsMinusUnknown = new ArrayList<>(Arrays.asList(AddressType.values())); + enumsMinusUnknown.remove(AddressType.UNKNOWN); + List onlyInTest = setdiff(addressTypeToLiteralMap.keySet(), enumsMinusUnknown); + List onlyInEnum = setdiff(enumsMinusUnknown, addressTypeToLiteralMap.keySet()); + assertEquals( + "Unexpected enum elements: Only in test: " + onlyInTest + ". Only in enum: " + onlyInEnum, + addressTypeToLiteralMap.size() + 1, // 1 for unknown + AddressType.values().length); } @Test public void testCanonicalLiteralsForAddressComponentType() { Map addressComponentTypeToLiteralMap = new HashMap(); - addressComponentTypeToLiteralMap.put(AddressComponentType.STREET_ADDRESS, "street_address"); - addressComponentTypeToLiteralMap.put(AddressComponentType.ROUTE, "route"); - addressComponentTypeToLiteralMap.put(AddressComponentType.INTERSECTION, "intersection"); - addressComponentTypeToLiteralMap.put(AddressComponentType.POLITICAL, "political"); - addressComponentTypeToLiteralMap.put(AddressComponentType.COUNTRY, "country"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_1, "administrative_area_level_1"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_2, "administrative_area_level_2"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_3, "administrative_area_level_3"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_4, "administrative_area_level_4"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_5, "administrative_area_level_5"); - addressComponentTypeToLiteralMap.put(AddressComponentType.COLLOQUIAL_AREA, "colloquial_area"); - addressComponentTypeToLiteralMap.put(AddressComponentType.LOCALITY, "locality"); - addressComponentTypeToLiteralMap.put(AddressComponentType.WARD, "ward"); - addressComponentTypeToLiteralMap.put(AddressComponentType.SUBLOCALITY, "sublocality"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.SUBLOCALITY_LEVEL_1, "sublocality_level_1"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.SUBLOCALITY_LEVEL_2, "sublocality_level_2"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.SUBLOCALITY_LEVEL_3, "sublocality_level_3"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.SUBLOCALITY_LEVEL_4, "sublocality_level_4"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.SUBLOCALITY_LEVEL_5, "sublocality_level_5"); - addressComponentTypeToLiteralMap.put(AddressComponentType.NEIGHBORHOOD, "neighborhood"); - addressComponentTypeToLiteralMap.put(AddressComponentType.PREMISE, "premise"); - addressComponentTypeToLiteralMap.put(AddressComponentType.SUBPREMISE, "subpremise"); - addressComponentTypeToLiteralMap.put(AddressComponentType.POSTAL_CODE, "postal_code"); - addressComponentTypeToLiteralMap.put(AddressComponentType.POST_BOX, "post_box"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.POSTAL_CODE_PREFIX, "postal_code_prefix"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.POSTAL_CODE_SUFFIX, "postal_code_suffix"); - addressComponentTypeToLiteralMap.put(AddressComponentType.NATURAL_FEATURE, "natural_feature"); - addressComponentTypeToLiteralMap.put(AddressComponentType.AIRPORT, "airport"); - addressComponentTypeToLiteralMap.put(AddressComponentType.PARK, "park"); - addressComponentTypeToLiteralMap.put(AddressComponentType.FLOOR, "floor"); - addressComponentTypeToLiteralMap.put(AddressComponentType.PARKING, "parking"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.POINT_OF_INTEREST, "point_of_interest"); - addressComponentTypeToLiteralMap.put(AddressComponentType.BUS_STATION, "bus_station"); - addressComponentTypeToLiteralMap.put(AddressComponentType.TRAIN_STATION, "train_station"); - addressComponentTypeToLiteralMap.put(AddressComponentType.SUBWAY_STATION, "subway_station"); - addressComponentTypeToLiteralMap.put(AddressComponentType.TRANSIT_STATION, "transit_station"); - addressComponentTypeToLiteralMap.put( - AddressComponentType.LIGHT_RAIL_STATION, "light_rail_station"); - addressComponentTypeToLiteralMap.put(AddressComponentType.ESTABLISHMENT, "establishment"); - addressComponentTypeToLiteralMap.put(AddressComponentType.POSTAL_TOWN, "postal_town"); - addressComponentTypeToLiteralMap.put(AddressComponentType.ROOM, "room"); - addressComponentTypeToLiteralMap.put(AddressComponentType.STREET_NUMBER, "street_number"); + // Short alias just to avoid line wrapping in the below code + Map m = addressComponentTypeToLiteralMap; + m.put(AddressComponentType.STREET_ADDRESS, "street_address"); + m.put(AddressComponentType.ROUTE, "route"); + m.put(AddressComponentType.INTERSECTION, "intersection"); + m.put(AddressComponentType.POLITICAL, "political"); + m.put(AddressComponentType.COUNTRY, "country"); + m.put(AddressComponentType.CONTINENT, "continent"); + m.put(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_1, "administrative_area_level_1"); + m.put(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_2, "administrative_area_level_2"); + m.put(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_3, "administrative_area_level_3"); + m.put(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_4, "administrative_area_level_4"); + m.put(AddressComponentType.ADMINISTRATIVE_AREA_LEVEL_5, "administrative_area_level_5"); + m.put(AddressComponentType.COLLOQUIAL_AREA, "colloquial_area"); + m.put(AddressComponentType.LOCALITY, "locality"); + m.put(AddressComponentType.WARD, "ward"); + m.put(AddressComponentType.SUBLOCALITY, "sublocality"); + m.put(AddressComponentType.SUBLOCALITY_LEVEL_1, "sublocality_level_1"); + m.put(AddressComponentType.SUBLOCALITY_LEVEL_2, "sublocality_level_2"); + m.put(AddressComponentType.SUBLOCALITY_LEVEL_3, "sublocality_level_3"); + m.put(AddressComponentType.SUBLOCALITY_LEVEL_4, "sublocality_level_4"); + m.put(AddressComponentType.SUBLOCALITY_LEVEL_5, "sublocality_level_5"); + m.put(AddressComponentType.NEIGHBORHOOD, "neighborhood"); + m.put(AddressComponentType.PREMISE, "premise"); + m.put(AddressComponentType.SUBPREMISE, "subpremise"); + m.put(AddressComponentType.POSTAL_CODE, "postal_code"); + m.put(AddressComponentType.POST_BOX, "post_box"); + m.put(AddressComponentType.POSTAL_CODE_PREFIX, "postal_code_prefix"); + m.put(AddressComponentType.POSTAL_CODE_SUFFIX, "postal_code_suffix"); + m.put(AddressComponentType.NATURAL_FEATURE, "natural_feature"); + m.put(AddressComponentType.AIRPORT, "airport"); + m.put(AddressComponentType.PARK, "park"); + m.put(AddressComponentType.FLOOR, "floor"); + m.put(AddressComponentType.PARKING, "parking"); + m.put(AddressComponentType.POINT_OF_INTEREST, "point_of_interest"); + m.put(AddressComponentType.BUS_STATION, "bus_station"); + m.put(AddressComponentType.TRAIN_STATION, "train_station"); + m.put(AddressComponentType.SUBWAY_STATION, "subway_station"); + m.put(AddressComponentType.TRANSIT_STATION, "transit_station"); + m.put(AddressComponentType.LIGHT_RAIL_STATION, "light_rail_station"); + m.put(AddressComponentType.ESTABLISHMENT, "establishment"); + m.put(AddressComponentType.POSTAL_TOWN, "postal_town"); + m.put(AddressComponentType.ROOM, "room"); + m.put(AddressComponentType.STREET_NUMBER, "street_number"); + m.put(AddressComponentType.GENERAL_CONTRACTOR, "general_contractor"); + m.put(AddressComponentType.FOOD, "food"); + m.put(AddressComponentType.REAL_ESTATE_AGENCY, "real_estate_agency"); + m.put(AddressComponentType.CAR_RENTAL, "car_rental"); + m.put(AddressComponentType.STORE, "store"); + m.put(AddressComponentType.SHOPPING_MALL, "shopping_mall"); + m.put(AddressComponentType.LODGING, "lodging"); + m.put(AddressComponentType.TRAVEL_AGENCY, "travel_agency"); + m.put(AddressComponentType.ELECTRONICS_STORE, "electronics_store"); + m.put(AddressComponentType.HOME_GOODS_STORE, "home_goods_store"); + m.put(AddressComponentType.SCHOOL, "school"); + m.put(AddressComponentType.ART_GALLERY, "art_gallery"); + m.put(AddressComponentType.LAWYER, "lawyer"); + m.put(AddressComponentType.RESTAURANT, "restaurant"); + m.put(AddressComponentType.BAR, "bar"); + m.put(AddressComponentType.MEAL_TAKEAWAY, "meal_takeaway"); + m.put(AddressComponentType.CLOTHING_STORE, "clothing_store"); + m.put(AddressComponentType.LOCAL_GOVERNMENT_OFFICE, "local_government_office"); + m.put(AddressComponentType.FINANCE, "finance"); + m.put(AddressComponentType.MOVING_COMPANY, "moving_company"); + m.put(AddressComponentType.STORAGE, "storage"); + m.put(AddressComponentType.CAFE, "cafe"); + m.put(AddressComponentType.CAR_REPAIR, "car_repair"); + m.put(AddressComponentType.HEALTH, "health"); + m.put(AddressComponentType.INSURANCE_AGENCY, "insurance_agency"); + m.put(AddressComponentType.PAINTER, "painter"); for (Map.Entry AddressComponentTypeLiteralPair : addressComponentTypeToLiteralMap.entrySet()) { @@ -157,7 +275,15 @@ public void testCanonicalLiteralsForAddressComponentType() { AddressComponentTypeLiteralPair.getValue(), AddressComponentTypeLiteralPair.getKey().toCanonicalLiteral()); } + List enumsMinusUnknown = + new ArrayList<>(Arrays.asList(AddressComponentType.values())); + enumsMinusUnknown.remove(AddressComponentType.UNKNOWN); + List onlyInTest = + setdiff(addressComponentTypeToLiteralMap.keySet(), enumsMinusUnknown); + List onlyInEnum = + setdiff(enumsMinusUnknown, addressComponentTypeToLiteralMap.keySet()); assertEquals( + "Unexpected enum elements: Only in test: " + onlyInTest + ". Only in enum: " + onlyInEnum, addressComponentTypeToLiteralMap.size() + 1, // 1 for unknown AddressComponentType.values().length); } @@ -171,4 +297,10 @@ private static void assertCannotGetUrlValue(T unknown) { // Expected. } } + + private static List setdiff(Collection a, Collection b) { + List out = new ArrayList<>(a); + out.removeAll(b); + return out; + } } diff --git a/src/test/resources/com/google/maps/PlaceDetailsLookupGoogleSydneyResponse.json b/src/test/resources/com/google/maps/PlaceDetailsLookupGoogleSydneyResponse.json index 918a4c237..b5090a9ef 100644 --- a/src/test/resources/com/google/maps/PlaceDetailsLookupGoogleSydneyResponse.json +++ b/src/test/resources/com/google/maps/PlaceDetailsLookupGoogleSydneyResponse.json @@ -250,6 +250,10 @@ } ], "place_id": "ChIJN1t_tDeuEmsRUsoyG83frY4", + "plus_code": { + "compound_code": "45MW+98 Pyrmont, New South Wales, Australia", + "global_code": "4RRH45MW+98" + }, "rating": 4.4, "reference": "CmRSAAAAGQJ6PTZr7ufM6fQmQKWECuhtbE5MxVWAVx1Potb6nllk7YrtrHYdMRttPrQfxHdAkFOaiZikxMustzx-R29lup1t8EZ5QhipfhEi9hJaM5AdNTBvo1Nrv7v03MtsEVj6EhDGokaqFIy6yIRgB6b_iKplGhQL3qLuxxusScGvkWpJCSJFafCbog", "reviews": [ diff --git a/src/test/resources/com/google/maps/PlaceDetailsResponse.json b/src/test/resources/com/google/maps/PlaceDetailsResponse.json index dd174cd5a..08effbce4 100644 --- a/src/test/resources/com/google/maps/PlaceDetailsResponse.json +++ b/src/test/resources/com/google/maps/PlaceDetailsResponse.json @@ -226,7 +226,9 @@ "author_name": "Danielle Lonnon", "author_url": "https://plus.google.com/118257578392162991040", "language": "en", + "profile_photo_url": "https://lh5.googleusercontent.com/photo.jpg", "rating": 5, + "relative_time_description": "a month ago", "text": "As someone who works in the theatre, I don't find the Google offices nerdy, I find it magical and theatrical. Themed rooms with useful props and big sets with unique and charismatic characters. You sure this isn't a theatre company? Oh no wait Google has money, while the performing art does not.", "time": 1425790392 }, @@ -240,7 +242,9 @@ "author_name": "Lachlan Martin", "author_url": "https://plus.google.com/101767769287488554641", "language": "en", + "profile_photo_url": "https://lh5.googleusercontent.com/-GnfIbf_lBA4/AAAAAAAAAAI/AAAAAAAAeVM/gkqipH58HoM/s128-c0x00010000-cc-rp-mo-ba2/photo.jpg", "rating": 5, + "relative_time_description": "a day ago", "text": "The cool-aid here tastes amazing!!! ", "time": 1439790358 }, @@ -254,7 +258,9 @@ "author_name": "Rob Mulally", "author_url": "https://plus.google.com/100839435712919930388", "language": "en", + "profile_photo_url": "https://lh5.googleusercontent.com/-GnfIbf_lBA4/AAAAAAAAAAI/AAAAAAAAeVM/gkqipH58HoM/s128-c0x00030000-cc-rp-mo-ba2/photo.jpg", "rating": 5, + "relative_time_description": "a month ago", "text": "What can I say, what a great building, cool offices and friendly staff!\nonly had a quick tour but there isn't much missing from this world class modern office.\n\nIf your staff who work here I hope you take advantage of all that it offers , because as a visitor it was a very impressive setup. \n\nThe thing that stood out besides the collaborative area's and beds for resting, was the food availability.\n\nImpressed. 5 Stars.\n", "time": 1408284830 }, @@ -268,7 +274,9 @@ "author_name": "Michael Yeung", "author_url": "https://plus.google.com/104161906493535874402", "language": "en", + "profile_photo_url": "https://lh5.googleusercontent.com/-GnfIbf_lBA4/AAAAAAAAAAI/AAAAAAAAeVM/gkqipH58HoM/s128-c0x00040000-cc-rp-mo-ba2/photo.jpg", "rating": 5, + "relative_time_description": "two month ago", "text": "Best company in the world. The view from the cafeteria is unreal, you take in the entire Darling harbour view like nowhere else :)", "time": 1435313350 }, @@ -282,7 +290,9 @@ "author_name": "Marco Palmero", "author_url": "https://plus.google.com/103363668747424636403", "language": "en", + "profile_photo_url": "https://lh5.googleusercontent.com/-GnfIbf_lBA4/AAAAAAAAAAI/AAAAAAAAeVM/gkqipH58HoM/s128-c0x00050000-cc-rp-mo-ba2/photo.jpg", "rating": 5, + "relative_time_description": "a day ago", "text": "I've been fortunate enough to have visited the Google offices on multiple occasions through the years and I've found this place to be quite awesome. This particular office is the original campus for Google Sydney and they've expanded to the Fairfax building where they've built an even more exciting office!\n\nTotally jealous of their cafeteria and the city views from their office!", "time": 1413529682 }