Skip to content

Commit ac7be23

Browse files
committed
GestureListener tests
1 parent c124eb1 commit ac7be23

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureListenerTracingTest.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import io.sentry.android.core.SentryAndroidOptions
2424
import io.sentry.protocol.SentryId
2525
import io.sentry.protocol.TransactionNameSource
2626
import org.mockito.ArgumentCaptor
27+
import org.mockito.ArgumentMatchers
2728
import org.mockito.kotlin.any
29+
import org.mockito.kotlin.argThat
2830
import org.mockito.kotlin.check
2931
import org.mockito.kotlin.clearInvocations
3032
import org.mockito.kotlin.doAnswer
@@ -37,6 +39,7 @@ import kotlin.test.Test
3739
import kotlin.test.assertEquals
3840
import kotlin.test.assertNotNull
3941
import kotlin.test.assertNull
42+
import kotlin.test.assertNotEquals
4043

4144
class SentryGestureListenerTracingTest {
4245
class Fixture {
@@ -59,12 +62,14 @@ class SentryGestureListenerTracingTest {
5962
hasViewIdInRes: Boolean = true,
6063
tracesSampleRate: Double? = 1.0,
6164
isEnableUserInteractionTracing: Boolean = true,
62-
transaction: SentryTracer? = null
65+
transaction: SentryTracer? = null,
66+
isEnableAutoTraceIdGeneration: Boolean = true
6367
): SentryGestureListener {
6468
options.tracesSampleRate = tracesSampleRate
6569
options.isEnableUserInteractionTracing = isEnableUserInteractionTracing
6670
options.isEnableUserInteractionBreadcrumbs = true
6771
options.gestureTargetLocators = listOf(AndroidViewGestureTargetLocator(true))
72+
options.isEnableAutoTraceIdGeneration = isEnableAutoTraceIdGeneration
6873

6974
whenever(scopes.options).thenReturn(options)
7075

@@ -370,6 +375,34 @@ class SentryGestureListenerTracingTest {
370375
assertEquals(OUT_OF_RANGE, fixture.transaction.status)
371376
}
372377

378+
@Test
379+
fun `when tracing is disabled and auto trace id generation is disabled, does not start a new trace`() {
380+
val sut = fixture.getSut<View>(tracesSampleRate = null, isEnableAutoTraceIdGeneration = false)
381+
val scope = Scope(fixture.options)
382+
383+
sut.onSingleTapUp(fixture.event)
384+
385+
verify(fixture.scopes, never()).configureScope(any())
386+
}
387+
388+
@Test
389+
fun `when tracing is disabled and auto trace id generation is enabled, starts a new trace`() {
390+
val sut = fixture.getSut<View>(tracesSampleRate = null, isEnableAutoTraceIdGeneration = true)
391+
val scope = Scope(fixture.options)
392+
val initialPropagationContext = scope.propagationContext
393+
394+
sut.onSingleTapUp(fixture.event)
395+
396+
verify(fixture.scopes).configureScope(
397+
check { callback ->
398+
callback.run(scope)
399+
// Verify that a new propagation context was set and it's different from the initial one
400+
assertNotNull(scope.propagationContext)
401+
assertNotEquals(initialPropagationContext, scope.propagationContext)
402+
}
403+
)
404+
}
405+
373406
internal open class ScrollableListView : AbsListView(mock()) {
374407
override fun getAdapter(): ListAdapter = mock()
375408
override fun setSelection(position: Int) = Unit

0 commit comments

Comments
 (0)