@@ -14,13 +14,15 @@ import kotlin.test.assertNotSame
1414import kotlin.test.assertNull
1515import kotlin.test.assertTrue
1616import org.junit.Assert.assertArrayEquals
17+ import org.mockito.kotlin.any
1718import org.mockito.kotlin.argThat
1819import org.mockito.kotlin.check
1920import org.mockito.kotlin.eq
2021import org.mockito.kotlin.mock
2122import org.mockito.kotlin.never
2223import org.mockito.kotlin.times
2324import org.mockito.kotlin.verify
25+ import org.mockito.kotlin.verifyNoInteractions
2426import org.mockito.kotlin.whenever
2527
2628class ScopeTest {
@@ -331,6 +333,69 @@ class ScopeTest {
331333 assertEquals(1 , scope.breadcrumbs.count())
332334 }
333335
336+ @Test
337+ fun `when adding breadcrumb and maxBreadcrumb is 0, beforeBreadcrumb is not executed` () {
338+ var called = false
339+ val options =
340+ SentryOptions ().apply {
341+ maxBreadcrumbs = 0
342+ beforeBreadcrumb =
343+ SentryOptions .BeforeBreadcrumbCallback { breadcrumb, _ ->
344+ called = true
345+ breadcrumb
346+ }
347+ }
348+
349+ val scope = Scope (options)
350+ scope.addBreadcrumb(Breadcrumb ())
351+ assertEquals(0 , scope.breadcrumbs.count())
352+ assertFalse(called)
353+ }
354+
355+ @Test
356+ fun `when adding breadcrumb and maxBreadcrumb is not 0, beforeBreadcrumb is executed` () {
357+ var called = false
358+ val options =
359+ SentryOptions ().apply {
360+ beforeBreadcrumb =
361+ SentryOptions .BeforeBreadcrumbCallback { breadcrumb, _ ->
362+ called = true
363+ breadcrumb
364+ }
365+ }
366+
367+ val scope = Scope (options)
368+ scope.addBreadcrumb(Breadcrumb ())
369+ assertEquals(1 , scope.breadcrumbs.count())
370+ assertTrue(called)
371+ }
372+
373+ @Test
374+ fun `when adding breadcrumb and maxBreadcrumb is 0, scopesObservers are not called` () {
375+ val observer = mock<IScopeObserver >()
376+ val options =
377+ SentryOptions ().apply {
378+ maxBreadcrumbs = 0
379+ addScopeObserver(observer)
380+ }
381+
382+ val scope = Scope (options)
383+ scope.addBreadcrumb(Breadcrumb ())
384+ assertEquals(0 , scope.breadcrumbs.count())
385+ verifyNoInteractions(observer)
386+ }
387+
388+ @Test
389+ fun `when adding breadcrumb and maxBreadcrumb is not 0, scopesObservers are called` () {
390+ val observer = mock<IScopeObserver >()
391+ val options = SentryOptions ().apply { addScopeObserver(observer) }
392+
393+ val scope = Scope (options)
394+ scope.addBreadcrumb(Breadcrumb ())
395+ assertEquals(1 , scope.breadcrumbs.count())
396+ verify(observer).addBreadcrumb(any())
397+ }
398+
334399 @Test
335400 fun `when adding eventProcessor, eventProcessor should be in the list` () {
336401 val processor = CustomEventProcessor ()
0 commit comments