ConcatAdapter extends PowerAdapter { @CallSuper @Override protected void onFirstObserverRegistered() { super.onFirstObserverRegistered(); mItemCount = mRangeTable.rebuild(mRealRangeClient); if (mItemCount > 0) { notifyItemRangeInserted(0, mItemCount); } for (Entry entry : mEntries) { entry.mShadowItemCount = entry.mAdapter.getItemCount(); } for (Entry entry : mEntries) { entry.register(); } } ConcatAdapter(@NonNull List<? extends PowerAdapter> adapters); @Override int getItemCount(); @Override boolean hasStableIds(); @Override long getItemId(int position); @Override boolean isEnabled(int position); @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
    );  }
@Test public void childState1() { List<FakeAdapter> childAdapters = newArrayList( spy(new FakeAdapter(1)), spy(new FakeAdapter(0)), spy(new FakeAdapter(1)) ); PowerAdapter concatAdapter = new ConcatAdapterBuilder().addAll(childAdapters).build(); concatAdapter.registerDataObserver(mock(DataObserver.class)); for (PowerAdapter adapter : childAdapters) { verify(adapter).registerDataObserver(any(DataObserver.class)); verify(adapter).onFirstObserverRegistered(); } verifySubAdapterAllGetCalls() .checkRange(childAdapters.get(0), 0, 1) .checkRange(childAdapters.get(2), 0, 1) .verify(concatAdapter); }
@Test public void childState2() { List<FakeAdapter> childAdapters = newArrayList( spy(new FakeAdapter(12)), spy(new FakeAdapter(6)), spy(new FakeAdapter(0)), spy(new FakeAdapter(0)), spy(new FakeAdapter(11)) ); PowerAdapter concatAdapter = new ConcatAdapterBuilder().addAll(childAdapters).build(); concatAdapter.registerDataObserver(mock(DataObserver.class)); for (PowerAdapter adapter : childAdapters) { verify(adapter).registerDataObserver(any(DataObserver.class)); verify(adapter).onFirstObserverRegistered(); } verifySubAdapterAllGetCalls() .checkRange(childAdapters.get(0), 0, 12) .checkRange(childAdapters.get(1), 0, 6) .checkRange(childAdapters.get(4), 0, 11) .verify(concatAdapter); }