### Question:
TextListItem extends ListItem<TextListItem.ViewHolder> { public void setSwitch(boolean checked, boolean showDivider, CompoundButton.OnCheckedChangeListener listener) { mSupplementalActionType = SUPPLEMENTAL_ACTION_SWITCH; mSwitchChecked = checked; mShowSwitchDivider = showDivider; mSwitchOnCheckedChangeListener = listener; markDirty(); } TextListItem(Context context); static ViewHolder createViewHolder(View itemView); @Override int getViewType(); @Override void onBind(ViewHolder viewHolder); void setOnClickListener(View.OnClickListener listener); void setPrimaryActionIcon(@DrawableRes int iconResId, boolean useLargeIcon); void setPrimaryActionIcon(Drawable drawable, boolean useLargeIcon); void setPrimaryActionEmptyIcon(); void setPrimaryActionNoIcon(); void setTitle(String title); void setBody(String body); void setBody(String body, boolean asPrimary); void setSupplementalIcon(int iconResId, boolean showDivider); void setSupplementalIcon(Drawable drawable, boolean showDivider); void setSupplementalIcon(int iconResId, boolean showDivider,
            View.OnClickListener listener); void setSupplementalIcon(Drawable drawable, boolean showDivider,
            View.OnClickListener listener); void setAction(String text, boolean showDivider, View.OnClickListener listener); void setActions(String action1Text, boolean showAction1Divider,
            View.OnClickListener action1OnClickListener,
            String action2Text, boolean showAction2Divider,
            View.OnClickListener action2OnClickListener); void setSwitch(boolean checked, boolean showDivider,
            CompoundButton.OnCheckedChangeListener listener); void setSwitchState(boolean isChecked);  }### Answer:
@Test public void testSwitchVisibleAndCheckedState() { TextListItem item0 = new TextListItem(mActivity); item0.setSwitch(true, true, null); TextListItem item1 = new TextListItem(mActivity); item1.setSwitch(false, true, null); List<TextListItem> items = Arrays.asList(item0, item1); setupPagedListView(items); TextListItem.ViewHolder viewHolder = getViewHolderAtPosition(0); assertThat(viewHolder.getSwitch().getVisibility(), is(equalTo(View.VISIBLE))); assertThat(viewHolder.getSwitch().isChecked(), is(equalTo(true))); assertThat(viewHolder.getSwitchDivider().getVisibility(), is(equalTo(View.VISIBLE))); viewHolder = getViewHolderAtPosition(1); assertThat(viewHolder.getSwitch().getVisibility(), is(equalTo(View.VISIBLE))); assertThat(viewHolder.getSwitch().isChecked(), is(equalTo(false))); assertThat(viewHolder.getSwitchDivider().getVisibility(), is(equalTo(View.VISIBLE))); }
@Test public void testCheckingSwitch() { final boolean[] clicked = {false, false}; TextListItem item0 = new TextListItem(mActivity); item0.setSwitch(false, false, (button, isChecked) -> { assertTrue(isChecked); clicked[0] = true; }); TextListItem item1 = new TextListItem(mActivity); item1.setSwitch(true, false, (button, isChecked) -> { assertFalse(isChecked); clicked[1] = true; }); List<TextListItem> items = Arrays.asList(item0, item1); setupPagedListView(items); onView(withId(R.id.recycler_view)).perform( actionOnItemAtPosition(0, clickChildViewWithId(R.id.switch_widget))); assertTrue(clicked[0]); onView(withId(R.id.recycler_view)).perform( actionOnItemAtPosition(1, clickChildViewWithId(R.id.switch_widget))); assertTrue(clicked[1]); }