summaryrefslogtreecommitdiff
path: root/library/recyclerview/test/instrumentation
diff options
context:
space:
mode:
Diffstat (limited to 'library/recyclerview/test/instrumentation')
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/items/RecyclerItemAdapterTest.java218
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/template/RecyclerMixinTest.java176
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/DividerItemDecorationTest.java334
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifPreferenceLayoutTest.java116
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifRecyclerLayoutTest.java250
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/HeaderRecyclerViewTest.java259
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardPreferenceLayoutTest.java118
-rw-r--r--library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardRecyclerLayoutTest.java257
8 files changed, 844 insertions, 884 deletions
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/items/RecyclerItemAdapterTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/items/RecyclerItemAdapterTest.java
index 6f42e84..bed736e 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/items/RecyclerItemAdapterTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/items/RecyclerItemAdapterTest.java
@@ -32,16 +32,13 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
+import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
+import android.widget.FrameLayout;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.widget.FrameLayout;
-
-import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
-
import com.android.setupwizardlib.items.RecyclerItemAdapter.PatchedLayerDrawable;
import com.android.setupwizardlib.test.R;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,111 +47,110 @@ import org.junit.runner.RunWith;
@SmallTest
public class RecyclerItemAdapterTest {
- private Item[] mItems = new Item[5];
- private ItemGroup mItemGroup = new ItemGroup();
-
- @Before
- public void setUp() throws Exception {
- for (int i = 0; i < 5; i++) {
- Item item = new Item();
- item.setTitle("TestTitle" + i);
- item.setId(i);
- // Layout resource: 0 -> 1, 1 -> 11, 2 -> 21, 3 -> 1, 4 -> 11.
- // (Resource IDs cannot be 0)
- item.setLayoutResource((i % 3) * 10 + 1);
- mItems[i] = item;
- mItemGroup.addChild(item);
- }
- }
-
- @Test
- public void testAdapter() {
- RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
- assertEquals("Adapter should have 5 items", 5, adapter.getItemCount());
- assertEquals("Adapter should return the first item", mItems[0], adapter.getItem(0));
- assertEquals("ID should be same as position", 2, adapter.getItemId(2));
-
- // ViewType is same as layout resource for RecyclerItemAdapter
- assertEquals("Second item should have view type 21", 21, adapter.getItemViewType(2));
- }
-
- @Test
- public void testGetRootItemHierarchy() {
- RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
- ItemHierarchy root = adapter.getRootItemHierarchy();
- assertSame("Root item hierarchy should be mItemGroup", mItemGroup, root);
- }
-
- @Test
- public void testPatchedLayerDrawableNoPadding() {
- ShapeDrawable child = new ShapeDrawable(new RectShape());
- child.setPadding(0, 0, 0, 0);
- PatchedLayerDrawable drawable = new PatchedLayerDrawable(new Drawable[] { child });
-
- Rect padding = new Rect();
- assertFalse("Patched layer drawable should not have padding", drawable.getPadding(padding));
- assertEquals(new Rect(0, 0, 0, 0), padding);
- }
-
- @Test
- public void testPatchedLayerDrawableWithPadding() {
- ShapeDrawable child = new ShapeDrawable(new RectShape());
- child.setPadding(10, 10, 10, 10);
- PatchedLayerDrawable drawable = new PatchedLayerDrawable(new Drawable[] { child });
-
- Rect padding = new Rect();
- assertTrue("Patched layer drawable should have padding", drawable.getPadding(padding));
- assertEquals(new Rect(10, 10, 10, 10), padding);
- }
-
- @Test
- public void testAdapterNotifications() {
- RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
- final AdapterDataObserver observer = mock(AdapterDataObserver.class);
- adapter.registerAdapterDataObserver(observer);
-
- mItems[0].setTitle("Child 1");
- verify(observer).onItemRangeChanged(eq(0), eq(1), anyObject());
-
- mItemGroup.removeChild(mItems[1]);
- verify(observer).onItemRangeRemoved(eq(1), eq(1));
-
- mItemGroup.addChild(mItems[1]);
- verify(observer).onItemRangeInserted(eq(4), eq(1));
- }
-
- @Test
- public void testCreateViewHolder() {
- RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
- FrameLayout parent = new FrameLayout(InstrumentationRegistry.getContext());
-
- final ItemViewHolder viewHolder =
- adapter.onCreateViewHolder(parent, R.layout.test_list_item);
- assertNotNull("Background should be set", viewHolder.itemView.getBackground());
- assertEquals("foobar", viewHolder.itemView.getTag());
- }
-
- @Test
- public void testCreateViewHolderNoBackground() {
- RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
- FrameLayout parent = new FrameLayout(InstrumentationRegistry.getContext());
-
- final ItemViewHolder viewHolder =
- adapter.onCreateViewHolder(parent, R.layout.test_list_item_no_background);
- assertNull("Background should be null", viewHolder.itemView.getBackground());
- }
-
- @Test
- public void testCreateViewHolderWithExistingBackground() {
- RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
- FrameLayout parent = new FrameLayout(InstrumentationRegistry.getContext());
-
- final ItemViewHolder viewHolder =
- adapter.onCreateViewHolder(parent, R.layout.test_existing_background);
- Drawable background = viewHolder.itemView.getBackground();
- assertTrue(background instanceof PatchedLayerDrawable);
-
- PatchedLayerDrawable layerDrawable = (PatchedLayerDrawable) background;
- assertTrue(layerDrawable.getDrawable(0) instanceof GradientDrawable);
+ private Item[] mItems = new Item[5];
+ private ItemGroup mItemGroup = new ItemGroup();
+
+ @Before
+ public void setUp() throws Exception {
+ for (int i = 0; i < 5; i++) {
+ Item item = new Item();
+ item.setTitle("TestTitle" + i);
+ item.setId(i);
+ // Layout resource: 0 -> 1, 1 -> 11, 2 -> 21, 3 -> 1, 4 -> 11.
+ // (Resource IDs cannot be 0)
+ item.setLayoutResource((i % 3) * 10 + 1);
+ mItems[i] = item;
+ mItemGroup.addChild(item);
}
+ }
+
+ @Test
+ public void testAdapter() {
+ RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
+ assertEquals("Adapter should have 5 items", 5, adapter.getItemCount());
+ assertEquals("Adapter should return the first item", mItems[0], adapter.getItem(0));
+ assertEquals("ID should be same as position", 2, adapter.getItemId(2));
+
+ // ViewType is same as layout resource for RecyclerItemAdapter
+ assertEquals("Second item should have view type 21", 21, adapter.getItemViewType(2));
+ }
+
+ @Test
+ public void testGetRootItemHierarchy() {
+ RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
+ ItemHierarchy root = adapter.getRootItemHierarchy();
+ assertSame("Root item hierarchy should be mItemGroup", mItemGroup, root);
+ }
+
+ @Test
+ public void testPatchedLayerDrawableNoPadding() {
+ ShapeDrawable child = new ShapeDrawable(new RectShape());
+ child.setPadding(0, 0, 0, 0);
+ PatchedLayerDrawable drawable = new PatchedLayerDrawable(new Drawable[] {child});
+
+ Rect padding = new Rect();
+ assertFalse("Patched layer drawable should not have padding", drawable.getPadding(padding));
+ assertEquals(new Rect(0, 0, 0, 0), padding);
+ }
+
+ @Test
+ public void testPatchedLayerDrawableWithPadding() {
+ ShapeDrawable child = new ShapeDrawable(new RectShape());
+ child.setPadding(10, 10, 10, 10);
+ PatchedLayerDrawable drawable = new PatchedLayerDrawable(new Drawable[] {child});
+
+ Rect padding = new Rect();
+ assertTrue("Patched layer drawable should have padding", drawable.getPadding(padding));
+ assertEquals(new Rect(10, 10, 10, 10), padding);
+ }
+
+ @Test
+ public void testAdapterNotifications() {
+ RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
+ final AdapterDataObserver observer = mock(AdapterDataObserver.class);
+ adapter.registerAdapterDataObserver(observer);
+
+ mItems[0].setTitle("Child 1");
+ verify(observer).onItemRangeChanged(eq(0), eq(1), anyObject());
+
+ mItemGroup.removeChild(mItems[1]);
+ verify(observer).onItemRangeRemoved(eq(1), eq(1));
+
+ mItemGroup.addChild(mItems[1]);
+ verify(observer).onItemRangeInserted(eq(4), eq(1));
+ }
+
+ @Test
+ public void testCreateViewHolder() {
+ RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
+ FrameLayout parent = new FrameLayout(InstrumentationRegistry.getContext());
+
+ final ItemViewHolder viewHolder = adapter.onCreateViewHolder(parent, R.layout.test_list_item);
+ assertNotNull("Background should be set", viewHolder.itemView.getBackground());
+ assertEquals("foobar", viewHolder.itemView.getTag());
+ }
+
+ @Test
+ public void testCreateViewHolderNoBackground() {
+ RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
+ FrameLayout parent = new FrameLayout(InstrumentationRegistry.getContext());
+
+ final ItemViewHolder viewHolder =
+ adapter.onCreateViewHolder(parent, R.layout.test_list_item_no_background);
+ assertNull("Background should be null", viewHolder.itemView.getBackground());
+ }
+
+ @Test
+ public void testCreateViewHolderWithExistingBackground() {
+ RecyclerItemAdapter adapter = new RecyclerItemAdapter(mItemGroup);
+ FrameLayout parent = new FrameLayout(InstrumentationRegistry.getContext());
+
+ final ItemViewHolder viewHolder =
+ adapter.onCreateViewHolder(parent, R.layout.test_existing_background);
+ Drawable background = viewHolder.itemView.getBackground();
+ assertTrue(background instanceof PatchedLayerDrawable);
+
+ PatchedLayerDrawable layerDrawable = (PatchedLayerDrawable) background;
+ assertTrue(layerDrawable.getDrawable(0) instanceof GradientDrawable);
+ }
}
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/template/RecyclerMixinTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/template/RecyclerMixinTest.java
index ece4bf9..f295b91 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/template/RecyclerMixinTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/template/RecyclerMixinTest.java
@@ -30,17 +30,14 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView.Adapter;
+import android.view.View;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.view.View;
-
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.recyclerview.widget.RecyclerView.Adapter;
-
import com.android.setupwizardlib.TemplateLayout;
import com.android.setupwizardlib.test.R;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,120 +48,119 @@ import org.mockito.MockitoAnnotations;
@SmallTest
public class RecyclerMixinTest {
- private Context mContext;
- private TemplateLayout mTemplateLayout;
+ private Context mContext;
+ private TemplateLayout mTemplateLayout;
- private RecyclerView mRecyclerView;
+ private RecyclerView mRecyclerView;
- @Mock
- private Adapter mAdapter;
+ @Mock private Adapter mAdapter;
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
- mContext = InstrumentationRegistry.getTargetContext();
- mTemplateLayout = spy(new TemplateLayout(mContext, R.layout.test_template,
- R.id.suw_layout_content));
+ mContext = InstrumentationRegistry.getTargetContext();
+ mTemplateLayout =
+ spy(new TemplateLayout(mContext, R.layout.test_template, R.id.suw_layout_content));
- mRecyclerView = mock(RecyclerView.class, delegatesTo(new RecyclerView(mContext)));
+ mRecyclerView = mock(RecyclerView.class, delegatesTo(new RecyclerView(mContext)));
- doReturn(true).when(mTemplateLayout).isLayoutDirectionResolved();
- }
+ doReturn(true).when(mTemplateLayout).isLayoutDirectionResolved();
+ }
- @Test
- public void testGetRecyclerView() {
- RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
- assertSame(mRecyclerView, mixin.getRecyclerView());
- }
+ @Test
+ public void testGetRecyclerView() {
+ RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
+ assertSame(mRecyclerView, mixin.getRecyclerView());
+ }
- @Test
- public void testGetAdapter() {
- mRecyclerView.setAdapter(mAdapter);
+ @Test
+ public void testGetAdapter() {
+ mRecyclerView.setAdapter(mAdapter);
- RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
- assertSame(mAdapter, mixin.getAdapter());
- }
+ RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
+ assertSame(mAdapter, mixin.getAdapter());
+ }
- @Test
- public void testSetAdapter() {
- assertNull(mRecyclerView.getAdapter());
+ @Test
+ public void testSetAdapter() {
+ assertNull(mRecyclerView.getAdapter());
- RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
- mixin.setAdapter(mAdapter);
+ RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
+ mixin.setAdapter(mAdapter);
- assertSame(mAdapter, mRecyclerView.getAdapter());
- }
+ assertSame(mAdapter, mRecyclerView.getAdapter());
+ }
- @Test
- public void testDividerLegacyInset() {
- RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
- mixin.setDividerInset(123);
+ @Test
+ public void testDividerLegacyInset() {
+ RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
+ mixin.setDividerInset(123);
- assertEquals(123, mixin.getDividerInset());
+ assertEquals(123, mixin.getDividerInset());
- final Drawable divider = mixin.getDivider();
- InsetDrawable insetDrawable = (InsetDrawable) divider;
- Rect rect = new Rect();
- insetDrawable.getPadding(rect);
+ final Drawable divider = mixin.getDivider();
+ InsetDrawable insetDrawable = (InsetDrawable) divider;
+ Rect rect = new Rect();
+ insetDrawable.getPadding(rect);
- assertEquals(new Rect(123, 0, 0, 0), rect);
- }
+ assertEquals(new Rect(123, 0, 0, 0), rect);
+ }
- @Test
- public void testDividerInsets() {
- RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
- mixin.setDividerInsets(123, 456);
+ @Test
+ public void testDividerInsets() {
+ RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
+ mixin.setDividerInsets(123, 456);
- assertEquals(123, mixin.getDividerInsetStart());
- assertEquals(456, mixin.getDividerInsetEnd());
+ assertEquals(123, mixin.getDividerInsetStart());
+ assertEquals(456, mixin.getDividerInsetEnd());
- final Drawable divider = mixin.getDivider();
- InsetDrawable insetDrawable = (InsetDrawable) divider;
- Rect rect = new Rect();
- insetDrawable.getPadding(rect);
+ final Drawable divider = mixin.getDivider();
+ InsetDrawable insetDrawable = (InsetDrawable) divider;
+ Rect rect = new Rect();
+ insetDrawable.getPadding(rect);
- assertEquals(new Rect(123, 0, 456, 0), rect);
- }
+ assertEquals(new Rect(123, 0, 456, 0), rect);
+ }
- @Test
- public void testDividerInsetLegacyRtl() {
- if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
- doReturn(View.LAYOUT_DIRECTION_RTL).when(mTemplateLayout).getLayoutDirection();
+ @Test
+ public void testDividerInsetLegacyRtl() {
+ if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
+ doReturn(View.LAYOUT_DIRECTION_RTL).when(mTemplateLayout).getLayoutDirection();
- RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
- mixin.setDividerInset(123);
+ RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
+ mixin.setDividerInset(123);
- assertEquals(123, mixin.getDividerInset());
+ assertEquals(123, mixin.getDividerInset());
- final Drawable divider = mixin.getDivider();
- InsetDrawable insetDrawable = (InsetDrawable) divider;
- Rect rect = new Rect();
- insetDrawable.getPadding(rect);
+ final Drawable divider = mixin.getDivider();
+ InsetDrawable insetDrawable = (InsetDrawable) divider;
+ Rect rect = new Rect();
+ insetDrawable.getPadding(rect);
- assertEquals(new Rect(0, 0, 123, 0), rect);
- }
- // else the test passes
+ assertEquals(new Rect(0, 0, 123, 0), rect);
}
+ // else the test passes
+ }
- @Test
- public void testDividerInsetsRtl() {
- if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
- doReturn(View.LAYOUT_DIRECTION_RTL).when(mTemplateLayout).getLayoutDirection();
+ @Test
+ public void testDividerInsetsRtl() {
+ if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
+ doReturn(View.LAYOUT_DIRECTION_RTL).when(mTemplateLayout).getLayoutDirection();
- RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
- mixin.setDividerInsets(123, 456);
+ RecyclerMixin mixin = new RecyclerMixin(mTemplateLayout, mRecyclerView);
+ mixin.setDividerInsets(123, 456);
- assertEquals(123, mixin.getDividerInsetStart());
- assertEquals(456, mixin.getDividerInsetEnd());
+ assertEquals(123, mixin.getDividerInsetStart());
+ assertEquals(456, mixin.getDividerInsetEnd());
- final Drawable divider = mixin.getDivider();
- InsetDrawable insetDrawable = (InsetDrawable) divider;
- Rect rect = new Rect();
- insetDrawable.getPadding(rect);
+ final Drawable divider = mixin.getDivider();
+ InsetDrawable insetDrawable = (InsetDrawable) divider;
+ Rect rect = new Rect();
+ insetDrawable.getPadding(rect);
- assertEquals(new Rect(456, 0, 123, 0), rect);
- }
- // else the test passes
+ assertEquals(new Rect(456, 0, 123, 0), rect);
}
+ // else the test passes
+ }
}
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/DividerItemDecorationTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/DividerItemDecorationTest.java
index 9cf33b9..a3a0cfe 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/DividerItemDecorationTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/DividerItemDecorationTest.java
@@ -28,17 +28,14 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-
import com.android.setupwizardlib.DividerItemDecoration;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,176 +43,179 @@ import org.junit.runner.RunWith;
@SmallTest
public class DividerItemDecorationTest {
- @Test
- public void testDivider() {
- final DividerItemDecoration decoration = new DividerItemDecoration();
- Drawable divider = new ColorDrawable();
- decoration.setDivider(divider);
- assertSame("Divider should be same as set", divider, decoration.getDivider());
- }
+ @Test
+ public void testDivider() {
+ final DividerItemDecoration decoration = new DividerItemDecoration();
+ Drawable divider = new ColorDrawable();
+ decoration.setDivider(divider);
+ assertSame("Divider should be same as set", divider, decoration.getDivider());
+ }
+
+ @Test
+ public void testDividerHeight() {
+ final DividerItemDecoration decoration = new DividerItemDecoration();
+ decoration.setDividerHeight(123);
+ assertEquals("Divider height should be 123", 123, decoration.getDividerHeight());
+ }
+
+ @Test
+ public void testShouldDrawDividerBelowWithEitherCondition() {
+ // Set up the item decoration, with 1px red divider line
+ final DividerItemDecoration decoration = new DividerItemDecoration();
+ Drawable divider = new ColorDrawable(Color.RED);
+ decoration.setDivider(divider);
+ decoration.setDividerHeight(1);
+
+ Bitmap bitmap = drawDecoration(decoration, true, true);
+
+ // Draw the expected result on a bitmap
+ Bitmap expectedBitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_4444);
+ Canvas expectedCanvas = new Canvas(expectedBitmap);
+ Paint paint = new Paint();
+ paint.setColor(Color.RED);
+ expectedCanvas.drawRect(0, 5, 20, 6, paint);
+ expectedCanvas.drawRect(0, 10, 20, 11, paint);
+ expectedCanvas.drawRect(0, 15, 20, 16, paint);
+ // Compare the two bitmaps
+ assertBitmapEquals(expectedBitmap, bitmap);
+
+ bitmap.recycle();
+ bitmap = drawDecoration(decoration, false, true);
+ // should still be the same.
+ assertBitmapEquals(expectedBitmap, bitmap);
+
+ bitmap.recycle();
+ bitmap = drawDecoration(decoration, true, false);
+ // last item should not have a divider below it now
+ paint.setColor(Color.TRANSPARENT);
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
+ expectedCanvas.drawRect(0, 15, 20, 16, paint);
+ assertBitmapEquals(expectedBitmap, bitmap);
+
+ bitmap.recycle();
+ bitmap = drawDecoration(decoration, false, false);
+ // everything should be transparent now
+ expectedCanvas.drawRect(0, 5, 20, 6, paint);
+ expectedCanvas.drawRect(0, 10, 20, 11, paint);
+ assertBitmapEquals(expectedBitmap, bitmap);
+ }
+
+ @Test
+ public void testShouldDrawDividerBelowWithBothCondition() {
+ // Set up the item decoration, with 1px green divider line
+ final DividerItemDecoration decoration = new DividerItemDecoration();
+ Drawable divider = new ColorDrawable(Color.GREEN);
+ decoration.setDivider(divider);
+ decoration.setDividerHeight(1);
+ decoration.setDividerCondition(DividerItemDecoration.DIVIDER_CONDITION_BOTH);
+
+ Bitmap bitmap = drawDecoration(decoration, true, true);
+ Paint paint = new Paint();
+ paint.setColor(Color.GREEN);
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD));
+ Bitmap expectedBitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_4444);
+ Canvas expectedCanvas = new Canvas(expectedBitmap);
+ expectedCanvas.drawRect(0, 5, 20, 6, paint);
+ expectedCanvas.drawRect(0, 10, 20, 11, paint);
+ expectedCanvas.drawRect(0, 15, 20, 16, paint);
+ // Should have all the dividers
+ assertBitmapEquals(expectedBitmap, bitmap);
+
+ bitmap.recycle();
+ bitmap = drawDecoration(decoration, false, true);
+ paint.setColor(Color.TRANSPARENT);
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
+ expectedCanvas.drawRect(0, 5, 20, 6, paint);
+ expectedCanvas.drawRect(0, 10, 20, 11, paint);
+ assertBitmapEquals(expectedBitmap, bitmap);
+
+ bitmap.recycle();
+ bitmap = drawDecoration(decoration, true, false);
+ // nothing should be drawn now.
+ expectedCanvas.drawRect(0, 15, 20, 16, paint);
+ assertBitmapEquals(expectedBitmap, bitmap);
+
+ bitmap.recycle();
+ bitmap = drawDecoration(decoration, false, false);
+ assertBitmapEquals(expectedBitmap, bitmap);
+ }
+
+ private Bitmap drawDecoration(
+ DividerItemDecoration decoration,
+ final boolean allowDividerAbove,
+ final boolean allowDividerBelow) {
+ // Set up the canvas to be drawn
+ Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_4444);
+ Canvas canvas = new Canvas(bitmap);
+
+ final Context context = InstrumentationRegistry.getContext();
+ // Set up recycler view with vertical linear layout manager
+ RecyclerView testRecyclerView = new RecyclerView(context);
+ testRecyclerView.setLayoutManager(new LinearLayoutManager(context));
+
+ // Set up adapter with 3 items, each 5px tall
+ testRecyclerView.setAdapter(
+ new RecyclerView.Adapter() {
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
+ final View itemView = new View(context);
+ itemView.setMinimumWidth(20);
+ itemView.setMinimumHeight(5);
+ return ViewHolder.createInstance(itemView, allowDividerAbove, allowDividerBelow);
+ }
+
+ @Override
+ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {}
+
+ @Override
+ public int getItemCount() {
+ return 3;
+ }
+ });
- @Test
- public void testDividerHeight() {
- final DividerItemDecoration decoration = new DividerItemDecoration();
- decoration.setDividerHeight(123);
- assertEquals("Divider height should be 123", 123, decoration.getDividerHeight());
+ testRecyclerView.layout(0, 0, 20, 20);
+ decoration.onDraw(canvas, testRecyclerView, null);
+ return bitmap;
+ }
+
+ private void assertBitmapEquals(Bitmap expected, Bitmap actual) {
+ assertEquals("Width should be the same", expected.getWidth(), actual.getWidth());
+ assertEquals("Height should be the same", expected.getHeight(), actual.getHeight());
+ for (int x = 0; x < expected.getWidth(); x++) {
+ for (int y = 0; y < expected.getHeight(); y++) {
+ assertEquals(
+ "Pixel at (" + x + ", " + y + ") should be the same",
+ expected.getPixel(x, y),
+ actual.getPixel(x, y));
+ }
}
+ }
- @Test
- public void testShouldDrawDividerBelowWithEitherCondition() {
- // Set up the item decoration, with 1px red divider line
- final DividerItemDecoration decoration = new DividerItemDecoration();
- Drawable divider = new ColorDrawable(Color.RED);
- decoration.setDivider(divider);
- decoration.setDividerHeight(1);
-
- Bitmap bitmap = drawDecoration(decoration, true, true);
-
- // Draw the expected result on a bitmap
- Bitmap expectedBitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_4444);
- Canvas expectedCanvas = new Canvas(expectedBitmap);
- Paint paint = new Paint();
- paint.setColor(Color.RED);
- expectedCanvas.drawRect(0, 5, 20, 6, paint);
- expectedCanvas.drawRect(0, 10, 20, 11, paint);
- expectedCanvas.drawRect(0, 15, 20, 16, paint);
- // Compare the two bitmaps
- assertBitmapEquals(expectedBitmap, bitmap);
-
- bitmap.recycle();
- bitmap = drawDecoration(decoration, false, true);
- // should still be the same.
- assertBitmapEquals(expectedBitmap, bitmap);
-
- bitmap.recycle();
- bitmap = drawDecoration(decoration, true, false);
- // last item should not have a divider below it now
- paint.setColor(Color.TRANSPARENT);
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
- expectedCanvas.drawRect(0, 15, 20, 16, paint);
- assertBitmapEquals(expectedBitmap, bitmap);
-
- bitmap.recycle();
- bitmap = drawDecoration(decoration, false, false);
- // everything should be transparent now
- expectedCanvas.drawRect(0, 5, 20, 6, paint);
- expectedCanvas.drawRect(0, 10, 20, 11, paint);
- assertBitmapEquals(expectedBitmap, bitmap);
+ private static class ViewHolder extends RecyclerView.ViewHolder
+ implements DividerItemDecoration.DividedViewHolder {
- }
+ private boolean mAllowDividerAbove;
+ private boolean mAllowDividerBelow;
- @Test
- public void testShouldDrawDividerBelowWithBothCondition() {
- // Set up the item decoration, with 1px green divider line
- final DividerItemDecoration decoration = new DividerItemDecoration();
- Drawable divider = new ColorDrawable(Color.GREEN);
- decoration.setDivider(divider);
- decoration.setDividerHeight(1);
- decoration.setDividerCondition(DividerItemDecoration.DIVIDER_CONDITION_BOTH);
-
- Bitmap bitmap = drawDecoration(decoration, true, true);
- Paint paint = new Paint();
- paint.setColor(Color.GREEN);
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD));
- Bitmap expectedBitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_4444);
- Canvas expectedCanvas = new Canvas(expectedBitmap);
- expectedCanvas.drawRect(0, 5, 20, 6, paint);
- expectedCanvas.drawRect(0, 10, 20, 11, paint);
- expectedCanvas.drawRect(0, 15, 20, 16, paint);
- // Should have all the dividers
- assertBitmapEquals(expectedBitmap, bitmap);
-
- bitmap.recycle();
- bitmap = drawDecoration(decoration, false, true);
- paint.setColor(Color.TRANSPARENT);
- paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
- expectedCanvas.drawRect(0, 5, 20, 6, paint);
- expectedCanvas.drawRect(0, 10, 20, 11, paint);
- assertBitmapEquals(expectedBitmap, bitmap);
-
- bitmap.recycle();
- bitmap = drawDecoration(decoration, true, false);
- // nothing should be drawn now.
- expectedCanvas.drawRect(0, 15, 20, 16, paint);
- assertBitmapEquals(expectedBitmap, bitmap);
-
- bitmap.recycle();
- bitmap = drawDecoration(decoration, false, false);
- assertBitmapEquals(expectedBitmap, bitmap);
+ public static ViewHolder createInstance(
+ View itemView, boolean allowDividerAbove, boolean allowDividerBelow) {
+ return new ViewHolder(itemView, allowDividerAbove, allowDividerBelow);
}
- private Bitmap drawDecoration(DividerItemDecoration decoration, final boolean allowDividerAbove,
- final boolean allowDividerBelow) {
- // Set up the canvas to be drawn
- Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_4444);
- Canvas canvas = new Canvas(bitmap);
-
- final Context context = InstrumentationRegistry.getContext();
- // Set up recycler view with vertical linear layout manager
- RecyclerView testRecyclerView = new RecyclerView(context);
- testRecyclerView.setLayoutManager(new LinearLayoutManager(context));
-
- // Set up adapter with 3 items, each 5px tall
- testRecyclerView.setAdapter(new RecyclerView.Adapter() {
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
- final View itemView = new View(context);
- itemView.setMinimumWidth(20);
- itemView.setMinimumHeight(5);
- return ViewHolder.createInstance(itemView, allowDividerAbove, allowDividerBelow);
- }
-
- @Override
- public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
- }
-
- @Override
- public int getItemCount() {
- return 3;
- }
- });
-
- testRecyclerView.layout(0, 0, 20, 20);
- decoration.onDraw(canvas, testRecyclerView, null);
- return bitmap;
+ private ViewHolder(View itemView, boolean allowDividerAbove, boolean allowDividerBelow) {
+ super(itemView);
+ mAllowDividerAbove = allowDividerAbove;
+ mAllowDividerBelow = allowDividerBelow;
}
- private void assertBitmapEquals(Bitmap expected, Bitmap actual) {
- assertEquals("Width should be the same", expected.getWidth(), actual.getWidth());
- assertEquals("Height should be the same", expected.getHeight(), actual.getHeight());
- for (int x = 0; x < expected.getWidth(); x++) {
- for (int y = 0; y < expected.getHeight(); y++) {
- assertEquals("Pixel at (" + x + ", " + y + ") should be the same",
- expected.getPixel(x, y), actual.getPixel(x, y));
- }
- }
+ @Override
+ public boolean isDividerAllowedAbove() {
+ return mAllowDividerAbove;
}
- private static class ViewHolder extends RecyclerView.ViewHolder
- implements DividerItemDecoration.DividedViewHolder {
-
- private boolean mAllowDividerAbove;
- private boolean mAllowDividerBelow;
-
- public static ViewHolder createInstance(View itemView, boolean allowDividerAbove,
- boolean allowDividerBelow) {
- return new ViewHolder(itemView, allowDividerAbove, allowDividerBelow);
- }
-
- private ViewHolder(View itemView, boolean allowDividerAbove, boolean allowDividerBelow) {
- super(itemView);
- mAllowDividerAbove = allowDividerAbove;
- mAllowDividerBelow = allowDividerBelow;
- }
-
- @Override
- public boolean isDividerAllowedAbove() {
- return mAllowDividerAbove;
- }
-
- @Override
- public boolean isDividerAllowedBelow() {
- return mAllowDividerBelow;
- }
+ @Override
+ public boolean isDividerAllowedBelow() {
+ return mAllowDividerBelow;
}
+ }
}
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifPreferenceLayoutTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifPreferenceLayoutTest.java
index 4d2876d..d55ba23 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifPreferenceLayoutTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifPreferenceLayoutTest.java
@@ -24,18 +24,15 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.recyclerview.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.RecyclerView;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.GlifPreferenceLayout;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,62 +41,63 @@ import org.junit.runner.RunWith;
@SmallTest
public class GlifPreferenceLayoutTest {
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeGlif_Light);
- }
-
- @Test
- public void testDefaultTemplate() {
- GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
- assertPreferenceTemplateInflated(layout);
- }
-
- @Test
- public void testGetRecyclerView() {
- GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
- assertPreferenceTemplateInflated(layout);
- assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(InstrumentationRegistry.getContext(), R.style.SuwThemeGlif_Light);
+ }
+
+ @Test
+ public void testDefaultTemplate() {
+ GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
+ assertPreferenceTemplateInflated(layout);
+ }
+
+ @Test
+ public void testGetRecyclerView() {
+ GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
+ assertPreferenceTemplateInflated(layout);
+ assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
+ }
+
+ @Test
+ public void testOnCreateRecyclerView() {
+ GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
+ assertPreferenceTemplateInflated(layout);
+ final RecyclerView recyclerView =
+ layout.onCreateRecyclerView(
+ LayoutInflater.from(mContext), layout, null /* savedInstanceState */);
+ assertNotNull("RecyclerView created should not be null", recyclerView);
+ }
+
+ @Test
+ public void testDividerInset() {
+ GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertPreferenceTemplateInflated(layout);
- @Test
- public void testOnCreateRecyclerView() {
- GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
- assertPreferenceTemplateInflated(layout);
- final RecyclerView recyclerView = layout.onCreateRecyclerView(LayoutInflater.from(mContext),
- layout, null /* savedInstanceState */);
- assertNotNull("RecyclerView created should not be null", recyclerView);
- }
-
- @Test
- public void testDividerInset() {
- GlifPreferenceLayout layout = new GlifPreferenceLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertPreferenceTemplateInflated(layout);
+ layout.addView(
+ layout.onCreateRecyclerView(
+ LayoutInflater.from(mContext), layout, null /* savedInstanceState */));
- layout.addView(layout.onCreateRecyclerView(LayoutInflater.from(mContext), layout,
- null /* savedInstanceState */));
+ layout.setDividerInset(10);
+ assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
- layout.setDividerInset(10);
- assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
+ private void assertPreferenceTemplateInflated(GlifPreferenceLayout layout) {
+ View contentContainer = layout.findViewById(R.id.suw_layout_content);
+ assertTrue(
+ "@id/suw_layout_content should be a ViewGroup", contentContainer instanceof ViewGroup);
- private void assertPreferenceTemplateInflated(GlifPreferenceLayout layout) {
- View contentContainer = layout.findViewById(R.id.suw_layout_content);
- assertTrue("@id/suw_layout_content should be a ViewGroup",
- contentContainer instanceof ViewGroup);
-
- assertNotNull("Header text view should not be null",
- layout.findManagedViewById(R.id.suw_layout_title));
- assertNotNull("Icon view should not be null",
- layout.findManagedViewById(R.id.suw_layout_icon));
- }
+ assertNotNull(
+ "Header text view should not be null", layout.findManagedViewById(R.id.suw_layout_title));
+ assertNotNull("Icon view should not be null", layout.findManagedViewById(R.id.suw_layout_icon));
+ }
}
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifRecyclerLayoutTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifRecyclerLayoutTest.java
index a68faf0..5db7db5 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifRecyclerLayoutTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/GlifRecyclerLayoutTest.java
@@ -26,20 +26,17 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView.Adapter;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.recyclerview.widget.RecyclerView.Adapter;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.GlifRecyclerLayout;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -48,130 +45,127 @@ import org.junit.runner.RunWith;
@SmallTest
public class GlifRecyclerLayoutTest {
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeGlif_Light);
- }
-
- @Test
- public void testDefaultTemplate() {
- GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
- }
-
- @Test
- public void testInflateFromXml() {
- LayoutInflater inflater = LayoutInflater.from(mContext);
- GlifRecyclerLayout layout = (GlifRecyclerLayout)
- inflater.inflate(R.layout.test_glif_recycler_layout, null);
- assertRecyclerTemplateInflated(layout);
- }
-
- @Test
- public void testGetRecyclerView() {
- GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
- assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
- }
-
- @Test
- public void testAdapter() {
- GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
-
- final RecyclerView.Adapter adapter = createTestAdapter(1);
- layout.setAdapter(adapter);
-
- final RecyclerView.Adapter gotAdapter = layout.getAdapter();
- // Note: The wrapped adapter should be returned, not the HeaderAdapter.
- assertSame("Adapter got from GlifRecyclerLayout should be same as set",
- adapter, gotAdapter);
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(InstrumentationRegistry.getContext(), R.style.SuwThemeGlif_Light);
+ }
+
+ @Test
+ public void testDefaultTemplate() {
+ GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+ }
+
+ @Test
+ public void testInflateFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ GlifRecyclerLayout layout =
+ (GlifRecyclerLayout) inflater.inflate(R.layout.test_glif_recycler_layout, null);
+ assertRecyclerTemplateInflated(layout);
+ }
+
+ @Test
+ public void testGetRecyclerView() {
+ GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+ assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
+ }
+
+ @Test
+ public void testAdapter() {
+ GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+
+ final RecyclerView.Adapter adapter = createTestAdapter(1);
+ layout.setAdapter(adapter);
+
+ final RecyclerView.Adapter gotAdapter = layout.getAdapter();
+ // Note: The wrapped adapter should be returned, not the HeaderAdapter.
+ assertSame("Adapter got from GlifRecyclerLayout should be same as set", adapter, gotAdapter);
+ }
+
+ @Test
+ public void testLayout() {
+ GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+
+ layout.setAdapter(createTestAdapter(3));
+
+ layout.measure(
+ MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY));
+ layout.layout(0, 0, 500, 500);
+ // Test that the layout code doesn't crash.
+ }
+
+ @Test
+ public void testDividerInsetLegacy() {
+ GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertRecyclerTemplateInflated(layout);
- @Test
- public void testLayout() {
- GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
+ layout.setDividerInset(10);
+ assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
- layout.setAdapter(createTestAdapter(3));
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
- layout.measure(
- MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY),
- MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY));
- layout.layout(0, 0, 500, 500);
- // Test that the layout code doesn't crash.
+ @Test
+ public void testDividerInsets() {
+ GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
-
- @Test
- public void testDividerInsetLegacy() {
- GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertRecyclerTemplateInflated(layout);
-
- layout.setDividerInset(10);
- assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
-
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
-
- @Test
- public void testDividerInsets() {
- GlifRecyclerLayout layout = new GlifRecyclerLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertRecyclerTemplateInflated(layout);
-
- layout.setDividerInsets(10, 15);
- assertEquals("Divider inset start should be 10", 10, layout.getDividerInsetStart());
- assertEquals("Divider inset end should be 15", 15, layout.getDividerInsetEnd());
-
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
-
- @Test
- public void testTemplateWithNoRecyclerView() {
- try {
- new GlifRecyclerLayout(mContext, R.layout.suw_glif_template);
- fail("Creating GlifRecyclerLayout with no recycler view should throw exception");
- } catch (Exception e) {
- // pass
- }
- }
-
- private void assertRecyclerTemplateInflated(GlifRecyclerLayout layout) {
- View recyclerView = layout.findViewById(R.id.suw_recycler_view);
- assertTrue("@id/suw_recycler_view should be a RecyclerView",
- recyclerView instanceof RecyclerView);
-
- assertNotNull("Header text view should not be null",
- layout.findManagedViewById(R.id.suw_layout_title));
- assertNotNull("Icon view should not be null",
- layout.findManagedViewById(R.id.suw_layout_icon));
- }
-
- private Adapter createTestAdapter(final int itemCount) {
- return new RecyclerView.Adapter() {
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
- return new RecyclerView.ViewHolder(new View(parent.getContext())) {};
- }
-
- @Override
- public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
- }
-
- @Override
- public int getItemCount() {
- return itemCount;
- }
- };
+ assertRecyclerTemplateInflated(layout);
+
+ layout.setDividerInsets(10, 15);
+ assertEquals("Divider inset start should be 10", 10, layout.getDividerInsetStart());
+ assertEquals("Divider inset end should be 15", 15, layout.getDividerInsetEnd());
+
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
+
+ @Test
+ public void testTemplateWithNoRecyclerView() {
+ try {
+ new GlifRecyclerLayout(mContext, R.layout.suw_glif_template);
+ fail("Creating GlifRecyclerLayout with no recycler view should throw exception");
+ } catch (Exception e) {
+ // pass
}
+ }
+
+ private void assertRecyclerTemplateInflated(GlifRecyclerLayout layout) {
+ View recyclerView = layout.findViewById(R.id.suw_recycler_view);
+ assertTrue(
+ "@id/suw_recycler_view should be a RecyclerView", recyclerView instanceof RecyclerView);
+
+ assertNotNull(
+ "Header text view should not be null", layout.findManagedViewById(R.id.suw_layout_title));
+ assertNotNull("Icon view should not be null", layout.findManagedViewById(R.id.suw_layout_icon));
+ }
+
+ private Adapter createTestAdapter(final int itemCount) {
+ return new RecyclerView.Adapter() {
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
+ return new RecyclerView.ViewHolder(new View(parent.getContext())) {};
+ }
+
+ @Override
+ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {}
+
+ @Override
+ public int getItemCount() {
+ return itemCount;
+ }
+ };
+ }
}
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/HeaderRecyclerViewTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/HeaderRecyclerViewTest.java
index 9af68a7..3d0f9da 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/HeaderRecyclerViewTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/HeaderRecyclerViewTest.java
@@ -19,160 +19,143 @@ package com.android.setupwizardlib.test;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
+import androidx.recyclerview.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.RecyclerView;
-
import com.android.setupwizardlib.view.HeaderRecyclerView.HeaderAdapter;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-/**
- * Test for {@link com.android.setupwizardlib.view.HeaderRecyclerView}
- */
+/** Test for {@link com.android.setupwizardlib.view.HeaderRecyclerView} */
@RunWith(AndroidJUnit4.class)
@SmallTest
public class HeaderRecyclerViewTest {
- private TestAdapter mWrappedAdapter;
- private HeaderAdapter mHeaderAdapter;
-
- @Mock
- private RecyclerView.AdapterDataObserver mObserver;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mWrappedAdapter = new TestAdapter();
-
- mHeaderAdapter = new HeaderAdapter(mWrappedAdapter);
- mHeaderAdapter.registerAdapterDataObserver(mObserver);
- }
-
- /**
- * Test that notifyDataSetChanged gets propagated by HeaderRecyclerView's adapter.
- */
- @Test
- public void testNotifyChanged() {
- mWrappedAdapter.notifyDataSetChanged();
-
- verify(mObserver).onChanged();
+ private TestAdapter mWrappedAdapter;
+ private HeaderAdapter mHeaderAdapter;
+
+ @Mock private RecyclerView.AdapterDataObserver mObserver;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mWrappedAdapter = new TestAdapter();
+
+ mHeaderAdapter = new HeaderAdapter(mWrappedAdapter);
+ mHeaderAdapter.registerAdapterDataObserver(mObserver);
+ }
+
+ /** Test that notifyDataSetChanged gets propagated by HeaderRecyclerView's adapter. */
+ @Test
+ public void testNotifyChanged() {
+ mWrappedAdapter.notifyDataSetChanged();
+
+ verify(mObserver).onChanged();
+ }
+
+ /** Test that notifyItemChanged gets propagated by HeaderRecyclerView's adapter. */
+ @Test
+ public void testNotifyItemChangedNoHeader() {
+ mWrappedAdapter.notifyItemChanged(12);
+
+ verify(mObserver).onItemRangeChanged(eq(12), eq(1), eq(null));
+ }
+
+ /**
+ * Test that notifyItemChanged gets propagated by HeaderRecyclerView's adapter and adds 1 to the
+ * position for the extra header items.
+ */
+ @Test
+ public void testNotifyItemChangedWithHeader() {
+ mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
+ mWrappedAdapter.notifyItemChanged(12);
+
+ verify(mObserver).onItemRangeChanged(eq(13), eq(1), eq(null));
+ }
+
+ /** Test that notifyItemInserted gets propagated by HeaderRecyclerView's adapter. */
+ @Test
+ public void testNotifyItemInsertedNoHeader() {
+ mWrappedAdapter.notifyItemInserted(12);
+
+ verify(mObserver).onItemRangeInserted(eq(12), eq(1));
+ }
+
+ /**
+ * Test that notifyItemInserted gets propagated by HeaderRecyclerView's adapter and adds 1 to the
+ * position for the extra header item.
+ */
+ @Test
+ public void testNotifyItemInsertedWithHeader() {
+ mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
+ mWrappedAdapter.notifyItemInserted(12);
+
+ verify(mObserver).onItemRangeInserted(eq(13), eq(1));
+ }
+
+ /** Test that notifyItemRemoved gets propagated by HeaderRecyclerView's adapter. */
+ @Test
+ public void testNotifyItemRemovedNoHeader() {
+ mWrappedAdapter.notifyItemRemoved(12);
+
+ verify(mObserver).onItemRangeRemoved(eq(12), eq(1));
+ }
+
+ /**
+ * Test that notifyItemRemoved gets propagated by HeaderRecyclerView's adapter and adds 1 to the
+ * position for the extra header item.
+ */
+ @Test
+ public void testNotifyItemRemovedWithHeader() {
+ mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
+ mWrappedAdapter.notifyItemRemoved(12);
+
+ verify(mObserver).onItemRangeRemoved(eq(13), eq(1));
+ }
+
+ /** Test that notifyItemMoved gets propagated by HeaderRecyclerView's adapter. */
+ @Test
+ public void testNotifyItemMovedNoHeader() {
+ mWrappedAdapter.notifyItemMoved(12, 18);
+
+ verify(mObserver).onItemRangeMoved(eq(12), eq(18), eq(1));
+ }
+
+ /**
+ * Test that notifyItemMoved gets propagated by HeaderRecyclerView's adapter and adds 1 to the
+ * position for the extra header item.
+ */
+ @Test
+ public void testNotifyItemMovedWithHeader() {
+ mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
+ mWrappedAdapter.notifyItemMoved(12, 18);
+
+ verify(mObserver).onItemRangeMoved(eq(13), eq(19), eq(1));
+ }
+
+ /**
+ * Test adapter to be wrapped inside {@link HeaderAdapter} to to send item change notifications.
+ */
+ public static class TestAdapter extends RecyclerView.Adapter {
+
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
+ return null;
}
- /**
- * Test that notifyItemChanged gets propagated by HeaderRecyclerView's adapter.
- */
- @Test
- public void testNotifyItemChangedNoHeader() {
- mWrappedAdapter.notifyItemChanged(12);
-
- verify(mObserver).onItemRangeChanged(eq(12), eq(1), eq(null));
- }
-
- /**
- * Test that notifyItemChanged gets propagated by HeaderRecyclerView's adapter and adds 1 to the
- * position for the extra header items.
- */
- @Test
- public void testNotifyItemChangedWithHeader() {
- mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
- mWrappedAdapter.notifyItemChanged(12);
-
- verify(mObserver).onItemRangeChanged(eq(13), eq(1), eq(null));
- }
-
- /**
- * Test that notifyItemInserted gets propagated by HeaderRecyclerView's adapter.
- */
- @Test
- public void testNotifyItemInsertedNoHeader() {
- mWrappedAdapter.notifyItemInserted(12);
-
- verify(mObserver).onItemRangeInserted(eq(12), eq(1));
- }
-
- /**
- * Test that notifyItemInserted gets propagated by HeaderRecyclerView's adapter and adds 1 to
- * the position for the extra header item.
- */
- @Test
- public void testNotifyItemInsertedWithHeader() {
- mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
- mWrappedAdapter.notifyItemInserted(12);
-
- verify(mObserver).onItemRangeInserted(eq(13), eq(1));
- }
-
- /**
- * Test that notifyItemRemoved gets propagated by HeaderRecyclerView's adapter.
- */
- @Test
- public void testNotifyItemRemovedNoHeader() {
- mWrappedAdapter.notifyItemRemoved(12);
-
- verify(mObserver).onItemRangeRemoved(eq(12), eq(1));
- }
-
- /**
- * Test that notifyItemRemoved gets propagated by HeaderRecyclerView's adapter and adds 1 to
- * the position for the extra header item.
- */
- @Test
- public void testNotifyItemRemovedWithHeader() {
- mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
- mWrappedAdapter.notifyItemRemoved(12);
-
- verify(mObserver).onItemRangeRemoved(eq(13), eq(1));
- }
-
- /**
- * Test that notifyItemMoved gets propagated by HeaderRecyclerView's adapter.
- */
- @Test
- public void testNotifyItemMovedNoHeader() {
- mWrappedAdapter.notifyItemMoved(12, 18);
-
- verify(mObserver).onItemRangeMoved(eq(12), eq(18), eq(1));
- }
-
- /**
- * Test that notifyItemMoved gets propagated by HeaderRecyclerView's adapter and adds 1 to
- * the position for the extra header item.
- */
- @Test
- public void testNotifyItemMovedWithHeader() {
- mHeaderAdapter.setHeader(new View(InstrumentationRegistry.getTargetContext()));
- mWrappedAdapter.notifyItemMoved(12, 18);
-
- verify(mObserver).onItemRangeMoved(eq(13), eq(19), eq(1));
- }
-
- /**
- * Test adapter to be wrapped inside {@link HeaderAdapter} to to send item change notifications.
- */
- public static class TestAdapter extends RecyclerView.Adapter {
-
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
- return null;
- }
-
- @Override
- public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
- }
+ @Override
+ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {}
- @Override
- public int getItemCount() {
- return 0;
- }
+ @Override
+ public int getItemCount() {
+ return 0;
}
+ }
}
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardPreferenceLayoutTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardPreferenceLayoutTest.java
index 316793f..39929dc 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardPreferenceLayoutTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardPreferenceLayoutTest.java
@@ -24,18 +24,15 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.recyclerview.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.RecyclerView;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.SetupWizardPreferenceLayout;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,62 +41,65 @@ import org.junit.runner.RunWith;
@SmallTest
public class SetupWizardPreferenceLayoutTest {
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeMaterial_Light);
- }
-
- @Test
- public void testDefaultTemplate() {
- SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
- assertPreferenceTemplateInflated(layout);
- }
-
- @Test
- public void testGetRecyclerView() {
- SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
- assertPreferenceTemplateInflated(layout);
- assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(
+ InstrumentationRegistry.getContext(), R.style.SuwThemeMaterial_Light);
+ }
+
+ @Test
+ public void testDefaultTemplate() {
+ SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
+ assertPreferenceTemplateInflated(layout);
+ }
+
+ @Test
+ public void testGetRecyclerView() {
+ SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
+ assertPreferenceTemplateInflated(layout);
+ assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
+ }
+
+ @Test
+ public void testOnCreateRecyclerView() {
+ SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
+ assertPreferenceTemplateInflated(layout);
+ final RecyclerView recyclerView =
+ layout.onCreateRecyclerView(
+ LayoutInflater.from(mContext), layout, null /* savedInstanceState */);
+ assertNotNull("RecyclerView created should not be null", recyclerView);
+ }
+
+ @Test
+ public void testDividerInset() {
+ SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertPreferenceTemplateInflated(layout);
- @Test
- public void testOnCreateRecyclerView() {
- SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
- assertPreferenceTemplateInflated(layout);
- final RecyclerView recyclerView = layout.onCreateRecyclerView(LayoutInflater.from(mContext),
- layout, null /* savedInstanceState */);
- assertNotNull("RecyclerView created should not be null", recyclerView);
- }
-
- @Test
- public void testDividerInset() {
- SetupWizardPreferenceLayout layout = new SetupWizardPreferenceLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertPreferenceTemplateInflated(layout);
+ layout.addView(
+ layout.onCreateRecyclerView(
+ LayoutInflater.from(mContext), layout, null /* savedInstanceState */));
- layout.addView(layout.onCreateRecyclerView(LayoutInflater.from(mContext), layout,
- null /* savedInstanceState */));
+ layout.setDividerInset(10);
+ assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
- layout.setDividerInset(10);
- assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
+ private void assertPreferenceTemplateInflated(SetupWizardPreferenceLayout layout) {
+ View contentContainer = layout.findViewById(R.id.suw_layout_content);
+ assertTrue(
+ "@id/suw_layout_content should be a ViewGroup", contentContainer instanceof ViewGroup);
- private void assertPreferenceTemplateInflated(SetupWizardPreferenceLayout layout) {
- View contentContainer = layout.findViewById(R.id.suw_layout_content);
- assertTrue("@id/suw_layout_content should be a ViewGroup",
- contentContainer instanceof ViewGroup);
-
- assertNotNull("Header text view should not be null",
- layout.findManagedViewById(R.id.suw_layout_title));
- assertNotNull("Decoration view should not be null",
- layout.findManagedViewById(R.id.suw_layout_decor));
- }
+ assertNotNull(
+ "Header text view should not be null", layout.findManagedViewById(R.id.suw_layout_title));
+ assertNotNull(
+ "Decoration view should not be null", layout.findManagedViewById(R.id.suw_layout_decor));
+ }
}
diff --git a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardRecyclerLayoutTest.java b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardRecyclerLayoutTest.java
index bbe773b..46a665d 100644
--- a/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardRecyclerLayoutTest.java
+++ b/library/recyclerview/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardRecyclerLayoutTest.java
@@ -26,21 +26,18 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView.Adapter;
+import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.recyclerview.widget.RecyclerView.Adapter;
-import androidx.recyclerview.widget.RecyclerView.ViewHolder;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.SetupWizardRecyclerLayout;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,133 +46,129 @@ import org.junit.runner.RunWith;
@SmallTest
public class SetupWizardRecyclerLayoutTest {
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeMaterial_Light);
- }
-
- @Test
- public void testDefaultTemplate() {
- SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
- }
-
- @Test
- public void testInflateFromXml() {
- LayoutInflater inflater = LayoutInflater.from(mContext);
- SetupWizardRecyclerLayout layout = (SetupWizardRecyclerLayout)
- inflater.inflate(R.layout.test_recycler_layout, null);
- assertRecyclerTemplateInflated(layout);
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(
+ InstrumentationRegistry.getContext(), R.style.SuwThemeMaterial_Light);
+ }
+
+ @Test
+ public void testDefaultTemplate() {
+ SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+ }
+
+ @Test
+ public void testInflateFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ SetupWizardRecyclerLayout layout =
+ (SetupWizardRecyclerLayout) inflater.inflate(R.layout.test_recycler_layout, null);
+ assertRecyclerTemplateInflated(layout);
+ }
+
+ @Test
+ public void testGetRecyclerView() {
+ SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+ assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
+ }
+
+ @Test
+ public void testAdapter() {
+ SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+
+ final Adapter adapter = createTestAdapter(1);
+ layout.setAdapter(adapter);
+
+ final Adapter gotAdapter = layout.getAdapter();
+ // Note: The wrapped adapter should be returned, not the HeaderAdapter.
+ assertSame("Adapter got from SetupWizardLayout should be same as set", adapter, gotAdapter);
+ }
+
+ @Test
+ public void testLayout() {
+ SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
+ assertRecyclerTemplateInflated(layout);
+
+ layout.setAdapter(createTestAdapter(3));
+
+ layout.measure(
+ MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY));
+ layout.layout(0, 0, 500, 500);
+ // Test that the layout code doesn't crash.
+ }
+
+ @Test
+ public void testDividerInsetLegacy() {
+ SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertRecyclerTemplateInflated(layout);
- @Test
- public void testGetRecyclerView() {
- SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
- assertNotNull("getRecyclerView should not be null", layout.getRecyclerView());
- }
-
- @Test
- public void testAdapter() {
- SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
-
- final Adapter adapter = createTestAdapter(1);
- layout.setAdapter(adapter);
-
- final Adapter gotAdapter = layout.getAdapter();
- // Note: The wrapped adapter should be returned, not the HeaderAdapter.
- assertSame("Adapter got from SetupWizardLayout should be same as set",
- adapter, gotAdapter);
- }
-
- @Test
- public void testLayout() {
- SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
- assertRecyclerTemplateInflated(layout);
-
- layout.setAdapter(createTestAdapter(3));
-
- layout.measure(
- MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY),
- MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY));
- layout.layout(0, 0, 500, 500);
- // Test that the layout code doesn't crash.
- }
-
- @Test
- public void testDividerInsetLegacy() {
- SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertRecyclerTemplateInflated(layout);
+ layout.setDividerInset(10);
+ assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
- layout.setDividerInset(10);
- assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ @Test
+ public void testDividerInsets() {
+ SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
-
- @Test
- public void testDividerInsets() {
- SetupWizardRecyclerLayout layout = new SetupWizardRecyclerLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertRecyclerTemplateInflated(layout);
-
- layout.setDividerInsets(10, 15);
- assertEquals("Divider inset start should be 10", 10, layout.getDividerInsetStart());
- assertEquals("Divider inset end should be 15", 15, layout.getDividerInsetEnd());
-
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
-
- @Test
- public void testTemplateWithNoRecyclerView() {
- try {
- new SetupWizardRecyclerLayout(
- mContext,
- R.layout.suw_glif_template,
- R.id.suw_recycler_view);
- fail("Creating SetupWizardRecyclerLayout with no recycler view should throw exception");
- } catch (Exception e) {
- // pass
- }
- }
-
- private void assertRecyclerTemplateInflated(SetupWizardRecyclerLayout layout) {
- View recyclerView = layout.findViewById(R.id.suw_recycler_view);
- assertTrue("@id/suw_recycler_view should be a RecyclerView",
- recyclerView instanceof RecyclerView);
-
- assertNotNull("Header text view should not be null",
- layout.findManagedViewById(R.id.suw_layout_title));
- assertNotNull("Decoration view should not be null",
- layout.findManagedViewById(R.id.suw_layout_decor));
- }
-
- private Adapter createTestAdapter(final int itemCount) {
- return new Adapter() {
- @Override
- public ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
- return new ViewHolder(new View(parent.getContext())) {};
- }
-
- @Override
- public void onBindViewHolder(ViewHolder viewHolder, int position) {
- }
-
- @Override
- public int getItemCount() {
- return itemCount;
- }
- };
+ assertRecyclerTemplateInflated(layout);
+
+ layout.setDividerInsets(10, 15);
+ assertEquals("Divider inset start should be 10", 10, layout.getDividerInsetStart());
+ assertEquals("Divider inset end should be 15", 15, layout.getDividerInsetEnd());
+
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
+
+ @Test
+ public void testTemplateWithNoRecyclerView() {
+ try {
+ new SetupWizardRecyclerLayout(mContext, R.layout.suw_glif_template, R.id.suw_recycler_view);
+ fail("Creating SetupWizardRecyclerLayout with no recycler view should throw exception");
+ } catch (Exception e) {
+ // pass
}
+ }
+
+ private void assertRecyclerTemplateInflated(SetupWizardRecyclerLayout layout) {
+ View recyclerView = layout.findViewById(R.id.suw_recycler_view);
+ assertTrue(
+ "@id/suw_recycler_view should be a RecyclerView", recyclerView instanceof RecyclerView);
+
+ assertNotNull(
+ "Header text view should not be null", layout.findManagedViewById(R.id.suw_layout_title));
+ assertNotNull(
+ "Decoration view should not be null", layout.findManagedViewById(R.id.suw_layout_decor));
+ }
+
+ private Adapter createTestAdapter(final int itemCount) {
+ return new Adapter() {
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
+ return new ViewHolder(new View(parent.getContext())) {};
+ }
+
+ @Override
+ public void onBindViewHolder(ViewHolder viewHolder, int position) {}
+
+ @Override
+ public int getItemCount() {
+ return itemCount;
+ }
+ };
+ }
}