### Question:
RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder> implements ItemHierarchy.Observer { @Override public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(parent.getContext()); final View view = inflater.inflate(viewType, parent, false); final ItemViewHolder viewHolder = new ItemViewHolder(view); final Object viewTag = view.getTag(); if (!TAG_NO_BACKGROUND.equals(viewTag)) { final TypedArray typedArray = parent.getContext().obtainStyledAttributes(R.styleable.SuwRecyclerItemAdapter); Drawable selectableItemBackground = typedArray.getDrawable( R.styleable.SuwRecyclerItemAdapter_android_selectableItemBackground); if (selectableItemBackground == null) { selectableItemBackground = typedArray.getDrawable(R.styleable.SuwRecyclerItemAdapter_selectableItemBackground); } Drawable background = view.getBackground(); if (background == null) { background = typedArray.getDrawable(R.styleable.SuwRecyclerItemAdapter_android_colorBackground); } if (selectableItemBackground == null || background == null) { Log.e( TAG, "Cannot resolve required attributes." + " selectableItemBackground=" + selectableItemBackground + " background=" + background); } else { final Drawable[] layers = {background, selectableItemBackground}; view.setBackgroundDrawable(new PatchedLayerDrawable(layers)); } typedArray.recycle(); } view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { final IItem item = viewHolder.getItem(); if (listener != null && item != null && item.isEnabled()) { listener.onItemSelected(item); } } }); return viewHolder; } RecyclerItemAdapter(ItemHierarchy hierarchy); IItem getItem(int position); @Override long getItemId(int position); @Override int getItemCount(); @Override ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType); @Override void onBindViewHolder(ItemViewHolder holder, int position); @Override int getItemViewType(int position); @Override void onChanged(ItemHierarchy hierarchy); @Override void onItemRangeChanged(ItemHierarchy itemHierarchy, int positionStart, int itemCount); @Override void onItemRangeInserted(ItemHierarchy itemHierarchy, int positionStart, int itemCount); @Override void onItemRangeMoved(
      ItemHierarchy itemHierarchy, int fromPosition, int toPosition, int itemCount); @Override void onItemRangeRemoved(ItemHierarchy itemHierarchy, int positionStart, int itemCount); ItemHierarchy findItemById(int id); ItemHierarchy getRootItemHierarchy(); void setOnItemSelectedListener(OnItemSelectedListener listener); static final String TAG_NO_BACKGROUND; }### Answer:
@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); }