Example #1
0
  public void testAddQueueItemSingleItemAlreadyInQueue()
      throws InterruptedException, ExecutionException, TimeoutException {
    final Context context = getInstrumentation().getTargetContext();
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
    feed.getItems().add(item);

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    assertTrue(item.getId() != 0);
    DBWriter.addQueueItem(context, item).get(TIMEOUT, TimeUnit.SECONDS);

    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor cursor = adapter.getQueueIDCursor();
    assertTrue(cursor.moveToFirst());
    assertTrue(cursor.getLong(0) == item.getId());
    cursor.close();
    adapter.close();

    DBWriter.addQueueItem(context, item).get(TIMEOUT, TimeUnit.SECONDS);
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    cursor = adapter.getQueueIDCursor();
    assertTrue(cursor.moveToFirst());
    assertTrue(cursor.getLong(0) == item.getId());
    assertTrue(cursor.getCount() == 1);
    cursor.close();
    adapter.close();
  }
Example #2
0
  private Feed queueTestSetupMultipleItems(final int NUM_ITEMS)
      throws InterruptedException, ExecutionException, TimeoutException {
    final Context context = getInstrumentation().getTargetContext();
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
      FeedItem item =
          new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.PLAYED, feed);
      feed.getItems().add(item);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
    }
    List<Future<?>> futures = new ArrayList<>();
    for (FeedItem item : feed.getItems()) {
      futures.add(DBWriter.addQueueItem(context, item));
    }
    for (Future<?> f : futures) {
      f.get(TIMEOUT, TimeUnit.SECONDS);
    }
    return feed;
  }