/**
* @throws Exception
*/
@Test
public void testSyncItemsManager() throws Exception {
SyncItemsManager manager = new SyncItemsManager();
manager.startup();
assertTrue(manager.getUncommittedItems().isEmpty());
IFeed feed = fFactory.createFeed(null, URI.create("rssowl.org"));
INews news1 = fFactory.createNews(null, feed, new Date());
news1.setInReplyTo(feed.getLink().toString());
news1.setGuid(fFactory.createGuid(news1, "tag:google.com/foo", true));
INews news2 = fFactory.createNews(null, feed, new Date());
news2.setInReplyTo(feed.getLink().toString());
news2.setGuid(fFactory.createGuid(news2, "tag:google.com/bar", true));
SyncItem item1 = SyncItem.toSyncItem(news1);
item1.setMarkedRead();
SyncItem item2 = SyncItem.toSyncItem(news2);
item2.addLabel("Foo");
item2.addLabel("Bar");
item2.removeLabel("Hello World");
manager.addUncommitted(Arrays.asList(item1, item2));
assertTrue(manager.hasUncommittedItems());
manager.shutdown();
assertFalse(manager.hasUncommittedItems());
manager.startup();
assertTrue(manager.hasUncommittedItems());
Collection<SyncItem> uncommittedItems = manager.getUncommittedItems().values();
assertEquals(2, uncommittedItems.size());
Iterator<SyncItem> iterator = uncommittedItems.iterator();
SyncItem loadedItem1 = iterator.next();
SyncItem loadedItem2 = iterator.next();
assertTrue(item1.isEquivalent(loadedItem1));
assertTrue(item2.isEquivalent(loadedItem2));
SyncItem item3 = SyncItem.toSyncItem(news1);
item3.setMarkedUnread();
item3.setStarred();
manager.addUncommitted(Collections.singleton(item3));
uncommittedItems = manager.getUncommittedItems().values();
assertEquals(2, uncommittedItems.size());
iterator = uncommittedItems.iterator();
loadedItem1 = iterator.next();