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 public void constructorSetsListenerOnChildren() { List<Group> children = new ArrayList<>(); Item item = Mockito.mock(Item.class); children.add(item); Section section = new Section(null, children); verify(item).registerGroupDataObserver(section); }
@Test public void testGetPosition() throws Exception { ExpandableGroup expandableGroup = new ExpandableGroup(parent); Section section = new Section(); expandableGroup.add(section); Section notAddedSection = new Section(); assertEquals(1, expandableGroup.getPosition(section)); assertEquals(-1, expandableGroup.getPosition(notAddedSection)); }
@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()); }
private List<Section> createFileSections(List<FullCommitFile> files) { List<Section> sections = new ArrayList<>(); for (FullCommitFile file : files) { Section section = new Section(new CommitFileHeaderItem(getActivity(), file.getFile())); List<CharSequence> lines = diffStyler.get(file.getFile().filename()); int number = 0; for (CharSequence line : lines) { section.add(new CommitFileLineItem(diffStyler, line)); for (GitComment comment : file.get(number)) { section.add(new CommitCommentItem(avatars, commentImageGetter, comment, true)); } number++; } sections.add(section); } return sections; }
@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 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 removeFooterRemovesFooter() { Section section = new Section(); section.setFooter(footer); section.registerGroupDataObserver(groupAdapter); section.removeFooter(); verify(groupAdapter).onItemRangeRemoved(section, 0, footerSize); }
@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 footerCountIsSizeOfFooter() { Section section = new Section(); section.setFooter(footer); assertEquals(footerSize, 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 noChildAddNotificationWhenCollapsed() { ExpandableGroup expandableGroup = new ExpandableGroup(parent); expandableGroup.registerGroupDataObserver(groupAdapter); Section section = new Section(); DummyItem item = new DummyItem(); expandableGroup.add(section); section.add(item); Mockito.verify(groupAdapter, Mockito.never()).onItemRangeInserted(expandableGroup, 1, 1); }
@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 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 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 groupCountIsZeroWhenEmptyAndSetHideWhenEmpty() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.setHideWhenEmpty(true); assertEquals(0, section.getGroupCount()); }