InfoViewHolder extends DataViewHolder<InfoItem> { @Override public void populate(final InfoItem infoItem) { Context c = itemView.getContext(); title.setText(infoItem.getTitle()); itemView.setOnClickListener(v -> infoItem.getType().doOnClick(v.getContext(), helper, infoItem)); Drawable more = infoItem.getType().getDrawable(itemView.getContext(), R.attr.colorPrimarySecondary); if (infoItem.getImage() != null) { int resId = c.getResources().getIdentifier(infoItem.getImage(), "drawable", c.getPackageName()); if (resId == 0) { Log.e(TAG, "Icon for info item " + infoItem.getImage() + " was not found!"); title.setCompoundDrawablesWithIntrinsicBounds(null, null, more, null); } else { try { Drawable icon = ViewUtils.getTintedVectorDrawableAttr(c, resId, R.attr.colorPrimarySecondary); title.setCompoundDrawablesWithIntrinsicBounds(icon, null, more, null); } catch (Resources.NotFoundException e) { Log.w(TAG, "On non-weird devices, this should not occur.", e); title.setCompoundDrawablesWithIntrinsicBounds(null, null, more, null); } } } else { title.setCompoundDrawablesWithIntrinsicBounds(null, null, more, null); } } InfoViewHolder(View v, ActivityHelper helper); @Override void populate(final InfoItem infoItem);  }
@Test public void populate() { View view = inflate(R.layout.info_card); InfoItem infoItem = generate(InfoItem.class, "image"); ActivityHelper helper = mock(ActivityHelper.class); InfoViewHolder holder = new InfoViewHolder(view, helper); holder.populate(infoItem); assertTextIs(infoItem.getTitle(), view.findViewById(R.id.info_name)); assertTrue(view.hasOnClickListeners()); }