Skip to content

Commit

Permalink
Tidyup warnings (#357)
Browse files Browse the repository at this point in the history
Remediating unused logger declarations, variables, and unclosed Closeables.
  • Loading branch information
domesticmouse authored Oct 6, 2017
1 parent 18d8437 commit 0301b9f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 106 deletions.
3 changes: 0 additions & 3 deletions src/main/java/com/google/maps/GeolocationApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -82,7 +80,6 @@ public ApiException getError() {
if (successful()) {
return null;
}
ApiException e;
return ApiException.from(reason, message);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/google/maps/OkHttpRequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@
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.
*
* @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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeolocationApi.Response> {
/**
Expand Down Expand Up @@ -62,8 +61,6 @@ public class GeolocationResponseAdapter extends TypeAdapter<GeolocationApi.Respo
* }
* </pre>
*/
private static final Logger LOG = Logger.getLogger(GeolocationApi.Response.class.getName());

@Override
public GeolocationApi.Response read(JsonReader reader) throws IOException {

Expand Down
103 changes: 47 additions & 56 deletions src/test/java/com/google/maps/DirectionsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
20 changes: 9 additions & 11 deletions src/test/java/com/google/maps/DistanceMatrixApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/google/maps/PlacesApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
39 changes: 20 additions & 19 deletions src/test/java/com/google/maps/RoadsApiIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/test/java/com/google/maps/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 4 additions & 3 deletions src/test/java/com/google/maps/TimeZoneApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}

0 comments on commit 0301b9f

Please sign in to comment.