@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); base = args.getString(EXTRA_BASE); repository = args.getParcelable(EXTRA_REPOSITORY); mainSection.add(commitSection); mainSection.add(filesSection); mainSection.add(commentSection); adapter.add(mainSection); adapter.setOnItemClickListener(this); }
@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); }
@Override public void onLoadMore(int currentPage) { int color = rainbow200[currentPage % rainbow200.length]; for (int i = 0; i < 5; i++) { infiniteLoadingSection.add(new CardItem(color)); } } });
@Test public void addAllAtPositionFrontWithNestedGroupNotifiesAdapterAtCorrectIndex() { final List<DummyItem> nestedItems = Arrays.asList(new DummyItem(), new DummyItem()); final Section nestedSection = new Section(nestedItems); final Section section = new Section(); section.add(nestedSection); section.registerGroupDataObserver(groupAdapter); section.addAll(0, Arrays.asList(new DummyItem(), new DummyItem(), new DummyItem())); verify(groupAdapter).onItemRangeInserted(section, 0, 3); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gistId = getArguments().getString(EXTRA_GIST_ID); gist = store.getGist(gistId); mainSection.add(filesSection); mainSection.add(commentsSection); adapter.add(mainSection); adapter.setOnItemClickListener(this); }
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; }
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 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 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 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 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 addBodyContentRemovesPlaceholder() { Section section = new Section(); section.registerGroupDataObserver(groupAdapter); section.setPlaceholder(placeholder); section.add(new DummyItem()); verify(groupAdapter).onItemRangeRemoved(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 getGroup() { Section section = new Section(); Item item = new DummyItem(); section.add(item); assertEquals(0, section.getPosition(item)); }
@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 childAddNotificationWhenExpanded() { ExpandableGroup expandableGroup = new ExpandableGroup(parent); expandableGroup.onToggleExpanded(); expandableGroup.registerGroupDataObserver(groupAdapter); Section section = new Section(); DummyItem item = new DummyItem(); expandableGroup.add(section); section.add(item); Mockito.verify(groupAdapter).onItemRangeInserted(expandableGroup, 1, 1); }
@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 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()); }