Skip to content

Commit

Permalink
Added unit tests and toBuilder method
Browse files Browse the repository at this point in the history
  • Loading branch information
Devota Aabel committed Feb 12, 2019
1 parent a6e16fc commit ad63326
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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 {
Expand Down Expand Up @@ -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<DirectionsRefreshResponse> 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<DirectionsRefreshResponse> response = mapboxDirectionsRefresh.executeCall();
DirectionsRefreshResponse directionsRefreshResponse = response.body();

assertNotNull(directionsRefreshResponse.route().legs());
assertNotNull(directionsRefreshResponse.route().legs().get(0).annotation());
}
}

0 comments on commit ad63326

Please sign in to comment.