RestoCardViewHolder extends CardViewHolder { @Override public void populate(Card card) { super.populate(card); RestoMenuCard menuCard = card.checkCard(Card.Type.RESTO); RestoMenu menu = menuCard.getRestoMenu(); RestoChoice choice = menuCard.getRestoChoice(); String text = itemView.getResources().getString(R.string.feed_resto_menu_title); toolbar.setTitle(String.format(text, DateUtils.getFriendlyDate(toolbar.getContext(), menu.getDate()), choice.getName())); @MenuTable.DisplayKind int mode = HomeFragment.getFeedRestoKind(itemView.getContext()); table.setMenu(menu, mode); itemView.setOnClickListener(v -> { Intent intent = new Intent(itemView.getContext(), MainActivity.class); intent.putExtra(MainActivity.ARG_TAB, R.id.drawer_resto); intent.putExtra(RestoFragment.ARG_DATE, menu.getDate()); itemView.getContext().startActivity(intent); }); } RestoCardViewHolder(View v, HomeFeedAdapter adapter); @Override void populate(Card card); @Override void onCreateMenu(Menu menu); @Override boolean onMenuItemClick(MenuItem item);  }
@Test public void populate() { View view = inflate(activityContext, R.layout.home_card_resto); RestoCardViewHolder viewHolder = new RestoCardViewHolder(view, adapter); RestoMenuCard card = generate(RestoMenuCard.class); viewHolder.populate(card); MenuTable table = view.findViewById(R.id.menu_table); RestoMenu actualMenu = table.getMenu(); assertEquals(card.getRestoMenu(), actualMenu); view.performClick(); Intent expected = new Intent(view.getContext(), MainActivity.class); Intent actual = getShadowApplication().getNextStartedActivity(); assertEquals(expected.getComponent(), actual.getComponent()); assertEquals(actualMenu.getDate(), actual.getSerializableExtra(RestoFragment.ARG_DATE)); assertEquals(R.id.drawer_resto, actual.getIntExtra(MainActivity.ARG_TAB, -1)); }