long now = System.currentTimeMillis();
/* First Reload */
InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", "http://www.guid.de", null);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(1, getNewCount(feed));
assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
/* Set to Unread */
fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);
/* Second Reload with updated Title */
InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link.de", "http://www.guid.de", null);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
/* Set to Read and Reload */
fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
/* Fourth Reload with updated Link */
InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link_updated.de", "http://www.guid.de", null);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
/* Set to Read and Reload */
fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
/* Fifth Reload with updated Title and Link */
InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", "http://www.link_updated_again.de", "http://www.guid.de", null);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
/* Set to Read and Reload */
fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
/* Sixth Reload with added News */
InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", "http://www.link_updated_again.de", "http://www.guid_other.de", null);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(2, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(1, getNewCount(feed));
List<INews> news = feedRef.resolve().getNews();
for (INews newsItem : news) {
if ("http://www.guid.de".equals(newsItem.getGuid().getValue()))
assertEquals(INews.State.READ, newsItem.getState());
else if ("http://www.guid_other.de".equals(newsItem.getGuid().getValue()))
assertEquals(INews.State.NEW, newsItem.getState());
}
/* Set to Read */
fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(2, feedRef.resolve().getNews().size());
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());