IFolder folder = fFactory.createFolder(null, null, "Root");
IFolder childFolder = fFactory.createFolder(null, folder, "Child");
DynamicDAO.save(folder);
FolderNewsMark mark = new FolderNewsMark(childFolder);
mark.resolve(NewsFilter.Type.SHOW_ALL, null);
IFeed feed = fFactory.createFeed(null, new URI("feed"));
INews news1 = fFactory.createNews(null, feed, new Date());
news1.setState(INews.State.NEW);
INews news2 = fFactory.createNews(null, feed, new Date());
news2.setState(INews.State.UNREAD);
INews news3 = fFactory.createNews(null, feed, new Date());
news3.setState(INews.State.READ);
DynamicDAO.save(feed);
fFactory.createBookMark(null, childFolder, new FeedLinkReference(feed.getLink()), "Mark");
IFeed otherFeed = fFactory.createFeed(null, new URI("otherfeed"));
INews othernews1 = fFactory.createNews(null, otherFeed, new Date());
othernews1.setState(INews.State.NEW);
INews othernews2 = fFactory.createNews(null, otherFeed, new Date());
othernews2.setState(INews.State.UNREAD);
INews othernews3 = fFactory.createNews(null, otherFeed, new Date());
othernews3.setState(INews.State.READ);
DynamicDAO.save(otherFeed);
fFactory.createBookMark(null, folder, new FeedLinkReference(otherFeed.getLink()), "Other Mark");
INewsBin bin = fFactory.createNewsBin(null, childFolder, "bin");
DynamicDAO.save(bin);
INews copiedNews1 = fFactory.createNews(news1, bin);
INews copiedNews2 = fFactory.createNews(news2, bin);
INews copiedNews3 = fFactory.createNews(news3, bin);
DynamicDAO.save(copiedNews1);
DynamicDAO.save(copiedNews2);
DynamicDAO.save(copiedNews3);
ISearchField stateField = fFactory.createSearchField(INews.STATE, INews.class.getName());
ISearchCondition condition = fFactory.createSearchCondition(stateField, SearchSpecifier.IS, EnumSet.of(INews.State.NEW));
ISearchMark search = fFactory.createSearchMark(null, childFolder, "search");
search.addSearchCondition(condition);
folder = DynamicDAO.save(folder);
waitForIndexer();
Controller.getDefault().getSavedSearchService().updateSavedSearches(true);
mark.add(Collections.singleton(news1));
mark.add(Collections.singleton(news2));
mark.add(Collections.singleton(news3));
mark.add(Collections.singleton(copiedNews1));
mark.add(Collections.singleton(copiedNews2));
mark.add(Collections.singleton(copiedNews3));
mark.add(Collections.singleton(othernews1));
{
List<INews> news = mark.getNews();
assertTrue(news.contains(news1));
assertTrue(news.contains(news2));
assertTrue(news.contains(news3));
assertTrue(news.contains(copiedNews1));
assertTrue(news.contains(copiedNews2));
assertTrue(news.contains(copiedNews3));
assertTrue(news.contains(othernews1));
}
{
List<INews> news = mark.getNews(INews.State.getVisible());
assertTrue(news.contains(news1));
assertTrue(news.contains(news2));
assertTrue(news.contains(news3));
assertTrue(news.contains(copiedNews1));
assertTrue(news.contains(copiedNews2));
assertTrue(news.contains(copiedNews3));
assertTrue(news.contains(othernews1));
}
{
List<INews> news = mark.getNews(EnumSet.of(INews.State.NEW));
assertTrue(news.contains(news1));
assertTrue(news.contains(othernews1));
}
{
List<INews> news = mark.getNews(EnumSet.of(INews.State.NEW, INews.State.UNREAD, INews.State.UPDATED));
assertTrue(news.contains(news1));
assertTrue(news.contains(news2));
assertTrue(news.contains(copiedNews1));
assertTrue(news.contains(copiedNews2));
assertTrue(news.contains(othernews1));
}
{
assertEquals(7, mark.getNewsCount(INews.State.getVisible()));
assertEquals(7, mark.getNewsCount(EnumSet.of(INews.State.NEW)));
assertEquals(7, mark.getNewsCount(EnumSet.of(INews.State.NEW, INews.State.UNREAD, INews.State.UPDATED)));
}
{
List<NewsReference> news = mark.getNewsRefs();
assertTrue(news.contains(news1.toReference()));
assertTrue(news.contains(news2.toReference()));
assertTrue(news.contains(news3.toReference()));
assertTrue(news.contains(copiedNews1.toReference()));
assertTrue(news.contains(copiedNews2.toReference()));
assertTrue(news.contains(copiedNews3.toReference()));
assertTrue(news.contains(othernews1.toReference()));
}
{
List<NewsReference> news = mark.getNewsRefs(INews.State.getVisible());
assertTrue(news.contains(news1.toReference()));
assertTrue(news.contains(news2.toReference()));
assertTrue(news.contains(news3.toReference()));
assertTrue(news.contains(copiedNews1.toReference()));
assertTrue(news.contains(copiedNews2.toReference()));
assertTrue(news.contains(copiedNews3.toReference()));
assertTrue(news.contains(othernews1.toReference()));
}
{
List<NewsReference> news = mark.getNewsRefs(EnumSet.of(INews.State.NEW));
assertTrue(news.contains(news1.toReference()));
assertTrue(news.contains(othernews1.toReference()));
}
{
List<NewsReference> news = mark.getNewsRefs(EnumSet.of(INews.State.NEW, INews.State.UNREAD, INews.State.UPDATED));
assertTrue(news.contains(news1.toReference()));
assertTrue(news.contains(news2.toReference()));
assertTrue(news.contains(copiedNews1.toReference()));
assertTrue(news.contains(copiedNews2.toReference()));
assertTrue(news.contains(othernews1.toReference()));
}
{
assertTrue(mark.containsNews(news1));
assertTrue(mark.containsNews(news2));
assertTrue(mark.containsNews(news3));
assertTrue(mark.containsNews(copiedNews1));
assertTrue(mark.containsNews(copiedNews2));
assertTrue(mark.containsNews(copiedNews3));
assertTrue(mark.containsNews(othernews1));
}
{
assertTrue(mark.isRelatedTo(news1));
assertTrue(mark.isRelatedTo(news2));
assertTrue(mark.isRelatedTo(news3));
assertTrue(mark.isRelatedTo(copiedNews1));
assertTrue(mark.isRelatedTo(copiedNews2));
assertTrue(mark.isRelatedTo(copiedNews3));
}
}