-
Notifications
You must be signed in to change notification settings - Fork 8
/
BackgroundActivityTest.kt
77 lines (70 loc) · 2.9 KB
/
BackgroundActivityTest.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
66
67
68
69
70
71
72
73
74
75
76
77
package io.embrace.android.embracesdk.payload
import com.squareup.moshi.JsonDataException
import io.embrace.android.embracesdk.assertJsonMatchesGoldenFile
import io.embrace.android.embracesdk.deserializeEmptyJsonString
import io.embrace.android.embracesdk.deserializeJsonFromResource
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test
internal class BackgroundActivityTest {
private val info = Session(
sessionId = "fake-session-id",
startTime = 123456789L,
appState = "foreground",
endTime = 987654321L,
number = 5,
messageType = "fake-message-type",
lastHeartbeatTime = 123456780L,
isColdStart = true,
eventIds = listOf("fake-event-id"),
infoLogIds = listOf("fake-info-id"),
warningLogIds = listOf("fake-warn-id"),
errorLogIds = listOf("fake-err-id"),
infoLogsAttemptedToSend = 1,
warnLogsAttemptedToSend = 2,
errorLogsAttemptedToSend = 3,
exceptionError = LegacyExceptionError(),
crashReportId = "fake-crash-id",
endType = Session.LifeEventType.BKGND_STATE,
startType = Session.LifeEventType.BKGND_STATE,
properties = mapOf("fake-key" to "fake-value"),
unhandledExceptions = 1
)
@Test
fun testSerialization() {
assertJsonMatchesGoldenFile("bg_activity_expected.json", info)
}
@Test
fun testDeserialization() {
val obj = deserializeJsonFromResource<Session>("bg_activity_expected.json")
assertNotNull(obj)
with(obj) {
assertEquals("fake-session-id", sessionId)
assertEquals(123456789L, startTime)
assertEquals(987654321L, endTime)
assertEquals(5, number)
assertEquals("foreground", appState)
assertEquals("fake-message-type", messageType)
assertEquals(123456780L, lastHeartbeatTime)
assertTrue(checkNotNull(isColdStart))
assertEquals(listOf("fake-event-id"), eventIds)
assertEquals(listOf("fake-info-id"), infoLogIds)
assertEquals(listOf("fake-warn-id"), warningLogIds)
assertEquals(listOf("fake-err-id"), errorLogIds)
assertEquals(1, infoLogsAttemptedToSend)
assertEquals(2, warnLogsAttemptedToSend)
assertEquals(3, errorLogsAttemptedToSend)
assertEquals("fake-crash-id", crashReportId)
assertEquals(Session.LifeEventType.BKGND_STATE, endType)
assertEquals(Session.LifeEventType.BKGND_STATE, startType)
assertEquals(1, unhandledExceptions)
assertEquals(LegacyExceptionError(), exceptionError)
assertEquals(mapOf("fake-key" to "fake-value"), properties)
}
}
@Test(expected = JsonDataException::class)
fun testEmptyObject() {
deserializeEmptyJsonString<Session>()
}
}