diff options
author | orionlee <orionlee@yahoo.com> | 2019-09-30 12:07:53 -0700 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2019-09-30 12:07:53 -0700 |
commit | cbf6103c00d4baad160ed5e6b6acba536d940c24 (patch) | |
tree | c92a49fdce5733127479e82bc67b1cb811aee365 /app | |
parent | 38e9cafee3afb7010fb870e547dceb0f8ae9feec (diff) | |
download | AntennaPod-cbf6103c00d4baad160ed5e6b6acba536d940c24.zip |
test tweak - ensure playback queue updated after download - await for the event explicitly.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java | 26 |
1 files changed, 24 insertions, 2 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 38b097d51..1d2a72c92 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,7 +5,9 @@ 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; @@ -16,6 +18,7 @@ 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; @@ -146,6 +149,9 @@ public class PlaybackServiceTaskManagerTest { assertThat("The item is not yet downloaded", testItem.getMedia().isDownloaded(), is(false)); + FeedItemEventListener feedItemEventListener = new FeedItemEventListener(); + EventBus.getDefault().register(feedItemEventListener); + { // simulate download complete (in DownloadService.MediaHandlerThread) FeedItem item = DBReader.getFeedItem(testItem.getId()); item.getMedia().setDownloaded(true); @@ -155,16 +161,32 @@ public class PlaybackServiceTaskManagerTest { DBWriter.setFeedItem(item).get(); } - // an approximation to ensure the item update event has been posted and processed. - Thread.sleep(10); + Awaitility.await() + .atMost(1000, TimeUnit.MILLISECONDS) + .until(() -> feedItemEventListener.getEvents().size() > 0); final FeedItem itemUpdated = pstm.getQueue().get(0); assertThat("The queue in PlaybackService has been updated item after download is completed", itemUpdated.getMedia().isDownloaded(), is(true)); + EventBus.getDefault().unregister(feedItemEventListener); pstm.shutdown(); } + 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(); |