-
Notifications
You must be signed in to change notification settings - Fork 66
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
eea8ccd
commit 61773e3
Showing
7 changed files
with
89 additions
and
18 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
27 changes: 27 additions & 0 deletions
27
core/src/main/java/com/mapzen/android/core/http/CallRequest.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,27 @@ | ||
package com.mapzen.android.core.http; | ||
|
||
import retrofit2.Call; | ||
|
||
/** | ||
* Default {@link Request} implementation. | ||
*/ | ||
public class CallRequest implements Request { | ||
|
||
private Call call; | ||
|
||
/** | ||
* Public constructor. | ||
* @param call | ||
*/ | ||
public CallRequest(Call call) { | ||
this.call = call; | ||
} | ||
|
||
@Override public boolean isCanceled() { | ||
return call.isCanceled(); | ||
} | ||
|
||
@Override public void cancel() { | ||
call.cancel(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
core/src/main/java/com/mapzen/android/core/http/Request.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,15 @@ | ||
package com.mapzen.android.core.http; | ||
|
||
/** | ||
* Generic interface for objects abstracting http requests. | ||
*/ | ||
public interface Request { | ||
/** | ||
* Returns whether or not the request has been canceled. | ||
*/ | ||
boolean isCanceled(); | ||
/** | ||
* Cancels the request. | ||
*/ | ||
void cancel(); | ||
} |
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
25 changes: 25 additions & 0 deletions
25
core/src/test/java/com/mapzen/android/core/http/CallRequestTest.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,25 @@ | ||
package com.mapzen.android.core.http; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import retrofit2.Call; | ||
|
||
public class CallRequestTest { | ||
|
||
Call call = mock(Call.class); | ||
CallRequest request = new CallRequest(call); | ||
|
||
@Test | ||
public void cancel_shouldCancelCall() throws Exception { | ||
request.cancel(); | ||
verify(call).cancel(); | ||
} | ||
|
||
@Test | ||
public void isCanceled_shouldCallCall() throws Exception { | ||
request.isCanceled(); | ||
verify(call).isCanceled(); | ||
} | ||
} |
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