LimitAdapter extends PowerAdapterWrapper { public void setLimit(int limit) { limit = max(0, limit); if (limit != mLimit) { int oldSize = getLimitedItemCount(); mLimit = limit; int newSize = getLimitedItemCount(); mItemCount = newSize; int deltaSize = newSize - oldSize; if (deltaSize < 0) { notifyItemRangeRemoved(oldSize + deltaSize, abs(deltaSize)); } else if (deltaSize > 0) { notifyItemRangeInserted(oldSize, deltaSize); } } } LimitAdapter(@NonNull PowerAdapter adapter);  LimitAdapter(@NonNull PowerAdapter adapter, int limit); int getLimit(); void setLimit(int limit); @Override int getItemCount(); @Override long getItemId(int position); @NonNull @Override Object getItemViewType(int position); @Override boolean isEnabled(int position);  }
@Test public void setLimitNotifiesOfInsertion() { mLimitAdapter.setLimit(10); verify(mObserver).onItemRangeInserted(5, 5); }
@Test public void setLimitNotifiesOfRemoval() { mLimitAdapter.setLimit(0); verify(mObserver).onItemRangeRemoved(0, 5); }