ViewFinder { public CompoundButton onCheck(final int id, final OnCheckedChangeListener listener) { CompoundButton checkable = find(id); checkable.setOnCheckedChangeListener(listener); return checkable; } ViewFinder(final View view);  ViewFinder(final Window window);  ViewFinder(final Activity activity); @SuppressWarnings("unchecked") V find(final int id); ImageView imageView(final int id); CompoundButton compoundButton(final int id); TextView textView(final int id); TextView setText(final int id, final CharSequence content); TextView setText(final int id, final int content); View onClick(final int id, final OnClickListener listener); View onClick(final int id, final Runnable runnable); void onClick(final OnClickListener listener, final int... ids); void onClick(final Runnable runnable, final int... ids); ImageView setDrawable(final int id, final int drawable); CompoundButton onCheck(final int id,
      final OnCheckedChangeListener listener); CompoundButton onCheck(final int id, final Runnable runnable); void onCheck(final OnCheckedChangeListener listener, final int... ids); void onCheck(final Runnable runnable, final int... ids);  }
@Test public void onCheckRunnable() { CheckBox checkbox = new CheckBox(new Activity()); checkbox.setId(android.R.id.button1); ViewFinder finder = new ViewFinder(checkbox); final AtomicBoolean run = new AtomicBoolean(false); finder.onCheck(android.R.id.button1, new Runnable() { public void run() { run.set(true); } }); checkbox.performClick(); assertTrue(run.get()); }
@Test public void onCheckRunnableWithMultipleIds() { Activity activity = new Activity(); FrameLayout root = new FrameLayout(activity); CheckBox checkbox1 = new CheckBox(activity); checkbox1.setId(android.R.id.button1); root.addView(checkbox1); CheckBox checkbox2 = new CheckBox(activity); checkbox2.setId(android.R.id.button2); root.addView(checkbox2); ViewFinder finder = new ViewFinder(root); final AtomicInteger run = new AtomicInteger(0); finder.onCheck(new Runnable() { public void run() { run.incrementAndGet(); } }, android.R.id.button1, android.R.id.button2); checkbox1.performClick(); assertEquals(1, run.get()); checkbox2.performClick(); assertEquals(2, run.get()); }
@Test public void onCheckListener() { CheckBox checkbox = new CheckBox(new Activity()); checkbox.setId(android.R.id.button1); ViewFinder finder = new ViewFinder(checkbox); final AtomicBoolean run = new AtomicBoolean(false); finder.onCheck(android.R.id.button1, new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { run.set(true); } }); checkbox.performClick(); assertTrue(run.get()); }