diff options
author | Maurice Lam <yukl@google.com> | 2017-03-27 16:24:08 -0700 |
---|---|---|
committer | Maurice Lam <yukl@google.com> | 2017-03-27 16:28:19 -0700 |
commit | 4dd5de226fefd5c2fdf040543157357f53ea932e (patch) | |
tree | 47d25e7a2649d047ae8ee53ec7a378a06f15b2fa /library/test/robotest/src/com | |
parent | 17e8d19de7fe82c0bc149265d787cfb40f227e81 (diff) | |
download | setupwizard-4dd5de226fefd5c2fdf040543157357f53ea932e.tar.gz |
Notify the correct position when removing the last item
Change ItemGroup#getChildPosition to return the position even for
empty childrem, so that when removing the last item in a nested
ItemGroup, the notification propagation will still be correct.
Test: ./gradlew connectedAndroidTest test
Bug: 36634677
Change-Id: I612e0c624dabee1bfaa6133fe976527e85523634
Diffstat (limited to 'library/test/robotest/src/com')
-rw-r--r-- | library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java b/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java index 73597c7..e0e7e8d 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/items/ItemGroupTest.java @@ -124,6 +124,52 @@ public class ItemGroupTest { } @Test + public void testNestedGroupClearNotification() { + ItemGroup parentGroup = new ItemGroup(); + ItemGroup childGroup = new ItemGroup(); + parentGroup.registerObserver(mObserver); + + parentGroup.addChild(CHILD_1); + childGroup.addChild(CHILD_2); + childGroup.addChild(CHILD_3); + parentGroup.addChild(childGroup); + parentGroup.addChild(CHILD_4); + + childGroup.clear(); + + final InOrder inOrder = inOrder(mObserver); + inOrder.verify(mObserver).onItemRangeInserted(eq(parentGroup), eq(0), eq(1)); + inOrder.verify(mObserver).onItemRangeInserted(eq(parentGroup), eq(1), eq(2)); + inOrder.verify(mObserver).onItemRangeInserted(eq(parentGroup), eq(3), eq(1)); + verify(mObserver).onItemRangeRemoved(eq(parentGroup), eq(1), eq(2)); + verifyNoMoreInteractions(mObserver); + } + + @Test + public void testNestedGroupRemoveNotification() { + ItemGroup parentGroup = new ItemGroup(); + ItemGroup childGroup = new ItemGroup(); + parentGroup.registerObserver(mObserver); + + parentGroup.addChild(CHILD_1); + childGroup.addChild(CHILD_2); + childGroup.addChild(CHILD_3); + parentGroup.addChild(childGroup); + parentGroup.addChild(CHILD_4); + + childGroup.removeChild(CHILD_3); + childGroup.removeChild(CHILD_2); + + final InOrder inOrder = inOrder(mObserver); + inOrder.verify(mObserver).onItemRangeInserted(eq(parentGroup), eq(0), eq(1)); + inOrder.verify(mObserver).onItemRangeInserted(eq(parentGroup), eq(1), eq(2)); + inOrder.verify(mObserver).onItemRangeInserted(eq(parentGroup), eq(3), eq(1)); + inOrder.verify(mObserver).onItemRangeRemoved(eq(parentGroup), eq(2), eq(1)); + inOrder.verify(mObserver).onItemRangeRemoved(eq(parentGroup), eq(1), eq(1)); + verifyNoMoreInteractions(mObserver); + } + + @Test public void testNotifyChange() { mItemGroup.addChild(CHILD_1); mItemGroup.addChild(CHILD_2); |