11package io.sentry
22
33import io.sentry.SentryLevel.WARNING
4+ import io.sentry.protocol.Contexts
45import io.sentry.protocol.Request
56import io.sentry.protocol.SentryId
67import io.sentry.protocol.User
@@ -13,6 +14,7 @@ import org.mockito.kotlin.mock
1314import org.mockito.kotlin.never
1415import org.mockito.kotlin.times
1516import org.mockito.kotlin.verify
17+ import org.mockito.kotlin.verifyNoInteractions
1618import org.mockito.kotlin.whenever
1719import java.util.concurrent.CopyOnWriteArrayList
1820import kotlin.test.Test
@@ -339,6 +341,37 @@ class ScopeTest {
339341 assertEquals(1 , scope.breadcrumbs.count())
340342 }
341343
344+ @Test
345+ fun `when adding breadcrumb and maxBreadcrumb is 0, beforeBreadcrumb is not executed` () {
346+ var called = false
347+ val options = SentryOptions ().apply {
348+ maxBreadcrumbs = 0
349+ beforeBreadcrumb = SentryOptions .BeforeBreadcrumbCallback { breadcrumb, _ ->
350+ called = true
351+ breadcrumb
352+ }
353+ }
354+
355+ val scope = Scope (options)
356+ scope.addBreadcrumb(Breadcrumb ())
357+ assertEquals(0 , scope.breadcrumbs.count())
358+ assertFalse(called)
359+ }
360+
361+ @Test
362+ fun `when adding breadcrumb and maxBreadcrumb is 0, scopesObservers are not called` () {
363+ val observer = mock<IScopeObserver >()
364+ val options = SentryOptions ().apply {
365+ maxBreadcrumbs = 0
366+ addScopeObserver(observer)
367+ }
368+
369+ val scope = Scope (options)
370+ scope.addBreadcrumb(Breadcrumb ())
371+ assertEquals(0 , scope.breadcrumbs.count())
372+ verifyNoInteractions(observer)
373+ }
374+
342375 @Test
343376 fun `when adding eventProcessor, eventProcessor should be in the list` () {
344377 val processor = CustomEventProcessor ()
0 commit comments