Search in sources :

Example 56 with FlakyTest

use of android.test.FlakyTest in project AntennaPod by AntennaPod.

the class DBNullCleanupAlgorithmTest method testPerformAutoCleanupShouldNotDelete.

/**
     * A test with no items in the queue, but multiple items downloaded.
     * The null algorithm should never delete any items, even if they're played and not in the queue.
     * @throws IOException
     */
@FlakyTest(tolerance = 3)
public void testPerformAutoCleanupShouldNotDelete() throws IOException {
    final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2;
    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    List<File> files = new ArrayList<>();
    for (int i = 0; i < NUM_ITEMS; i++) {
        FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
        File f = new File(destFolder, "file " + i);
        assertTrue(f.createNewFile());
        files.add(f);
        item.setMedia(new FeedMedia(0, item, 1, 0, 1L, "m", f.getAbsolutePath(), "url", true, new Date(NUM_ITEMS - i), 0, 0));
        items.add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    for (FeedItem item : items) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
    }
    DBTasks.performAutoCleanup(context);
    for (int i = 0; i < files.size(); i++) {
        assertTrue(files.get(i).exists());
    }
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed) FlakyTest(android.test.FlakyTest)

Example 57 with FlakyTest

use of android.test.FlakyTest in project AntennaPod by AntennaPod.

the class DBQueueCleanupAlgorithmTest method testPerformAutoCleanupHandleUnplayed.

/**
     * For APQueueCleanupAlgorithm we expect even unplayed episodes to be deleted if needed
     * if they aren't in the queue
     */
@FlakyTest(tolerance = 3)
public void testPerformAutoCleanupHandleUnplayed() throws IOException {
    final int NUM_ITEMS = EPISODE_CACHE_SIZE * 2;
    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    List<File> files = new ArrayList<>();
    populateItems(NUM_ITEMS, feed, items, files, FeedItem.UNPLAYED, false, false);
    DBTasks.performAutoCleanup(context);
    for (int i = 0; i < files.size(); i++) {
        if (i < EPISODE_CACHE_SIZE) {
            assertTrue(files.get(i).exists());
        } else {
            assertFalse(files.get(i).exists());
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ArrayList(java.util.ArrayList) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed) FlakyTest(android.test.FlakyTest)

Example 58 with FlakyTest

use of android.test.FlakyTest in project AntennaPod by AntennaPod.

the class PlaybackSonicTest method testContinousPlaybackOffMultipleEpisodes.

@FlakyTest(tolerance = 3)
public void testContinousPlaybackOffMultipleEpisodes() throws Exception {
    setContinuousPlaybackPreference(false);
    uiTestUtils.addLocalFeedData(true);
    List<FeedItem> queue = DBReader.getQueue();
    final FeedItem first = queue.get(0);
    startLocalPlaybackFromQueue();
    boolean stopped = solo.waitForCondition(() -> {
        if (uiTestUtils.getPlaybackController(getActivity()).getStatus() != PlayerStatus.PLAYING) {
            return true;
        } else if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
            return uiTestUtils.getCurrentMedia(getActivity()).getId() != first.getMedia().getId();
        } else {
            return true;
        }
    }, Timeout.getSmallTimeout());
    assertTrue(stopped);
    Thread.sleep(1000);
    PlayerStatus status = uiTestUtils.getPlaybackController(getActivity()).getStatus();
    assertFalse(status.equals(PlayerStatus.PLAYING));
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) PlayerStatus(de.danoeh.antennapod.core.service.playback.PlayerStatus) FlakyTest(android.test.FlakyTest)

Example 59 with FlakyTest

use of android.test.FlakyTest in project AntennaPod by AntennaPod.

the class PlaybackSonicTest method testContinuousPlaybackOnMultipleEpisodes.

@FlakyTest(tolerance = 3)
public void testContinuousPlaybackOnMultipleEpisodes() throws Exception {
    setContinuousPlaybackPreference(true);
    uiTestUtils.addLocalFeedData(true);
    List<FeedItem> queue = DBReader.getQueue();
    final FeedItem first = queue.get(0);
    final FeedItem second = queue.get(1);
    startLocalPlaybackFromQueue();
    boolean firstPlaying = solo.waitForCondition(() -> {
        if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
            return uiTestUtils.getCurrentMedia(getActivity()).getId() == first.getMedia().getId();
        } else {
            return false;
        }
    }, Timeout.getSmallTimeout());
    assertTrue(firstPlaying);
    boolean secondPlaying = solo.waitForCondition(() -> {
        if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
            return uiTestUtils.getCurrentMedia(getActivity()).getId() == second.getMedia().getId();
        } else {
            return false;
        }
    }, Timeout.getLargeTimeout());
    assertTrue(secondPlaying);
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FlakyTest(android.test.FlakyTest)

Example 60 with FlakyTest

use of android.test.FlakyTest in project AntennaPod by AntennaPod.

the class PlaybackTest method testContinuousPlaybackOnMultipleEpisodes.

@FlakyTest(tolerance = 3)
public void testContinuousPlaybackOnMultipleEpisodes() throws Exception {
    setContinuousPlaybackPreference(true);
    uiTestUtils.addLocalFeedData(true);
    List<FeedItem> queue = DBReader.getQueue();
    final FeedItem first = queue.get(0);
    final FeedItem second = queue.get(1);
    startLocalPlaybackFromQueue();
    boolean firstPlaying = solo.waitForCondition(() -> {
        if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
            return uiTestUtils.getCurrentMedia(getActivity()).getId() == first.getMedia().getId();
        } else {
            return false;
        }
    }, Timeout.getSmallTimeout());
    assertTrue(firstPlaying);
    boolean secondPlaying = solo.waitForCondition(() -> {
        if (uiTestUtils.getCurrentMedia(getActivity()) != null) {
            return uiTestUtils.getCurrentMedia(getActivity()).getId() == second.getMedia().getId();
        } else {
            return false;
        }
    }, Timeout.getLargeTimeout());
    assertTrue(secondPlaying);
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FlakyTest(android.test.FlakyTest)

Aggregations

FlakyTest (android.test.FlakyTest)78 Instrumentation (android.app.Instrumentation)49 Intent (android.content.Intent)13 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)11 Feed (de.danoeh.antennapod.core.feed.Feed)9 ArrayList (java.util.ArrayList)7 File (java.io.File)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)3 UiObject (com.android.uiautomator.core.UiObject)2 UiSelector (com.android.uiautomator.core.UiSelector)2 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)2 PlayerStatus (de.danoeh.antennapod.core.service.playback.PlayerStatus)2 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)2 Date (java.util.Date)2 Uri (android.net.Uri)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 AppLink (bolts.AppLink)1 FacebookAppLinkResolver (com.facebook.applinks.FacebookAppLinkResolver)1 SdkSuppress (com.google.android.apps.common.testing.testrunner.annotations.SdkSuppress)1