summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java/de/test/antennapod/service/download
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2019-12-02 15:49:57 +0100
committerByteHamster <info@bytehamster.com>2019-12-12 09:47:16 +0100
commit376600d5b4c41f6167d5d4161a7ef8e3a132d715 (patch)
treea740703cb837839476f2e5a00a2ef54d4048249f /app/src/androidTest/java/de/test/antennapod/service/download
parent51442cb047ef47c0ddaf922ffb559804e4100fa8 (diff)
downloadAntennaPod-376600d5b4c41f6167d5d4161a7ef8e3a132d715.zip
Read current media from preferences instead of activity->fragment->controller
Diffstat (limited to 'app/src/androidTest/java/de/test/antennapod/service/download')
-rw-r--r--app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java68
1 files changed, 34 insertions, 34 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java b/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java
index 6b020efcb..1ca4de1ad 100644
--- a/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java
@@ -1,5 +1,7 @@
package de.test.antennapod.service.download;
+import android.content.Context;
+import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.InstrumentationRegistry;
@@ -80,6 +82,10 @@ public class DownloadServiceTest {
@After
public void tearDown() throws Exception {
DownloadService.setDownloaderFactory(origFactory);
+ Context context = InstrumentationRegistry.getTargetContext();
+ DownloadRequester.getInstance().cancelAllDownloads(context);
+ context.stopService(new Intent(context, DownloadService.class));
+ EspressoTestUtils.tryKillDownloadService();
}
@Test
@@ -139,8 +145,9 @@ public class DownloadServiceTest {
}
private void doTestCancelDownload_UndoEnqueue(boolean itemAlreadyInQueue) throws Exception {
+ Context context = InstrumentationRegistry.getTargetContext();
// let download takes longer to ensure the test can cancel the download in time
- DownloadService.setDownloaderFactory(new StubDownloaderFactory(150, downloadStatus -> {
+ DownloadService.setDownloaderFactory(new StubDownloaderFactory(10000, downloadStatus -> {
downloadStatus.setSuccessful();
}));
UserPreferences.setEnqueueDownloadedEpisodes(true);
@@ -149,45 +156,38 @@ public class DownloadServiceTest {
final long item1Id = testMedia11.getItem().getId();
if (itemAlreadyInQueue) {
// simulate item already in queue condition
- DBWriter.addQueueItem(InstrumentationRegistry.getTargetContext(), false, item1Id).get();
+ DBWriter.addQueueItem(context, false, item1Id).get();
assertTrue(DBReader.getQueueIDList().contains(item1Id));
} else {
assertFalse(DBReader.getQueueIDList().contains(item1Id));
}
withFeedItemEventListener(feedItemEventListener -> {
- try {
- DownloadRequester.getInstance().downloadMedia(false, InstrumentationRegistry.getTargetContext(),
- testMedia11.getItem());
- if (itemAlreadyInQueue) {
- Awaitility.await("download service receives the request - "
- + "no event is expected before cancel is issued")
- .atLeast(100, TimeUnit.MILLISECONDS)
- .until(() -> true);
- } else {
- Awaitility.await("item enqueue event")
- .atMost(1000, TimeUnit.MILLISECONDS)
- .until(() -> feedItemEventListener.getEvents().size() >= 1);
- }
- DownloadRequester.getInstance().cancelDownload(InstrumentationRegistry.getTargetContext(),
- testMedia11);
- final int totalNumEventsExpected = itemAlreadyInQueue ? 1 : 3;
- Awaitility.await("item dequeue event + download termination event")
- .atMost(1000, TimeUnit.MILLISECONDS)
- .until(() -> feedItemEventListener.getEvents().size() >= totalNumEventsExpected);
- assertFalse("The download should have been canceled",
- DBReader.getFeedMedia(testMedia11.getId()).isDownloaded());
- if (itemAlreadyInQueue) {
- assertTrue("The FeedItem should still be in the queue after the download is cancelled."
- + " It's there before download.",
- DBReader.getQueueIDList().contains(item1Id));
- } else {
- assertFalse("The FeedItem should not be in the queue after the download is cancelled.",
- DBReader.getQueueIDList().contains(item1Id));
- }
- } catch (ConditionTimeoutException cte) {
- fail("The expected FeedItemEvent (for media download complete) has not been posted. "
- + cte.getMessage());
+ DownloadRequester.getInstance().downloadMedia(false, context, testMedia11.getItem());
+ if (itemAlreadyInQueue) {
+ Awaitility.await("download service receives the request - "
+ + "no event is expected before cancel is issued")
+ .atLeast(100, TimeUnit.MILLISECONDS)
+ .until(() -> true);
+ } else {
+ Awaitility.await("item enqueue event")
+ .atMost(2000, TimeUnit.MILLISECONDS)
+ .until(() -> feedItemEventListener.getEvents().size() >= 1);
+ }
+ DownloadRequester.getInstance().cancelDownload(context, testMedia11);
+ final int totalNumEventsExpected = itemAlreadyInQueue ? 1 : 3;
+ Awaitility.await("item dequeue event + download termination event")
+ .atMost(1000, TimeUnit.MILLISECONDS)
+ .until(() -> feedItemEventListener.getEvents().size() >= totalNumEventsExpected);
+ assertFalse("The download should have been canceled",
+ DBReader.getFeedMedia(testMedia11.getId()).isDownloaded());
+ if (itemAlreadyInQueue) {
+ assertTrue("The FeedItem should still be in the queue after the download is cancelled."
+ + " It's there before download.",
+ DBReader.getQueueIDList().contains(item1Id));
+ } else {
+ assertFalse("The FeedItem should not be in the queue after the download is cancelled.",
+ DBReader.getQueueIDList().contains(item1Id));
}
});
}