IFeed feed = fFactory.createFeed(null, new URI("feed"));
INews news = fFactory.createNews(null, feed, new Date());
DynamicDAO.save(feed);
final AtomicInteger mode = new AtomicInteger(0);
final AtomicInteger counter = new AtomicInteger(0);
NewsListener listener = null;
try {
listener = new NewsAdapter() {
@Override
public void entitiesUpdated(Set<NewsEvent> events) {
assertEquals(1, events.size());
if (mode.get() == 0) {
assertTrue(CoreUtils.isStickyStateChange(events.iterator().next()));
assertTrue(CoreUtils.isStickyStateChange(events));
assertTrue(CoreUtils.isStickyStateChange(events, true));
counter.incrementAndGet();
}
else if (mode.get() == 1) {
assertFalse(CoreUtils.isStickyStateChange(events.iterator().next()));
assertFalse(CoreUtils.isStickyStateChange(events));
assertFalse(CoreUtils.isStickyStateChange(events, true));
counter.incrementAndGet();
}
else if (mode.get() == 2) {
assertTrue(CoreUtils.isStickyStateChange(events.iterator().next()));
assertTrue(CoreUtils.isStickyStateChange(events));
assertFalse(CoreUtils.isStickyStateChange(events, true));
counter.incrementAndGet();
}
}
};
DynamicDAO.addEntityListener(INews.class, listener);
mode.set(0);
news.setFlagged(true);
DynamicDAO.save(news);
mode.set(1);
news.setTitle("Foo");
DynamicDAO.save(news);
mode.set(2);
news.setFlagged(false);
DynamicDAO.save(news);
assertEquals(3, counter.get());
} finally {
if (listener != null)
DynamicDAO.removeEntityListener(INews.class, listener);
}
}