Skip to content

Commit 9016498

Browse files
committed
unit tests
./gradlew :sentry-okhttp:test --tests="*SentryOkHttpEventTest*setNetworkDetails*"
1 parent 5dc9fab commit 9016498

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventTest.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import io.sentry.TransactionContext
1515
import io.sentry.TypeCheckHint
1616
import io.sentry.exception.SentryHttpClientException
1717
import io.sentry.test.getProperty
18+
import io.sentry.util.network.NetworkRequestData
1819
import kotlin.test.Test
1920
import kotlin.test.assertEquals
2021
import kotlin.test.assertFalse
@@ -425,6 +426,34 @@ class SentryOkHttpEventTest {
425426
verify(fixture.scopes, never()).captureEvent(any(), any<Hint>())
426427
}
427428

429+
@Test
430+
fun `when finish is called, the breadcrumb sent includes network details data on its hint`() {
431+
val sut = fixture.getSut()
432+
val networkRequestData = NetworkRequestData("GET")
433+
434+
sut.setNetworkDetails(networkRequestData)
435+
sut.finish()
436+
437+
verify(fixture.scopes)
438+
.addBreadcrumb(
439+
any<Breadcrumb>(),
440+
check { assertEquals(networkRequestData, it[TypeCheckHint.SENTRY_REPLAY_NETWORK_DETAILS]) }
441+
)
442+
}
443+
444+
@Test
445+
fun `when setNetworkDetails is not called, no network details data is captured`() {
446+
val sut = fixture.getSut()
447+
448+
sut.finish()
449+
450+
verify(fixture.scopes)
451+
.addBreadcrumb(
452+
any<Breadcrumb>(),
453+
check { assertNull(it[TypeCheckHint.SENTRY_REPLAY_NETWORK_DETAILS]) }
454+
)
455+
}
456+
428457
/** Retrieve all the spans started in the event using reflection. */
429458
private fun SentryOkHttpEvent.getEventDates() =
430459
getProperty<MutableMap<String, SentryDate>>("eventDates")

0 commit comments

Comments
 (0)