INews news3 = fFactory.createNews(3L, feed, new Date());
DynamicDAO.save(feed);
Object[] elements = new Object[] { news1, news2, news3, feed };
NewsBrowserViewModel model = new NewsBrowserViewModel(null);
model.setInput(elements, 0);
assertTrue(model.isFirstItemUnread());
assertEquals(-1L, model.findGroup(5L));
assertEquals(-1L, model.getExpandedNews());
model.setNewsExpanded(news3, true);
assertEquals(3L, model.getExpandedNews());
assertTrue(model.getGroups().isEmpty());
assertEquals(0, model.getGroupSize(5L));
assertTrue(model.getNewsIds(5L).isEmpty());
assertFalse(model.hasGroup(5L));
assertFalse(model.hasNews(5L));
assertFalse(model.isNewsExpanded(news2));
assertTrue(model.isNewsExpanded(news3));
assertTrue(model.isGroupExpanded(5L));
assertEquals(3, model.getNewsCount());
assertEquals(3, model.getVisibleNewsCount());
assertEquals(news3.getId().longValue(), model.getLastVisibleNews());
assertFalse(model.hasHiddenNews());
assertEquals(2, model.getVisibleUnreadNews().size());
assertEquals(3L, model.getLastNews());
assertTrue(model.hasNews(1L));
assertTrue(model.hasNews(2L));
assertTrue(model.hasNews(3L));
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));
assertEquals(-1L, model.removeNews(news2));
assertEquals(3L, model.nextNews(false, 1L));
assertEquals(3L, model.nextNews(true, 1L));
assertEquals(3L, model.getLastNews());
assertEquals(2, model.getNewsCount());
assertEquals(2, model.getVisibleNewsCount());
assertEquals(2, model.getVisibleUnreadNews().size());
model.setNewsVisible(news1, false);
assertEquals(2, model.getNewsCount());
assertEquals(1, model.getVisibleNewsCount());
assertTrue(model.hasHiddenNews());
model.setNewsVisible(news3, false);
assertEquals(2, model.getNewsCount());
assertEquals(0, model.getVisibleNewsCount());
assertEquals(0, model.getVisibleUnreadNews().size());
model.setNewsVisible(news1, true);
model.setNewsVisible(news3, true);
assertEquals(2, model.getNewsCount());
assertEquals(2, model.getVisibleNewsCount());
Pair<List<Long>, List<Long>> nextPage = model.getNextPage(0);
assertTrue(nextPage.getFirst().isEmpty());
assertTrue(nextPage.getSecond().isEmpty());
nextPage = model.getNextPage(5);
assertTrue(nextPage.getFirst().isEmpty());
assertTrue(nextPage.getSecond().isEmpty());
Pair<List<Long>, List<Long>> revealed = model.revealPage(5L, 5);
assertTrue(revealed.getFirst().isEmpty());
assertTrue(revealed.getSecond().isEmpty());
model.setNewsVisible(news1, false);
model.setNewsVisible(news3, true);
revealed = model.revealPage(news1.getId(), 5);
assertTrue(revealed.getFirst().isEmpty());
assertEquals(2, revealed.getSecond().size());
assertEquals(news1.getId(), revealed.getSecond().get(0));
assertEquals(news3.getId(), revealed.getSecond().get(1));
revealed = model.revealPage(news3.getId(), 5);
assertTrue(revealed.getFirst().isEmpty());
assertEquals(news1.getId(), revealed.getSecond().get(0));
model.setNewsVisible(news1, false);
model.setNewsVisible(news3, false);
revealed = model.revealPage(news3.getId(), 5);
assertEquals(2, revealed.getSecond().size());
assertEquals(news1.getId(), revealed.getSecond().get(0));
assertEquals(news3.getId(), revealed.getSecond().get(1));
}