SchamperViewHolder extends DataViewHolder<Article> { @Override public void populate(final Article article) { title.setText(article.getTitle()); date.setText(DateUtils.relativeDateTimeString(article.getPubDate(), itemView.getContext())); author.setText(article.getAuthor()); category.setText(article.getCategory()); if (article.hasCategoryColour()) { int colour = Color.parseColor(article.getCategoryColour()); if (ColourUtils.isDark(colour)) { schamperCardView.setCardBackgroundColor(Color.parseColor(article.getCategoryColour())); title.setTextColor(Color.WHITE); date.setTextColor(Color.WHITE); author.setTextColor(Color.WHITE); category.setTextColor(Color.WHITE); } else { setDefaultColours(); } } else { setDefaultColours(); } if (NetworkUtils.isMeteredConnection(itemView.getContext())) { Picasso.get().load(article.getImage()).into(image); } else { Picasso.get().load(article.getLargeImage()).into(image); } this.itemView.setOnClickListener(v -> ArticleViewer.viewArticle(v.getContext(), article, helper)); } SchamperViewHolder(View itemView, ActivityHelper helper); @Override void populate(final Article article);  }
@Test public void populate() { View view = inflate(R.layout.item_schamper); SchamperViewHolder viewHolder = new SchamperViewHolder(view, helper); Article article = generate(Article.class, "categoryColour"); viewHolder.populate(article); assertTextIs(article.getTitle(), view.findViewById(R.id.title)); assertNotEmpty(view.findViewById(R.id.date)); assertTextIs(article.getAuthor(), view.findViewById(R.id.author)); assertTrue(view.hasOnClickListeners()); }