@@ -14,13 +14,15 @@ import kotlin.test.assertNotSame
14
14
import kotlin.test.assertNull
15
15
import kotlin.test.assertTrue
16
16
import org.junit.Assert.assertArrayEquals
17
+ import org.mockito.kotlin.any
17
18
import org.mockito.kotlin.argThat
18
19
import org.mockito.kotlin.check
19
20
import org.mockito.kotlin.eq
20
21
import org.mockito.kotlin.mock
21
22
import org.mockito.kotlin.never
22
23
import org.mockito.kotlin.times
23
24
import org.mockito.kotlin.verify
25
+ import org.mockito.kotlin.verifyNoInteractions
24
26
import org.mockito.kotlin.whenever
25
27
26
28
class ScopeTest {
@@ -331,6 +333,69 @@ class ScopeTest {
331
333
assertEquals(1 , scope.breadcrumbs.count())
332
334
}
333
335
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
+
334
399
@Test
335
400
fun `when adding eventProcessor, eventProcessor should be in the list` () {
336
401
val processor = CustomEventProcessor ()
0 commit comments