@@ -140,7 +140,7 @@ public void testNonFatalEvent_persistsNormalPriorityEventWithoutAllThreadsForSes
140140
141141 reportingCoordinator .onBeginSession (sessionId , timestamp );
142142 reportingCoordinator .persistNonFatalEvent (
143- mockException , mockThread , new EventMetadata (sessionId , timestamp , Map . of () ));
143+ mockException , mockThread , new EventMetadata (sessionId , timestamp ));
144144
145145 crashlyticsWorkers .diskWrite .await ();
146146
@@ -166,7 +166,7 @@ public void testNonFatalEvent_addsLogsToEvent() throws Exception {
166166
167167 reportingCoordinator .onBeginSession (sessionId , timestamp );
168168 reportingCoordinator .persistNonFatalEvent (
169- mockException , mockThread , new EventMetadata (sessionId , timestamp , Map . of () ));
169+ mockException , mockThread , new EventMetadata (sessionId , timestamp ));
170170
171171 crashlyticsWorkers .diskWrite .await ();
172172
@@ -188,7 +188,7 @@ public void testNonFatalEvent_addsNoLogsToEventWhenNoneAvailable() throws Except
188188
189189 reportingCoordinator .onBeginSession (sessionId , timestamp );
190190 reportingCoordinator .persistNonFatalEvent (
191- mockException , mockThread , new EventMetadata (sessionId , timestamp , Map . of () ));
191+ mockException , mockThread , new EventMetadata (sessionId , timestamp ));
192192
193193 crashlyticsWorkers .diskWrite .await ();
194194
@@ -266,7 +266,7 @@ public void testNonFatalEvent_addsSortedKeysToEvent() throws Exception {
266266
267267 reportingCoordinator .onBeginSession (sessionId , timestamp );
268268 reportingCoordinator .persistNonFatalEvent (
269- mockException , mockThread , new EventMetadata (sessionId , timestamp , Map . of () ));
269+ mockException , mockThread , new EventMetadata (sessionId , timestamp ));
270270
271271 crashlyticsWorkers .diskWrite .await ();
272272
@@ -292,7 +292,7 @@ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable() throws Except
292292
293293 reportingCoordinator .onBeginSession (sessionId , timestamp );
294294 reportingCoordinator .persistNonFatalEvent (
295- mockException , mockThread , new EventMetadata (sessionId , timestamp , Map . of () ));
295+ mockException , mockThread , new EventMetadata (sessionId , timestamp ));
296296
297297 crashlyticsWorkers .diskWrite .await ();
298298
@@ -303,6 +303,95 @@ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable() throws Except
303303 verify (logFileManager , never ()).clearLog ();
304304 }
305305
306+ @ Test
307+ public void testNonFatalEvent_addsUserInfoKeysToEventWhenAvailable () throws Exception {
308+ final long timestamp = System .currentTimeMillis ();
309+
310+ mockEventInteractions ();
311+
312+ final String sessionId = "testSessionId" ;
313+
314+ final Map <String , String > attributes = Collections .emptyMap ();
315+ when (reportMetadata .getCustomKeys ()).thenReturn (attributes );
316+
317+ final String testKey1 = "testKey1" ;
318+ final String testValue1 = "testValue1" ;
319+
320+ final Map <String , String > userInfo = new HashMap <>();
321+ userInfo .put (testKey1 , testValue1 );
322+
323+ final CustomAttribute customAttribute1 =
324+ CustomAttribute .builder ().setKey (testKey1 ).setValue (testValue1 ).build ();
325+
326+ final List <CustomAttribute > expectedCustomAttributes = new ArrayList <>();
327+ expectedCustomAttributes .add (customAttribute1 );
328+
329+ reportingCoordinator .onBeginSession (sessionId , timestamp );
330+ reportingCoordinator .persistNonFatalEvent (
331+ mockException , mockThread , new EventMetadata (sessionId , timestamp , userInfo ));
332+
333+ crashlyticsWorkers .diskWrite .await ();
334+
335+ verify (mockEventAppBuilder ).setCustomAttributes (expectedCustomAttributes );
336+ verify (mockEventAppBuilder ).build ();
337+ verify (mockEventBuilder ).setApp (mockEventApp );
338+ verify (mockEventBuilder ).build ();
339+ verify (logFileManager , never ()).clearLog ();
340+ }
341+
342+ @ Test
343+ public void testNonFatalEvent_mergesUserInfoKeysWithCustomKeys () throws Exception {
344+ final long timestamp = System .currentTimeMillis ();
345+
346+ mockEventInteractions ();
347+
348+ final String sessionId = "testSessionId" ;
349+
350+ final String testKey1 = "testKey1" ;
351+ final String testValue1 = "testValue1" ;
352+
353+ final String testKey2 = "testKey2" ;
354+ final String testValue2 = "testValue2" ;
355+
356+ final Map <String , String > attributes = new HashMap <>();
357+ attributes .put (testKey1 , testValue1 );
358+ attributes .put (testKey2 , testValue2 );
359+
360+ when (reportMetadata .getCustomKeys ()).thenReturn (attributes );
361+
362+ final String testValue1UserInfo = "testValue1" ;
363+ final String testKey3 = "testKey3" ;
364+ final String testValue3 = "testValue3" ;
365+
366+ final Map <String , String > userInfo = new HashMap <>();
367+ userInfo .put (testKey1 , testValue1UserInfo );
368+ userInfo .put (testKey3 , testValue3 );
369+
370+ final CustomAttribute customAttribute1 =
371+ CustomAttribute .builder ().setKey (testKey1 ).setValue (testValue1UserInfo ).build ();
372+ final CustomAttribute customAttribute2 =
373+ CustomAttribute .builder ().setKey (testKey2 ).setValue (testValue2 ).build ();
374+ final CustomAttribute customAttribute3 =
375+ CustomAttribute .builder ().setKey (testKey3 ).setValue (testValue3 ).build ();
376+
377+ final List <CustomAttribute > expectedCustomAttributes = new ArrayList <>();
378+ expectedCustomAttributes .add (customAttribute1 );
379+ expectedCustomAttributes .add (customAttribute2 );
380+ expectedCustomAttributes .add (customAttribute3 );
381+
382+ reportingCoordinator .onBeginSession (sessionId , timestamp );
383+ reportingCoordinator .persistNonFatalEvent (
384+ mockException , mockThread , new EventMetadata (sessionId , timestamp , userInfo ));
385+
386+ crashlyticsWorkers .diskWrite .await ();
387+
388+ verify (mockEventAppBuilder ).setCustomAttributes (expectedCustomAttributes );
389+ verify (mockEventAppBuilder ).build ();
390+ verify (mockEventBuilder ).setApp (mockEventApp );
391+ verify (mockEventBuilder ).build ();
392+ verify (logFileManager , never ()).clearLog ();
393+ }
394+
306395 @ Test
307396 public void testNonFatalEvent_addRolloutsEvent () throws Exception {
308397 long timestamp = System .currentTimeMillis ();
@@ -316,7 +405,7 @@ public void testNonFatalEvent_addRolloutsEvent() throws Exception {
316405
317406 reportingCoordinator .onBeginSession (sessionId , timestamp );
318407 reportingCoordinator .persistNonFatalEvent (
319- mockException , mockThread , new EventMetadata (sessionId , timestamp , Map . of () ));
408+ mockException , mockThread , new EventMetadata (sessionId , timestamp ));
320409
321410 crashlyticsWorkers .diskWrite .await ();
322411
0 commit comments