@Test public void addEmptyBodyContentDoesNotRemovePlaceholder() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setPlaceholder(placeholder); section.add(emptyGroup); verify(groupAdapter, never()).onItemRangeRemoved(any(Section.class), anyInt(), anyInt()); }
@Test public void replacingAnExistingPlaceholderNotifiesChange() { Section section = new Section(); section.setPlaceholder(placeholder); section.registerGroupDataObserver(groupAdapter); final int newPlaceholderSize = 1; Group newPlaceholder = new DummyGroup() { @Override public int getItemCount() { return newPlaceholderSize; } }; section.setPlaceholder(newPlaceholder); verify(groupAdapter).onItemRangeRemoved(section, 0, placeholderSize); verify(groupAdapter).onItemRangeInserted(section, 0, newPlaceholderSize); }
@Test public void setPlaceholderOnNonEmptySectionDoesNotAddPlaceholder() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.add(new DummyItem()); section.registerGroupDataObserver(groupAdapter); section.setPlaceholder(placeholder); verify(groupAdapter, never()).onItemRangeInserted(any(Section.class), anyInt(), anyInt()); }
@Test public void setHideWhenEmptyRemovesAnExistingPlaceholder() { Section section = new Section(); section.setPlaceholder(placeholder); section.registerGroupDataObserver(groupAdapter); section.setHideWhenEmpty(true); verify(groupAdapter).onItemRangeRemoved(section, 0, placeholderSize); }
@Test public void updateGroupWithPlaceholderNotifiesRemovePlaceholderAndInsert() { List<Item> children = new ArrayList<Item>(); children.add(new AlwaysUpdatingItem(1)); children.add(new AlwaysUpdatingItem(2)); Section group = new Section(); group.setHeader(new DummyItem()); group.setPlaceholder(new DummyItem()); group.registerGroupDataObserver(groupAdapter); group.update(children); verify(groupAdapter).onItemRangeRemoved(group, 1, 1); verify(groupAdapter).onItemRangeInserted(group, 1, 2); verifyNoMoreInteractions(groupAdapter); }
@Test public void updateGroupToEmptyWithPlaceholderNotifiesRemoveAndInsertPlaceholder() { List<Item> children = new ArrayList<Item>(); children.add(new AlwaysUpdatingItem(1)); children.add(new AlwaysUpdatingItem(2)); Section group = new Section(); group.setHeader(new DummyItem()); group.setPlaceholder(new DummyItem()); group.update(children); group.registerGroupDataObserver(groupAdapter); group.update(new ArrayList<Group>()); verify(groupAdapter).onItemRangeRemoved(group, 1, 2); verify(groupAdapter).onItemRangeInserted(group, 1, 1); verifyNoMoreInteractions(groupAdapter); } }
@Test public void setPlaceholderOnEmptySectionAddsPlaceholder() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.registerGroupDataObserver(groupAdapter); section.setPlaceholder(placeholder); verify(groupAdapter).onItemRangeInserted(section, headerSize, placeholderSize); }
@Test public void addBodyContentRemovesPlaceholder() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setPlaceholder(placeholder); section.add(new DummyItem()); verify(groupAdapter).onItemRangeRemoved(section, 0, placeholderSize); }
@Test public void removeAllBodyContentAddsPlaceholder() { Section section = new Section(); section.setPlaceholder(placeholder); Item item = new DummyItem(); section.add(item); section.registerGroupDataObserver(groupAdapter); section.remove(item); verify(groupAdapter).onItemRangeInserted(section, 0, placeholderSize); }
@Test public void removePlaceholderNotifies() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setPlaceholder(placeholder); section.registerGroupDataObserver(groupAdapter); section.removePlaceholder(); verify(groupAdapter).onItemRangeRemoved(section, headerSize, placeholderSize); }
@Test public void setHideWhenEmptyRemovesExistingHeaderFooterAndPlaceholder() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setPlaceholder(placeholder); section.registerGroupDataObserver(groupAdapter); section.setHideWhenEmpty(true); verify(groupAdapter).onItemRangeRemoved(section, 0, headerSize + footerSize + placeholderSize); }
@Test public void getGroupReturnsPlaceholder() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setPlaceholder(placeholder); assertEquals(placeholder, section.getGroup(1)); }
@Test public void groupCountIsHeaderFooterAndPlaceholderWhenEmpty() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); assertEquals(3, section.getGroupCount()); }
@Test(expected = IndexOutOfBoundsException.class) public void whenSectionIsEmptyAndSetHideWhenEmptyGetGroupThrowsException() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.setHideWhenEmpty(true); section.getGroup(0); }
@Test public void placeholderIsIncludedInItemCountIfBodyIsEmpty() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setPlaceholder(placeholder); assertEquals(headerSize + placeholderSize + footerSize, section.getItemCount()); }
@Test public void removeAllBodyContentByModifyingAChildGroupAddsPlaceholder() { Section section = new Section(); section.setPlaceholder(placeholder); Section childGroup = new Section(); Item childItem = new DummyItem(); childGroup.add(childItem); section.add(childGroup); section.registerGroupDataObserver(groupAdapter); childGroup.remove(childItem); verify(groupAdapter).onItemRangeInserted(section, 0, placeholderSize); }
@Test public void groupCountIsZeroWhenEmptyAndSetHideWhenEmpty() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.setHideWhenEmpty(true); assertEquals(0, section.getGroupCount()); }
@Test public void itemCountIsZeroWhenSetHideWhenEmptyTrue() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.setHideWhenEmpty(true); assertEquals(0, section.getItemCount()); }
@Test public void placeholderIsNotIncludedInItemCountIfBodyHasContent() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setPlaceholder(placeholder); section.add(new DummyItem()); assertEquals(headerSize + footerSize + 1, section.getItemCount()); }
@Test public void groupCountIsHeaderFooterAndChildrenWhenNonEmpty() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.add(new DummyItem()); section.add(new DummyItem()); assertEquals(4, section.getGroupCount()); }