news2.setState(INews.State.READ);
INews news3 = fFactory.createNews(3L, feed, new Date());
DynamicDAO.save(feed);
EntityGroup group1 = new EntityGroup(100, "foo");
EntityGroup group2 = new EntityGroup(101, "foo");
Object[] elements = new Object[] { group1, news1, news2, group2, news3, feed };
NewsBrowserViewModel model = new NewsBrowserViewModel(null);
model.setInput(elements, 2);
assertFalse(model.isFirstItemUnread());
assertEquals(-1L, model.findGroup(5L));
assertEquals(100L, model.findGroup(1L));
assertEquals(100L, model.findGroup(2L));
assertEquals(101L, model.findGroup(3L));
assertEquals(-1L, model.getExpandedNews());
model.setNewsExpanded(news3, true);
assertEquals(3L, model.getExpandedNews());
assertEquals(2, model.getGroups().size());
assertEquals(2, model.getGroupSize(100L));
assertEquals(1, model.getGroupSize(101L));
Map<Long, List<Long>> groups = model.getGroups();
List<Long> group_1 = groups.get(100L);
List<Long> group_2 = groups.get(101L);
assertEquals(1, group_1.get(0).longValue());
assertEquals(2, group_1.get(1).longValue());
assertEquals(3, group_2.get(0).longValue());
List<Long> newsIds = model.getNewsIds(100L);
assertEquals(1, newsIds.get(0).longValue());
assertEquals(2, newsIds.get(1).longValue());
assertFalse(model.hasGroup(5L));
assertTrue(model.hasGroup(100L));
assertTrue(model.hasGroup(101L));
assertFalse(model.isNewsExpanded(news2));
assertTrue(model.isNewsExpanded(news3));
assertTrue(model.isGroupExpanded(5L));
model.setGroupExpanded(100L, false);
assertFalse(model.isGroupExpanded(100L));
assertEquals(1L, model.nextNews(false, -1L));
assertEquals(1L, model.nextNews(true, -1L));
assertEquals(2L, model.nextNews(false, 1L));
assertEquals(3L, model.nextNews(true, 1L));
assertEquals(-1L, model.nextNews(true, 3L));
assertEquals(1L, model.nextNews(true, 5L));
assertEquals(-1L, model.nextNews(false, 3L));
assertEquals(1L, model.nextNews(false, 5L));
assertEquals(3L, model.previousNews(false, -1L));
assertEquals(3L, model.previousNews(true, -1L));
assertEquals(-1L, model.previousNews(false, 1L));
assertEquals(-1L, model.previousNews(true, 1L));
assertEquals(2L, model.previousNews(false, 3L));
assertEquals(1L, model.previousNews(true, 3L));
assertEquals(3L, model.previousNews(true, 5L));
assertEquals(3L, model.previousNews(false, 5L));
Pair<List<Long>, List<Long>> nextPage = model.getNextPage(2);
assertEquals(1, nextPage.getFirst().size());
assertEquals(group2.getId(), nextPage.getFirst().get(0).longValue());
assertEquals(1, nextPage.getSecond().size());
assertEquals(news3.getId(), nextPage.getSecond().get(0));
model.setGroupVisible(group2.getId(), true);
model.setNewsVisible(news3, true);
nextPage = model.getNextPage(2);
assertTrue(nextPage.getFirst().isEmpty());
assertTrue(nextPage.getSecond().isEmpty());
model.setGroupVisible(group2.getId(), false);
model.setNewsVisible(news3, false);
Pair<List<Long>, List<Long>> revealed = model.revealPage(news3.getId(), 2);
assertEquals(1, revealed.getFirst().size());
assertEquals(group2.getId(), revealed.getFirst().get(0).longValue());
assertEquals(1, revealed.getSecond().size());
assertEquals(news3.getId(), revealed.getSecond().get(0));
}