use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBReaderTest method testGetNavDrawerDataQueueNotEmptyWithUnreadItems.
public void testGetNavDrawerDataQueueNotEmptyWithUnreadItems() {
final int NUM_FEEDS = 10;
final int NUM_ITEMS = 10;
final int NUM_QUEUE = 1;
final int NUM_NEW = 2;
List<Feed> feeds = DBTestUtils.saveFeedlist(NUM_FEEDS, NUM_ITEMS, true);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
for (int i = 0; i < NUM_NEW; i++) {
FeedItem item = feeds.get(0).getItems().get(i);
item.setNew();
adapter.setSingleFeedItem(item);
}
List<FeedItem> queue = new ArrayList<>();
for (int i = 0; i < NUM_QUEUE; i++) {
FeedItem item = feeds.get(1).getItems().get(i);
queue.add(item);
}
adapter.setQueue(queue);
adapter.close();
DBReader.NavDrawerData navDrawerData = DBReader.getNavDrawerData();
assertEquals(NUM_FEEDS, navDrawerData.feeds.size());
assertEquals(NUM_NEW, navDrawerData.numNewItems);
assertEquals(NUM_QUEUE, navDrawerData.queueSize);
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBReaderTest method testGetPlaybackHistory.
public void testGetPlaybackHistory() {
final int numItems = (DBReader.PLAYBACK_HISTORY_SIZE + 1) * 2;
final int playedItems = DBReader.PLAYBACK_HISTORY_SIZE + 1;
final int numReturnedItems = Math.min(playedItems, DBReader.PLAYBACK_HISTORY_SIZE);
final int numFeeds = 1;
Feed feed = DBTestUtils.saveFeedlist(numFeeds, numItems, true).get(0);
long[] ids = new long[playedItems];
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
for (int i = 0; i < playedItems; i++) {
FeedMedia m = feed.getItems().get(i).getMedia();
m.setPlaybackCompletionDate(new Date(i + 1));
adapter.setFeedMediaPlaybackCompletionDate(m);
ids[ids.length - 1 - i] = m.getItem().getId();
}
adapter.close();
List<FeedItem> saved = DBReader.getPlaybackHistory();
assertNotNull(saved);
assertEquals("Wrong size: ", numReturnedItems, saved.size());
for (int i = 0; i < numReturnedItems; i++) {
FeedItem item = saved.get(i);
assertNotNull(item.getMedia().getPlaybackCompletionDate());
assertEquals("Wrong sort order: ", item.getId(), ids[i]);
}
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBReaderTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
// create new database
PodDBAdapter.init(getInstrumentation().getTargetContext());
PodDBAdapter.deleteDatabase();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.close();
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBReaderTest method saveUnreadItems.
private List<FeedItem> saveUnreadItems(int numItems) {
if (numItems <= 0) {
throw new IllegalArgumentException("numItems<=0");
}
List<Feed> feeds = saveFeedlist(numItems, numItems, true);
List<FeedItem> items = new ArrayList<>();
for (Feed f : feeds) {
items.addAll(f.getItems());
}
List<FeedItem> unread = new ArrayList<>();
Random random = new Random();
while (unread.size() < numItems) {
int i = random.nextInt(numItems);
if (!unread.contains(items.get(i))) {
FeedItem item = items.get(i);
item.setPlayed(false);
unread.add(item);
}
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setFeedItemlist(unread);
adapter.close();
return unread;
}
use of de.danoeh.antennapod.core.storage.PodDBAdapter in project AntennaPod by AntennaPod.
the class DBTasksTest method testUpdateFeedMediaUrlResetState.
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(Arrays.asList(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);
feed.setItems(Arrays.asList(item));
final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
assertTrue(feed != newFeed);
final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
final FeedItem feedItemFromDB = feedFromDB.getItems().get(0);
assertTrue("state: " + feedItemFromDB.getState(), feedItemFromDB.isNew());
}
Aggregations