ArtistViewHolder extends DataViewHolder<ArtistOrTitle> implements View.OnCreateContextMenuListener, MenuItem.OnMenuItemClickListener { @Override public void populate(ArtistOrTitle artistOrTitle) { this.artist = artistOrTitle.getArtist(); title.setText(artist.getName()); date.setText(artist.getDisplayDate(date.getContext())); Picasso.get().load(artist.getImage()).into(image); itemView.setOnClickListener(v -> { Intent intent = ArtistDetailsActivity.start(v.getContext(), artist); v.getContext().startActivity(intent); }); } ArtistViewHolder(View itemView); @Override void populate(ArtistOrTitle artistOrTitle); @Override void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo); @Override boolean onMenuItemClick(MenuItem item);  }
@Test public void populate() { View view = inflate(R.layout.item_sko_lineup_artist); ArtistViewHolder viewHolder = new ArtistViewHolder(view); Artist artist = generate(Artist.class); viewHolder.populate(new ArtistOrTitle(artist)); assertTextIs(artist.getName(), view.findViewById(R.id.title)); assertTextIs(artist.getDisplayDate(view.getContext()), view.findViewById(R.id.date)); ShadowApplication application = getShadowApplication(); view.performClick(); Intent expected = ArtistDetailsActivity.start(view.getContext(), artist); Intent actual = application.getNextStartedActivity(); assertEquals(expected.getComponent(), actual.getComponent()); MenuItem item = mock(MenuItem.class); when(item.getItemId()).thenReturn(ArtistViewHolder.MENU_ID_ADD_TO_CALENDAR); viewHolder.onMenuItemClick(item); expected = artist.addToCalendarIntent(); actual = application.getNextStartedActivity(); assertEquals(expected.getComponent(), actual.getComponent()); }