This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
MainEventProcessorTest.kt
65 lines (54 loc) · 2.22 KB
/
MainEventProcessorTest.kt
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
package io.sentry.core
import com.nhaarman.mockitokotlin2.mock
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertSame
import kotlin.test.assertTrue
class MainEventProcessorTest {
class Fixture {
private val sentryOptions: SentryOptions = SentryOptions().apply {
dsn = dsnString
release = "release"
environment = "environment"
}
fun getSut() = MainEventProcessor(sentryOptions)
}
private val fixture = Fixture()
@Test
fun `when processing an event from UncaughtExceptionHandlerIntegration, crashed thread is flaged, mechanism added`() {
val sut = fixture.getSut()
val crashedThread = Thread.currentThread()
var event = generateCrashedEvent(crashedThread)
event = sut.process(event, null)
assertSame(crashedThread.id, event.exceptions.first().threadId)
assertTrue(event.threads.first { t -> t.id == crashedThread.id }.isCrashed)
assertFalse(event.exceptions.first().mechanism.isHandled)
}
@Test
fun `When hint is not Cached, data should be applied`() {
val sut = fixture.getSut()
val crashedThread = Thread.currentThread()
var event = generateCrashedEvent(crashedThread)
event = sut.process(event, null)
assertEquals("release", event.release)
assertEquals("environment", event.environment)
assertTrue(event.threads.first { t -> t.id == crashedThread.id }.isCrashed)
}
@Test
fun `When hint is Cached, data should not be applied`() {
val sut = fixture.getSut()
val crashedThread = Thread.currentThread()
var event = generateCrashedEvent(crashedThread)
event = sut.process(event, CachedEvent())
assertNull(event.release)
assertNull(event.environment)
assertNull(event.threads)
}
private fun generateCrashedEvent(crashedThread: Thread = Thread.currentThread()) = SentryEvent().apply {
val mockThrowable = mock<Throwable>()
val actualThrowable = UncaughtExceptionHandlerIntegration.getUnhandledThrowable(crashedThread, mockThrowable)
throwable = actualThrowable
}
}