AssociationViewHolder extends DataViewHolder<Pair<Association, Boolean>> { @Override public void populate(Pair<Association, Boolean> data) { title.setText(data.first.getName()); checkBox.setChecked(data.second); parent.setOnClickListener(v -> { adapter.setChecked(getAdapterPosition()); checkBox.toggle(); }); checkBox.setOnClickListener(v -> adapter.setChecked(getAdapterPosition())); } AssociationViewHolder(View itemView, SearchableAssociationsAdapter adapter); @Override void populate(Pair<Association, Boolean> data);  }
@Test public void populateChecked() { View view = inflate(R.layout.item_checkbox_string); Association association = generate(Association.class); Pair<Association, Boolean> data = new Pair<>(association, true); AssociationViewHolder viewHolder = new AssociationViewHolder(view, associationsAdapter); viewHolder.populate(data); CheckBox checkBox = view.findViewById(R.id.checkbox); assertTextIs(association.getName(), view.findViewById(R.id.title_checkbox)); assertTrue(checkBox.isChecked()); view.performClick(); assertFalse(checkBox.isChecked()); verify(associationsAdapter, times(1)).setChecked(RecyclerView.NO_POSITION); }