-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathSentryTimberIntegrationTest.kt
More file actions
115 lines (94 loc) · 3.02 KB
/
SentryTimberIntegrationTest.kt
File metadata and controls
115 lines (94 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package io.sentry.android.timber
import io.sentry.IScopes
import io.sentry.SentryLevel
import io.sentry.SentryLogLevel
import io.sentry.SentryOptions
import io.sentry.protocol.SdkVersion
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import timber.log.Timber
class SentryTimberIntegrationTest {
private class Fixture {
val scopes = mock<IScopes>()
val options = SentryOptions().apply { sdkVersion = SdkVersion("test", "1.2.3") }
fun getSut(
minEventLevel: SentryLevel = SentryLevel.ERROR,
minBreadcrumbLevel: SentryLevel = SentryLevel.INFO,
minLogsLevel: SentryLogLevel = SentryLogLevel.INFO,
): SentryTimberIntegration =
SentryTimberIntegration(
minEventLevel = minEventLevel,
minBreadcrumbLevel = minBreadcrumbLevel,
minLogLevel = minLogsLevel,
)
}
private val fixture = Fixture()
@BeforeTest
fun beforeTest() {
Timber.uprootAll()
}
@Test
fun `Integrations plants a tree into Timber on register`() {
val sut = fixture.getSut()
sut.register(fixture.scopes, fixture.options)
assertEquals(1, Timber.treeCount())
val trees = Timber.forest()
val first = trees.first()
assertTrue(first is SentryTimberTree)
}
@Test
fun `Integrations plants the SentryTimberTree tree`() {
val sut = fixture.getSut()
sut.register(fixture.scopes, fixture.options)
Timber.e(Throwable())
verify(fixture.scopes).captureEvent(any())
}
@Test
fun `Integrations removes a tree from Timber on close integration`() {
val sut = fixture.getSut()
sut.register(fixture.scopes, fixture.options)
assertEquals(1, Timber.treeCount())
sut.close()
assertEquals(0, Timber.treeCount())
}
@Test
fun `Integrations do not throw if close is called before register`() {
val sut = fixture.getSut()
sut.close()
assertEquals(0, Timber.treeCount())
}
@Test
fun `Integrations pass the right min levels`() {
val sut =
fixture.getSut(
minEventLevel = SentryLevel.INFO,
minBreadcrumbLevel = SentryLevel.DEBUG,
minLogsLevel = SentryLogLevel.TRACE,
)
sut.register(fixture.scopes, fixture.options)
assertEquals(sut.minEventLevel, SentryLevel.INFO)
assertEquals(sut.minBreadcrumbLevel, SentryLevel.DEBUG)
assertEquals(sut.minLogLevel, SentryLogLevel.TRACE)
}
@Test
fun `Integration adds itself to the package list`() {
val sut = fixture.getSut()
sut.register(fixture.scopes, fixture.options)
assertTrue(
fixture.options.sdkVersion!!.packageSet.any {
it.name == "maven:io.sentry:sentry-android-timber" && it.version == BuildConfig.VERSION_NAME
}
)
}
@Test
fun `Integration adds itself to the integration list`() {
val sut = fixture.getSut()
sut.register(fixture.scopes, fixture.options)
assertTrue(fixture.options.sdkVersion!!.integrationSet.contains("Timber"))
}
}