final NewsReference[] newsRef = new NewsReference[1];
newsAdapter = new NewsAdapter() {
@Override
public void newsAdded(Set<NewsEvent> events) {
assertEquals(1, events.size());
newsRef[0] = new NewsReference(events.iterator().next().getEntity().getId());
}
};
NewsModel.getDefault().addNewsListener(newsAdapter);
final News initialNews1 = (News) createNews(feed1);
initialNews1.setGuid(null);
initialNews1.setState(State.NEW);
final News initialNews2 = (News) createNews(feed2);
initialNews2.setGuid(null);
initialNews2.setState(State.NEW);
INews newsItem1 = null;
NewsReference newsRef1 = null;
INews newsItem2 = null;
NewsReference newsRef2 = null;
NewsReference newsRef3 = null;
try {
fModelDAO.saveFeed(feed1);
newsRef1 = newsRef[0];
newsItem1 = newsRef1.resolve();
feed2 = fModelDAO.saveFeed(feed2);
newsRef2 = newsRef[0];
newsItem2 = newsRef2.resolve();
final News initialNews3 = (News) createNews(feed2);
initialNews3.setTitle("Some other title");
initialNews3.setGuid(null);
initialNews3.setLink(null);
initialNews3.setState(State.NEW);
fModelDAO.saveFeed(feed2);
newsRef3 = newsRef[0];
} catch (PersistenceException e) {
fail(e.getMessage());
return;
} finally {
NewsModel.getDefault().removeNewsListener(newsAdapter);
}
try {
List<INews> newsList1 = new ArrayList<INews>();
newsList1.add(newsItem1);
List<INews> newsList2 = new ArrayList<INews>();
newsList2.add(newsItem2);
fAppLayer.setNewsState(newsList1, State.UPDATED, true, false);
INews news1 = newsRef1.resolve();
INews news2 = newsRef2.resolve();
INews news3 = newsRef3.resolve();
assertEquals(State.UPDATED, news1.getState());
assertEquals(State.UPDATED, news2.getState());
assertEquals(State.NEW, news3.getState());
fAppLayer.setNewsState(newsList2, State.DELETED, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.DELETED, news1.getState());
assertEquals(State.DELETED, news2.getState());
assertEquals(State.NEW, news3.getState());
fAppLayer.setNewsState(newsList1, State.HIDDEN, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.HIDDEN, news1.getState());
assertEquals(State.HIDDEN, news2.getState());
assertEquals(State.NEW, news3.getState());
fAppLayer.setNewsState(newsList2, State.READ, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.READ, news1.getState());
assertEquals(State.READ, news2.getState());
assertEquals(State.NEW, news3.getState());
fAppLayer.setNewsState(newsList1, State.UNREAD, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.UNREAD, news1.getState());
assertEquals(State.UNREAD, news2.getState());
assertEquals(State.NEW, news3.getState());
fAppLayer.setNewsState(newsList2, State.NEW, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.NEW, news1.getState());
assertEquals(State.NEW, news2.getState());
assertEquals(State.NEW, news3.getState());
// Make sure it doesn't change when we set it to the same
fAppLayer.setNewsState(newsList1, State.NEW, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.NEW, news1.getState());
assertEquals(State.NEW, news2.getState());
assertEquals(State.NEW, news3.getState());
fModelDAO.deleteNews(newsRef1);