-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from auth0/fixed-close-response-body
Ensure closing the response body after it was parsed
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
auth0/src/main/java/com/auth0/android/request/internal/ResponseUtils.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,19 @@ | ||
package com.auth0.android.request.internal; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
||
class ResponseUtils { | ||
|
||
/** | ||
* Attempts to close a stream. No exception will be thrown if an IOException was raised. | ||
* | ||
* @param closeable the stream to close | ||
*/ | ||
static void closeStream(Closeable closeable) { | ||
try { | ||
closeable.close(); | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
auth0/src/test/java/com/auth0/android/request/internal/ResponseUtilsTest.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,24 @@ | ||
package com.auth0.android.request.internal; | ||
|
||
import com.squareup.okhttp.ResponseBody; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class ResponseUtilsTest { | ||
|
||
@Rule | ||
public ExpectedException exception = ExpectedException.none(); | ||
|
||
@Test | ||
public void shouldCloseBody() throws Exception { | ||
ResponseBody body = mock(ResponseBody.class); | ||
ResponseUtils.closeStream(body); | ||
|
||
verify(body).close(); | ||
} | ||
} |