LibraryViewHolder extends DataViewHolder<Pair<Library, Boolean>> implements RecycleViewHolder,
        Observer<Result<Optional<OpeningHours>>> { @Override public void populate(Pair<Library, Boolean> data) { visible = data.second; openingHours.setVisibility(visible ? View.VISIBLE : View.GONE); title.setText(data.first.getName()); subtitle.setText(data.first.getCampus()); itemView.setOnClickListener(v -> LibraryDetailActivity.launchActivity(v.getContext(), data.first)); favourite.setVisibility(visible ? View.VISIBLE : View.GONE); adapter.registerListener(data.first, this); } LibraryViewHolder(View itemView, LibraryListAdapter adapter); @Override void populate(Pair<Library, Boolean> data); @Override void onViewRecycled(); @Override void onChanged(@Nullable Result<Optional<OpeningHours>> result);  }
@Test public void populate() { View view = inflate(R.layout.item_library); Library library = generate(Library.class); LibraryListAdapter adapter = mock(LibraryListAdapter.class); LibraryViewHolder viewHolder = new LibraryViewHolder(view, adapter); viewHolder.populate(Pair.create(library, true)); assertTextIs(library.getName(), view.findViewById(R.id.title)); assertTextIs(library.getCampus(), view.findViewById(R.id.subtitle)); view.performClick(); Intent expected = new Intent(view.getContext(), LibraryDetailActivity.class); Intent actual = getShadowApplication().getNextStartedActivity(); assertEquals(expected.getComponent(), actual.getComponent()); assertEquals(library, actual.getParcelableExtra(LibraryDetailActivity.ARG_LIBRARY)); }
@Test public void populateFavourite() { View view = inflate(R.layout.item_library); Library library = generate(Library.class); LibraryListAdapter adapter = mock(LibraryListAdapter.class); LibraryViewHolder viewHolder = new LibraryViewHolder(view, adapter); viewHolder.populate(Pair.create(library, true)); assertEquals(view.findViewById(R.id.library_favourite_image).getVisibility(), View.VISIBLE); viewHolder.populate(Pair.create(library, false)); assertEquals(view.findViewById(R.id.library_favourite_image).getVisibility(), View.GONE); }