Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up broken tests #167

Merged
merged 2 commits into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 12 additions & 72 deletions src/test/java/com/google/maps/DirectionsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,29 @@

package com.google.maps;

import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.maps.DirectionsApi.RouteRestriction;
import com.google.maps.errors.NotFoundException;
import com.google.maps.model.AddressType;
import com.google.maps.model.DirectionsLeg;
import com.google.maps.model.DirectionsResult;
import com.google.maps.model.DirectionsRoute;
import com.google.maps.model.GeocodedWaypointStatus;
import com.google.maps.model.TrafficModel;
import com.google.maps.model.TransitMode;
import com.google.maps.model.TransitRoutingPreference;
import com.google.maps.model.TravelMode;
import com.google.maps.model.Unit;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.concurrent.TimeUnit;

import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@Category(LargeTests.class)
public class DirectionsApiTest extends AuthenticatedTest {

Expand Down Expand Up @@ -175,34 +170,6 @@ public void testBostonToConcordViaCharlestownAndLexignton() throws Exception {
assertNotNull(result.routes);
}

/**
* A wine tour around Adelaide in South Australia. This shows off how to get Directions Web
* Service API to find the shortest path amongst a set of way points.
*
* {@code http://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA}
*/
@Test
public void testAdelaideWineTour() throws Exception {
DirectionsResult result = DirectionsApi.newRequest(context)
.origin("Adelaide,SA")
.destination("Adelaide,SA")
.optimizeWaypoints(true)
.waypoints("Barossa Valley, SA", "Clare, SA", "Connawarra, SA",
"McLaren Vale, SA")
.await();

assertNotNull(result.routes);
assertEquals(1, result.routes.length);

// optimize:true returns the waypoint_order of the optimized route.
// "waypoint_order": [ 1, 0, 2, 3 ]
assertNotNull(result.routes[0].waypointOrder);
assertEquals(1, result.routes[0].waypointOrder[0]);
assertEquals(0, result.routes[0].waypointOrder[1]);
assertEquals(2, result.routes[0].waypointOrder[2]);
assertEquals(3, result.routes[0].waypointOrder[3]);
}

/**
* Toledo to Madrid, in Spain. This showcases region biasing results.
*
Expand Down Expand Up @@ -250,34 +217,22 @@ public void testLanguageParameter() throws Exception {
assertNotNull(result.routes);
}

/**
* Testing the alternatives param.
*/
@Test
public void testAlternatives() throws Exception {
DirectionsResult result = DirectionsApi.newRequest(context)
.origin("Sydney Town Hall")
.destination("Parramatta Town Hall")
.alternatives(true)
.await();

assertNotNull(result.routes);
assertTrue(result.routes.length > 1);
}

/**
* Tests the {@code traffic_model} and {@code duration_in_traffic} parameters.
*/
@Test
public void testTrafficModel() throws Exception {
DirectionsResult result = DirectionsApi.newRequest(context)
.origin("Sydney Town Hall")
.destination("Parramatta Town Hall")
.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();

assertNotNull(result);
assertTrue(result.routes.length > 0);
assertTrue(result.routes[0].legs.length > 0);
assertNotNull(result.routes[0].legs[0].durationInTraffic);
}

Expand Down Expand Up @@ -331,25 +286,10 @@ public void testGeocodedWaypoints() throws Exception {
assertNotNull(result.geocodedWaypoints);
assertEquals(2, result.geocodedWaypoints.length);
assertEquals(GeocodedWaypointStatus.OK, result.geocodedWaypoints[0].geocoderStatus);
assertEquals(AddressType.PREMISE, result.geocodedWaypoints[0].types[0]);
assertEquals(AddressType.STREET_ADDRESS, result.geocodedWaypoints[0].types[0]);
assertEquals(GeocodedWaypointStatus.OK, result.geocodedWaypoints[1].geocoderStatus);
assertEquals(AddressType.ROUTE, result.geocodedWaypoints[1].types[0]);

}

/**
* Test {@code local_icon} for Directions in Paris.
*/
@Test
public void testLocalIconInParis() throws Exception {
DirectionsResult result = DirectionsApi.newRequest(context)
.origin("paris metro bibliotheque francois mitterrand")
.destination("paris metro pyramides")
.mode(TravelMode.TRANSIT)
.await();
assertNotNull(result);
assertEquals("//maps.gstatic.com/mapfiles/transit/iw2/6/fr-paris-metro.png",
result.routes[0].legs[0].steps[1].transitDetails.line.vehicle.localIcon);
}

}
8 changes: 4 additions & 4 deletions src/test/java/com/google/maps/GeocodingApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@Category(LargeTests.class)
public class GeocodingApiTest extends AuthenticatedTest {

public static final double EPSILON = 0.000001;
private static final double EPSILON = 0.005;

private GeoApiContext context;

Expand Down Expand Up @@ -169,7 +169,7 @@ public void testGeocodeWithRegionBiasing() throws Exception {
.await();

assertNotNull(results);
assertEquals("Toledo, Toledo, Spain", results[0].formattedAddress);
assertEquals("Toledo, Spain", results[0].formattedAddress);
}

/**
Expand All @@ -183,8 +183,8 @@ public void testGeocodeWithComponentFilter() throws Exception {
.components(ComponentFilter.country("ES")).await();

assertNotNull(results);
assertEquals("Santa Cruz de Tenerife, Santa Cruz de Tenerife, Spain",
results[0].formattedAddress);
assertTrue(results[0].formattedAddress.contains("Santa Cruz de Tenerife"));
assertTrue(results[0].formattedAddress.contains("Spain"));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/google/maps/PlacesApiIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@

@Category(LargeTests.class)
public class PlacesApiIntegrationTest extends KeyOnlyAuthenticatedTest {
public static final String GOOGLE_SYDNEY = "ChIJN1t_tDeuEmsRUsoyG83frY4";
public static final LatLng SYDNEY = new LatLng(-33.8650, 151.2094);
public static final long TWO_SECONDS = 2 * 1000;
private static final String GOOGLE_SYDNEY = "ChIJN1t_tDeuEmsRUsoyG83frY4";
private static final LatLng SYDNEY = new LatLng(-33.8650, 151.2094);
private static final long TWO_SECONDS = 2 * 1000;

public PlacesApiIntegrationTest(GeoApiContext context) {
this.context = context
Expand All @@ -70,7 +70,7 @@ public void testPlaceDetailsLookupGoogleSydney() throws Exception {
assertNotNull(placeDetails.formattedAddress);
assertEquals("5, 48 Pirrama Rd, Pyrmont NSW 2009, Australia", placeDetails.formattedAddress);
assertNotNull(placeDetails.vicinity);
assertEquals("5 48 Pirrama Road, Pyrmont", placeDetails.vicinity);
assertEquals("5 48 Pirrama Rd, Pyrmont", placeDetails.vicinity);

// Phone numbers
assertNotNull(placeDetails.formattedPhoneNumber);
Expand Down