Search in sources :

Example 31 with FeedItem

use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.

the class DbCleanupTests method testPerformAutoCleanupHandleUnplayed.

@Test
public void testPerformAutoCleanupHandleUnplayed() throws IOException {
    final int numItems = 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(numItems, feed, items, files, FeedItem.UNPLAYED, false, false);
    DBTasks.performAutoCleanup(context);
    for (File file : files) {
        assertTrue(file.exists());
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 32 with FeedItem

use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.

the class DbCleanupTests method testPerformAutoCleanupShouldDelete.

@Test
public void testPerformAutoCleanupShouldDelete() throws IOException {
    final int numItems = 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(numItems, feed, items, files, FeedItem.PLAYED, 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.model.feed.FeedItem) ArrayList(java.util.ArrayList) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 33 with FeedItem

use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.

the class DbCleanupTests method testPerformAutoCleanupShouldNotDeleteBecauseInQueue.

@Test
public void testPerformAutoCleanupShouldNotDeleteBecauseInQueue() throws IOException {
    final int numItems = 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(numItems, feed, items, files, FeedItem.PLAYED, true, false);
    DBTasks.performAutoCleanup(context);
    for (File file : files) {
        assertTrue(file.exists());
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 34 with FeedItem

use of de.danoeh.antennapod.model.feed.FeedItem 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.
 */
@Test
public void testPerformAutoCleanupHandleUnplayed() throws IOException {
    final int numItems = 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(numItems, 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.model.feed.FeedItem) ArrayList(java.util.ArrayList) File(java.io.File) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 35 with FeedItem

use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.

the class DbTasksTest method testUpdateFeedMediaUrlResetState.

@Test
public void testUpdateFeedMediaUrlResetState() {
    final Feed feed = new Feed("url", null, "title");
    FeedItem item = new FeedItem(0, "item", "id", "link", new Date(), FeedItem.PLAYED, feed);
    feed.setItems(singletonList(item));
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    // ensure that objects have been saved in db, then reset
    assertTrue(feed.getId() != 0);
    assertTrue(item.getId() != 0);
    FeedMedia media = new FeedMedia(item, "url", 1024, "mime/type");
    item.setMedia(media);
    List<FeedItem> list = new ArrayList<>();
    list.add(item);
    feed.setItems(list);
    final Feed newFeed = DBTasks.updateFeed(context, feed, false);
    assertNotSame(newFeed, feed);
    final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
    final FeedItem feedItemFromDB = feedFromDB.getItems().get(0);
    assertTrue(feedItemFromDB.isNew());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Aggregations

FeedItem (de.danoeh.antennapod.model.feed.FeedItem)178 Feed (de.danoeh.antennapod.model.feed.Feed)74 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)48 Date (java.util.Date)47 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)46 File (java.io.File)26 Cursor (android.database.Cursor)20 NonNull (androidx.annotation.NonNull)15 Nullable (androidx.annotation.Nullable)11 Subscribe (org.greenrobot.eventbus.Subscribe)9 Intent (android.content.Intent)7 FeedFilter (de.danoeh.antennapod.model.feed.FeedFilter)7 View (android.view.View)6 LongList (de.danoeh.antennapod.core.util.LongList)6 SQLException (android.database.SQLException)5 Playable (de.danoeh.antennapod.model.playback.Playable)5 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)5 ExecutionException (java.util.concurrent.ExecutionException)5 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)4