-
Notifications
You must be signed in to change notification settings - Fork 320
Update RouteRetrievalEvent #1731
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
...ation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/LongCounter.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...in/java/com/mapbox/services/android/navigation/v5/navigation/NavigationRouteCallback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.mapbox.services.android.navigation.v5.navigation; | ||
|
|
||
| import android.support.annotation.NonNull; | ||
|
|
||
| import com.mapbox.api.directions.v5.models.DirectionsResponse; | ||
|
|
||
| import retrofit2.Call; | ||
| import retrofit2.Callback; | ||
| import retrofit2.Response; | ||
|
|
||
| class NavigationRouteCallback implements Callback<DirectionsResponse> { | ||
|
|
||
| private final NavigationTelemetry telemetry; | ||
| private final NavigationRouteEventListener listener; | ||
| private final Callback<DirectionsResponse> callback; | ||
|
|
||
| NavigationRouteCallback(NavigationRouteEventListener listener, Callback<DirectionsResponse> callback) { | ||
| this(NavigationTelemetry.getInstance(), listener, callback); | ||
| } | ||
|
|
||
| NavigationRouteCallback(NavigationTelemetry telemetry, NavigationRouteEventListener listener, | ||
| Callback<DirectionsResponse> callback) { | ||
| this.telemetry = telemetry; | ||
| this.listener = listener; | ||
| this.callback = callback; | ||
| } | ||
|
|
||
| @Override | ||
| public void onResponse(@NonNull Call<DirectionsResponse> call, @NonNull Response<DirectionsResponse> response) { | ||
| callback.onResponse(call, response); | ||
| if (isValid(response)) { | ||
| String uuid = response.body().uuid(); | ||
| sendEventWith(listener.getTime(), uuid); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(@NonNull Call<DirectionsResponse> call, @NonNull Throwable throwable) { | ||
| callback.onFailure(call, throwable); | ||
| } | ||
|
|
||
| private boolean isValid(Response<DirectionsResponse> response) { | ||
| return response.body() != null && !response.body().routes().isEmpty(); | ||
| } | ||
|
|
||
| private void sendEventWith(ElapsedTime time, String uuid) { | ||
| telemetry.routeRetrievalEvent(time, uuid); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
...va/com/mapbox/services/android/navigation/v5/navigation/NavigationRouteEventListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.mapbox.services.android.navigation.v5.navigation; | ||
|
|
||
| import okhttp3.Call; | ||
| import okhttp3.EventListener; | ||
|
|
||
| class NavigationRouteEventListener extends EventListener { | ||
|
|
||
| private final ElapsedTime time; | ||
|
|
||
| NavigationRouteEventListener() { | ||
| this(new ElapsedTime()); | ||
| } | ||
|
|
||
| NavigationRouteEventListener(ElapsedTime time) { | ||
| this.time = time; | ||
| } | ||
|
|
||
| @Override | ||
| public void callStart(Call call) { | ||
| super.callStart(call); | ||
| time.start(); | ||
| } | ||
|
|
||
| @Override | ||
| public void callEnd(Call call) { | ||
| super.callEnd(call); | ||
| time.end(); | ||
| } | ||
|
|
||
| ElapsedTime getTime() { | ||
| return time; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ava/com/mapbox/services/android/navigation/v5/navigation/NavigationRouteCallbackTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.mapbox.services.android.navigation.v5.navigation; | ||
|
|
||
| import android.support.annotation.NonNull; | ||
|
|
||
| import com.mapbox.api.directions.v5.models.DirectionsResponse; | ||
| import com.mapbox.api.directions.v5.models.DirectionsRoute; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| import retrofit2.Call; | ||
| import retrofit2.Callback; | ||
| import retrofit2.Response; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class NavigationRouteCallbackTest { | ||
|
|
||
| @Test | ||
| public void onResponse_callbackIsCalled() { | ||
| NavigationTelemetry telemetry = mock(NavigationTelemetry.class); | ||
| NavigationRouteEventListener listener = mock(NavigationRouteEventListener.class); | ||
| Callback<DirectionsResponse> callback = mock(Callback.class); | ||
| Call call = mock(Call.class); | ||
| String uuid = "some_uuid"; | ||
| Response response = buildMockResponse(uuid); | ||
| NavigationRouteCallback routeCallback = new NavigationRouteCallback(telemetry, listener, callback); | ||
|
|
||
| routeCallback.onResponse(call, response); | ||
|
|
||
| verify(callback).onResponse(call, response); | ||
| } | ||
|
|
||
| @Test | ||
| public void onResponse_validResponseSendsEvent() { | ||
| NavigationTelemetry telemetry = mock(NavigationTelemetry.class); | ||
| NavigationRouteEventListener listener = mock(NavigationRouteEventListener.class); | ||
| ElapsedTime elapsedTime = mock(ElapsedTime.class); | ||
| when(listener.getTime()).thenReturn(elapsedTime); | ||
| Callback<DirectionsResponse> callback = mock(Callback.class); | ||
| Call call = mock(Call.class); | ||
| String uuid = "some_uuid"; | ||
| Response response = buildMockResponse(uuid); | ||
| NavigationRouteCallback routeCallback = new NavigationRouteCallback(telemetry, listener, callback); | ||
|
|
||
| routeCallback.onResponse(call, response); | ||
|
|
||
| verify(telemetry).routeRetrievalEvent(eq(elapsedTime), eq(uuid)); | ||
| } | ||
|
|
||
| @Test | ||
| public void onFailure_callbackIsCalled() { | ||
| NavigationTelemetry telemetry = mock(NavigationTelemetry.class); | ||
| NavigationRouteEventListener listener = mock(NavigationRouteEventListener.class); | ||
| Callback<DirectionsResponse> callback = mock(Callback.class); | ||
| Call call = mock(Call.class); | ||
| Throwable throwable = mock(Throwable.class); | ||
| NavigationRouteCallback routeCallback = new NavigationRouteCallback(telemetry, listener, callback); | ||
|
|
||
| routeCallback.onFailure(call, throwable); | ||
|
|
||
| verify(callback).onFailure(call, throwable); | ||
| } | ||
|
|
||
| @NonNull | ||
| private Response buildMockResponse(String uuid) { | ||
| Response response = mock(Response.class); | ||
| DirectionsResponse directionsResponse = mock(DirectionsResponse.class); | ||
| ArrayList<DirectionsRoute> routes = new ArrayList<>(); | ||
| routes.add(mock(DirectionsRoute.class)); | ||
| when(directionsResponse.uuid()).thenReturn(uuid); | ||
| when(directionsResponse.routes()).thenReturn(routes); | ||
| when(response.body()).thenReturn(directionsResponse); | ||
| return response; | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...om/mapbox/services/android/navigation/v5/navigation/NavigationRouteEventListenerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.mapbox.services.android.navigation.v5.navigation; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import okhttp3.Call; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| public class NavigationRouteEventListenerTest { | ||
|
|
||
| @Test | ||
| public void callStart_timeStartIsCalled() { | ||
| ElapsedTime time = mock(ElapsedTime.class); | ||
| NavigationRouteEventListener listener = new NavigationRouteEventListener(time); | ||
|
|
||
| listener.callStart(mock(Call.class)); | ||
|
|
||
| verify(time).start(); | ||
| } | ||
|
|
||
| @Test | ||
| public void callEnd_timeEndIsCalled() { | ||
| ElapsedTime time = mock(ElapsedTime.class); | ||
| NavigationRouteEventListener listener = new NavigationRouteEventListener(time); | ||
|
|
||
| listener.callEnd(mock(Call.class)); | ||
|
|
||
| verify(time).end(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove it altogether?