33
33
34
34
import com .google .android .gms .tasks .Task ;
35
35
import com .google .android .gms .tasks .Tasks ;
36
- import com .google .firebase .concurrent .TestOnlyExecutors ;
37
- import com .google .firebase .crashlytics .internal .CrashlyticsWorker ;
38
36
import com .google .firebase .crashlytics .internal .metadata .LogFileManager ;
39
37
import com .google .firebase .crashlytics .internal .metadata .UserMetadata ;
40
38
import com .google .firebase .crashlytics .internal .model .CrashlyticsReport ;
@@ -71,8 +69,6 @@ public class SessionReportingCoordinatorTest {
71
69
72
70
private SessionReportingCoordinator reportingCoordinator ;
73
71
74
- private CrashlyticsWorker diskWriteWorker = new CrashlyticsWorker (TestOnlyExecutors .background ());
75
-
76
72
@ Before
77
73
public void setUp () {
78
74
MockitoAnnotations .initMocks (this );
@@ -84,8 +80,7 @@ public void setUp() {
84
80
reportSender ,
85
81
logFileManager ,
86
82
reportMetadata ,
87
- idManager ,
88
- diskWriteWorker );
83
+ idManager );
89
84
}
90
85
91
86
@ Test
@@ -121,8 +116,7 @@ public void testFatalEvent_persistsHighPriorityEventWithAllThreadsForSessionId()
121
116
}
122
117
123
118
@ Test
124
- public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSessionId ()
125
- throws Exception {
119
+ public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSessionId () {
126
120
final String eventType = "error" ;
127
121
final String sessionId = "testSessionId" ;
128
122
final long timestamp = System .currentTimeMillis ();
@@ -132,8 +126,6 @@ public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSes
132
126
reportingCoordinator .onBeginSession (sessionId , timestamp );
133
127
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
134
128
135
- diskWriteWorker .await ();
136
-
137
129
final boolean expectedAllThreads = false ;
138
130
final boolean expectedHighPriority = false ;
139
131
@@ -144,7 +136,7 @@ public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSes
144
136
}
145
137
146
138
@ Test
147
- public void testNonFatalEvent_addsLogsToEvent () throws Exception {
139
+ public void testNonFatalEvent_addsLogsToEvent () {
148
140
long timestamp = System .currentTimeMillis ();
149
141
150
142
mockEventInteractions ();
@@ -157,16 +149,14 @@ public void testNonFatalEvent_addsLogsToEvent() throws Exception {
157
149
reportingCoordinator .onBeginSession (sessionId , timestamp );
158
150
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
159
151
160
- diskWriteWorker .await ();
161
-
162
152
verify (mockEventBuilder )
163
153
.setLog (CrashlyticsReport .Session .Event .Log .builder ().setContent (testLog ).build ());
164
154
verify (mockEventBuilder ).build ();
165
155
verify (logFileManager , never ()).clearLog ();
166
156
}
167
157
168
158
@ Test
169
- public void testNonFatalEvent_addsNoLogsToEventWhenNoneAvailable () throws Exception {
159
+ public void testNonFatalEvent_addsNoLogsToEventWhenNoneAvailable () {
170
160
long timestamp = System .currentTimeMillis ();
171
161
172
162
mockEventInteractions ();
@@ -178,8 +168,6 @@ public void testNonFatalEvent_addsNoLogsToEventWhenNoneAvailable() throws Except
178
168
reportingCoordinator .onBeginSession (sessionId , timestamp );
179
169
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
180
170
181
- diskWriteWorker .await ();
182
-
183
171
verify (mockEventBuilder , never ()).setLog (any (CrashlyticsReport .Session .Event .Log .class ));
184
172
verify (mockEventBuilder ).build ();
185
173
verify (logFileManager , never ()).clearLog ();
@@ -224,7 +212,7 @@ public void testFatalEvent_addsNoLogsToEventWhenNoneAvailable() {
224
212
}
225
213
226
214
@ Test
227
- public void testNonFatalEvent_addsSortedKeysToEvent () throws Exception {
215
+ public void testNonFatalEvent_addsSortedKeysToEvent () {
228
216
final long timestamp = System .currentTimeMillis ();
229
217
230
218
mockEventInteractions ();
@@ -255,8 +243,6 @@ public void testNonFatalEvent_addsSortedKeysToEvent() throws Exception {
255
243
reportingCoordinator .onBeginSession (sessionId , timestamp );
256
244
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
257
245
258
- diskWriteWorker .await ();
259
-
260
246
verify (mockEventAppBuilder ).setCustomAttributes (expectedCustomAttributes );
261
247
verify (mockEventAppBuilder ).setInternalKeys (expectedCustomAttributes );
262
248
verify (mockEventAppBuilder ).build ();
@@ -266,7 +252,7 @@ public void testNonFatalEvent_addsSortedKeysToEvent() throws Exception {
266
252
}
267
253
268
254
@ Test
269
- public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable () throws Exception {
255
+ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable () {
270
256
final long timestamp = System .currentTimeMillis ();
271
257
272
258
mockEventInteractions ();
@@ -280,8 +266,6 @@ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable() throws Except
280
266
reportingCoordinator .onBeginSession (sessionId , timestamp );
281
267
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
282
268
283
- diskWriteWorker .await ();
284
-
285
269
verify (mockEventAppBuilder , never ()).setCustomAttributes (anyList ());
286
270
verify (mockEventAppBuilder , never ()).build ();
287
271
verify (mockEventBuilder , never ()).setApp (mockEventApp );
@@ -290,7 +274,7 @@ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable() throws Except
290
274
}
291
275
292
276
@ Test
293
- public void testNonFatalEvent_addRolloutsEvent () throws Exception {
277
+ public void testNonFatalEvent_addRolloutsEvent () {
294
278
long timestamp = System .currentTimeMillis ();
295
279
String sessionId = "testSessionId" ;
296
280
mockEventInteractions ();
@@ -303,8 +287,6 @@ public void testNonFatalEvent_addRolloutsEvent() throws Exception {
303
287
reportingCoordinator .onBeginSession (sessionId , timestamp );
304
288
reportingCoordinator .persistNonFatalEvent (mockException , mockThread , sessionId , timestamp );
305
289
306
- diskWriteWorker .await ();
307
-
308
290
verify (mockEventAppBuilder , never ()).setCustomAttributes (anyList ());
309
291
verify (mockEventAppBuilder , never ()).build ();
310
292
verify (mockEventBuilder , never ()).setApp (mockEventApp );
@@ -435,6 +417,35 @@ public void testFatalEvent_addRolloutsToEvent() {
435
417
verify (mockEventBuilder , times (2 )).build ();
436
418
}
437
419
420
+ @ Test
421
+ public void onLog_writesToLogFileManager () {
422
+ long timestamp = System .currentTimeMillis ();
423
+ String log = "this is a log" ;
424
+
425
+ reportingCoordinator .onLog (timestamp , log );
426
+
427
+ verify (logFileManager ).writeToLog (timestamp , log );
428
+ }
429
+
430
+ @ Test
431
+ public void onCustomKey_writesToReportMetadata () {
432
+ final String key = "key" ;
433
+ final String value = "value" ;
434
+
435
+ reportingCoordinator .onCustomKey (key , value );
436
+
437
+ verify (reportMetadata ).setCustomKey (key , value );
438
+ }
439
+
440
+ @ Test
441
+ public void onUserId_writesUserToReportMetadata () {
442
+ final String userId = "testUser" ;
443
+
444
+ reportingCoordinator .onUserId (userId );
445
+
446
+ verify (reportMetadata ).setUserId (userId );
447
+ }
448
+
438
449
@ Test
439
450
public void testFinalizeSessionWithNativeEvent_createsCrashlyticsReportWithNativePayload () {
440
451
byte [] testBytes = {0 , 2 , 20 , 10 };
0 commit comments