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()); } }
/** 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); }
@Override public int deletePodcast(Podcast podcast) { synchronized (cache) { cache.remove(podcast.getId()); } return dao.deletePodcast(podcast); }
@Override public boolean localDeletePodcast(Podcast podcast) { synchronized (cache) { cache.remove(podcast.getId()); } return dao.localDeletePodcast(podcast); }
/** 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()); }
/** 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()); }
/** 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()); }
/** 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); }
@Override public Podcast insertPodcast(Podcast podcast) { if (dao.insertPodcast(podcast) == null) { return null; } synchronized (cache) { cache.put(podcast.getId(), podcast); } return podcast; }
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); }
/** * 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); }
@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; }
@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; }