@Test(expected = NullPointerException.class) public void settingNullFooterThrowsNullPointerException() { Section section = new Section(); section.setFooter(null); }
@Test(expected = NullPointerException.class) public void settingNullHeaderThrowsNullPointerException() { Section section = new Section(); section.setFooter(null); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (gist != null) { updateHeader(gist); updateFiles(gist); } if (gist == null || (gist.comments() > 0 && comments == null)) { mainSection.setFooter(new LoadingItem(R.string.loading_comments)); } if (gist != null && comments != null) { updateList(gist, comments); } else { refreshGist(); } }
@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 setFooterAddsFooter() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setFooter(footer); verify(groupAdapter).onItemRangeInserted(section, 0, footerSize); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); commit = store.getCommit(repository, base); if (files == null || (commit != null && commit.commit().commentCount() > 0 && comments == null)) { mainSection.setFooter(new LoadingItem(R.string.loading_files_and_comments)); } if (commit != null && comments != null && files != null) { updateList(commit, comments, files); } else { if (commit != null) { updateHeader(commit); } refreshCommit(); } }
@Test public void removeFooterRemovesFooter() { Section section = new Section(); section.setFooter(footer); section.registerGroupDataObserver(groupAdapter); section.removeFooter(); verify(groupAdapter).onItemRangeRemoved(section, 0, footerSize); }
@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 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 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 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 removingFooterNotifiesPreviousFooterRemoved() { Section section = new Section(); section.setHeader(header); section.add(new DummyItem()); section.setFooter(footer); section.registerGroupDataObserver(groupAdapter); section.removeFooter(); verify(groupAdapter).onItemRangeRemoved(section, headerSize + 1, footerSize); }
@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 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 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()); }