-
Notifications
You must be signed in to change notification settings - Fork 147
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 #503 from auth0/fix-json-header
Fix bug parsing content type headers
- Loading branch information
Showing
2 changed files
with
70 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
auth0/src/test/java/com/auth0/android/request/ServerResponseTest.kt
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,65 @@ | ||
package com.auth0.android.request | ||
|
||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import org.mockito.Mockito.mock | ||
import java.io.InputStream | ||
|
||
public class ServerResponseTest { | ||
|
||
@Test | ||
public fun shouldDetectSuccessfulResponse() { | ||
val responseSuccess = ServerResponse( | ||
200, | ||
mock(InputStream::class.java), | ||
emptyMap() | ||
) | ||
val responseNoContent = ServerResponse( | ||
204, | ||
mock(InputStream::class.java), | ||
emptyMap() | ||
) | ||
assertTrue(responseSuccess.isSuccess()) | ||
assertTrue(responseNoContent.isSuccess()) | ||
} | ||
|
||
@Test | ||
public fun shouldDetectFailedResponse() { | ||
val responseMultipleChoices = ServerResponse( | ||
300, | ||
mock(InputStream::class.java), | ||
emptyMap() | ||
) | ||
val responseUnauthorized = ServerResponse( | ||
401, | ||
mock(InputStream::class.java), | ||
emptyMap() | ||
) | ||
assertFalse(responseMultipleChoices.isSuccess()) | ||
assertFalse(responseUnauthorized.isSuccess()) | ||
} | ||
|
||
@Test | ||
public fun shouldDetectJsonContentHeader() { | ||
val responseMixed = ServerResponse( | ||
200, | ||
mock(InputStream::class.java), | ||
mapOf("Content-Type" to listOf("application/json")) | ||
) | ||
val responseLower = ServerResponse( | ||
200, | ||
mock(InputStream::class.java), | ||
mapOf("content-type" to listOf("application/json")) | ||
) | ||
val responseUpper = ServerResponse( | ||
200, | ||
mock(InputStream::class.java), | ||
mapOf("CONTENT-TYPE" to listOf("application/json")) | ||
) | ||
|
||
assertTrue(responseMixed.isJson()) | ||
assertTrue(responseLower.isJson()) | ||
assertTrue(responseUpper.isJson()) | ||
} | ||
} |