26
26
import static com .google .firebase .appdistribution .impl .ErrorMessages .NETWORK_ERROR ;
27
27
import static com .google .firebase .appdistribution .impl .ErrorMessages .RELEASE_NOT_FOUND_ERROR ;
28
28
import static com .google .firebase .appdistribution .impl .ErrorMessages .UPDATE_CANCELED ;
29
+ import static com .google .firebase .appdistribution .impl .TestUtils .awaitAsyncOperations ;
30
+ import static com .google .firebase .appdistribution .impl .TestUtils .awaitTask ;
31
+ import static com .google .firebase .appdistribution .impl .TestUtils .awaitTaskFailure ;
32
+ import static com .google .firebase .appdistribution .impl .TestUtils .awaitTermination ;
33
+ import static com .google .firebase .appdistribution .impl .TestUtils .mockForegroundActivity ;
29
34
import static org .junit .Assert .assertEquals ;
30
35
import static org .junit .Assert .assertFalse ;
31
36
import static org .junit .Assert .assertNull ;
@@ -181,7 +186,7 @@ public void setup() throws FirebaseAppDistributionException {
181
186
shadowPackageManager .installPackage (packageInfo );
182
187
183
188
activity = spy (Robolectric .buildActivity (TestActivity .class ).create ().get ());
184
- TestUtils . mockForegroundActivity (mockLifecycleNotifier , activity );
189
+ mockForegroundActivity (mockLifecycleNotifier , activity );
185
190
}
186
191
187
192
@ Test
@@ -194,7 +199,7 @@ public void checkForNewRelease_whenCheckForNewReleaseFails_throwsError() {
194
199
195
200
Task <AppDistributionRelease > task = firebaseAppDistribution .checkForNewRelease ();
196
201
197
- TestUtils . awaitTaskFailure (task , NETWORK_FAILURE , JSON_PARSING_ERROR );
202
+ awaitTaskFailure (task , NETWORK_FAILURE , JSON_PARSING_ERROR );
198
203
}
199
204
200
205
@ Test
@@ -203,7 +208,7 @@ public void checkForNewRelease_testerIsNotSignedIn_taskFails() {
203
208
204
209
Task <AppDistributionRelease > task = firebaseAppDistribution .checkForNewRelease ();
205
210
206
- TestUtils . awaitTaskFailure (task , AUTHENTICATION_FAILURE , "Tester is not signed in" );
211
+ awaitTaskFailure (task , AUTHENTICATION_FAILURE , "Tester is not signed in" );
207
212
}
208
213
209
214
@ Test
@@ -213,7 +218,7 @@ public void checkForNewRelease_whenCheckForNewReleaseSucceeds_returnsRelease()
213
218
when (mockNewReleaseFetcher .checkForNewRelease ()).thenReturn (Tasks .forResult (internalRelease ));
214
219
215
220
Task <AppDistributionRelease > task = firebaseAppDistribution .checkForNewRelease ();
216
- TestUtils . awaitTask (task );
221
+ awaitTask (task );
217
222
218
223
assertEquals (TEST_RELEASE_NEWER_AAB , task .getResult ());
219
224
assertEquals (internalRelease , firebaseAppDistribution .getCachedNewRelease ().getSnapshot ());
@@ -228,8 +233,8 @@ public void checkForNewRelease_authenticationFailure_signOutTester() throws Inte
228
233
229
234
Task <AppDistributionRelease > task = firebaseAppDistribution .checkForNewRelease ();
230
235
231
- TestUtils . awaitTaskFailure (task , AUTHENTICATION_FAILURE , "Test" );
232
- TestUtils . awaitTermination (testExecutor );
236
+ awaitTaskFailure (task , AUTHENTICATION_FAILURE , "Test" );
237
+ awaitTermination (testExecutor );
233
238
verify (mockSignInStorage , times (1 )).setSignInStatus (false );
234
239
}
235
240
@@ -239,7 +244,7 @@ public void updateApp_whenNotSignedIn_throwsError() {
239
244
240
245
UpdateTask updateTask = firebaseAppDistribution .updateApp ();
241
246
242
- TestUtils . awaitTaskFailure (updateTask , AUTHENTICATION_FAILURE , "Tester is not signed in" );
247
+ awaitTaskFailure (updateTask , AUTHENTICATION_FAILURE , "Tester is not signed in" );
243
248
}
244
249
245
250
@ Test
@@ -249,7 +254,7 @@ public void updateIfNewReleaseAvailable_whenNewAabReleaseAvailable_showsUpdateDi
249
254
.thenReturn (Tasks .forResult ((TEST_RELEASE_NEWER_AAB_INTERNAL )));
250
255
251
256
firebaseAppDistribution .updateIfNewReleaseAvailable ();
252
- TestUtils . awaitAsyncOperations (testExecutor );
257
+ awaitAsyncOperations (testExecutor );
253
258
254
259
AlertDialog dialog = assertAlertDialogShown ();
255
260
assertEquals (
@@ -269,7 +274,7 @@ public void updateIfNewReleaseAvailable_fromABackgroundThread_showsUpdateDialog(
269
274
270
275
ExecutorService executorService = Executors .newSingleThreadExecutor ();
271
276
executorService .submit (() -> firebaseAppDistribution .updateIfNewReleaseAvailable ());
272
- TestUtils . awaitAsyncOperations (executorService );
277
+ awaitAsyncOperations (executorService );
273
278
274
279
assertAlertDialogShown ();
275
280
}
@@ -283,7 +288,7 @@ public void updateIfNewReleaseAvailable_whenReleaseNotesEmpty_doesNotShowRelease
283
288
(TEST_RELEASE_NEWER_AAB_INTERNAL .toBuilder ().setReleaseNotes ("" ).build ())));
284
289
285
290
firebaseAppDistribution .updateIfNewReleaseAvailable ();
286
- TestUtils . awaitAsyncOperations (testExecutor );
291
+ awaitAsyncOperations (testExecutor );
287
292
288
293
AlertDialog dialog = assertAlertDialogShown ();
289
294
assertEquals (
@@ -302,7 +307,7 @@ public void updateIfNewReleaseAvailable_whenNoReleaseAvailable_updateDialogNotSh
302
307
303
308
List <UpdateProgress > progressEvents = new ArrayList <>();
304
309
task .addOnProgressListener (FirebaseExecutors .directExecutor (), progressEvents ::add );
305
- TestUtils . awaitTermination (testExecutor );
310
+ awaitTermination (testExecutor );
306
311
307
312
assertEquals (1 , progressEvents .size ());
308
313
assertEquals (UpdateStatus .NEW_RELEASE_NOT_AVAILABLE , progressEvents .get (0 ).getUpdateStatus ());
@@ -318,7 +323,7 @@ public void updateIfNewReleaseAvailable_whenActivityBackgrounded_updateDialogNot
318
323
319
324
List <UpdateProgress > progressEvents = new ArrayList <>();
320
325
task .addOnProgressListener (FirebaseExecutors .directExecutor (), progressEvents ::add );
321
- TestUtils . awaitTermination (testExecutor );
326
+ awaitTermination (testExecutor );
322
327
323
328
assertEquals (1 , progressEvents .size ());
324
329
assertEquals (UpdateStatus .NEW_RELEASE_NOT_AVAILABLE , progressEvents .get (0 ).getUpdateStatus ());
@@ -339,7 +344,7 @@ public void updateIfNewReleaseAvailable_whenSignInCancelled_checkForUpdateNotCal
339
344
AlertDialog signInDialog = assertAlertDialogShown ();
340
345
signInDialog .getButton (DialogInterface .BUTTON_POSITIVE ).performClick ();
341
346
342
- TestUtils . awaitTaskFailure (
347
+ awaitTaskFailure (
343
348
updateTask , AUTHENTICATION_CANCELED , ErrorMessages .AUTHENTICATION_CANCELED );
344
349
verify (mockTesterSignInManager , times (1 )).signInTester ();
345
350
verify (mockNewReleaseFetcher , never ()).checkForNewRelease ();
@@ -359,7 +364,7 @@ public void updateIfNewReleaseAvailable_whenSignInFailed_checkForUpdateNotCalled
359
364
AlertDialog signInDialog = assertAlertDialogShown ();
360
365
signInDialog .getButton (DialogInterface .BUTTON_POSITIVE ).performClick ();
361
366
362
- TestUtils . awaitTaskFailure (updateTask , AUTHENTICATION_FAILURE , AUTHENTICATION_ERROR );
367
+ awaitTaskFailure (updateTask , AUTHENTICATION_FAILURE , AUTHENTICATION_ERROR );
363
368
}
364
369
365
370
@ Test
@@ -369,12 +374,12 @@ public void updateIfNewReleaseAvailable_whenDialogDismissed_taskFails()
369
374
.thenReturn (Tasks .forResult (TEST_RELEASE_NEWER_AAB_INTERNAL ));
370
375
371
376
UpdateTask updateTask = firebaseAppDistribution .updateIfNewReleaseAvailable ();
372
- TestUtils . awaitAsyncOperations (testExecutor );
377
+ awaitAsyncOperations (testExecutor );
373
378
374
379
AlertDialog updateDialog = assertAlertDialogShown ();
375
380
updateDialog .getButton (AlertDialog .BUTTON_NEGATIVE ).performClick (); // dismiss dialog
376
381
377
- TestUtils . awaitTaskFailure (updateTask , INSTALLATION_CANCELED , UPDATE_CANCELED );
382
+ awaitTaskFailure (updateTask , INSTALLATION_CANCELED , UPDATE_CANCELED );
378
383
assertFalse (updateDialog .isShowing ());
379
384
}
380
385
@@ -387,15 +392,15 @@ public void updateIfNewReleaseAvailable_whenDialogCanceled_taskFails()
387
392
UpdateTask updateTask = firebaseAppDistribution .updateIfNewReleaseAvailable ();
388
393
389
394
// Task callbacks happen on the executor
390
- TestUtils . awaitTermination (testExecutor );
395
+ awaitTermination (testExecutor );
391
396
392
397
// Show update confirmation dialog happens on the UI thread
393
398
shadowOf (getMainLooper ()).idle ();
394
399
395
400
AlertDialog updateDialog = assertAlertDialogShown ();
396
401
updateDialog .onBackPressed (); // cancels the dialog
397
402
398
- TestUtils . awaitTaskFailure (updateTask , INSTALLATION_CANCELED , UPDATE_CANCELED );
403
+ awaitTaskFailure (updateTask , INSTALLATION_CANCELED , UPDATE_CANCELED );
399
404
assertFalse (updateDialog .isShowing ());
400
405
}
401
406
@@ -412,7 +417,7 @@ public void updateIfNewReleaseAvailable_whenCheckForUpdateFails_updateAppNotCall
412
417
List <UpdateProgress > progressEvents = new ArrayList <>();
413
418
updateTask .addOnProgressListener (FirebaseExecutors .directExecutor (), progressEvents ::add );
414
419
415
- TestUtils . awaitTaskFailure (updateTask , NETWORK_FAILURE , NETWORK_ERROR );
420
+ awaitTaskFailure (updateTask , NETWORK_FAILURE , NETWORK_ERROR );
416
421
assertEquals (1 , progressEvents .size ());
417
422
assertEquals (UpdateStatus .NEW_RELEASE_CHECK_FAILED , progressEvents .get (0 ).getUpdateStatus ());
418
423
verify (firebaseAppDistribution , never ()).updateApp ();
@@ -425,7 +430,7 @@ public void updateIfNewReleaseAvailable_whenTesterIsSignedIn_doesNotOpenDialog()
425
430
when (mockSignInStorage .getSignInStatus ()).thenReturn (true );
426
431
427
432
UpdateTask task = firebaseAppDistribution .updateIfNewReleaseAvailable ();
428
- TestUtils . awaitTask (task );
433
+ awaitTask (task );
429
434
430
435
assertNull (ShadowAlertDialog .getLatestAlertDialog ());
431
436
}
@@ -438,7 +443,7 @@ public void signInTester_whenDialogDismissed_taskFails() {
438
443
AlertDialog dialog = assertAlertDialogShown ();
439
444
dialog .getButton (AlertDialog .BUTTON_NEGATIVE ).performClick (); // dismiss dialog
440
445
441
- TestUtils . awaitTaskFailure (
446
+ awaitTaskFailure (
442
447
updateTask , AUTHENTICATION_CANCELED , ErrorMessages .AUTHENTICATION_CANCELED );
443
448
}
444
449
@@ -450,7 +455,7 @@ public void updateIfNewReleaseAvailable_whenSignInDialogCanceled_taskFails() {
450
455
AlertDialog dialog = assertAlertDialogShown ();
451
456
dialog .onBackPressed (); // cancel dialog
452
457
453
- TestUtils . awaitTaskFailure (
458
+ awaitTaskFailure (
454
459
signInTask , AUTHENTICATION_CANCELED , ErrorMessages .AUTHENTICATION_CANCELED );
455
460
}
456
461
@@ -463,8 +468,9 @@ private AlertDialog assertAlertDialogShown() {
463
468
}
464
469
465
470
@ Test
466
- public void signOutTester_setsSignInStatusFalse () {
471
+ public void signOutTester_setsSignInStatusFalse () throws InterruptedException {
467
472
firebaseAppDistribution .signOutTester ();
473
+ awaitTermination (testExecutor );
468
474
verify (mockSignInStorage ).setSignInStatus (false );
469
475
}
470
476
@@ -486,12 +492,12 @@ public void updateIfNewReleaseAvailable_receiveProgressUpdateFromUpdateApp()
486
492
487
493
List <UpdateProgress > progressEvents = new ArrayList <>();
488
494
updateTask .addOnProgressListener (FirebaseExecutors .directExecutor (), progressEvents ::add );
489
- TestUtils . awaitAsyncOperations (testExecutor );
495
+ awaitAsyncOperations (testExecutor );
490
496
491
497
// Clicking the update button.
492
498
AlertDialog updateDialog = (AlertDialog ) ShadowAlertDialog .getLatestDialog ();
493
499
updateDialog .getButton (Dialog .BUTTON_POSITIVE ).performClick ();
494
- TestUtils . awaitAsyncOperations (testExecutor );
500
+ awaitAsyncOperations (testExecutor );
495
501
496
502
// Update flow
497
503
assertEquals (1 , progressEvents .size ());
@@ -506,7 +512,7 @@ public void updateIfNewReleaseAvailable_fromABackgroundThread_showsSignInDialog(
506
512
ExecutorService executorService = Executors .newSingleThreadExecutor ();
507
513
Future <UpdateTask > future =
508
514
executorService .submit (() -> firebaseAppDistribution .updateIfNewReleaseAvailable ());
509
- TestUtils . awaitAsyncOperations (executorService );
515
+ awaitAsyncOperations (executorService );
510
516
511
517
assertAlertDialogShown ();
512
518
assertFalse (((UpdateTask ) future .get ()).isComplete ());
@@ -536,7 +542,7 @@ public void updateIfNewReleaseAvailable_whenScreenRotates_updateDialogReappears(
536
542
when (activity .isChangingConfigurations ()).thenReturn (true );
537
543
538
544
UpdateTask updateTask = firebaseAppDistribution .updateIfNewReleaseAvailable ();
539
- TestUtils . awaitAsyncOperations (testExecutor );
545
+ awaitAsyncOperations (testExecutor );
540
546
541
547
// Mimic activity recreation due to a configuration change
542
548
firebaseAppDistribution .onActivityDestroyed (activity );
@@ -558,7 +564,7 @@ public void updateIfNewReleaseAvailable_whenScreenRotates_updateDialogReappears(
558
564
firebaseAppDistribution .onActivityPaused (activity );
559
565
firebaseAppDistribution .onActivityResumed (testActivity2 );
560
566
561
- TestUtils . awaitTaskFailure (
567
+ awaitTaskFailure (
562
568
updateTask , HOST_ACTIVITY_INTERRUPTED , ErrorMessages .HOST_ACTIVITY_INTERRUPTED );
563
569
}
564
570
@@ -571,13 +577,13 @@ public void updateIfNewReleaseAvailable_whenScreenRotates_updateDialogReappears(
571
577
when (mockNewReleaseFetcher .checkForNewRelease ()).thenReturn (Tasks .forResult (newRelease ));
572
578
573
579
UpdateTask updateTask = firebaseAppDistribution .updateIfNewReleaseAvailable ();
574
- TestUtils . awaitAsyncOperations (testExecutor );
580
+ awaitAsyncOperations (testExecutor );
575
581
576
582
// Mimic different activity getting resumed
577
583
firebaseAppDistribution .onActivityPaused (activity );
578
584
firebaseAppDistribution .onActivityResumed (testActivity2 );
579
585
580
- TestUtils . awaitTaskFailure (
586
+ awaitTaskFailure (
581
587
updateTask , HOST_ACTIVITY_INTERRUPTED , ErrorMessages .HOST_ACTIVITY_INTERRUPTED );
582
588
}
583
589
@@ -588,7 +594,7 @@ public void updateAppTask_whenNoReleaseAvailable_throwsError() {
588
594
589
595
UpdateTask updateTask = firebaseAppDistribution .updateApp ();
590
596
591
- TestUtils . awaitTaskFailure (updateTask , UPDATE_NOT_AVAILABLE , RELEASE_NOT_FOUND_ERROR );
597
+ awaitTaskFailure (updateTask , UPDATE_NOT_AVAILABLE , RELEASE_NOT_FOUND_ERROR );
592
598
}
593
599
594
600
@ Test
@@ -605,7 +611,7 @@ public void updateApp_withAabReleaseAvailable_returnsSameAabTask()
605
611
606
612
// Complete original task
607
613
updateTaskToReturn .setResult ();
608
- TestUtils . awaitTask (updateTask );
614
+ awaitTask (updateTask );
609
615
610
616
// Returned task is complete
611
617
assertTrue (updateTask .isSuccessful ());
@@ -625,7 +631,7 @@ public void updateApp_withApkReleaseAvailable_returnsSameApkTask()
625
631
626
632
// Complete original task
627
633
updateTaskToReturn .setResult ();
628
- TestUtils . awaitTask (updateTask );
634
+ awaitTask (updateTask );
629
635
630
636
// Returned task is complete
631
637
assertTrue (updateTask .isSuccessful ());
0 commit comments