ComponentGroup extends Component { @NonNull public ComponentGroup addComponent(@NonNull Component component) { return addComponent(getSize(), component); } ComponentGroup(); int getSpan(); int getSize(); @NonNull Component get(int index); @NonNull Component componentAt(int position); boolean contains(@NonNull Component component); int indexOf(@NonNull Component component); @Nullable Range rangeOf(@NonNull Component component); @NonNull ComponentGroup addComponent(@NonNull Component component); @NonNull ComponentGroup addComponent(@NonNull ComponentGroup componentGroup); @NonNull ComponentGroup addComponent(int index, @NonNull final Component component); @NonNull ComponentGroup addComponent(int index, @NonNull ComponentGroup componentGroup); @NonNull ComponentGroup addAll(@NonNull Collection<? extends Component> components); @NonNull ComponentGroup replaceComponent(int index, @NonNull Component component); @NonNull ComponentGroup replaceComponent(int index, @NonNull ComponentGroup componentGroup); @NonNull Component remove(int index); boolean remove(@NonNull Component component); void clear(); @NonNull @SuppressWarnings("unchecked") // Unchecked Component generics. Class<? extends ComponentViewHolder> getHolderType(int position); @Nullable @Override Object getPresenter(int position); @Override int getCount(); @Override @CallSuper void onItemVisible(int index); @Override void onItemNotVisible(int index); void registerComponentGroupObserver(@NonNull ComponentGroupDataObserver observer); void unregisterComponentGroupObserver(@NonNull ComponentGroupDataObserver observer); @Override Object getItem(int position); @Override final int getNumberLanes(); @NonNull @Override SpanSizeLookup getSpanSizeLookup(); int findComponentOffset(@NonNull Component component); Component findComponentWithIndex(int index); RangedValue<Component> findRangedComponentWithIndex(int index);  }
@Test public void test_NotifyRangeInserted_ComponentAddedInTheMiddle_CallsNotifyItemRangeInserted() { List<String> fakeData = new ArrayList<>(Arrays.asList("a", "b", "c")); ListComponent<String, String> listComponent0 = new ListComponent<>(null, null); listComponent0.toggleDivider(false); listComponent0.setData(fakeData); ListComponent<String, String> listComponent1 = new ListComponent<>(null, null); listComponent1.toggleDivider(false); listComponent1.setData(fakeData); ComponentGroup group = new ComponentGroup(); group.addComponent(listComponent0); group.addComponent(listComponent1); List<String> insertedData = new ArrayList<>(Arrays.asList("0", "1", "2", "3")); ListComponent<String, String> insertedComponent = new ListComponent<>(null, null); insertedComponent.toggleDivider(false); insertedComponent.setData(insertedData); ComponentGroup spyGroup = spy(group); spyGroup.addComponent(1, insertedComponent); verify(spyGroup, times(1)).notifyItemRangeInserted(3, 4); }
@Test public void test_NotifyRangeInserted_ComponentAddedAtLastPosition_CallsNotifyItemRangeInserted() { List<String> fakeData = new ArrayList<>(Arrays.asList("a", "b", "c", "d")); ListComponent<String, String> listComponent0 = new ListComponent<>(null, null); listComponent0.toggleDivider(false); listComponent0.setData(fakeData); ComponentGroup group = new ComponentGroup(); group.addComponent(listComponent0); List<String> insertedData = new ArrayList<>(Arrays.asList("0", "1", "2", "3")); ListComponent<String, String> insertedComponent = new ListComponent<>(null, null); insertedComponent.toggleDivider(false); insertedComponent.setData(insertedData); ComponentGroup spyGroup = spy(group); spyGroup.addComponent(insertedComponent); verify(spyGroup, times(1)).notifyItemRangeInserted(4, 4); }
@Test public void test_NotifyRangeInserted_ComponentAddedAtIndex0_CallsNotifyItemRangeInserted() { List<String> fakeData = new ArrayList<>(Arrays.asList("a", "b", "c", "d")); ListComponent<String, String> listComponent0 = new ListComponent<>(null, null); listComponent0.toggleDivider(false); listComponent0.setData(fakeData); ComponentGroup group = new ComponentGroup(); group.addComponent(listComponent0); List<String> insertedData = new ArrayList<>(Arrays.asList("0", "1", "2")); ListComponent<String, String> insertedComponent = new ListComponent<>(null, null); insertedComponent.toggleDivider(false); insertedComponent.setData(insertedData); ComponentGroup spyGroup = spy(group); spyGroup.addComponent(insertedComponent); verify(spyGroup, times(0)).notifyItemRangeInserted(0, 4); }