@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 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()); }
@Test public void itemCountIsZeroWhenSetHideWhenEmptyTrue() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.setHideWhenEmpty(true); assertEquals(0, section.getItemCount()); }
private int getBodyItemCount() { return isPlaceholderVisible ? getPlaceholderItemCount() : getItemCount(children); }
@Override public void addAll(@NonNull Collection<? extends Group> groups) { if (groups.isEmpty()) return; super.addAll(groups); int position = getItemCountWithoutFooter(); this.children.addAll(groups); notifyItemRangeInserted(position, getItemCount(groups)); refreshEmptyState(); }
@Override public void addAll(int position, @NonNull Collection<? extends Group> groups) { if (groups.isEmpty()) { return; } super.addAll(position, groups); this.children.addAll(position, groups); final int notifyPosition = getHeaderItemCount() + getItemCount(children.subList(0, position)); notifyItemRangeInserted(notifyPosition, getItemCount(groups)); refreshEmptyState(); }
@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); }
private List<Section> createFileSections(List<GitHubFile> files) { List<Section> sections = new ArrayList<>(); for (GitHubFile file : files) { Section section = new Section(new CommitFileHeaderItem(getActivity(), file)); List<CharSequence> lines = diffStyler.get(file.filename()); for (CharSequence line : lines) { section.add(new CommitFileLineItem(diffStyler, line)); } sections.add(section); } return sections; }
@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 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); }
Section fullBleedItemSection = new Section(new HeaderItem(R.string.full_bleed_item)); fullBleedItemSection.add(new FullBleedCardItem(R.color.purple_200)); groupAdapter.add(fullBleedItemSection); Section updatingSection = new Section(); View.OnClickListener onShuffleClicked = new View.OnClickListener() { @Override public void onClick(View view) { R.drawable.shuffle, onShuffleClicked); updatingSection.setHeader(updatingHeader); updatingGroup = new Section(); updatableItems = new ArrayList<>(); for (int i = 1; i <= 12; i++) { updatableItems.add(new UpdatableItem(rainbow200[i], i)); updatingGroup.update(updatableItems); updatingSection.add(updatingGroup); groupAdapter.add(updatingSection); Section columnSection = new Section(new HeaderItem(R.string.vertical_columns)); ColumnGroup columnGroup = makeColumnGroup(); columnSection.add(columnGroup); groupAdapter.add(columnSection); Section multipleColumnsSection = new Section(new HeaderItem(R.string.multiple_columns)); for (int i = 0; i < 12; i++) { multipleColumnsSection.add(new SmallCardItem(rainbow200[5]));
@Test public void addItemToNestedSectionNotifiesAtCorrectIndex() 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(); rootSection.add(nestedSection2); reset(groupAdapter); nestedSection2.add(new DummyItem()); verify(groupAdapter).onItemRangeInserted(rootSection, 3, 1); }
@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 removingHeaderNotifiesPreviousHeaderRemoved() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setHeader(header); section.removeHeader(); verify(groupAdapter).onItemRangeRemoved(section, 0, headerSize); }
@Test public void removeAllGroupFromNestedSectionNotifiesAtCorrectIndex() 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())); rootSection.add(nestedSection2); reset(groupAdapter); rootSection.removeAll(Collections.singletonList(nestedSection2)); verify(groupAdapter).onItemRangeRemoved(rootSection, 3, 2); }
@Test public void headerCountIsSizeOfHeader() { Section section = new Section(); section.setHeader(header); assertEquals(headerSize, section.getItemCount()); }
@Test public void settingHeaderNotifiesHeaderAdded() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setHeader(header); verify(groupAdapter).onItemRangeInserted(section, 0, headerSize); }
@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 footerCountIs0WhenThereIsNoFooter() { Section section = new Section(); section.removeFooter(); assertEquals(0, section.getItemCount()); }
@Test public void footerCountIsSizeOfFooter() { Section section = new Section(); section.setFooter(footer); assertEquals(footerSize, section.getItemCount()); }