@Test public void showMandatoryDownloadReadyDialogTest() { mockStatic(DistributeUtils.class); when(DistributeUtils.getStoredDownloadState()).thenReturn(-1).thenReturn(DOWNLOAD_STATE_INSTALLING); when(SharedPreferencesManager.getLong(eq(PREFERENCE_KEY_DOWNLOAD_TIME))).thenReturn(3L); when(DistributeUtils.loadCachedReleaseDetails()).thenReturn(mReleaseDetails); when(mReleaseDetails.isMandatoryUpdate()).thenReturn(true); resumeWorkflow(mock(Activity.class)); Distribute.getInstance().onActivityResumed(mock(Activity.class)); when(mDialog.isShowing()).thenReturn(false).thenReturn(true); Distribute.getInstance().onActivityResumed(mock(Activity.class)); Distribute.getInstance().onActivityResumed(mActivity); verify(mDialog, times(1)).hide(); Distribute.getInstance().onActivityResumed(mActivity); ArgumentCaptor<DialogInterface.OnClickListener> clickListener = ArgumentCaptor.forClass(DialogInterface.OnClickListener.class); verify(mDialogBuilder, times(3)).setPositiveButton(eq(R.string.appcenter_distribute_install), clickListener.capture()); verify(mDialogBuilder, times(3)).create(); clickListener.getValue().onClick(mDialog, DialogInterface.BUTTON_POSITIVE); Distribute.getInstance().completeWorkflow(); doNothing().when(mToast).show(); clickListener.getValue().onClick(mDialog, DialogInterface.BUTTON_POSITIVE); verify(mReleaseDownloader, times(2)).resume(); }
private synchronized void showMandatoryDownloadReadyDialog() { if (shouldRefreshDialog(mCompletedDownloadDialog)) { final ReleaseDetails releaseDetails = mReleaseDetails; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mForegroundActivity); dialogBuilder.setCancelable(false); dialogBuilder.setTitle(R.string.appcenter_distribute_install_ready_title); dialogBuilder.setMessage(getInstallReadyMessage()); dialogBuilder.setPositiveButton(R.string.appcenter_distribute_install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { installMandatoryUpdate(releaseDetails); } }); mCompletedDownloadDialog = dialogBuilder.create(); showAndRememberDialogActivity(mCompletedDownloadDialog); } }
Distribute extends AbstractAppCenterService { private synchronized void showMandatoryDownloadReadyDialog() { if (shouldRefreshDialog(mCompletedDownloadDialog)) { final ReleaseDetails releaseDetails = mReleaseDetails; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mForegroundActivity); dialogBuilder.setCancelable(false); dialogBuilder.setTitle(R.string.appcenter_distribute_install_ready_title); dialogBuilder.setMessage(getInstallReadyMessage()); dialogBuilder.setPositiveButton(R.string.appcenter_distribute_install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { installMandatoryUpdate(releaseDetails); } }); mCompletedDownloadDialog = dialogBuilder.create(); showAndRememberDialogActivity(mCompletedDownloadDialog); } } }
Distribute extends AbstractAppCenterService { private synchronized void showMandatoryDownloadReadyDialog() { if (shouldRefreshDialog(mCompletedDownloadDialog)) { final ReleaseDetails releaseDetails = mReleaseDetails; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mForegroundActivity); dialogBuilder.setCancelable(false); dialogBuilder.setTitle(R.string.appcenter_distribute_install_ready_title); dialogBuilder.setMessage(getInstallReadyMessage()); dialogBuilder.setPositiveButton(R.string.appcenter_distribute_install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { installMandatoryUpdate(releaseDetails); } }); mCompletedDownloadDialog = dialogBuilder.create(); showAndRememberDialogActivity(mCompletedDownloadDialog); } } private  Distribute(); }
Distribute extends AbstractAppCenterService { private synchronized void showMandatoryDownloadReadyDialog() { if (shouldRefreshDialog(mCompletedDownloadDialog)) { final ReleaseDetails releaseDetails = mReleaseDetails; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mForegroundActivity); dialogBuilder.setCancelable(false); dialogBuilder.setTitle(R.string.appcenter_distribute_install_ready_title); dialogBuilder.setMessage(getInstallReadyMessage()); dialogBuilder.setPositiveButton(R.string.appcenter_distribute_install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { installMandatoryUpdate(releaseDetails); } }); mCompletedDownloadDialog = dialogBuilder.create(); showAndRememberDialogActivity(mCompletedDownloadDialog); } } private  Distribute(); static synchronized Distribute getInstance(); static AppCenterFuture<Boolean> isEnabled(); static AppCenterFuture<Void> setEnabled(boolean enabled); static void setInstallUrl(String installUrl); static void setApiUrl(String apiUrl); @SuppressWarnings("WeakerAccess") static int getUpdateTrack(); static void setUpdateTrack(@UpdateTrack int updateTrack); static void setListener(DistributeListener listener); static void setEnabledForDebuggableBuild(boolean enabled); static void notifyUpdateAction(@UpdateAction int updateAction); static void checkForUpdate(); static void disableAutomaticCheckForUpdate(); @Override String getServiceName(); @Override Map<String, LogFactory> getLogFactories(); @Override synchronized void onStarted(@NonNull Context context, @NonNull Channel channel, String appSecret, String transmissionTargetToken, boolean startedFromApp); @Override synchronized void onActivityResumed(Activity activity); @Override synchronized void onActivityPaused(Activity activity); @Override void onApplicationEnterForeground(); }
Distribute extends AbstractAppCenterService { private synchronized void showMandatoryDownloadReadyDialog() { if (shouldRefreshDialog(mCompletedDownloadDialog)) { final ReleaseDetails releaseDetails = mReleaseDetails; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mForegroundActivity); dialogBuilder.setCancelable(false); dialogBuilder.setTitle(R.string.appcenter_distribute_install_ready_title); dialogBuilder.setMessage(getInstallReadyMessage()); dialogBuilder.setPositiveButton(R.string.appcenter_distribute_install, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { installMandatoryUpdate(releaseDetails); } }); mCompletedDownloadDialog = dialogBuilder.create(); showAndRememberDialogActivity(mCompletedDownloadDialog); } } private  Distribute(); static synchronized Distribute getInstance(); static AppCenterFuture<Boolean> isEnabled(); static AppCenterFuture<Void> setEnabled(boolean enabled); static void setInstallUrl(String installUrl); static void setApiUrl(String apiUrl); @SuppressWarnings("WeakerAccess") static int getUpdateTrack(); static void setUpdateTrack(@UpdateTrack int updateTrack); static void setListener(DistributeListener listener); static void setEnabledForDebuggableBuild(boolean enabled); static void notifyUpdateAction(@UpdateAction int updateAction); static void checkForUpdate(); static void disableAutomaticCheckForUpdate(); @Override String getServiceName(); @Override Map<String, LogFactory> getLogFactories(); @Override synchronized void onStarted(@NonNull Context context, @NonNull Channel channel, String appSecret, String transmissionTargetToken, boolean startedFromApp); @Override synchronized void onActivityResumed(Activity activity); @Override synchronized void onActivityPaused(Activity activity); @Override void onApplicationEnterForeground();  }