Skip to content

Commit 2bbf265

Browse files
author
Rachel Prince
committed
Fix test setup methods
1 parent a01e43c commit 2bbf265

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

firebase-app-distribution/src/test/java/com/google/firebase/app/distribution/FirebaseAppDistributionTest.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ public void setup() {
165165

166166
activity = Robolectric.buildActivity(TestActivity.class).create().get();
167167
when(mockLifecycleNotifier.getCurrentActivity()).thenReturn(activity);
168+
when(mockSignInStorage.getSignInStatus()).thenReturn(true);
168169
}
169170

170171
@Test
171172
public void checkForNewRelease_whenCheckForNewReleaseFails_throwsError() {
172-
firebaseAppDistribution.setCachedNewRelease(null);
173173
when(mockCheckForNewReleaseClient.checkForNewRelease())
174174
.thenReturn(
175175
Tasks.forException(
@@ -234,7 +234,10 @@ public void updateApp_whenNotSignedIn_throwsError() {
234234

235235
@Test
236236
public void updateToNewRelease_whenNewAabReleaseAvailable_showsUpdateDialog() {
237-
updateToNewRelease(TEST_RELEASE_NEWER_AAB_INTERNAL.build());
237+
when(mockCheckForNewReleaseClient.checkForNewRelease())
238+
.thenReturn(Tasks.forResult((TEST_RELEASE_NEWER_AAB_INTERNAL.build())));
239+
240+
firebaseAppDistribution.updateIfNewReleaseAvailable();
238241

239242
AlertDialog dialog = verifyUpdateAlertDialog();
240243
assertEquals(
@@ -248,7 +251,10 @@ public void updateToNewRelease_whenNewAabReleaseAvailable_showsUpdateDialog() {
248251

249252
@Test
250253
public void updateToNewRelease_whenReleaseNotesEmpty_doesNotShowReleaseNotes() {
251-
updateToNewRelease(TEST_RELEASE_NEWER_AAB_INTERNAL.setReleaseNotes("").build());
254+
when(mockCheckForNewReleaseClient.checkForNewRelease())
255+
.thenReturn(Tasks.forResult((TEST_RELEASE_NEWER_AAB_INTERNAL.setReleaseNotes("").build())));
256+
257+
firebaseAppDistribution.updateIfNewReleaseAvailable();
252258

253259
AlertDialog dialog = verifyUpdateAlertDialog();
254260
assertEquals(
@@ -262,7 +268,6 @@ public void updateToNewRelease_whenReleaseNotesEmpty_doesNotShowReleaseNotes() {
262268
public void updateToNewRelease_whenNoReleaseAvailable_updateDialogNotShown() {
263269
when(mockSignInStorage.getSignInStatus()).thenReturn(false);
264270
when(mockCheckForNewReleaseClient.checkForNewRelease()).thenReturn(Tasks.forResult(null));
265-
firebaseAppDistribution.setCachedNewRelease(null);
266271

267272
UpdateTask task = firebaseAppDistribution.updateIfNewReleaseAvailable();
268273

@@ -278,7 +283,6 @@ public void updateToNewRelease_whenNoReleaseAvailable_updateDialogNotShown() {
278283
public void updateToNewRelease_whenActivityBackgrounded_updateDialogNotShown() {
279284
when(mockSignInStorage.getSignInStatus()).thenReturn(false);
280285
when(mockCheckForNewReleaseClient.checkForNewRelease()).thenReturn(Tasks.forResult(null));
281-
firebaseAppDistribution.setCachedNewRelease(null);
282286
when(mockLifecycleNotifier.getCurrentActivity()).thenReturn(null);
283287

284288
UpdateTask task = firebaseAppDistribution.updateIfNewReleaseAvailable();
@@ -334,7 +338,10 @@ public void updateToNewRelease_whenSignInFailed_checkForUpdateNotCalled() {
334338

335339
@Test
336340
public void updateToNewRelease_whenDialogDismissed_taskFails() {
337-
UpdateTask updateTask = updateToNewRelease(TEST_RELEASE_NEWER_AAB_INTERNAL.build());
341+
when(mockCheckForNewReleaseClient.checkForNewRelease())
342+
.thenReturn(Tasks.forResult(TEST_RELEASE_NEWER_AAB_INTERNAL.build()));
343+
344+
UpdateTask updateTask = firebaseAppDistribution.updateIfNewReleaseAvailable();
338345
AlertDialog updateDialog = verifyUpdateAlertDialog();
339346
updateDialog.getButton(AlertDialog.BUTTON_NEGATIVE).performClick(); // dismiss dialog
340347

@@ -348,7 +355,11 @@ public void updateToNewRelease_whenDialogDismissed_taskFails() {
348355

349356
@Test
350357
public void updateToNewRelease_whenDialogCanceled_taskFails() {
351-
UpdateTask updateTask = updateToNewRelease(TEST_RELEASE_NEWER_AAB_INTERNAL.build());
358+
when(mockCheckForNewReleaseClient.checkForNewRelease())
359+
.thenReturn(Tasks.forResult(TEST_RELEASE_NEWER_AAB_INTERNAL.build()));
360+
361+
UpdateTask updateTask = firebaseAppDistribution.updateIfNewReleaseAvailable();
362+
352363
AlertDialog updateDialog = verifyUpdateAlertDialog();
353364
updateDialog.onBackPressed(); // cancels the dialog
354365

@@ -390,10 +401,8 @@ public void signOutTester_setsSignInStatusFalse() {
390401

391402
@Test
392403
public void updateToNewRelease_receiveProgressUpdateFromUpdateApp() {
393-
when(mockSignInStorage.getSignInStatus()).thenReturn(true);
394404
AppDistributionReleaseInternal newRelease = TEST_RELEASE_NEWER_AAB_INTERNAL.build();
395405
when(mockCheckForNewReleaseClient.checkForNewRelease()).thenReturn(Tasks.forResult(newRelease));
396-
firebaseAppDistribution.setCachedNewRelease(newRelease);
397406
UpdateTaskImpl mockTask = new UpdateTaskImpl();
398407
when(mockUpdateAabClient.updateAab(newRelease)).thenReturn(mockTask);
399408
mockTask.updateProgress(
@@ -419,10 +428,8 @@ public void updateToNewRelease_receiveProgressUpdateFromUpdateApp() {
419428

420429
@Test
421430
public void taskCancelledOnScreenRotation() {
422-
when(mockSignInStorage.getSignInStatus()).thenReturn(true);
423431
AppDistributionReleaseInternal newRelease = TEST_RELEASE_NEWER_AAB_INTERNAL.build();
424432
when(mockCheckForNewReleaseClient.checkForNewRelease()).thenReturn(Tasks.forResult(newRelease));
425-
firebaseAppDistribution.setCachedNewRelease(newRelease);
426433

427434
UpdateTask task = firebaseAppDistribution.updateIfNewReleaseAvailable();
428435

@@ -476,14 +483,6 @@ public void updateApp_withApkReleaseAvailable_returnsSameApkTask() {
476483
assertEquals(updateTask, updateTaskToReturn);
477484
}
478485

479-
private UpdateTask updateToNewRelease(AppDistributionReleaseInternal newRelease) {
480-
when(mockSignInStorage.getSignInStatus()).thenReturn(true);
481-
when(mockCheckForNewReleaseClient.checkForNewRelease()).thenReturn(Tasks.forResult(newRelease));
482-
firebaseAppDistribution.setCachedNewRelease(newRelease);
483-
484-
return firebaseAppDistribution.updateIfNewReleaseAvailable();
485-
}
486-
487486
private AlertDialog verifyUpdateAlertDialog() {
488487
assertTrue(ShadowAlertDialog.getLatestDialog() instanceof AlertDialog);
489488
AlertDialog dialog = (AlertDialog) ShadowAlertDialog.getLatestDialog();

0 commit comments

Comments
 (0)