From 0301b9f6283389ba06bb23d5c642607d2a09dbb1 Mon Sep 17 00:00:00 2001 From: Brett Morgan Date: Fri, 6 Oct 2017 15:51:14 +1100 Subject: [PATCH] Tidyup warnings (#357) Remediating unused logger declarations, variables, and unclosed Closeables. --- .../java/com/google/maps/GeolocationApi.java | 3 - .../com/google/maps/OkHttpRequestHandler.java | 3 - .../internal/GeolocationResponseAdapter.java | 3 - .../com/google/maps/DirectionsApiTest.java | 103 ++++++++---------- .../google/maps/DistanceMatrixApiTest.java | 20 ++-- .../java/com/google/maps/PlacesApiTest.java | 2 - .../google/maps/RoadsApiIntegrationTest.java | 39 +++---- src/test/java/com/google/maps/TestUtils.java | 15 ++- .../java/com/google/maps/TimeZoneApiTest.java | 7 +- 9 files changed, 89 insertions(+), 106 deletions(-) diff --git a/src/main/java/com/google/maps/GeolocationApi.java b/src/main/java/com/google/maps/GeolocationApi.java index 96be5314a..48ef2e5c7 100644 --- a/src/main/java/com/google/maps/GeolocationApi.java +++ b/src/main/java/com/google/maps/GeolocationApi.java @@ -22,7 +22,6 @@ import com.google.maps.model.GeolocationPayload; import com.google.maps.model.GeolocationResult; import com.google.maps.model.LatLng; -import java.util.logging.Logger; /* * The Google Maps Geolocation API returns a location and accuracy radius based on information @@ -35,7 +34,6 @@ */ public class GeolocationApi { private static final String API_BASE_URL = "https://www.googleapis.com"; - private static final Logger LOG = Logger.getLogger(GeolocationApi.class.getName()); static final ApiConfig GEOLOCATION_API_CONFIG = new ApiConfig("/geolocation/v1/geolocate") @@ -82,7 +80,6 @@ public ApiException getError() { if (successful()) { return null; } - ApiException e; return ApiException.from(reason, message); } } diff --git a/src/main/java/com/google/maps/OkHttpRequestHandler.java b/src/main/java/com/google/maps/OkHttpRequestHandler.java index b75a4e43a..8c08d16bc 100644 --- a/src/main/java/com/google/maps/OkHttpRequestHandler.java +++ b/src/main/java/com/google/maps/OkHttpRequestHandler.java @@ -33,8 +33,6 @@ import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.Route; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * A strategy for handling URL requests using OkHttp. @@ -42,7 +40,6 @@ * @see com.google.maps.GeoApiContext.RequestHandler */ public class OkHttpRequestHandler implements GeoApiContext.RequestHandler { - private static final Logger LOG = LoggerFactory.getLogger(OkHttpRequestHandler.class.getName()); private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); private final OkHttpClient client; diff --git a/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java b/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java index 1d21903ec..1e4cb19fa 100644 --- a/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java +++ b/src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java @@ -21,7 +21,6 @@ import com.google.gson.stream.JsonWriter; import com.google.maps.GeolocationApi; import java.io.IOException; -import java.util.logging.Logger; public class GeolocationResponseAdapter extends TypeAdapter { /** @@ -62,8 +61,6 @@ public class GeolocationResponseAdapter extends TypeAdapter */ - private static final Logger LOG = Logger.getLogger(GeolocationApi.Response.class.getName()); - @Override public GeolocationApi.Response read(JsonReader reader) throws IOException { diff --git a/src/test/java/com/google/maps/DirectionsApiTest.java b/src/test/java/com/google/maps/DirectionsApiTest.java index 49bb25492..b51cf4e56 100644 --- a/src/test/java/com/google/maps/DirectionsApiTest.java +++ b/src/test/java/com/google/maps/DirectionsApiTest.java @@ -147,8 +147,7 @@ public void testResponseTimesArePopulatedCorrectly() throws Exception { public void testTorontoToMontreal() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context).origin("Toronto").destination("Montreal").await(); + DirectionsApi.newRequest(sc.context).origin("Toronto").destination("Montreal").await(); sc.assertParamValue("Toronto", "origin"); sc.assertParamValue("Montreal", "destination"); @@ -165,13 +164,12 @@ public void testTorontoToMontreal() throws Exception { public void testTorontoToMontrealByBicycleAvoidingHighways() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("Toronto") - .destination("Montreal") - .avoid(DirectionsApi.RouteRestriction.HIGHWAYS) - .mode(TravelMode.BICYCLING) - .await(); + DirectionsApi.newRequest(sc.context) + .origin("Toronto") + .destination("Montreal") + .avoid(DirectionsApi.RouteRestriction.HIGHWAYS) + .mode(TravelMode.BICYCLING) + .await(); sc.assertParamValue("Toronto", "origin"); sc.assertParamValue("Montreal", "destination"); @@ -190,12 +188,11 @@ public void testTorontoToMontrealByBicycleAvoidingHighways() throws Exception { public void testBrooklynToQueensByTransit() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("Brooklyn") - .destination("Queens") - .mode(TravelMode.TRANSIT) - .await(); + DirectionsApi.newRequest(sc.context) + .origin("Brooklyn") + .destination("Queens") + .mode(TravelMode.TRANSIT) + .await(); sc.assertParamValue("Brooklyn", "origin"); sc.assertParamValue("Queens", "destination"); @@ -213,12 +210,11 @@ public void testBrooklynToQueensByTransit() throws Exception { public void testBostonToConcordViaCharlestownAndLexignton() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("Boston,MA") - .destination("Concord,MA") - .waypoints("Charlestown,MA", "Lexington,MA") - .await(); + DirectionsApi.newRequest(sc.context) + .origin("Boston,MA") + .destination("Concord,MA") + .waypoints("Charlestown,MA", "Lexington,MA") + .await(); sc.assertParamValue("Boston,MA", "origin"); sc.assertParamValue("Concord,MA", "destination"); @@ -237,12 +233,11 @@ public void testBostonToConcordViaCharlestownAndLexignton() throws Exception { public void testBostonToConcordViaCharlestownAndLexigntonLatLng() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("Boston,MA") - .destination("Concord,MA") - .waypoints(new LatLng(42.379322, -71.063384), new LatLng(42.444303, -71.229087)) - .await(); + DirectionsApi.newRequest(sc.context) + .origin("Boston,MA") + .destination("Concord,MA") + .waypoints(new LatLng(42.379322, -71.063384), new LatLng(42.444303, -71.229087)) + .await(); sc.assertParamValue("Boston,MA", "origin"); sc.assertParamValue("Concord,MA", "destination"); @@ -260,12 +255,11 @@ public void testBostonToConcordViaCharlestownAndLexigntonLatLng() throws Excepti public void testToledoToMadridInSpain() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("Toledo") - .destination("Madrid") - .region("es") - .await(); + DirectionsApi.newRequest(sc.context) + .origin("Toledo") + .destination("Madrid") + .region("es") + .await(); sc.assertParamValue("Toledo", "origin"); sc.assertParamValue("Madrid", "destination"); @@ -278,13 +272,12 @@ public void testToledoToMadridInSpain() throws Exception { public void testLanguageParameter() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("Toledo") - .destination("Madrid") - .region("es") - .language("es") - .await(); + DirectionsApi.newRequest(sc.context) + .origin("Toledo") + .destination("Madrid") + .region("es") + .language("es") + .await(); sc.assertParamValue("Toledo", "origin"); sc.assertParamValue("Madrid", "destination"); @@ -298,14 +291,13 @@ public void testLanguageParameter() throws Exception { public void testTrafficModel() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}"); ) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("48 Pirrama Road, Pyrmont NSW 2009") - .destination("182 Church St, Parramatta NSW 2150") - .mode(TravelMode.DRIVING) - .departureTime(new DateTime().plus(Duration.standardMinutes(2))) - .trafficModel(TrafficModel.PESSIMISTIC) - .await(); + DirectionsApi.newRequest(sc.context) + .origin("48 Pirrama Road, Pyrmont NSW 2009") + .destination("182 Church St, Parramatta NSW 2150") + .mode(TravelMode.DRIVING) + .departureTime(new DateTime().plus(Duration.standardMinutes(2))) + .trafficModel(TrafficModel.PESSIMISTIC) + .await(); sc.assertParamValue("48 Pirrama Road, Pyrmont NSW 2009", "origin"); sc.assertParamValue("182 Church St, Parramatta NSW 2150", "destination"); @@ -336,14 +328,13 @@ public void testTransitWithoutSpecifyingTime() throws Exception { public void testTransitParams() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) { - DirectionsResult result = - DirectionsApi.newRequest(sc.context) - .origin("Fisherman's Wharf, San Francisco") - .destination("Union Square, San Francisco") - .mode(TravelMode.TRANSIT) - .transitMode(TransitMode.BUS, TransitMode.TRAM) - .transitRoutingPreference(TransitRoutingPreference.LESS_WALKING) - .await(); + DirectionsApi.newRequest(sc.context) + .origin("Fisherman's Wharf, San Francisco") + .destination("Union Square, San Francisco") + .mode(TravelMode.TRANSIT) + .transitMode(TransitMode.BUS, TransitMode.TRAM) + .transitRoutingPreference(TransitRoutingPreference.LESS_WALKING) + .await(); sc.assertParamValue("Fisherman's Wharf, San Francisco", "origin"); sc.assertParamValue("Union Square, San Francisco", "destination"); diff --git a/src/test/java/com/google/maps/DistanceMatrixApiTest.java b/src/test/java/com/google/maps/DistanceMatrixApiTest.java index c3bce44bb..49f1358af 100644 --- a/src/test/java/com/google/maps/DistanceMatrixApiTest.java +++ b/src/test/java/com/google/maps/DistanceMatrixApiTest.java @@ -119,17 +119,15 @@ public void testNewRequestWithAllPossibleParams() throws Exception { "The Pinnacles, Australia" }; - DistanceMatrix matrix = - DistanceMatrixApi.newRequest(sc.context) - .origins(origins) - .destinations(destinations) - .mode(TravelMode.DRIVING) - .language("en-AU") - .avoid(RouteRestriction.TOLLS) - .units(Unit.IMPERIAL) - .departureTime( - new DateTime().plusMinutes(2)) // this is ignored when an API key is used - .await(); + DistanceMatrixApi.newRequest(sc.context) + .origins(origins) + .destinations(destinations) + .mode(TravelMode.DRIVING) + .language("en-AU") + .avoid(RouteRestriction.TOLLS) + .units(Unit.IMPERIAL) + .departureTime(new DateTime().plusMinutes(2)) // this is ignored when an API key is used + .await(); sc.assertParamValue(StringUtils.join(origins, "|"), "origins"); sc.assertParamValue(StringUtils.join(destinations, "|"), "destinations"); diff --git a/src/test/java/com/google/maps/PlacesApiTest.java b/src/test/java/com/google/maps/PlacesApiTest.java index fc9a68cf4..9d009921b 100644 --- a/src/test/java/com/google/maps/PlacesApiTest.java +++ b/src/test/java/com/google/maps/PlacesApiTest.java @@ -61,7 +61,6 @@ public class PlacesApiTest { private final String queryAutocompleteWithPlaceIdResponseBody; private final String textSearchResponseBody; private final String textSearchPizzaInNYCbody; - private final String placeDetailsLookupGoogleSydney; private final String placesApiTextSearch; private final String placesApiPhoto; private final String placesApiPizzaInNewYork; @@ -88,7 +87,6 @@ public PlacesApiTest() { retrieveBody("QueryAutocompleteResponseWithPlaceID.json"); textSearchResponseBody = retrieveBody("TextSearchResponse.json"); textSearchPizzaInNYCbody = retrieveBody("TextSearchPizzaInNYC.json"); - placeDetailsLookupGoogleSydney = retrieveBody("PlaceDetailsLookupGoogleSydneyResponse.json"); placesApiTextSearch = retrieveBody("PlacesApiTextSearchResponse.json"); placesApiPhoto = retrieveBody("PlacesApiPhotoResponse.json"); placesApiPizzaInNewYork = retrieveBody("PlacesApiPizzaInNewYorkResponse.json"); diff --git a/src/test/java/com/google/maps/RoadsApiIntegrationTest.java b/src/test/java/com/google/maps/RoadsApiIntegrationTest.java index 8e7f9a4a4..1a8512b25 100644 --- a/src/test/java/com/google/maps/RoadsApiIntegrationTest.java +++ b/src/test/java/com/google/maps/RoadsApiIntegrationTest.java @@ -49,25 +49,26 @@ public RoadsApiIntegrationTest() { @Test public void testSnapToRoad() throws Exception { - LocalTestServerContext sc = new LocalTestServerContext(snapToRoadResponse); - LatLng[] path = - new LatLng[] { - new LatLng(-33.865382, 151.192861), - new LatLng(-33.865837, 151.193376), - new LatLng(-33.866745, 151.19373), - new LatLng(-33.867128, 151.19344), - new LatLng(-33.867547, 151.193676), - new LatLng(-33.867841, 151.194137), - new LatLng(-33.868224, 151.194116) - }; - SnappedPoint[] points = RoadsApi.snapToRoads(sc.context, false, path).await(); - - sc.assertParamValue(join('|', path), "path"); - sc.assertParamValue("false", "interpolate"); - assertEquals(7, points.length); - assertEquals(-33.865233402568428, points[0].location.lat, 0.0001); - assertEquals(151.19288612197704, points[0].location.lng, 0.0001); - assertEquals("ChIJjXkMCDauEmsRp5xab4Ske6k", points[0].placeId); + try (LocalTestServerContext sc = new LocalTestServerContext(snapToRoadResponse)) { + LatLng[] path = + new LatLng[] { + new LatLng(-33.865382, 151.192861), + new LatLng(-33.865837, 151.193376), + new LatLng(-33.866745, 151.19373), + new LatLng(-33.867128, 151.19344), + new LatLng(-33.867547, 151.193676), + new LatLng(-33.867841, 151.194137), + new LatLng(-33.868224, 151.194116) + }; + SnappedPoint[] points = RoadsApi.snapToRoads(sc.context, false, path).await(); + + sc.assertParamValue(join('|', path), "path"); + sc.assertParamValue("false", "interpolate"); + assertEquals(7, points.length); + assertEquals(-33.865233402568428, points[0].location.lat, 0.0001); + assertEquals(151.19288612197704, points[0].location.lng, 0.0001); + assertEquals("ChIJjXkMCDauEmsRp5xab4Ske6k", points[0].placeId); + } } @Test diff --git a/src/test/java/com/google/maps/TestUtils.java b/src/test/java/com/google/maps/TestUtils.java index 312177937..77b929c16 100644 --- a/src/test/java/com/google/maps/TestUtils.java +++ b/src/test/java/com/google/maps/TestUtils.java @@ -21,12 +21,15 @@ public class TestUtils { public static String retrieveBody(String filename) { InputStream input = TestUtils.class.getResourceAsStream(filename); - Scanner s = new java.util.Scanner(input).useDelimiter("\\A"); - String body = s.next(); - if (body == null || body.length() == 0) { - throw new IllegalArgumentException( - "filename '" + filename + "' resulted in null or empty body"); + try (Scanner s = new java.util.Scanner(input)) { + s.useDelimiter("\\A"); + String body = s.next(); + + if (body == null || body.length() == 0) { + throw new IllegalArgumentException( + "filename '" + filename + "' resulted in null or empty body"); + } + return body; } - return body; } } diff --git a/src/test/java/com/google/maps/TimeZoneApiTest.java b/src/test/java/com/google/maps/TimeZoneApiTest.java index 91f537f24..cd0015c02 100644 --- a/src/test/java/com/google/maps/TimeZoneApiTest.java +++ b/src/test/java/com/google/maps/TimeZoneApiTest.java @@ -68,9 +68,10 @@ public void testNoResult() throws Exception { sc.assertParamValue("0.00000000,0.00000000", "location"); - LocalTestServerContext sc2 = - new LocalTestServerContext("\n{\n \"status\" : \"ZERO_RESULTS\"\n}\n"); - TimeZoneApi.getTimeZone(sc2.context, new LatLng(0, 0)).await(); + try (LocalTestServerContext sc2 = + new LocalTestServerContext("\n{\n \"status\" : \"ZERO_RESULTS\"\n}\n")) { + TimeZoneApi.getTimeZone(sc2.context, new LatLng(0, 0)).await(); + } } } }