Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ protected synchronized OkHttpClient getOkHttpClient() {
if (interceptor != null) {
httpClient.addInterceptor(interceptor);
}
Interceptor networkInterceptor = networkInterceptor();
if (networkInterceptor != null) {
httpClient.addNetworkInterceptor(networkInterceptor);
}
EventListener eventListener = eventListener();
if (eventListener != null) {
httpClient.eventListener(eventListener);
Expand Down Expand Up @@ -329,6 +333,9 @@ private static String formatWaypointTargets(Point[] waypointTargets) {
@Nullable
abstract Interceptor interceptor();

@Nullable
abstract Interceptor networkInterceptor();

@Nullable
abstract EventListener eventListener();

Expand Down Expand Up @@ -754,6 +761,14 @@ public Builder radiuses(@FloatRange(from = 0) double... radiuses) {
*/
public abstract Builder interceptor(Interceptor interceptor);

/**
* Adds an optional network interceptor to set in the OkHttp client.
*
* @param interceptor to set for OkHttp
* @return this builder for chaining options together
*/
public abstract Builder networkInterceptor(Interceptor interceptor);

/**
* Adds an optional event listener to set in the OkHttp client.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,30 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
assertEquals(interceptor, mapboxDirections.interceptor());
}

@Test
public void testWithNetworkInterceptor() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing Could we rename the test so it's clearer (although not consistently applied 👀 at the "naming" convention of the rest of the tests)? We should also remove test prefix from tests names, it's implicit with the usage of @Test annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah completely agree! i was only being consistent within this change. addressing naming conventions can be part of a separate PR to maintain consistency

Interceptor interceptor = new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
return null;
}
};
MapboxDirections mapboxDirections = MapboxDirections.builder()
.profile(PROFILE_CYCLING)
.origin(Point.fromLngLat(-122.42,37.78))
.destination(Point.fromLngLat(-77.03,38.91))
.steps(true)
.voiceInstructions(true)
.voiceUnits(DirectionsCriteria.IMPERIAL)
.addWaypointNames("Home", "Work")
.accessToken(ACCESS_TOKEN)
.baseUrl(mockUrl.toString())
.networkInterceptor(interceptor)
.build();

assertEquals(interceptor, mapboxDirections.networkInterceptor());
}

@Test
public void testWithEventListener() throws Exception {
EventListener eventListener = new EventListener() {
Expand Down