From ad63326cfe61697cd2a4d1b946acbe7c4ba8247d Mon Sep 17 00:00:00 2001 From: Devota Aabel Date: Tue, 12 Feb 2019 16:08:45 -0500 Subject: [PATCH] Added unit tests and toBuilder method --- .../v5/MapboxDirectionsRefresh.java | 9 ++--- .../v5/MapboxDirectionsRefreshTest.java | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/services-directions-refresh/src/main/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefresh.java b/services-directions-refresh/src/main/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefresh.java index b1d5711f2..1e28f79d8 100644 --- a/services-directions-refresh/src/main/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefresh.java +++ b/services-directions-refresh/src/main/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefresh.java @@ -65,12 +65,11 @@ protected GsonBuilder getGsonBuilder() { } /** - * Convert the current {@link MapboxDirectionsRefresh} to its builder holding the currently assigned - * values. This allows you to modify a single property and then rebuild the object resulting in - * an updated and modified {@link MapboxDirectionsRefresh}. + * Convert the current {@link MapboxDirectionsRefresh} to its builder holding the currently + * assigned values. This allows you to modify a single property and then rebuild the object + * resulting in an updated and modified {@link MapboxDirectionsRefresh}. * - * @return a {@link MapboxDirectionsRefresh.Builder} with the same values set to match the ones defined - * in this {@link MapboxDirectionsRefresh} + * @return a {@link MapboxDirectionsRefresh.Builder} with the same values * @since 4.4.0 */ public abstract Builder toBuilder(); diff --git a/services-directions-refresh/src/test/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefreshTest.java b/services-directions-refresh/src/test/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefreshTest.java index a6e553f8a..039ca24a5 100644 --- a/services-directions-refresh/src/test/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefreshTest.java +++ b/services-directions-refresh/src/test/java/com/mapbox/api/directionsrefresh/v5/MapboxDirectionsRefreshTest.java @@ -1,5 +1,6 @@ package com.mapbox.api.directionsrefresh.v5; +import com.mapbox.api.directionsrefresh.v5.models.DirectionsRefreshResponse; import com.mapbox.core.TestUtils; import org.hamcrest.junit.ExpectedException; @@ -15,6 +16,10 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; +import retrofit2.Response; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; public class MapboxDirectionsRefreshTest extends TestUtils { @@ -31,7 +36,6 @@ public void setUp() throws IOException { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { - // Switch response on geometry parameter (only false supported, so nice and simple) String resource = DIRECTIONS_REFRESH_V5_FIXTURE; try { @@ -63,4 +67,36 @@ public void sanity() throws Exception { Assert.assertNotNull(mapboxDirectionsRefresh); } + + @Test + public void testResponse() throws IOException { + MapboxDirectionsRefresh mapboxDirectionsRefresh = MapboxDirectionsRefresh.builder() + .accessToken(ACCESS_TOKEN) + .requestId("") + .baseUrl(mockUrl.toString()) + .build(); + + Response response = mapboxDirectionsRefresh.executeCall(); + DirectionsRefreshResponse directionsRefreshResponse = response.body(); + + assertEquals(200, response.code()); + assertEquals("Ok", directionsRefreshResponse.code()); + assertNotNull(directionsRefreshResponse.route().legs()); + assertNotNull(directionsRefreshResponse.route().legs().get(0).annotation()); + } + + @Test + public void testRoute() throws IOException { + MapboxDirectionsRefresh mapboxDirectionsRefresh = MapboxDirectionsRefresh.builder() + .accessToken(ACCESS_TOKEN) + .requestId("") + .baseUrl(mockUrl.toString()) + .build(); + + Response response = mapboxDirectionsRefresh.executeCall(); + DirectionsRefreshResponse directionsRefreshResponse = response.body(); + + assertNotNull(directionsRefreshResponse.route().legs()); + assertNotNull(directionsRefreshResponse.route().legs().get(0).annotation()); + } }