|
40 | 40 | import org.junit.Test; |
41 | 41 | import org.mockito.ArgumentCaptor; |
42 | 42 | import org.mockito.Matchers; |
| 43 | +import org.mockito.Mockito; |
43 | 44 | import org.mockito.internal.util.reflection.Whitebox; |
44 | 45 | import org.mockito.invocation.InvocationOnMock; |
45 | 46 | import org.mockito.stubbing.Answer; |
@@ -996,6 +997,65 @@ public void checkInstallProgressState() { |
996 | 997 | verify(mReleaseInstallerListener, times(2)).hideInstallProgressDialog(); |
997 | 998 | } |
998 | 999 |
|
| 1000 | + @Test |
| 1001 | + public void showSystemSettingsDialogWhenPackageInstallerNull() { |
| 1002 | + |
| 1003 | + /* Try to show dialog. */ |
| 1004 | + Distribute.getInstance().showSystemSettingsDialogOrStartInstalling(1L, 1L); |
| 1005 | + |
| 1006 | + /* Verify that log was called. */ |
| 1007 | + verifyStatic(); |
| 1008 | + AppCenterLog.debug(eq(LOG_TAG), eq("Installing couldn't start due to the release installer wasn't initialized.")); |
| 1009 | + } |
| 1010 | + |
| 1011 | + @Test |
| 1012 | + public void showUpdateDialogAfterShowingInstallReleaseDialogTest() { |
| 1013 | + |
| 1014 | + /* Mock App Center log. */ |
| 1015 | + mockStatic(AppCenterLog.class); |
| 1016 | + |
| 1017 | + /* Mock system alert settings. */ |
| 1018 | + mockStatic(InstallerUtils.class); |
| 1019 | + when(InstallerUtils.isSystemAlertWindowsEnabled(any(Context.class))).thenReturn(false); |
| 1020 | + |
| 1021 | + /* Mock distribute utils. */ |
| 1022 | + mockStatic(DistributeUtils.class); |
| 1023 | + when(DistributeUtils.getStoredDownloadState()).thenReturn(-1).thenReturn(1); |
| 1024 | + |
| 1025 | + /* Mock that download time is bigger than packageInfo.lastUpdateTime. */ |
| 1026 | + when(SharedPreferencesManager.getLong(eq(PREFERENCE_KEY_DOWNLOAD_TIME))).thenReturn(3L); |
| 1027 | + |
| 1028 | + /* mReleaseDetails is not null and it's a mandatory update. */ |
| 1029 | + when(DistributeUtils.loadCachedReleaseDetails()).thenReturn(mReleaseDetails); |
| 1030 | + when(mReleaseDetails.isMandatoryUpdate()).thenReturn(true); |
| 1031 | + when(mReleaseDownloader.isDownloading()).thenReturn(false); |
| 1032 | + |
| 1033 | + /* Prepare distribute listener. */ |
| 1034 | + Distribute.setListener(Mockito.mock(DistributeListener.class)); |
| 1035 | + |
| 1036 | + /* Show install settings dialog. */ |
| 1037 | + Distribute.getInstance().startFromBackground(mContext); |
| 1038 | + resumeWorkflow(mActivity); |
| 1039 | + Distribute.getInstance().showSystemSettingsDialogOrStartInstalling(1L, 1L); |
| 1040 | + |
| 1041 | + /* Emulate that settings was applied. */ |
| 1042 | + Distribute.getInstance().onActivityPaused(mActivity); |
| 1043 | + Distribute.getInstance().onActivityStopped(mActivity); |
| 1044 | + resumeWorkflow(mActivity); |
| 1045 | + |
| 1046 | + /* Verify that install progress was started. */ |
| 1047 | + verify(mReleaseInstallerListener).startInstall(); |
| 1048 | + |
| 1049 | + /* Emulate system confirmation dialog about installing new release. */ |
| 1050 | + Distribute.getInstance().onActivityPaused(mActivity); |
| 1051 | + Distribute.getInstance().onActivityStopped(mActivity); |
| 1052 | + resumeWorkflow(mActivity); |
| 1053 | + |
| 1054 | + /* Verify that SDK wasn't crash with NPE and don't show dialog. */ |
| 1055 | + verifyStatic(never()); |
| 1056 | + AppCenterLog.debug(eq(LOG_TAG), eq("Show default update dialog.")); |
| 1057 | + } |
| 1058 | + |
999 | 1059 | private void firstDownloadNotification(int apiLevel) throws Exception { |
1000 | 1060 | TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", apiLevel); |
1001 | 1061 | mockStatic(DistributeUtils.class); |
|
0 commit comments