Skip to content

Commit a74f4c6

Browse files
committed
updated changelog
added test
1 parent fe17b7d commit a74f4c6

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- Optimize scope when maxBreadcrumb is 0 ([#4504](https://github.com/getsentry/sentry-java/pull/4504))
78
- No longer send out empty log envelopes ([#4497](https://github.com/getsentry/sentry-java/pull/4497))
89

910
### Dependencies

sentry/src/test/java/io/sentry/ScopeTest.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry
22

33
import io.sentry.SentryLevel.WARNING
4+
import io.sentry.protocol.Contexts
45
import io.sentry.protocol.Request
56
import io.sentry.protocol.SentryId
67
import io.sentry.protocol.User
@@ -13,6 +14,7 @@ import org.mockito.kotlin.mock
1314
import org.mockito.kotlin.never
1415
import org.mockito.kotlin.times
1516
import org.mockito.kotlin.verify
17+
import org.mockito.kotlin.verifyNoInteractions
1618
import org.mockito.kotlin.whenever
1719
import java.util.concurrent.CopyOnWriteArrayList
1820
import 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

Comments
 (0)