@Test public void testSwapItem() { final SimpleAdapterDataSet<String> dataSet = new SimpleAdapterDataSet<>(); dataSet.swapItems(createItems(10)); final SimpleAdapterDataSet.ItemsCallback mockCallback = mock(SimpleAdapterDataSet.ItemsCallback.class); dataSet.setItemsCallback(mockCallback); for (int i = 0; i < dataSet.getItemCount(); i++) { assertThat(dataSet.swapItem(i, "SwappedItem at: " + i), is("Test item no. " + (i + 1))); assertThat(dataSet.getItem(i), is("SwappedItem at: " + i)); verify(mockCallback, times(1)).onItemRangeChanged(i, 1); } verify(mockCallback, times(0)).onItemRangeInserted(anyInt(), anyInt()); verify(mockCallback, times(0)).onItemMoved(anyInt(), anyInt()); verify(mockCallback, times(0)).onItemRangeRemoved(anyInt(), anyInt()); }
@Override @NonNull public I swapItem(final int position, @NonNull final I item) { if (!hasItemAt(position)) { throw new AssertionError("No item to be swapped at position(" + position + ") found!"); } final I oldItem = items.set(position, item); AdaptersLogging.d(TAG, "Swapped item at position(" + position + ")."); this.notifyItemRangeChanged(position, 1); return oldItem; }
SimpleAdapterDataSet implements SimpleDataSet<I> { @Override @NonNull public I swapItem(final int position, @NonNull final I item) { if (!hasItemAt(position)) { throw new AssertionError("No item to be swapped at position(" + position + ") found!"); } final I oldItem = items.set(position, item); AdaptersLogging.d(TAG, "Swapped item at position(" + position + ")."); this.notifyItemRangeChanged(position, 1); return oldItem; } }
SimpleAdapterDataSet implements SimpleDataSet<I> { @Override @NonNull public I swapItem(final int position, @NonNull final I item) { if (!hasItemAt(position)) { throw new AssertionError("No item to be swapped at position(" + position + ") found!"); } final I oldItem = items.set(position, item); AdaptersLogging.d(TAG, "Swapped item at position(" + position + ")."); this.notifyItemRangeChanged(position, 1); return oldItem; } SimpleAdapterDataSet();   SimpleAdapterDataSet(@Nullable final List<I> items); }
SimpleAdapterDataSet implements SimpleDataSet<I> { @Override @NonNull public I swapItem(final int position, @NonNull final I item) { if (!hasItemAt(position)) { throw new AssertionError("No item to be swapped at position(" + position + ") found!"); } final I oldItem = items.set(position, item); AdaptersLogging.d(TAG, "Swapped item at position(" + position + ")."); this.notifyItemRangeChanged(position, 1); return oldItem; } SimpleAdapterDataSet();   SimpleAdapterDataSet(@Nullable final List<I> items); @Override boolean isEmpty(); @Override int getItemCount(); @Override void insertItem(@NonNull final I item); @Override void insertItem(final int position, @NonNull final I item); @Override void insertItems(@NonNull final List<I> items); @Override void insertItems(final int positionStart, @NonNull final List<I> items); @Override @NonNull I swapItemById(final long itemId, @NonNull final I item); @Override @NonNull I swapItem(final int position, @NonNull final I item); @Override void moveItem(final int fromPosition, final int toPosition); @Override int removeItem(@NonNull final I item); @Override @NonNull I removeItemById(final long itemId); @Override @NonNull I removeItem(final int position); @Override @NonNull List<I> removeItems(final int positionStart, final int itemCount); @Override boolean hasItemAt(final int position); @Override boolean isEnabled(final int position); @Override boolean hasStableIds(); @Override long getItemId(final int position); @SuppressWarnings({"unchecked", "ConstantConditions"}) @Override @NonNull I getItem(int position); }
SimpleAdapterDataSet implements SimpleDataSet<I> { @Override @NonNull public I swapItem(final int position, @NonNull final I item) { if (!hasItemAt(position)) { throw new AssertionError("No item to be swapped at position(" + position + ") found!"); } final I oldItem = items.set(position, item); AdaptersLogging.d(TAG, "Swapped item at position(" + position + ")."); this.notifyItemRangeChanged(position, 1); return oldItem; } SimpleAdapterDataSet();   SimpleAdapterDataSet(@Nullable final List<I> items); @Override boolean isEmpty(); @Override int getItemCount(); @Override void insertItem(@NonNull final I item); @Override void insertItem(final int position, @NonNull final I item); @Override void insertItems(@NonNull final List<I> items); @Override void insertItems(final int positionStart, @NonNull final List<I> items); @Override @NonNull I swapItemById(final long itemId, @NonNull final I item); @Override @NonNull I swapItem(final int position, @NonNull final I item); @Override void moveItem(final int fromPosition, final int toPosition); @Override int removeItem(@NonNull final I item); @Override @NonNull I removeItemById(final long itemId); @Override @NonNull I removeItem(final int position); @Override @NonNull List<I> removeItems(final int positionStart, final int itemCount); @Override boolean hasItemAt(final int position); @Override boolean isEnabled(final int position); @Override boolean hasStableIds(); @Override long getItemId(final int position); @SuppressWarnings({"unchecked", "ConstantConditions"}) @Override @NonNull I getItem(int position);  }