diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-09-30 21:34:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-30 21:34:17 +0200 |
commit | f862d157531edb0db7ed7c89f69248b8deb0f907 (patch) | |
tree | 9d80d634941d650cb63f30a68caa12faa217f38e /app | |
parent | 694d0f8d349adabe984732a976ba2556b79d5555 (diff) | |
parent | c0befc98542bc147a8aa341c48e6445d4cfbbfb7 (diff) | |
download | AntennaPod-f862d157531edb0db7ed7c89f69248b8deb0f907.zip |
Merge pull request #3471 from orionlee/bugfix2_player_not_using_downloaded_media_2947
New fix player stuck due to streaming rather than using downloaded media
Diffstat (limited to 'app')
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java index 9c0e90929..3a3a64d80 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java @@ -5,23 +5,31 @@ import android.support.test.InstrumentationRegistry; import android.support.test.annotation.UiThreadTest; import android.support.test.filters.LargeTest; +import org.awaitility.Awaitility; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.event.FeedItemEvent; import de.danoeh.antennapod.core.event.QueueEvent; import de.danoeh.antennapod.core.feed.EventDistributor; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager; +import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.playback.Playable; -import org.greenrobot.eventbus.EventBus; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import io.reactivex.functions.Consumer; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -124,6 +132,72 @@ public class PlaybackServiceTaskManagerTest { } @Test + public void testQueueUpdatedUponDownloadComplete() throws Exception { + final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext(); + { // Setup test data + List<FeedItem> queue = writeTestQueue("a"); + FeedItem item = DBReader.getFeedItem(queue.get(0).getId()); + FeedMedia media = new FeedMedia(item, "http://example.com/episode.mp3", 12345, "audio/mp3"); + item.setMedia(media); + DBWriter.setFeedMedia(media).get(); + DBWriter.setFeedItem(item).get(); + } + + PlaybackServiceTaskManager pstm = new PlaybackServiceTaskManager(c, defaultPSTM); + final FeedItem testItem = pstm.getQueue().get(0); + assertFalse("The item should not yet be downloaded", testItem.getMedia().isDownloaded()); + + withFeedItemEventListener( feedItemEventListener -> { + // simulate download complete (in DownloadService.MediaHandlerThread) + FeedItem item = DBReader.getFeedItem(testItem.getId()); + item.getMedia().setDownloaded(true); + item.getMedia().setFile_url("file://123"); + item.setAutoDownload(false); + DBWriter.setFeedMedia(item.getMedia()).get(); + DBWriter.setFeedItem(item).get(); + + Awaitility.await() + .atMost(1000, TimeUnit.MILLISECONDS) + .until(() -> feedItemEventListener.getEvents().size() > 0); + + final FeedItem itemUpdated = pstm.getQueue().get(0); + assertTrue("media.isDownloaded() should be true - The queue in PlaybackService should be updated after download is completed", + itemUpdated.getMedia().isDownloaded()); + }); + + pstm.shutdown(); + } + + /** + * Provides an listener subscribing to {@link FeedItemEvent} that the callers can use + * + * Note: it uses RxJava's version of {@link Consumer} because it allows exceptions to be thrown. + */ + private static void withFeedItemEventListener(Consumer<FeedItemEventListener> consumer) throws Exception { + FeedItemEventListener feedItemEventListener = new FeedItemEventListener(); + try { + EventBus.getDefault().register(feedItemEventListener); + consumer.accept(feedItemEventListener); + } finally { + EventBus.getDefault().unregister(feedItemEventListener); + } + } + + private static class FeedItemEventListener { + + private final List<FeedItemEvent> events = new ArrayList<>(); + + @Subscribe + public void onEvent(FeedItemEvent event) { + events.add(event); + } + + List<? extends FeedItemEvent> getEvents() { + return events; + } + } + + @Test public void testStartPositionSaver() throws InterruptedException { final Context c = InstrumentationRegistry.getInstrumentation().getTargetContext(); final int NUM_COUNTDOWNS = 2; |