Esempio n. 1
0
  private List<Podcast> cacheResults(List<Podcast> ps) {
    if (ps == null) {
      return null;
    }

    synchronized (cache) {
      for (Podcast p : ps) {
        if (!cache.containsKey(p.getId())) {
          cache.put(p.getId(), p);
        }
      }

      return new ArrayList<Podcast>(cache.values());
    }
  }
Esempio n. 2
0
 /** tests the insertPodcast functionality */
 public void testInsertPodcast() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   int countBeforeInsert = pdao.getAllPodcasts().size();
   p1 = pdao.insertPodcast(p1);
   int countAfterInsert = pdao.getAllPodcasts().size();
   assertEquals(countBeforeInsert + 1, countAfterInsert);
   assertTrue(p1.getId() > 0);
 }
Esempio n. 3
0
  @Override
  public int deletePodcast(Podcast podcast) {
    synchronized (cache) {
      cache.remove(podcast.getId());
    }

    return dao.deletePodcast(podcast);
  }
Esempio n. 4
0
  @Override
  public boolean localDeletePodcast(Podcast podcast) {
    synchronized (cache) {
      cache.remove(podcast.getId());
    }

    return dao.localDeletePodcast(podcast);
  }
Esempio n. 5
0
 /** tests the updateLogoFilePath functionality */
 public void testUpdateLogoFilePath() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1 = pdao.insertPodcast(p1);
   String newFilePath = "new path haha";
   p1.setLogoFilePath(newFilePath);
   assertEquals(1, pdao.updateLogoFilePath(p1));
   Podcast pod = pdao.getPodcastById(p1.getId());
   assertEquals(newFilePath, pod.getLogoFilePath());
 }
Esempio n. 6
0
 /** tests the updateLastUpdate functionality */
 public void testUpdateLastUpdate() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1 = pdao.insertPodcast(p1);
   long currentMilis = System.currentTimeMillis();
   p1.setLastUpdate(currentMilis);
   assertEquals(1, pdao.updateLastUpdate(p1));
   Podcast pod = pdao.getPodcastById(p1.getId());
   assertEquals(currentMilis, pod.getLastUpdate());
 }
Esempio n. 7
0
 /** tests the getPodcastById functionality */
 public void testGetPodcastById() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1.setTitle("expected title");
   p1 = pdao.insertPodcast(p1);
   Podcast pod = pdao.getPodcastById(p1.getId());
   assertEquals("expected title", pod.getTitle());
   assertEquals(p1.getLastUpdate(), pod.getLastUpdate());
   assertEquals(p1.hashCode(), pod.hashCode());
 }
Esempio n. 8
0
  /** Upon adding a new podcast to the DAO, it should be displayed in the podcast list. */
  public void testAddPodcast() {
    Podcast p = insertPodcast();

    while (solo.scrollDown()) ;

    assertTrue(
        String.format("New podcast %s should be displayed in list", uuid), solo.searchText(uuid));
    assertTrue(
        String.format("New podcast %s should be in DAO", uuid),
        dao.getPodcastById(p.getId()) != null);
  }
Esempio n. 9
0
  @Override
  public Podcast insertPodcast(Podcast podcast) {
    if (dao.insertPodcast(podcast) == null) {
      return null;
    }

    synchronized (cache) {
      cache.put(podcast.getId(), podcast);
    }

    return podcast;
  }
Esempio n. 10
0
  public void testRotation() {
    Podcast p = insertPodcast();

    solo.setActivityOrientation(Solo.LANDSCAPE);
    while (solo.scrollDown()) ;

    assertTrue(
        String.format("New podcast %s should be displayed in list", uuid), solo.searchText(uuid));
    assertTrue(
        String.format("New podcast %s should be in DAO", uuid),
        dao.getPodcastById(p.getId()) != null);
  }
Esempio n. 11
0
  /**
   * After deleting the newly added podcast, it should not be displayed in the podcast list, and
   * should not be contained in the podcast DAO.
   */
  public void testRemovePodcast() {
    Podcast p = insertPodcast();

    while (solo.scrollDown()) ;

    solo.clickLongOnText(uuid);
    solo.clickOnText(getActivity().getString(at.ac.tuwien.detlef.R.string.delete_feed));

    assertFalse(
        String.format("Deleted podcast %s should not be displayed in list", uuid),
        solo.searchText(uuid));
    assertFalse(
        String.format("Deleted podcast %s should not be in DAO", uuid),
        dao.getPodcastById(p.getId()) != null);
  }
Esempio n. 12
0
  @Override
  public Podcast getPodcastByUrl(String url) {
    synchronized (cache) {
      for (Podcast p : cache.values()) {
        if (p.getUrl().equals(url)) {
          return p;
        }
      }
    }

    Podcast p = dao.getPodcastByUrl(url);
    if (p == null) {
      return null;
    }

    synchronized (cache) {
      cache.put(p.getId(), p);
    }

    return p;
  }
Esempio n. 13
0
  @Override
  public Podcast getPodcastById(long podcastId) {
    Podcast p;
    synchronized (cache) {
      p = cache.get(podcastId);
    }

    if (p != null) {
      return p;
    }

    p = dao.getPodcastById(podcastId);
    if (p == null) {
      return null;
    }

    synchronized (cache) {
      cache.put(p.getId(), p);
    }

    return p;
  }