HttpConnectionReleaseDownloader extends AbstractReleaseDownloader { @AnyThread @Override public synchronized void resume() { if (isCancelled()) { return; } if (!NetworkStateHelper.getSharedInstance(mContext).isNetworkConnected()) { mListener.onError("No network connection, abort downloading."); return; } String[] permissions = requiredPermissions(); int[] permissionsState = PermissionUtils.permissionsState(mContext, permissions); if (!PermissionUtils.permissionsAreGranted(permissionsState)) { mListener.onError("No external storage permission."); return; } check(); } HttpConnectionReleaseDownloader(@NonNull Context context, @NonNull ReleaseDetails releaseDetails, @NonNull Listener listener); @Override synchronized boolean isDownloading(); @AnyThread @Override synchronized void resume(); @Override synchronized void cancel();  }
@Test public void resumeStartsCheck() { mReleaseDownloader.resume(); verifyStatic(); AsyncTaskUtils.execute(anyString(), isA(HttpConnectionCheckTask.class), Mockito.<Void>anyVararg()); }
@Test public void resumeWithoutNetwork() { when(mNetworkStateHelper.isNetworkConnected()).thenReturn(false); mReleaseDownloader.resume(); verify(mListener).onError(anyString()); verifyStatic(never()); AsyncTaskUtils.execute(anyString(), isA(HttpConnectionCheckTask.class), Mockito.<Void>anyVararg()); }
@Test public void resumeWithoutPermissions() { when(PermissionUtils.permissionsAreGranted(any(int[].class))).thenReturn(false); mReleaseDownloader.resume(); verify(mListener).onError(anyString()); verifyStatic(never()); AsyncTaskUtils.execute(anyString(), isA(HttpConnectionCheckTask.class), Mockito.<Void>anyVararg()); }
@Test public void resumeDoesCheckingStatusEachTime() { mReleaseDownloader.resume(); mReleaseDownloader.resume(); mReleaseDownloader.resume(); verifyStatic(times(3)); AsyncTaskUtils.execute(anyString(), isA(HttpConnectionCheckTask.class), Mockito.<Void>anyVararg()); }