ConditionalAdapter extends PowerAdapter { @Override public int getItemCount() { return mVisible ? mAdapter.getItemCount() : 0; } ConditionalAdapter(@NonNull PowerAdapter adapter, @NonNull Condition condition); @Override int getItemCount(); @Override boolean hasStableIds(); @Override long getItemId(int position); @NonNull @Override Object getItemViewType(int position); @Override boolean isEnabled(int position); @NonNull @Override View newView(@NonNull ViewGroup parent, @NonNull Object viewType); @Override void bindView(
            @NonNull Container container,
            @NonNull View v,
            @NonNull Holder holder,
            @NonNull List<Object> payloads
    );  }
@Test public void itemCountIsZeroWhenFalse() { setCondition(Condition.never()); assertThat(mConditionalAdapter.getItemCount()).isEqualTo(0); assertItemCountConsistent(); }
@Test public void itemCountIsNonZeroWhenTrue() { setCondition(always()); assertThat(mConditionalAdapter.getItemCount()).isEqualTo(10); assertItemCountConsistent(); }
@Test public void childInsertionUponFirstRegistrationIsNotDuplicated() { PowerAdapter fakeAdapter = new FakeAdapter(10); ConditionalAdapter nestedConditionalAdapter = new ConditionalAdapter(fakeAdapter, always()); ConditionalAdapter conditionalAdapter = new ConditionalAdapter(nestedConditionalAdapter, always()); VerifyingAdapterObserver verifyingObserver = new VerifyingAdapterObserver(conditionalAdapter); conditionalAdapter.registerDataObserver(verifyingObserver); conditionalAdapter.registerDataObserver(mObserver); assertThat(conditionalAdapter.getItemCount()).isEqualTo(10); verifyNoMoreInteractions(mObserver); verifyingObserver.assertItemCountConsistent(); }