INews currentNews = fFactory.createNews(null, feed, new Date());
currentNews.setInReplyTo(feed.getLink().toString());
currentNews.setGuid(fFactory.createGuid(currentNews, "tag:google.com/foo", true));
SyncItem item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertNull(item);
currentNews.setState(INews.State.READ);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertTrue(item.isMarkedRead());
assertFalse(item.isMarkedUnread());
assertFalse(item.isStarred());
assertFalse(item.isUnStarred());
assertTrue(item.getAddedLabels().isEmpty());
assertTrue(item.getRemovedLabels().isEmpty());
oldNews.setState(INews.State.READ);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertNull(item);
currentNews.setState(INews.State.DELETED);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertNull(item);
currentNews.setState(INews.State.HIDDEN);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertNull(item);
currentNews.setState(INews.State.UNREAD);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertFalse(item.isStarred());
assertFalse(item.isUnStarred());
assertTrue(item.getAddedLabels().isEmpty());
assertTrue(item.getRemovedLabels().isEmpty());
currentNews.setFlagged(true);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertTrue(item.isStarred());
assertFalse(item.isUnStarred());
assertTrue(item.getAddedLabels().isEmpty());
assertTrue(item.getRemovedLabels().isEmpty());
oldNews.setFlagged(true);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertFalse(item.isStarred());
assertFalse(item.isUnStarred());
assertTrue(item.getAddedLabels().isEmpty());
assertTrue(item.getRemovedLabels().isEmpty());
currentNews.setFlagged(false);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertFalse(item.isStarred());
assertTrue(item.isUnStarred());
assertTrue(item.getAddedLabels().isEmpty());
assertTrue(item.getRemovedLabels().isEmpty());
currentNews.addLabel(label1);
currentNews.addLabel(label2);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertFalse(item.isStarred());
assertTrue(item.isUnStarred());
assertEquals(2, item.getAddedLabels().size());
assertTrue(item.getRemovedLabels().isEmpty());
oldNews.addLabel(label1);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertFalse(item.isStarred());
assertTrue(item.isUnStarred());
assertEquals(1, item.getAddedLabels().size());
assertTrue(item.getRemovedLabels().isEmpty());
currentNews.removeLabel(label1);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertFalse(item.isStarred());
assertTrue(item.isUnStarred());
assertEquals(1, item.getAddedLabels().size());
assertEquals("Bar", item.getAddedLabels().get(0));
assertEquals(1, item.getRemovedLabels().size());
assertEquals("Foo", item.getRemovedLabels().get(0));
oldNews.addLabel(label2);
currentNews.removeLabel(label2);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertFalse(item.isMarkedRead());
assertTrue(item.isMarkedUnread());
assertFalse(item.isStarred());
assertTrue(item.isUnStarred());
assertEquals(0, item.getAddedLabels().size());
assertEquals(2, item.getRemovedLabels().size());
currentNews.setState(INews.State.HIDDEN);
oldNews.setState(INews.State.NEW);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertTrue(item.isMarkedRead());
assertFalse(item.isMarkedUnread());
assertFalse(item.isStarred());
assertTrue(item.isUnStarred());
assertEquals(0, item.getAddedLabels().size());
assertEquals(2, item.getRemovedLabels().size());
currentNews.setFlagged(true);
oldNews.setFlagged(true);
item = SyncItem.toSyncItem(new NewsEvent(oldNews, currentNews, true));
assertTrue(item.isMarkedRead());
assertFalse(item.isMarkedUnread());
assertFalse(item.isStarred());
assertTrue(item.isUnStarred());
assertEquals(0, item.getAddedLabels().size());
assertEquals(2, item.getRemovedLabels().size());
}