WrappingDividerAdapter extends PowerAdapterWrapper { @Override public int getItemCount() { if (getObserverCount() > 0) { return mItemCount; } return getItemCount(super.getItemCount()); } WrappingDividerAdapter(@NonNull PowerAdapter adapter,
                           @NonNull DividerAdapterBuilder.EmptyPolicy emptyPolicy,
                           @Nullable Item leadingItem,
                           @Nullable Item trailingItem,
                           @Nullable Item innerItem); @Override int getItemCount(); @NonNull @Override Object getItemViewType(int position); @NonNull @Override View newView(@NonNull ViewGroup parent, @NonNull Object viewType); @Override void bindView(
            @NonNull Container container,
            @NonNull View view,
            @NonNull Holder holder,
            @NonNull List<Object> payloads
    ); @Override boolean isEnabled(int position); @Override long getItemId(int position);  }
@Test public void itemCountOne() { configure(1, SHOW_LEADING); assertThat(mDividerAdapter.getItemCount()).isEqualTo(1); }
@Test public void itemCountZeroShowLeading() { configure(0, SHOW_LEADING); assertThat(mDividerAdapter.getItemCount()).isEqualTo(1); }
@Test public void itemCountZeroShowTrailing() { configure(0, SHOW_TRAILING); assertThat(mDividerAdapter.getItemCount()).isEqualTo(1); }
@Test public void itemCountZeroShowLeadingAndTrailing() { configure(0, SHOW_LEADING_AND_TRAILING); assertThat(mDividerAdapter.getItemCount()).isEqualTo(2); }
@Test public void itemCountConsistentAfterCoarseNotification() { configure(10); mFakeAdapter.setNotificationType(COARSE); mFakeAdapter.insert(0, 10); assertThat(mDividerAdapter.getItemCount()).isEqualTo(20); verify(mObserver).onChanged(); }
@Test public void removeToEmptyShowNothing() { configure(5, SHOW_NOTHING); mFakeAdapter.clear(); assertThat(mDividerAdapter.getItemCount()).isEqualTo(0); verify(mObserver).onItemRangeRemoved(0, 5); verifyNoMoreInteractions(mObserver); }
@Test public void removeToEmptyShowLeading() { configure(5, SHOW_LEADING); mFakeAdapter.clear(); assertThat(mDividerAdapter.getItemCount()).isEqualTo(1); verify(mObserver).onItemRangeRemoved(0, 5); verify(mObserver).onItemRangeInserted(0, 1); verifyNoMoreInteractions(mObserver); }
@Test public void removeToEmptyShowTrailing() { configure(5, SHOW_TRAILING); mFakeAdapter.clear(); assertThat(mDividerAdapter.getItemCount()).isEqualTo(1); verify(mObserver).onItemRangeRemoved(0, 5); verify(mObserver).onItemRangeInserted(0, 1); verifyNoMoreInteractions(mObserver); }
@Test public void removeToEmptyShowLeadingAndTrailing() { configure(5, SHOW_LEADING_AND_TRAILING); mFakeAdapter.clear(); assertThat(mDividerAdapter.getItemCount()).isEqualTo(2); verify(mObserver).onItemRangeRemoved(0, 5); verify(mObserver).onItemRangeInserted(0, 1); verify(mObserver).onItemRangeInserted(1, 1); verifyNoMoreInteractions(mObserver); }
@Test public void removeToNonEmptyFromStartRange() { configure(15); mFakeAdapter.remove(0, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(10); verify(mObserver).onItemRangeRemoved(0, 5); verify(mObserver).onItemRangeChanged(0, 1, null); verifyNoMoreInteractions(mObserver); }
@Test public void removeToNonEmptyFromEndRange() { configure(15); mFakeAdapter.remove(10, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(10); verify(mObserver).onItemRangeRemoved(10, 5); verify(mObserver).onItemRangeChanged(9, 1, null); verifyNoMoreInteractions(mObserver); }
@Test public void removeToNonEmptyFromMidRange() { configure(15); mFakeAdapter.remove(5, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(10); verify(mObserver).onItemRangeRemoved(5, 5); verifyNoMoreInteractions(mObserver); }
@Test public void insertFromEmptyShowNothing() { configure(0, SHOW_NOTHING); mFakeAdapter.insert(0, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(5); verify(mObserver).onItemRangeInserted(0, 5); verifyNoMoreInteractions(mObserver); }
@Test public void insertFromEmptyShowLeading() { configure(0, SHOW_LEADING); mFakeAdapter.insert(0, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(5); verify(mObserver).onItemRangeRemoved(0, 1); verify(mObserver).onItemRangeInserted(0, 5); verifyNoMoreInteractions(mObserver); }
@Test public void insertFromEmptyShowTrailing() { configure(0, SHOW_TRAILING); mFakeAdapter.insert(0, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(5); verify(mObserver).onItemRangeRemoved(0, 1); verify(mObserver).onItemRangeInserted(0, 5); verifyNoMoreInteractions(mObserver); }
@Test public void insertFromEmptyShowLeadingAndTrailing() { configure(0, SHOW_LEADING_AND_TRAILING); mFakeAdapter.insert(0, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(5); verify(mObserver).onItemRangeRemoved(0, 1); verify(mObserver).onItemRangeRemoved(1, 1); verify(mObserver).onItemRangeInserted(0, 5); verifyNoMoreInteractions(mObserver); }
@Test public void insertFromNonEmptyToStartRange() { configure(10); mFakeAdapter.insert(0, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(15); verify(mObserver).onItemRangeInserted(0, 5); verify(mObserver).onItemRangeChanged(5, 1, null); verifyNoMoreInteractions(mObserver); }
@Test public void insertFromNonEmptyToEndRange() { configure(10); mFakeAdapter.insert(10, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(15); verify(mObserver).onItemRangeInserted(10, 5); verify(mObserver).onItemRangeChanged(9, 1, null); verifyNoMoreInteractions(mObserver); }
@Test public void insertFromNonEmptyToMidRange() { configure(10); mFakeAdapter.insert(5, 5); assertThat(mDividerAdapter.getItemCount()).isEqualTo(15); verify(mObserver).onItemRangeInserted(5, 5); verifyNoMoreInteractions(mObserver); }
@Test public void itemCountGreaterThanOne() { configure(5, SHOW_LEADING); assertThat(mDividerAdapter.getItemCount()).isEqualTo(5); }