DynamicRecyclerViewAdapter extends RecyclerView.Adapter { @Override public final int getItemViewType(int position) { return sectionedItemList.get(position).isHeader() ? TITLE_TYPE : ITEM_TYPE; }  abstract ViewHolder onCreateViewHolder(@NonNull ViewGroup parent); abstract TitleViewHolder onCreateTitleViewHolder(@NonNull ViewGroup parent); abstract void onBindViewHolder(@NonNull ViewHolder holder, @NonNull DataObject item, int position); abstract void onBindTitleViewHolder(@NonNull TitleViewHolder holder,
                                               @NonNull String sectionName,
                                               @NonNull Collection<DataObject> dataItems,
                                               int position); @Override final RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType); @Override final void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position); @Override final int getItemViewType(int position); @Override final int getItemCount(); final void setData(@Nullable Collection<DataObject> items,
                              @NonNull SectionEvaluator<DataObject> sectionEvaluator); final void setData(@Nullable Collection<DataObject> items,
                              @NonNull SectionEvaluator<DataObject> sectionEvaluator,
                              @NonNull Comparator<Section> comparator);  }
@Test public void shouldProvideCorrectViewTypeForHeadersAndNonHeader() { assertThat(dynamicRecyclerViewAdapter.getItemViewType(0)).isEqualTo(DynamicRecyclerViewAdapter.TITLE_TYPE); assertThat(dynamicRecyclerViewAdapter.getItemViewType(1)).isEqualTo(DynamicRecyclerViewAdapter.ITEM_TYPE); assertThat(dynamicRecyclerViewAdapter.getItemViewType(2)).isEqualTo(DynamicRecyclerViewAdapter.TITLE_TYPE); assertThat(dynamicRecyclerViewAdapter.getItemViewType(3)).isEqualTo(DynamicRecyclerViewAdapter.ITEM_TYPE); }