@Test public void completeDownloadingFallbackOnNewDevices() { mockStatic(Uri.class); when(Uri.parse(anyString())).thenReturn(mock(Uri.class)); when(mListener.onComplete(any(Uri.class))).thenReturn(false).thenReturn(true); Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.O); mReleaseDownloader.onDownloadComplete(mock(Cursor.class)); verify(mListener).onComplete(any(Uri.class)); verify(mListener).onError(anyString()); }
@WorkerThread synchronized void onDownloadComplete(Cursor cursor) { if (isCancelled()) { return; } AppCenterLog.debug(LOG_TAG, "Download was successful for id=" + mDownloadId); Uri localUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI))); boolean installerFound = false; if (!mListener.onComplete(localUri)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { installerFound = mListener.onComplete(getFileUriOnOldDevices(cursor)); } } else { installerFound = true; } if (!installerFound) { mListener.onError("Installer not found"); } }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadComplete(Cursor cursor) { if (isCancelled()) { return; } AppCenterLog.debug(LOG_TAG, "Download was successful for id=" + mDownloadId); Uri localUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI))); boolean installerFound = false; if (!mListener.onComplete(localUri)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { installerFound = mListener.onComplete(getFileUriOnOldDevices(cursor)); } } else { installerFound = true; } if (!installerFound) { mListener.onError("Installer not found"); } } }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadComplete(Cursor cursor) { if (isCancelled()) { return; } AppCenterLog.debug(LOG_TAG, "Download was successful for id=" + mDownloadId); Uri localUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI))); boolean installerFound = false; if (!mListener.onComplete(localUri)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { installerFound = mListener.onComplete(getFileUriOnOldDevices(cursor)); } } else { installerFound = true; } if (!installerFound) { mListener.onError("Installer not found"); } } DownloadManagerReleaseDownloader(@NonNull Context context, @NonNull ReleaseDetails releaseDetails, @NonNull Listener listener); }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadComplete(Cursor cursor) { if (isCancelled()) { return; } AppCenterLog.debug(LOG_TAG, "Download was successful for id=" + mDownloadId); Uri localUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI))); boolean installerFound = false; if (!mListener.onComplete(localUri)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { installerFound = mListener.onComplete(getFileUriOnOldDevices(cursor)); } } else { installerFound = true; } if (!installerFound) { mListener.onError("Installer not found"); } } DownloadManagerReleaseDownloader(@NonNull Context context, @NonNull ReleaseDetails releaseDetails, @NonNull Listener listener); @Override synchronized boolean isDownloading(); @AnyThread @Override synchronized void resume(); @Override synchronized void cancel(); }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadComplete(Cursor cursor) { if (isCancelled()) { return; } AppCenterLog.debug(LOG_TAG, "Download was successful for id=" + mDownloadId); Uri localUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI))); boolean installerFound = false; if (!mListener.onComplete(localUri)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { installerFound = mListener.onComplete(getFileUriOnOldDevices(cursor)); } } else { installerFound = true; } if (!installerFound) { mListener.onError("Installer not found"); } } DownloadManagerReleaseDownloader(@NonNull Context context, @NonNull ReleaseDetails releaseDetails, @NonNull Listener listener); @Override synchronized boolean isDownloading(); @AnyThread @Override synchronized void resume(); @Override synchronized void cancel();  }