diff options
author | orionlee <orionlee@yahoo.com> | 2019-09-30 13:46:59 -0700 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2019-09-30 13:46:59 -0700 |
commit | d84fc95f0d7b9bee3eb3970c853072f35bb24c55 (patch) | |
tree | 4c7532bb73f36476952478c79efeb7c5ea3346db /core | |
parent | f3b3d5c4229b909b916807abe7dcb4815810a583 (diff) | |
download | AntennaPod-d84fc95f0d7b9bee3eb3970c853072f35bb24c55.zip |
test for DownloadService, case media download successful.
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 8e74d1c42..b429740bf 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -14,6 +14,7 @@ import android.os.Handler; import android.os.IBinder; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import android.util.Log; @@ -434,12 +435,40 @@ public class DownloadService extends Service { queryDownloads(); } - private Downloader getDownloader(DownloadRequest request) { - if (!URLUtil.isHttpUrl(request.getSource()) && !URLUtil.isHttpsUrl(request.getSource())) { - Log.e(TAG, "Could not find appropriate downloader for " + request.getSource()); - return null; + @VisibleForTesting + public interface DownloaderFactory { + @Nullable + Downloader create(@NonNull DownloadRequest request); + } + + private static class DefaultDownloaderFactory implements DownloaderFactory { + @Nullable + @Override + public Downloader create(@NonNull DownloadRequest request) { + if (!URLUtil.isHttpUrl(request.getSource()) && !URLUtil.isHttpsUrl(request.getSource())) { + Log.e(TAG, "Could not find appropriate downloader for " + request.getSource()); + return null; + } + return new HttpDownloader(request); } - return new HttpDownloader(request); + } + + private static DownloaderFactory downloaderFactory = new DefaultDownloaderFactory(); + + @VisibleForTesting + public static DownloaderFactory getDownloaderFactory() { + return downloaderFactory; + } + + // public scope rather than package private, + // because androidTest put classes in the non-standard de.test.antennapod hierarchy + @VisibleForTesting + public static void setDownloaderFactory(DownloaderFactory downloaderFactory) { + DownloadService.downloaderFactory = downloaderFactory; + } + + private Downloader getDownloader(@NonNull DownloadRequest request) { + return downloaderFactory.create(request); } /** |