NewsItemViewHolder extends CardViewHolder { @Override public void populate(final Card card) { super.populate(card); UgentNewsArticle newsItem = card.<NewsItemCard>checkCard(Card.Type.NEWS_ITEM).getNewsItem(); title.setText(newsItem.getTitle()); String author = newsItem.getCreators().isEmpty() ? "" : newsItem.getCreators().iterator().next(); CharSequence dateString; if (newsItem.getCreated().toLocalDate().isEqual(newsItem.getModified().toLocalDate())) { dateString = DateUtils.relativeDateTimeString(newsItem.getCreated(), itemView.getContext()); } else { dateString = itemView.getContext().getString(R.string.article_date_changed, DateUtils.relativeDateTimeString(newsItem.getCreated(), itemView.getContext(), true), DateUtils.relativeDateTimeString(newsItem.getModified(), itemView.getContext(), true) ); } String infoText = itemView.getContext().getString(R.string.deprecated_dot_separated, dateString, author); info.setText(infoText); title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); itemView.setOnClickListener(v -> ArticleViewer.viewArticle(v.getContext(), newsItem, adapter.getCompanion().getHelper())); } NewsItemViewHolder(View v, HomeFeedAdapter adapter); @Override void populate(final Card card);  }
@Test public void populate() { View view = inflate(activityContext, R.layout.home_card_news_item); NewsItemViewHolder viewHolder = new NewsItemViewHolder(view, adapter); NewsItemCard card = generate(NewsItemCard.class); UgentNewsArticle item = card.getNewsItem(); viewHolder.populate(card); assertTextIs(item.getTitle(), view.findViewById(R.id.name)); assertNotEmpty(view.findViewById(R.id.info)); }