private void updateHeader(Gist gist) { mainSection.setHeader(new GistHeaderItem(getActivity(), gist)); progress.setVisibility(GONE); list.setVisibility(VISIBLE); }
private void updateHeader(Commit commit) { progress.setVisibility(View.GONE); list.setVisibility(View.VISIBLE); mainSection.setHeader(new CommitHeaderItem(avatars, getActivity(), commit)); addCommitParents(commit); }
private void updateList(Commit commit, List<GitComment> comments, List<FullCommitFile> files) { if (!isAdded()) { return; } this.commit = commit; this.comments = comments; this.files = files; updateHeader(commit); mainSection.removeFooter(); filesSection.setHeader( new TextItem(R.layout.commit_file_details_header, R.id.tv_commit_file_summary, CommitUtils.formatStats(commit.files())) ); updateItems(comments, files); }
@Test public void setHeaderAddsHeader() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setHeader(header); verify(groupAdapter).onItemRangeInserted(section, 0, headerSize); }
@Test public void updateWithTheSameItemAndSameContentsDoesNotNotifyChange() { List<Item> children = new ArrayList<Item>(); Item item = new ContentUpdatingItem(1, "contents"); children.add(item); Section group = new Section(); group.setHeader(new DummyItem()); group.update(children); group.registerGroupDataObserver(groupAdapter); group.update(children); verifyNoMoreInteractions(groupAdapter); }
@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 headerCountIsSizeOfHeader() { Section section = new Section(); section.setHeader(header); assertEquals(headerSize, section.getItemCount()); }
@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 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 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 groupCountIsZeroWhenEmptyAndSetHideWhenEmpty() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.setHideWhenEmpty(true); assertEquals(0, section.getGroupCount()); }
@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()); }