@Test public void errorResponseCode() throws IOException { when(mUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR); mDownloadFileTask.doInBackground(); verify(mDownloader).onDownloadStarted(anyLong()); verify(mDownloader, never()).onDownloadComplete(any(File.class)); verify(mDownloader).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);   }