RepositoryAdapter extends RecyclerView.Adapter<ViewHolder> implements Updatable { @Override public final long getItemId(final int position) { resolveIndices(position); return parts[resolvedPartIndex].getItemId(resolvedItemIndex, staticItemCount); } RepositoryAdapter(@NonNull final Builder builder); @NonNull static Builder repositoryAdapter(); final void startObserving(); final void stopObserving(); @Override final void update(); @Override final int getItemCount(); @Override final int getItemViewType(final int position); @Override final long getItemId(final int position); @Override ViewHolder onCreateViewHolder(final ViewGroup parent,
      final int layoutResourceId); @Override final void onBindViewHolder(final ViewHolder holder, final int position); @Override boolean onFailedToRecycleView(final ViewHolder holder); @Override void onViewRecycled(final ViewHolder holder);  }
@Test(expected = IndexOutOfBoundsException.class) public void shouldThrowExceptionForNegativeIndex() { repositoryAdapter.getItemId(-1); }
@Test public void shouldReturnItemIdFromFirstPresenter() { when(repositoryPresenter.getItemId(REPOSITORY_ITEM, 0)).thenReturn(10L); assertThat(repositoryAdapter.getItemId(0), is(10L + STATIC_ITEM_COUNT)); verify(secondRepositoryPresenter, never()).getItemId(any(), anyInt()); }
@Test public void shouldReturnItemIdFromFirstPresenterWithoutStatic() { when(repositoryPresenter.getItemId(REPOSITORY_ITEM, 0)).thenReturn(10L); assertThat(repositoryAdapterWithoutStatic.getItemId(0), is(10L)); }
@Test public void shouldReturnItemIdFromSecondPresenter() { when(secondRepositoryPresenter.getItemId(REPOSITORY_LIST, 0)).thenReturn(11L); assertThat(repositoryAdapter.getItemId(1), is(11L + STATIC_ITEM_COUNT)); verify(repositoryPresenter, never()).getItemId(any(), anyInt()); }
@Test public void shouldReturnItemIdForStaticItems() { for (int i = 4; i <= 9; i++) { assertThat(repositoryAdapter.getItemId(i), is(i - 4L)); } }
@Test(expected = IndexOutOfBoundsException.class) public void shouldThrowExceptionForOutOfBoundsIndex() { repositoryAdapter.getItemId(10); }