From cdd5d38d3d2c3ef10d17603a582bf27e055e18d1 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 19 Aug 2019 19:31:35 +0200 Subject: [PATCH] add getHeaderPositionForItem unit test Signed-off-by: alex Signed-off-by: Andy Scherzinger --- .../ui/adapter/ActivityListAdapterTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/test/java/com/owncloud/android/ui/adapter/ActivityListAdapterTest.java b/src/test/java/com/owncloud/android/ui/adapter/ActivityListAdapterTest.java index a1d5bbd9ca..92c3a07b64 100644 --- a/src/test/java/com/owncloud/android/ui/adapter/ActivityListAdapterTest.java +++ b/src/test/java/com/owncloud/android/ui/adapter/ActivityListAdapterTest.java @@ -52,4 +52,66 @@ public final class ActivityListAdapterTest { activityListAdapter.values.add(activity); Assert.assertFalse(activityListAdapter.isHeader(1)); } + + @Test + public void getHeaderPositionForItem__AdapterIsEmpty_ReturnZero(){ + Mockito.when(activityListAdapter.isHeader(0)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(0)).thenCallRealMethod(); + + Assert.assertEquals(0,activityListAdapter.getHeaderPositionForItem(0)); + } + + @Test + public void getHeaderPositionForItem__ItemIsHeader_ReturnCurrentItem() { + Object header = "Hello"; + Object activity = Mockito.mock(Activity.class); + + Mockito.when(activityListAdapter.isHeader(0)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(0)).thenCallRealMethod(); + Mockito.when(activityListAdapter.isHeader(1)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(1)).thenCallRealMethod(); + Mockito.when(activityListAdapter.isHeader(2)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(2)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getHeaderPositionForItem(2)).thenCallRealMethod(); + Mockito.when(activityListAdapter.isHeader(3)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(3)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getHeaderPositionForItem(3)).thenCallRealMethod(); + + + activityListAdapter.values.add(header); + activityListAdapter.values.add(activity); + activityListAdapter.values.add(header); + activityListAdapter.values.add(activity); + + + Assert.assertEquals(2, activityListAdapter.getHeaderPositionForItem(2)); + + } + + @Test + public void getHeaderPositionForItem__ItemIsActivity_ReturnNextHeader() { + Object header = "Hello"; + Object activity = Mockito.mock(Activity.class); + + Mockito.when(activityListAdapter.isHeader(0)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(0)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getHeaderPositionForItem(0)).thenCallRealMethod(); + Mockito.when(activityListAdapter.isHeader(1)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(1)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getHeaderPositionForItem(1)).thenCallRealMethod(); + Mockito.when(activityListAdapter.isHeader(2)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(2)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getHeaderPositionForItem(2)).thenCallRealMethod(); + Mockito.when(activityListAdapter.isHeader(3)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getItemViewType(3)).thenCallRealMethod(); + Mockito.when(activityListAdapter.getHeaderPositionForItem(3)).thenCallRealMethod(); + + activityListAdapter.values.add(header); + activityListAdapter.values.add(activity); + activityListAdapter.values.add(header); + activityListAdapter.values.add(activity); + + Assert.assertEquals(2, activityListAdapter.getHeaderPositionForItem(2)); + } + }