Skip to content

Commit

Permalink
Add description into empty body items during export (ChuckerTeam#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuberen authored Apr 7, 2020
1 parent 871f916 commit 9106c3c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ internal object FormatUtils {
}

text += if (transaction.isRequestBodyPlainText) {
transaction.getFormattedRequestBody()
if (transaction.requestBody.isNullOrBlank()) {
context.getString(R.string.chucker_body_empty)
} else {
transaction.getFormattedRequestBody()
}
} else {
context.getString(R.string.chucker_body_omitted)
}
Expand All @@ -135,7 +139,11 @@ internal object FormatUtils {
}

text += if (transaction.isResponseBodyPlainText) {
transaction.getFormattedResponseBody()
if (transaction.responseBody.isNullOrBlank()) {
context.getString(R.string.chucker_body_empty)
} else {
transaction.getFormattedResponseBody()
}
} else {
context.getString(R.string.chucker_body_omitted)
}
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<string name="chucker_save_failed_to_open_document">Failed to open file chooser</string>
<string name="chucker_file_saved">File was saved successfully!</string>
<string name="chucker_file_not_saved">Failed to save file</string>
<string name="chucker_body_empty">(body is empty)</string>
<string name="chucker_body_omitted">(encoded or binary body omitted)</string>
<string name="chucker_search">Search</string>
<string name="chucker_body_unexpected_eof">\n\n--- Unexpected end of content ---</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object TestTransactionFactory {
---------- Request ----------
(body is empty)
---------- Response ----------
Expand Down Expand Up @@ -84,7 +84,7 @@ object TestTransactionFactory {
---------- Request ----------
(body is empty)
---------- Response ----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 com.google.common.truth.Truth.assertThat
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Test
Expand All @@ -27,18 +27,19 @@ class FormatUtilsSharedTextTest {
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)"
every { getString(R.string.chucker_body_empty) } returns "(body is empty)"
}

@Test
fun getShareTextForGetTransaction() {
val shareText = getShareText("GET")
Truth.assertThat(shareText).isEqualTo(TestTransactionFactory.expectedGetHttpTransaction)
assertThat(shareText).isEqualTo(TestTransactionFactory.expectedGetHttpTransaction)
}

@Test
fun getShareTextForPostTransaction() {
val shareText = getShareText("POST")
Truth.assertThat(shareText).isEqualTo(TestTransactionFactory.expectedHttpPostTransaction)
assertThat(shareText).isEqualTo(TestTransactionFactory.expectedHttpPostTransaction)
}

private fun getShareText(method: String): String {
Expand Down

0 comments on commit 9106c3c

Please sign in to comment.