-
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 91b5e43
Showing
11 changed files
with
84 additions
and
70 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 java.io.IOException; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
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! | ||
*/ | ||
@Singleton | ||
public class HostSelectionInterceptor implements Interceptor { | ||
|
||
private volatile String baseUrl; | ||
|
||
@Inject | ||
public HostSelectionInterceptor() { | ||
// Add a no-argument constructor with the @Inject annotation to indicate that Dagger may create instances. | ||
} | ||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
final String host = baseUrl; | ||
if (host != null) { | ||
final HttpUrl newUrl = request.url() | ||
.newBuilder() | ||
.host(host) | ||
.build(); | ||
request = request.newBuilder() | ||
.url(newUrl) | ||
.build(); | ||
} | ||
return chain.proceed(request); | ||
} | ||
|
||
public void setBaseUrl(String baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
public String getBaseUrl() { | ||
return baseUrl; | ||
} | ||
} |
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