@Test public void reportProgressBasedOnDownloadTime() throws IOException { long totalSize = UPDATE_PROGRESS_BYTES_THRESHOLD * 3; when(mUrlConnection.getContentLength()).thenReturn((int) totalSize); String apk = generateString((int) totalSize, '*'); mockConnectionContent(apk); mDownloadFileTask.doInBackground(); verifyDownloadedContent(apk); verify(mDownloader).onDownloadStarted(anyLong()); verify(mDownloader).onDownloadProgress(WRITE_BUFFER_SIZE, totalSize); verify(mDownloader).onDownloadProgress(totalSize, totalSize); verify(mDownloader).onDownloadComplete(eq(mTargetFile)); verify(mDownloader, never()).onDownloadError(anyString()); }
@Override protected Void doInBackground(Void... params) { TrafficStats.setThreadStatsTag(THREAD_STATS_TAG); try { long enqueueTime = System.currentTimeMillis(); mDownloader.onDownloadStarted(enqueueTime); URLConnection connection = createConnection(); long totalBytesDownloaded = downloadFile(connection); if (totalBytesDownloaded > 0) { mDownloader.onDownloadComplete(mTargetFile); } else { throw new IOException("The content of downloaded file is empty"); } } catch (IOException e) { mDownloader.onDownloadError(e.getMessage()); } finally { TrafficStats.clearThreadStatsTag(); } return null; }
HttpConnectionDownloadFileTask extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { TrafficStats.setThreadStatsTag(THREAD_STATS_TAG); try { long enqueueTime = System.currentTimeMillis(); mDownloader.onDownloadStarted(enqueueTime); URLConnection connection = createConnection(); long totalBytesDownloaded = downloadFile(connection); if (totalBytesDownloaded > 0) { mDownloader.onDownloadComplete(mTargetFile); } else { throw new IOException("The content of downloaded file is empty"); } } catch (IOException e) { mDownloader.onDownloadError(e.getMessage()); } finally { TrafficStats.clearThreadStatsTag(); } return null; } }
HttpConnectionDownloadFileTask extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { TrafficStats.setThreadStatsTag(THREAD_STATS_TAG); try { long enqueueTime = System.currentTimeMillis(); mDownloader.onDownloadStarted(enqueueTime); URLConnection connection = createConnection(); long totalBytesDownloaded = downloadFile(connection); if (totalBytesDownloaded > 0) { mDownloader.onDownloadComplete(mTargetFile); } else { throw new IOException("The content of downloaded file is empty"); } } catch (IOException e) { mDownloader.onDownloadError(e.getMessage()); } finally { TrafficStats.clearThreadStatsTag(); } return null; } HttpConnectionDownloadFileTask(HttpConnectionReleaseDownloader downloader, Uri downloadUri, File targetFile); }
HttpConnectionDownloadFileTask extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { TrafficStats.setThreadStatsTag(THREAD_STATS_TAG); try { long enqueueTime = System.currentTimeMillis(); mDownloader.onDownloadStarted(enqueueTime); URLConnection connection = createConnection(); long totalBytesDownloaded = downloadFile(connection); if (totalBytesDownloaded > 0) { mDownloader.onDownloadComplete(mTargetFile); } else { throw new IOException("The content of downloaded file is empty"); } } catch (IOException e) { mDownloader.onDownloadError(e.getMessage()); } finally { TrafficStats.clearThreadStatsTag(); } return null; } HttpConnectionDownloadFileTask(HttpConnectionReleaseDownloader downloader, Uri downloadUri, File targetFile);  }
HttpConnectionDownloadFileTask extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { TrafficStats.setThreadStatsTag(THREAD_STATS_TAG); try { long enqueueTime = System.currentTimeMillis(); mDownloader.onDownloadStarted(enqueueTime); URLConnection connection = createConnection(); long totalBytesDownloaded = downloadFile(connection); if (totalBytesDownloaded > 0) { mDownloader.onDownloadComplete(mTargetFile); } else { throw new IOException("The content of downloaded file is empty"); } } catch (IOException e) { mDownloader.onDownloadError(e.getMessage()); } finally { TrafficStats.clearThreadStatsTag(); } return null; } HttpConnectionDownloadFileTask(HttpConnectionReleaseDownloader downloader, Uri downloadUri, File targetFile);   }