Skip to content

Commit 0301b9f

Browse files
Tidyup warnings (#357)
Remediating unused logger declarations, variables, and unclosed Closeables.
1 parent 18d8437 commit 0301b9f

9 files changed

Lines changed: 89 additions & 106 deletions

File tree

src/main/java/com/google/maps/GeolocationApi.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.maps.model.GeolocationPayload;
2323
import com.google.maps.model.GeolocationResult;
2424
import com.google.maps.model.LatLng;
25-
import java.util.logging.Logger;
2625

2726
/*
2827
* The Google Maps Geolocation API returns a location and accuracy radius based on information
@@ -35,7 +34,6 @@
3534
*/
3635
public class GeolocationApi {
3736
private static final String API_BASE_URL = "https://www.googleapis.com";
38-
private static final Logger LOG = Logger.getLogger(GeolocationApi.class.getName());
3937

4038
static final ApiConfig GEOLOCATION_API_CONFIG =
4139
new ApiConfig("/geolocation/v1/geolocate")
@@ -82,7 +80,6 @@ public ApiException getError() {
8280
if (successful()) {
8381
return null;
8482
}
85-
ApiException e;
8683
return ApiException.from(reason, message);
8784
}
8885
}

src/main/java/com/google/maps/OkHttpRequestHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@
3333
import okhttp3.RequestBody;
3434
import okhttp3.Response;
3535
import okhttp3.Route;
36-
import org.slf4j.Logger;
37-
import org.slf4j.LoggerFactory;
3836

3937
/**
4038
* A strategy for handling URL requests using OkHttp.
4139
*
4240
* @see com.google.maps.GeoApiContext.RequestHandler
4341
*/
4442
public class OkHttpRequestHandler implements GeoApiContext.RequestHandler {
45-
private static final Logger LOG = LoggerFactory.getLogger(OkHttpRequestHandler.class.getName());
4643
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
4744
private final OkHttpClient client;
4845

src/main/java/com/google/maps/internal/GeolocationResponseAdapter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.gson.stream.JsonWriter;
2222
import com.google.maps.GeolocationApi;
2323
import java.io.IOException;
24-
import java.util.logging.Logger;
2524

2625
public class GeolocationResponseAdapter extends TypeAdapter<GeolocationApi.Response> {
2726
/**
@@ -62,8 +61,6 @@ public class GeolocationResponseAdapter extends TypeAdapter<GeolocationApi.Respo
6261
* }
6362
* </pre>
6463
*/
65-
private static final Logger LOG = Logger.getLogger(GeolocationApi.Response.class.getName());
66-
6764
@Override
6865
public GeolocationApi.Response read(JsonReader reader) throws IOException {
6966

src/test/java/com/google/maps/DirectionsApiTest.java

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ public void testResponseTimesArePopulatedCorrectly() throws Exception {
147147
public void testTorontoToMontreal() throws Exception {
148148
try (LocalTestServerContext sc =
149149
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
150-
DirectionsResult result =
151-
DirectionsApi.newRequest(sc.context).origin("Toronto").destination("Montreal").await();
150+
DirectionsApi.newRequest(sc.context).origin("Toronto").destination("Montreal").await();
152151

153152
sc.assertParamValue("Toronto", "origin");
154153
sc.assertParamValue("Montreal", "destination");
@@ -165,13 +164,12 @@ public void testTorontoToMontreal() throws Exception {
165164
public void testTorontoToMontrealByBicycleAvoidingHighways() throws Exception {
166165
try (LocalTestServerContext sc =
167166
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
168-
DirectionsResult result =
169-
DirectionsApi.newRequest(sc.context)
170-
.origin("Toronto")
171-
.destination("Montreal")
172-
.avoid(DirectionsApi.RouteRestriction.HIGHWAYS)
173-
.mode(TravelMode.BICYCLING)
174-
.await();
167+
DirectionsApi.newRequest(sc.context)
168+
.origin("Toronto")
169+
.destination("Montreal")
170+
.avoid(DirectionsApi.RouteRestriction.HIGHWAYS)
171+
.mode(TravelMode.BICYCLING)
172+
.await();
175173

176174
sc.assertParamValue("Toronto", "origin");
177175
sc.assertParamValue("Montreal", "destination");
@@ -190,12 +188,11 @@ public void testTorontoToMontrealByBicycleAvoidingHighways() throws Exception {
190188
public void testBrooklynToQueensByTransit() throws Exception {
191189
try (LocalTestServerContext sc =
192190
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
193-
DirectionsResult result =
194-
DirectionsApi.newRequest(sc.context)
195-
.origin("Brooklyn")
196-
.destination("Queens")
197-
.mode(TravelMode.TRANSIT)
198-
.await();
191+
DirectionsApi.newRequest(sc.context)
192+
.origin("Brooklyn")
193+
.destination("Queens")
194+
.mode(TravelMode.TRANSIT)
195+
.await();
199196

200197
sc.assertParamValue("Brooklyn", "origin");
201198
sc.assertParamValue("Queens", "destination");
@@ -213,12 +210,11 @@ public void testBrooklynToQueensByTransit() throws Exception {
213210
public void testBostonToConcordViaCharlestownAndLexignton() throws Exception {
214211
try (LocalTestServerContext sc =
215212
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
216-
DirectionsResult result =
217-
DirectionsApi.newRequest(sc.context)
218-
.origin("Boston,MA")
219-
.destination("Concord,MA")
220-
.waypoints("Charlestown,MA", "Lexington,MA")
221-
.await();
213+
DirectionsApi.newRequest(sc.context)
214+
.origin("Boston,MA")
215+
.destination("Concord,MA")
216+
.waypoints("Charlestown,MA", "Lexington,MA")
217+
.await();
222218

223219
sc.assertParamValue("Boston,MA", "origin");
224220
sc.assertParamValue("Concord,MA", "destination");
@@ -237,12 +233,11 @@ public void testBostonToConcordViaCharlestownAndLexignton() throws Exception {
237233
public void testBostonToConcordViaCharlestownAndLexigntonLatLng() throws Exception {
238234
try (LocalTestServerContext sc =
239235
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
240-
DirectionsResult result =
241-
DirectionsApi.newRequest(sc.context)
242-
.origin("Boston,MA")
243-
.destination("Concord,MA")
244-
.waypoints(new LatLng(42.379322, -71.063384), new LatLng(42.444303, -71.229087))
245-
.await();
236+
DirectionsApi.newRequest(sc.context)
237+
.origin("Boston,MA")
238+
.destination("Concord,MA")
239+
.waypoints(new LatLng(42.379322, -71.063384), new LatLng(42.444303, -71.229087))
240+
.await();
246241

247242
sc.assertParamValue("Boston,MA", "origin");
248243
sc.assertParamValue("Concord,MA", "destination");
@@ -260,12 +255,11 @@ public void testBostonToConcordViaCharlestownAndLexigntonLatLng() throws Excepti
260255
public void testToledoToMadridInSpain() throws Exception {
261256
try (LocalTestServerContext sc =
262257
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
263-
DirectionsResult result =
264-
DirectionsApi.newRequest(sc.context)
265-
.origin("Toledo")
266-
.destination("Madrid")
267-
.region("es")
268-
.await();
258+
DirectionsApi.newRequest(sc.context)
259+
.origin("Toledo")
260+
.destination("Madrid")
261+
.region("es")
262+
.await();
269263

270264
sc.assertParamValue("Toledo", "origin");
271265
sc.assertParamValue("Madrid", "destination");
@@ -278,13 +272,12 @@ public void testToledoToMadridInSpain() throws Exception {
278272
public void testLanguageParameter() throws Exception {
279273
try (LocalTestServerContext sc =
280274
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
281-
DirectionsResult result =
282-
DirectionsApi.newRequest(sc.context)
283-
.origin("Toledo")
284-
.destination("Madrid")
285-
.region("es")
286-
.language("es")
287-
.await();
275+
DirectionsApi.newRequest(sc.context)
276+
.origin("Toledo")
277+
.destination("Madrid")
278+
.region("es")
279+
.language("es")
280+
.await();
288281

289282
sc.assertParamValue("Toledo", "origin");
290283
sc.assertParamValue("Madrid", "destination");
@@ -298,14 +291,13 @@ public void testLanguageParameter() throws Exception {
298291
public void testTrafficModel() throws Exception {
299292
try (LocalTestServerContext sc =
300293
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}"); ) {
301-
DirectionsResult result =
302-
DirectionsApi.newRequest(sc.context)
303-
.origin("48 Pirrama Road, Pyrmont NSW 2009")
304-
.destination("182 Church St, Parramatta NSW 2150")
305-
.mode(TravelMode.DRIVING)
306-
.departureTime(new DateTime().plus(Duration.standardMinutes(2)))
307-
.trafficModel(TrafficModel.PESSIMISTIC)
308-
.await();
294+
DirectionsApi.newRequest(sc.context)
295+
.origin("48 Pirrama Road, Pyrmont NSW 2009")
296+
.destination("182 Church St, Parramatta NSW 2150")
297+
.mode(TravelMode.DRIVING)
298+
.departureTime(new DateTime().plus(Duration.standardMinutes(2)))
299+
.trafficModel(TrafficModel.PESSIMISTIC)
300+
.await();
309301

310302
sc.assertParamValue("48 Pirrama Road, Pyrmont NSW 2009", "origin");
311303
sc.assertParamValue("182 Church St, Parramatta NSW 2150", "destination");
@@ -336,14 +328,13 @@ public void testTransitWithoutSpecifyingTime() throws Exception {
336328
public void testTransitParams() throws Exception {
337329
try (LocalTestServerContext sc =
338330
new LocalTestServerContext("{\"routes\": [{}],\"status\": \"OK\"}")) {
339-
DirectionsResult result =
340-
DirectionsApi.newRequest(sc.context)
341-
.origin("Fisherman's Wharf, San Francisco")
342-
.destination("Union Square, San Francisco")
343-
.mode(TravelMode.TRANSIT)
344-
.transitMode(TransitMode.BUS, TransitMode.TRAM)
345-
.transitRoutingPreference(TransitRoutingPreference.LESS_WALKING)
346-
.await();
331+
DirectionsApi.newRequest(sc.context)
332+
.origin("Fisherman's Wharf, San Francisco")
333+
.destination("Union Square, San Francisco")
334+
.mode(TravelMode.TRANSIT)
335+
.transitMode(TransitMode.BUS, TransitMode.TRAM)
336+
.transitRoutingPreference(TransitRoutingPreference.LESS_WALKING)
337+
.await();
347338

348339
sc.assertParamValue("Fisherman's Wharf, San Francisco", "origin");
349340
sc.assertParamValue("Union Square, San Francisco", "destination");

src/test/java/com/google/maps/DistanceMatrixApiTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,15 @@ public void testNewRequestWithAllPossibleParams() throws Exception {
119119
"The Pinnacles, Australia"
120120
};
121121

122-
DistanceMatrix matrix =
123-
DistanceMatrixApi.newRequest(sc.context)
124-
.origins(origins)
125-
.destinations(destinations)
126-
.mode(TravelMode.DRIVING)
127-
.language("en-AU")
128-
.avoid(RouteRestriction.TOLLS)
129-
.units(Unit.IMPERIAL)
130-
.departureTime(
131-
new DateTime().plusMinutes(2)) // this is ignored when an API key is used
132-
.await();
122+
DistanceMatrixApi.newRequest(sc.context)
123+
.origins(origins)
124+
.destinations(destinations)
125+
.mode(TravelMode.DRIVING)
126+
.language("en-AU")
127+
.avoid(RouteRestriction.TOLLS)
128+
.units(Unit.IMPERIAL)
129+
.departureTime(new DateTime().plusMinutes(2)) // this is ignored when an API key is used
130+
.await();
133131

134132
sc.assertParamValue(StringUtils.join(origins, "|"), "origins");
135133
sc.assertParamValue(StringUtils.join(destinations, "|"), "destinations");

src/test/java/com/google/maps/PlacesApiTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public class PlacesApiTest {
6161
private final String queryAutocompleteWithPlaceIdResponseBody;
6262
private final String textSearchResponseBody;
6363
private final String textSearchPizzaInNYCbody;
64-
private final String placeDetailsLookupGoogleSydney;
6564
private final String placesApiTextSearch;
6665
private final String placesApiPhoto;
6766
private final String placesApiPizzaInNewYork;
@@ -88,7 +87,6 @@ public PlacesApiTest() {
8887
retrieveBody("QueryAutocompleteResponseWithPlaceID.json");
8988
textSearchResponseBody = retrieveBody("TextSearchResponse.json");
9089
textSearchPizzaInNYCbody = retrieveBody("TextSearchPizzaInNYC.json");
91-
placeDetailsLookupGoogleSydney = retrieveBody("PlaceDetailsLookupGoogleSydneyResponse.json");
9290
placesApiTextSearch = retrieveBody("PlacesApiTextSearchResponse.json");
9391
placesApiPhoto = retrieveBody("PlacesApiPhotoResponse.json");
9492
placesApiPizzaInNewYork = retrieveBody("PlacesApiPizzaInNewYorkResponse.json");

src/test/java/com/google/maps/RoadsApiIntegrationTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,26 @@ public RoadsApiIntegrationTest() {
4949

5050
@Test
5151
public void testSnapToRoad() throws Exception {
52-
LocalTestServerContext sc = new LocalTestServerContext(snapToRoadResponse);
53-
LatLng[] path =
54-
new LatLng[] {
55-
new LatLng(-33.865382, 151.192861),
56-
new LatLng(-33.865837, 151.193376),
57-
new LatLng(-33.866745, 151.19373),
58-
new LatLng(-33.867128, 151.19344),
59-
new LatLng(-33.867547, 151.193676),
60-
new LatLng(-33.867841, 151.194137),
61-
new LatLng(-33.868224, 151.194116)
62-
};
63-
SnappedPoint[] points = RoadsApi.snapToRoads(sc.context, false, path).await();
64-
65-
sc.assertParamValue(join('|', path), "path");
66-
sc.assertParamValue("false", "interpolate");
67-
assertEquals(7, points.length);
68-
assertEquals(-33.865233402568428, points[0].location.lat, 0.0001);
69-
assertEquals(151.19288612197704, points[0].location.lng, 0.0001);
70-
assertEquals("ChIJjXkMCDauEmsRp5xab4Ske6k", points[0].placeId);
52+
try (LocalTestServerContext sc = new LocalTestServerContext(snapToRoadResponse)) {
53+
LatLng[] path =
54+
new LatLng[] {
55+
new LatLng(-33.865382, 151.192861),
56+
new LatLng(-33.865837, 151.193376),
57+
new LatLng(-33.866745, 151.19373),
58+
new LatLng(-33.867128, 151.19344),
59+
new LatLng(-33.867547, 151.193676),
60+
new LatLng(-33.867841, 151.194137),
61+
new LatLng(-33.868224, 151.194116)
62+
};
63+
SnappedPoint[] points = RoadsApi.snapToRoads(sc.context, false, path).await();
64+
65+
sc.assertParamValue(join('|', path), "path");
66+
sc.assertParamValue("false", "interpolate");
67+
assertEquals(7, points.length);
68+
assertEquals(-33.865233402568428, points[0].location.lat, 0.0001);
69+
assertEquals(151.19288612197704, points[0].location.lng, 0.0001);
70+
assertEquals("ChIJjXkMCDauEmsRp5xab4Ske6k", points[0].placeId);
71+
}
7172
}
7273

7374
@Test

src/test/java/com/google/maps/TestUtils.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
public class TestUtils {
2222
public static String retrieveBody(String filename) {
2323
InputStream input = TestUtils.class.getResourceAsStream(filename);
24-
Scanner s = new java.util.Scanner(input).useDelimiter("\\A");
25-
String body = s.next();
26-
if (body == null || body.length() == 0) {
27-
throw new IllegalArgumentException(
28-
"filename '" + filename + "' resulted in null or empty body");
24+
try (Scanner s = new java.util.Scanner(input)) {
25+
s.useDelimiter("\\A");
26+
String body = s.next();
27+
28+
if (body == null || body.length() == 0) {
29+
throw new IllegalArgumentException(
30+
"filename '" + filename + "' resulted in null or empty body");
31+
}
32+
return body;
2933
}
30-
return body;
3134
}
3235
}

src/test/java/com/google/maps/TimeZoneApiTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ public void testNoResult() throws Exception {
6868

6969
sc.assertParamValue("0.00000000,0.00000000", "location");
7070

71-
LocalTestServerContext sc2 =
72-
new LocalTestServerContext("\n{\n \"status\" : \"ZERO_RESULTS\"\n}\n");
73-
TimeZoneApi.getTimeZone(sc2.context, new LatLng(0, 0)).await();
71+
try (LocalTestServerContext sc2 =
72+
new LocalTestServerContext("\n{\n \"status\" : \"ZERO_RESULTS\"\n}\n")) {
73+
TimeZoneApi.getTimeZone(sc2.context, new LatLng(0, 0)).await();
74+
}
7475
}
7576
}
7677
}

0 commit comments

Comments
 (0)