-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19912a0
commit 889c8ad
Showing
12 changed files
with
98 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
30 changes: 0 additions & 30 deletions
30
app/src/main/java/com/artemzin/qualitymatters/api/ChangeableBaseUrl.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/artemzin/qualitymatters/network/HostSelectionInterceptor.java
This file contains 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,47 @@ | ||
package com.artemzin.qualitymatters.network; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
/** | ||
* Such implementation allows us easily change base url in the integration and functional tests! | ||
*/ | ||
public class HostSelectionInterceptor implements Interceptor { | ||
|
||
@Nullable | ||
private volatile String baseUrl; | ||
|
||
@Override @NonNull | ||
public Response intercept(@NonNull Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
final String baseUrl = this.baseUrl; | ||
if (baseUrl != null) { | ||
final URL url = new URL(baseUrl); | ||
final HttpUrl newUrl = request.url() | ||
.newBuilder() | ||
.scheme(url.getProtocol()) | ||
.host(url.getHost()) | ||
.port(url.getPort()) | ||
.build(); | ||
request = request.newBuilder() | ||
.url(newUrl) | ||
.build(); | ||
} | ||
return chain.proceed(request); | ||
} | ||
|
||
public void setBaseUrl(@Nullable String baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
@Nullable | ||
public String getBaseUrl() { | ||
return baseUrl; | ||
} | ||
} |
This file contains 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
23 changes: 0 additions & 23 deletions
23
app/src/unitTests/java/com/artemzin/qualitymatters/api/ChangeableBaseUrlTest.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
app/src/unitTests/java/com/artemzin/qualitymatters/network/HostSelectionInterceptorTest.java
This file contains 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,22 @@ | ||
package com.artemzin.qualitymatters.network; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class HostSelectionInterceptorTest { | ||
|
||
private static final String BASE_URL = "http://www.example.com"; | ||
private HostSelectionInterceptor interceptor = new HostSelectionInterceptor(); | ||
|
||
@Test | ||
public void shouldNotHaveBaseUrlAfterCreation() { | ||
assertThat(interceptor.getBaseUrl()).isNull(); | ||
} | ||
|
||
@Test | ||
public void shouldStoreBaseUrl() { | ||
interceptor.setBaseUrl(BASE_URL); | ||
assertThat(interceptor.getBaseUrl()).isEqualTo(BASE_URL); | ||
} | ||
} |
This file contains 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