@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 setHeaderAddsHeader() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setHeader(header); verify(groupAdapter).onItemRangeInserted(section, 0, headerSize); }
@Test public void addAllAtPositionWhenEmptyNotifiesAdapterAtIndexZero() { final Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.addAll(0, Arrays.asList(new DummyItem(), new DummyItem())); verify(groupAdapter).onItemRangeInserted(section, 0, 2); }
@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 removeFooterRemovesFooter() { Section section = new Section(); section.setFooter(footer); section.registerGroupDataObserver(groupAdapter); section.removeFooter(); verify(groupAdapter).onItemRangeRemoved(section, 0, footerSize); }
@Test(expected = IndexOutOfBoundsException.class) public void addAllAtNonZeroPositionWhenEmptyThrowIndexOutOfBoundsException() { final Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.addAll(1, Arrays.asList(new DummyItem(), new DummyItem())); }
@Test public void removeHeaderRemovesHeader() { Section section = new Section(); section.setHeader(header); section.registerGroupDataObserver(groupAdapter); section.removeHeader(); verify(groupAdapter).onItemRangeRemoved(section, 0, headerSize); }
@Test public void notifyChangeInAnItemCausesParentToNotifyChange() { List<Item> children = new ArrayList<Item>(); Item item = new DummyItem(); children.add(item); Section group = new Section(); group.setHeader(new DummyItem()); group.update(children); group.registerGroupDataObserver(groupAdapter); item.notifyChanged(); verify(groupAdapter).onItemChanged(group, 1); }
@Test public void updateWithADifferentItemNotifiesRemoveAndAdd() { Item oldItem = new ContentUpdatingItem(1, "contents"); Section group = new Section(); group.setHeader(new DummyItem()); group.update(Collections.singletonList(oldItem)); group.registerGroupDataObserver(groupAdapter); Item newItem = new ContentUpdatingItem(2, "contents"); group.update(Collections.singletonList(newItem)); verify(groupAdapter).onItemRangeRemoved(group, 1, 1); verify(groupAdapter).onItemRangeInserted(group, 1, 1); }
@Test public void setHideWhenEmptyRemovesExistingHeaderAndFooter() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.registerGroupDataObserver(groupAdapter); section.setHideWhenEmpty(true); verify(groupAdapter).onItemRangeRemoved(section, 0, headerSize + footerSize); }
@Test public void setHideWhenEmptyFalseAddsExistingHeaderAndFooter() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setHideWhenEmpty(true); section.registerGroupDataObserver(groupAdapter); section.setHideWhenEmpty(false); verify(groupAdapter).onItemRangeInserted(section, 0, headerSize); verify(groupAdapter).onItemRangeInserted(section, headerSize, footerSize); }
@Test public void settingFooterNotifiesFooterAdded() { Section section = new Section(); section.setHeader(header); section.add(new DummyItem()); section.registerGroupDataObserver(groupAdapter); section.setFooter(footer); verify(groupAdapter).onItemRangeInserted(section, headerSize + 1, footerSize); }
@Test public void addAllAtPositionWhenNonEmptyNotifiesAdapterAtCorrectIndex() { final Section section = new Section(Arrays.asList(new DummyItem(), new DummyItem())); section.registerGroupDataObserver(groupAdapter); section.addAll(2, Arrays.asList(new DummyItem(), new DummyItem(), new DummyItem())); verify(groupAdapter).onItemRangeInserted(section, 2, 3); }
@Test public void addAllAtPositionWithEmptyNestedGroupNotifiesAdapterAtZeroIndex() { final Section nestedSection = new Section(); final Section section = new Section(); section.add(nestedSection); section.registerGroupDataObserver(groupAdapter); section.addAll(1, Arrays.asList(new DummyItem(), new DummyItem(), new DummyItem())); verify(groupAdapter).onItemRangeInserted(section, 0, 3); }
@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 addAllAtPositionMiddleWithNestedGroupNotifiesAdapterAtCorrectIndex() { final Section nestedSection1 = new Section(Arrays.asList(new DummyItem(), new DummyItem())); final Section nestedSection2 = new Section(Arrays.asList(new DummyItem(), new DummyItem())); final Section section = new Section(Arrays.asList(nestedSection1, nestedSection2)); section.registerGroupDataObserver(groupAdapter); section.addAll(1, Arrays.asList(new DummyItem(), new DummyItem(), new DummyItem())); verify(groupAdapter).onItemRangeInserted(section, 2, 3); }
@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 addGroupToNestedSectionNotifiesAtCorrectIndex() throws Exception { final Section rootSection = new Section(); rootSection.registerGroupDataObserver(groupAdapter); groupAdapter.add(rootSection); final Section nestedSection1 = new Section(Arrays.asList(new DummyItem(), new DummyItem(), new DummyItem())); rootSection.add(nestedSection1); final Section nestedSection2 = new Section(Arrays.asList(new DummyItem(), new DummyItem())); reset(groupAdapter); rootSection.add(nestedSection2); verify(groupAdapter).onItemRangeInserted(rootSection, 3, 2); }
@Test public void addGroupToNestedSectionWithHeaderNotifiesAtCorrectIndex() throws Exception { final Section rootSection = new Section(); rootSection.setHeader(new DummyItem()); rootSection.registerGroupDataObserver(groupAdapter); groupAdapter.add(rootSection); final Section nestedSection1 = new Section(Arrays.asList(new DummyItem(), new DummyItem(), new DummyItem())); rootSection.add(nestedSection1); final Section nestedSection2 = new Section(Arrays.asList(new DummyItem(), new DummyItem())); reset(groupAdapter); rootSection.add(nestedSection2); verify(groupAdapter).onItemRangeInserted(rootSection, 4, 2); }