TreeAdapter extends PowerAdapter { @Override public int getItemCount() { if (getObserverCount() <= 0) { return 0; } if (mEntries.size() == 0) { return 0; } Entry entry = mEntries.get(mEntries.size() - 1); return entry.getOffset() + entry.getItemCount(); } TreeAdapter(@NonNull PowerAdapter rootAdapter, @NonNull ChildAdapterSupplier childAdapterSupplier); @NonNull Parcelable saveInstanceState(); void restoreInstanceState(@Nullable Parcelable parcelable); boolean isAutoExpand(); void setAutoExpand(boolean autoExpand); boolean isExpanded(int position); void setExpanded(int position, boolean expanded); boolean toggleExpanded(int position); void setAllExpanded(boolean expanded); @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 rootRemovalItemCountIsConsistent() { final FakeAdapter childAdapter = new FakeAdapter(10); FakeAdapter rootAdapter = new FakeAdapter(1); TreeAdapter treeAdapter = new TreeAdapter(rootAdapter, new ChildAdapterSupplier() { @NonNull @Override public PowerAdapter get(int position) { return childAdapter; } }); VerifyingAdapterObserver verifyingObserver = new VerifyingAdapterObserver(treeAdapter); treeAdapter.registerDataObserver(verifyingObserver); rootAdapter.clear(); assertThat(treeAdapter.getItemCount()).isEqualTo(0); verifyingObserver.assertItemCountConsistent(); }