* @throws Exception
*/
@Test
public void testLoadAllNewsByFeedAndState() throws Exception {
IFeed feed = fFactory.createFeed(null, new URI("http://www.feed.com"));
INews news = fFactory.createNews(null, feed, new Date());
FeedLinkReference feedRef = news.getFeedReference();
news.setState(INews.State.HIDDEN);
fFactory.createNews(null, feed, new Date()).setState(INews.State.UNREAD);
fFactory.createNews(null, feed, new Date()).setState(INews.State.UPDATED);
DynamicDAO.save(feed);
IFeed anotherFeed = fFactory.createFeed(null, new URI("http://www.anotherfeed.com"));
INews anotherNews = fFactory.createNews(null, anotherFeed, new Date());
FeedLinkReference anotherFeedRef = anotherNews.getFeedReference();
fFactory.createNews(null, anotherFeed, new Date());
fFactory.createNews(null, anotherFeed, new Date()).setState(INews.State.DELETED);
DynamicDAO.save(anotherFeed);
INewsDAO newsDao = DynamicDAO.getDAO(INewsDAO.class);
/* All states */
Collection<INews> newsCollection = newsDao.loadAll(feedRef, EnumSet.allOf(INews.State.class));
assertEquals(feed.getNews().size(), newsCollection.size());
for (INews newsItem : feed.getNews())
assertEquals(true, newsCollection.contains(newsItem));
newsCollection = newsDao.loadAll(anotherFeedRef, EnumSet.allOf(INews.State.class));
assertEquals(anotherFeed.getNews().size(), newsCollection.size());
for (INews newsItem : anotherFeed.getNews())
assertEquals(true, newsCollection.contains(newsItem));
/* Two matching states */
newsCollection = newsDao.loadAll(feedRef, EnumSet.of(INews.State.UNREAD, INews.State.UPDATED));
assertEquals(2, newsCollection.size());
assertEquals(true, newsCollection.contains(feed.getNews().get(1)));
assertEquals(true, newsCollection.contains(feed.getNews().get(2)));
/* One matching state */
newsCollection = newsDao.loadAll(anotherFeedRef, EnumSet.of(INews.State.DELETED));
assertEquals(1, newsCollection.size());
assertEquals(anotherFeed.getNews().get(2), newsCollection.iterator().next());
/* No matching state */
newsCollection = newsDao.loadAll(feedRef, EnumSet.of(INews.State.DELETED));
assertEquals(0, newsCollection.size());
/* One state with two matches and two states with no matches */
newsCollection = newsDao.loadAll(anotherFeedRef, EnumSet.of(INews.State.NEW, INews.State.HIDDEN, INews.State.UPDATED));
assertEquals(2, newsCollection.size());
assertEquals(true, newsCollection.contains(anotherFeed.getNews().get(0)));
assertEquals(true, newsCollection.contains(anotherFeed.getNews().get(1)));
/* Empty states */
newsCollection = newsDao.loadAll(feedRef, EnumSet.noneOf(INews.State.class));
assertEquals(0, newsCollection.size());
}