@Test(expected = NullPointerException.class) public void somethingGoingWrong() { doThrow(new NullPointerException()).when(mDownloader).onDownloadStarted(anyLong()); mDownloadFileTask.doInBackground(); }
@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);   }