@@ -35,6 +35,34 @@ class SessionSerializationTest {
3535 " b2d0224b-4b1f-49db-94c9-fd4a439b3ef5" ,
3636 " anr_foreground" ,
3737 )
38+
39+ /* *
40+ * An unhandled session cannot be built by mutating [getSut]: the flag is only reachable through
41+ * [Session.recordNonTerminatingUnhandledError], which no-ops unless the session is still `Ok`,
42+ * and a crash would clear it again. Ending on a fixed timestamp keeps `seq` and `duration`
43+ * deterministic.
44+ */
45+ fun getUnhandledSut () =
46+ Session (
47+ Session .State .Ok ,
48+ DateUtils .getDateTime(" 1945-06-16T06:36:49.000Z" ),
49+ DateUtils .getDateTime(" 1970-04-21T09:32:21.000Z" ),
50+ 9001 ,
51+ " 631693c2-3d61-4a93-8fd1-89817426ba5a" ,
52+ " 3c1ffc32-f68f-4af2-a1ee-dd72f4d62d17" ,
53+ true ,
54+ 4 ,
55+ 5.5 ,
56+ " 5a174e69-a297-4ba4-b6e1-2244a8299ec8" ,
57+ " 790da4ae-50ca-48a2-98f6-9b7f4e05a8c3" ,
58+ " d732be55-b57e-48ec-afe6-b0040c7f93de" ,
59+ " b2d0224b-4b1f-49db-94c9-fd4a439b3ef5" ,
60+ null ,
61+ )
62+ .apply {
63+ recordNonTerminatingUnhandledError()
64+ end(DateUtils .getDateTime(" 1970-04-21T09:32:21.000Z" ))
65+ }
3866 }
3967
4068 private val fixture = Fixture ()
@@ -55,23 +83,19 @@ class SessionSerializationTest {
5583 }
5684
5785 @Test
58- fun `serialize and deserialize round-trips Unhandled status and non-terminating flag` () {
59- val session = Session (null , null , " environment" , " release" )
60- session.recordNonTerminatingUnhandledError()
61- session.end()
62- assertThat(session.status).isEqualTo(Session .State .Unhandled )
63-
64- val deserialized = deserialize(serialize(session))
65-
66- assertThat(deserialized.status).isEqualTo(Session .State .Unhandled )
67- assertThat(deserialized.hasNonTerminatingUnhandledError()).isTrue()
86+ fun serializeUnhandled () {
87+ val expected = sanitizedFile(" json/session_unhandled.json" )
88+ val actual = serialize(fixture.getUnhandledSut())
89+ assertThat(actual).isEqualTo(expected)
6890 }
6991
7092 @Test
71- fun `non-terminating flag is omitted when unset` () {
72- val session = Session (null , null , " environment" , " release" )
73-
74- assertThat(serialize(session)).doesNotContain(" non_terminating_unhandled_error" )
93+ fun deserializeUnhandled () {
94+ val expectedJson = sanitizedFile(" json/session_unhandled.json" )
95+ val actual = deserialize(expectedJson)
96+ assertThat(actual.status).isEqualTo(Session .State .Unhandled )
97+ assertThat(actual.hasNonTerminatingUnhandledError()).isTrue()
98+ assertThat(serialize(actual)).isEqualTo(expectedJson)
7599 }
76100
77101 // Helper
0 commit comments