feed = DynamicDAO.save(feed);
int newNewsCount = 4;
List<INews> newNews = new ArrayList<INews>();
for (int i = 0; i < newNewsCount; ++i) {
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("new News: " + i);
news.setState(State.NEW);
newNews.add(news);
}
int readNewsCount = 2;
List<INews> readNews = new ArrayList<INews>();
for (int i = 0; i < readNewsCount; ++i) {
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("read News: " + i);
news.setState(State.READ);
readNews.add(news);
}
int unreadNewsCount = 3;
List<INews> unreadNews = new ArrayList<INews>();
for (int i = 0; i < unreadNewsCount; ++i) {
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("unread News: " + i);
news.setState(State.UNREAD);
unreadNews.add(news);
}
int updatedNewsCount = 6;
List<INews> updatedNews = new ArrayList<INews>();
for (int i = 0; i < updatedNewsCount; ++i) {
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("updated News: " + i);
news.setState(State.UPDATED);
updatedNews.add(news);
}
int hiddenNewsCount = 8;
List<INews> hiddenNews = new ArrayList<INews>();
for (int i = 0; i < hiddenNewsCount; ++i) {
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("hidden News: " + i);
news.setState(State.HIDDEN);
hiddenNews.add(news);
}
int deletedNewsCount = 7;
List<INews> deletedNews = new ArrayList<INews>();
for (int i = 0; i < deletedNewsCount; ++i) {
INews news = fFactory.createNews(null, feed, new Date());
news.setTitle("deleted News: " + i);
news.setState(State.DELETED);
deletedNews.add(news);
}
assertEquals(newNewsCount, feed.getNewsByStates(EnumSet.of(State.NEW)).size());
int counter = 0;
for (INews news : feed.getNewsByStates(EnumSet.of(State.NEW))) {
INews newsItem = newNews.get(counter++);
assertEquals(newsItem.getTitle(), news.getTitle());
}
assertEquals(readNewsCount, feed.getNewsByStates(EnumSet.of(State.READ)).size());
counter = 0;
for (INews news : feed.getNewsByStates(EnumSet.of(State.READ))) {
INews newsItem = readNews.get(counter++);
assertEquals(newsItem.getTitle(), news.getTitle());
}
assertEquals(unreadNewsCount, feed.getNewsByStates(EnumSet.of(State.UNREAD)).size());
counter = 0;
for (INews news : feed.getNewsByStates(EnumSet.of(State.UNREAD))) {
INews newsItem = unreadNews.get(counter++);
assertEquals(newsItem.getTitle(), news.getTitle());
}
assertEquals(updatedNewsCount, feed.getNewsByStates(EnumSet.of(State.UPDATED)).size());
counter = 0;
for (INews news : feed.getNewsByStates(EnumSet.of(State.UPDATED))) {
INews newsItem = updatedNews.get(counter++);
assertEquals(newsItem.getTitle(), news.getTitle());
}
assertEquals(hiddenNewsCount, feed.getNewsByStates(EnumSet.of(State.HIDDEN)).size());
counter = 0;
for (INews news : feed.getNewsByStates(EnumSet.of(State.HIDDEN))) {
INews newsItem = hiddenNews.get(counter++);
assertEquals(newsItem.getTitle(), news.getTitle());
}
assertEquals(deletedNewsCount, feed.getNewsByStates(EnumSet.of(State.DELETED)).size());
counter = 0;
for (INews news : feed.getNewsByStates(EnumSet.of(State.DELETED))) {
INews newsItem = deletedNews.get(counter++);
assertEquals(newsItem.getTitle(), news.getTitle());
}
int visibleNewsCount = newNewsCount + readNewsCount + unreadNewsCount + updatedNewsCount;
assertEquals(visibleNewsCount, feed.getVisibleNews().size());
for (INews news : feed.getVisibleNews()) {
boolean matchFound = false;
for (INews newsItem : newNews) {
if (news.getTitle().equals(newsItem.getTitle())) {
matchFound = true;
break;
}
}
if (matchFound)
continue;
for (INews newsItem : readNews) {
if (news.getTitle().equals(newsItem.getTitle())) {
matchFound = true;
break;
}
}
if (matchFound)
continue;
for (INews newsItem : unreadNews) {
if (news.getTitle().equals(newsItem.getTitle())) {
matchFound = true;
break;
}
}
if (matchFound)
continue;
for (INews newsItem : updatedNews) {
if (news.getTitle().equals(newsItem.getTitle())) {
matchFound = true;
break;
}
}
if (matchFound)
continue;
fail("No match was found. A news that had the wrong state was returned");
}
for (INews news : feed.getNewsByStates(EnumSet.of(State.NEW, State.HIDDEN, State.DELETED))) {
boolean matchFound = false;
for (INews newsItem : newNews) {
if (news.getTitle().equals(newsItem.getTitle())) {
matchFound = true;
break;
}
}
if (matchFound)
continue;
for (INews newsItem : hiddenNews) {
if (news.getTitle().equals(newsItem.getTitle())) {
matchFound = true;
break;
}
}
if (matchFound)
continue;
for (INews newsItem : deletedNews) {
if (news.getTitle().equals(newsItem.getTitle())) {
matchFound = true;
break;
}
}
if (matchFound)