TreeAdapter extends PowerAdapter { public void setAllExpanded(boolean expanded) { for (int i = 0; i < mRootAdapter.getItemCount(); i++) { setExpanded(i, expanded); } } 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 rootBindViewContainerScrollToStartScrollsToRootAdapterStart() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); Container innerContainer = bindViewAndReturnInnerContainer(4, mRootAdapter, rootContainer); innerContainer.scrollToStart(); verify(rootContainer).scrollToPosition(0); }
@Test public void rootBindViewContainerScrollToEndScrollsToRootAdapterEnd() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); Container innerContainer = bindViewAndReturnInnerContainer(8, mRootAdapter, rootContainer); innerContainer.scrollToEnd(); verify(rootContainer).scrollToPosition(8); }
@Test public void rootBindViewContainerScrollToPosition() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); Container innerContainer = bindViewAndReturnInnerContainer(0, mRootAdapter, rootContainer); innerContainer.scrollToPosition(1); verify(rootContainer).scrollToPosition(4); }
@Test public void rootBindViewContainerRootContainerIsActuallyRootContainer() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); when(rootContainer.getRootContainer()).thenReturn(rootContainer); Container innerContainer = bindViewAndReturnInnerContainer(4, mRootAdapter, rootContainer); assertThat(innerContainer.getRootContainer()).isEqualTo(rootContainer); }
@Test public void rootBindViewContainerViewGroupIsRootContainerViewGroup() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); when(rootContainer.getViewGroup()).thenReturn(mContainerViewGroup); Container innerContainer = bindViewAndReturnInnerContainer(0, mRootAdapter, rootContainer); assertThat(innerContainer.getViewGroup()).isEqualTo(mContainerViewGroup); }
@Test public void childBindViewContainerScrollToStartScrollsToChildAdapterStart() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); Container innerContainer = bindViewAndReturnInnerContainer(11, mChildAdapters.get(2), rootContainer); innerContainer.scrollToStart(); verify(rootContainer).scrollToPosition(9); }
@Test public void childBindViewContainerScrollToEndScrollsToChildAdapterEnd() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); Container innerContainer = bindViewAndReturnInnerContainer(7, mChildAdapters.get(1), rootContainer); innerContainer.scrollToEnd(); verify(rootContainer).scrollToPosition(7); }
@Test public void childBindViewContainerScrollToPosition() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); Container innerContainer = bindViewAndReturnInnerContainer(9, mChildAdapters.get(2), rootContainer); innerContainer.scrollToPosition(1); verify(rootContainer).scrollToPosition(10); }
@Test public void childBindViewContainerChildRootContainerIsActuallyRootContainer() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); when(rootContainer.getRootContainer()).thenReturn(rootContainer); Container innerContainer = bindViewAndReturnInnerContainer(2, mChildAdapters.get(0), rootContainer); assertThat(innerContainer.getRootContainer()).isEqualTo(rootContainer); }
@Test public void childBindViewContainerViewGroupIsChildContainerViewGroup() { mTreeAdapter.setAllExpanded(true); Container rootContainer = mock(Container.class); when(rootContainer.getViewGroup()).thenReturn(mContainerViewGroup); Container innerContainer = bindViewAndReturnInnerContainer(5, mChildAdapters.get(1), rootContainer); assertThat(innerContainer.getViewGroup()).isEqualTo(mContainerViewGroup); }
@Test public void rootChangeThenRemovalDoesNotThrow() { mTreeAdapter.setAllExpanded(false); DataObserver observer = registerMockDataObserver(); mRootAdapter.change(0, 1, null); mRootAdapter.remove(2, 1); verify(observer).onItemRangeChanged(0, 1, null); verify(observer).onItemRangeRemoved(2, 1); verifyNoMoreInteractions(observer); }
@Test public void childChangeWhileNotExpandedIsIgnored() { mTreeAdapter.setAllExpanded(false); DataObserver observer = registerMockDataObserver(); mChildAdapters.get(2).change(2, 1, null); verifyZeroInteractions(observer); }
@Test public void childInsertWhileNotExpandedIsIgnored() { mTreeAdapter.setAllExpanded(false); DataObserver observer = registerMockDataObserver(); mChildAdapters.get(2).append(4); verifyZeroInteractions(observer); }
@Test public void childRemoveWhileNotExpandedIsIgnored() { mTreeAdapter.setAllExpanded(false); DataObserver observer = registerMockDataObserver(); mChildAdapters.get(0).remove(1, 2); verifyZeroInteractions(observer); }
@Test public void childMoveWhileNotExpandedIsIgnored() { mTreeAdapter.setAllExpanded(false); DataObserver observer = registerMockDataObserver(); mChildAdapters.get(2).move(1, 2, 1); verifyZeroInteractions(observer); }