-
-
Notifications
You must be signed in to change notification settings - Fork 426
/
assertions.kt
39 lines (37 loc) · 1.17 KB
/
assertions.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
package io.sentry.test
import com.nhaarman.mockitokotlin2.check
import io.sentry.GsonSerializer
import io.sentry.SentryEnvelope
import io.sentry.SentryEvent
import io.sentry.SentryOptions
import io.sentry.protocol.SentryTransaction
import java.lang.AssertionError
/**
* Verifies is [SentryEnvelope] contains first event matching a predicate.
*/
fun checkEvent(predicate: (SentryEvent) -> Unit): SentryEnvelope {
val options = SentryOptions().apply {
setSerializer(GsonSerializer(SentryOptions()))
}
return check {
val event: SentryEvent? = it.items.first().getEvent(options.serializer)
if (event != null) {
predicate(event)
} else {
throw AssertionError("event is null")
}
}
}
fun checkTransaction(predicate: (SentryTransaction) -> Unit): SentryEnvelope {
val options = SentryOptions().apply {
setSerializer(GsonSerializer(SentryOptions()))
}
return check {
val transaction = it.items.first().getTransaction(options.serializer)
if (transaction != null) {
predicate(transaction)
} else {
throw AssertionError("transaction is null")
}
}
}