forked from ChuckerTeam/chucker
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from ChuckerTeam/develop
Add tests to format utils (ChuckerTeam#281)
- Loading branch information
Showing
3 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
library/src/test/java/com/chuckerteam/chucker/TestTransactionFactory.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,95 @@ | ||
package com.chuckerteam.chucker | ||
|
||
import com.chuckerteam.chucker.internal.data.entity.HttpTransaction | ||
import java.util.Date | ||
|
||
object TestTransactionFactory { | ||
|
||
internal fun createTransaction(method: String): HttpTransaction { | ||
return HttpTransaction( | ||
id = 0, | ||
requestDate = Date(1300000).time, | ||
responseDate = Date(1300300).time, | ||
tookMs = 1000L, | ||
protocol = "HTTP", | ||
method = method, | ||
url = "http://localhost/getUsers", | ||
host = "localhost", | ||
path = "/getUsers", | ||
scheme = "", | ||
responseTlsVersion = "", | ||
responseCipherSuite = "", | ||
requestContentLength = 1000L, | ||
requestContentType = "application/json", | ||
requestHeaders = null, | ||
requestBody = null, | ||
isRequestBodyPlainText = true, | ||
responseCode = 200, | ||
responseMessage = "OK", | ||
error = null, | ||
responseContentLength = 1000L, | ||
responseContentType = "application/json", | ||
responseHeaders = null, | ||
responseBody = | ||
"""{"field": "value"}""", | ||
isResponseBodyPlainText = true, | ||
responseImageData = null | ||
) | ||
} | ||
|
||
val expectedGetHttpTransaction = | ||
""" | ||
URL: http://localhost/getUsers | ||
Method: GET | ||
Protocol: HTTP | ||
Status: Complete | ||
Response: 200 OK | ||
SSL: No | ||
Request time: ${Date(1300000)} | ||
Response time: ${Date(1300300)} | ||
Duration: 1000 ms | ||
Request size: 1.0 kB | ||
Response size: 1.0 kB | ||
Total size: 2.0 kB | ||
---------- Request ---------- | ||
---------- Response ---------- | ||
{ | ||
"field": "value" | ||
} | ||
""".trimIndent() | ||
|
||
val expectedHttpPostTransaction = | ||
""" | ||
URL: http://localhost/getUsers | ||
Method: POST | ||
Protocol: HTTP | ||
Status: Complete | ||
Response: 200 OK | ||
SSL: No | ||
Request time: ${Date(1300000)} | ||
Response time: ${Date(1300300)} | ||
Duration: 1000 ms | ||
Request size: 1.0 kB | ||
Response size: 1.0 kB | ||
Total size: 2.0 kB | ||
---------- Request ---------- | ||
---------- Response ---------- | ||
{ | ||
"field": "value" | ||
} | ||
""".trimIndent() | ||
} |
47 changes: 47 additions & 0 deletions
47
library/src/test/java/com/chuckerteam/chucker/internal/support/FormatUtilsSharedTextTest.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,47 @@ | ||
package com.chuckerteam.chucker.internal.support | ||
|
||
import android.content.Context | ||
import com.chuckerteam.chucker.R | ||
import com.chuckerteam.chucker.TestTransactionFactory | ||
import com.google.common.truth.Truth | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.Test | ||
|
||
class FormatUtilsSharedTextTest { | ||
|
||
private val contextMock = mockk<Context> { | ||
every { getString(R.string.chucker_url) } returns "URL" | ||
every { getString(R.string.chucker_method) } returns "Method" | ||
every { getString(R.string.chucker_protocol) } returns "Protocol" | ||
every { getString(R.string.chucker_status) } returns "Status" | ||
every { getString(R.string.chucker_response) } returns "Response" | ||
every { getString(R.string.chucker_ssl) } returns "SSL" | ||
every { getString(R.string.chucker_yes) } returns "Yes" | ||
every { getString(R.string.chucker_no) } returns "No" | ||
every { getString(R.string.chucker_request_time) } returns "Request time" | ||
every { getString(R.string.chucker_response_time) } returns "Response time" | ||
every { getString(R.string.chucker_duration) } returns "Duration" | ||
every { getString(R.string.chucker_request_size) } returns "Request size" | ||
every { getString(R.string.chucker_response_size) } returns "Response size" | ||
every { getString(R.string.chucker_total_size) } returns "Total size" | ||
every { getString(R.string.chucker_request) } returns "Request" | ||
every { getString(R.string.chucker_body_omitted) } returns "(encoded or binary body omitted)" | ||
} | ||
|
||
@Test | ||
fun getShareTextForGetTransaction() { | ||
Truth.assertThat( | ||
FormatUtils.getShareText(contextMock, TestTransactionFactory.createTransaction("GET"), false) | ||
) | ||
.isEqualTo(TestTransactionFactory.expectedGetHttpTransaction) | ||
} | ||
|
||
@Test | ||
fun getShareTextForPostTransaction() { | ||
Truth.assertThat( | ||
FormatUtils.getShareText(contextMock, TestTransactionFactory.createTransaction("POST"), false) | ||
) | ||
.isEqualTo(TestTransactionFactory.expectedHttpPostTransaction) | ||
} | ||
} |
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