ClickGuard { public static ClickGuard guard(View view, View... others) { return guard(DEFAULT_WATCH_PERIOD_MILLIS, view, others); } private  ClickGuard(); static ClickGuard newGuard(); static ClickGuard newGuard(long watchPeriodMillis); static GuardedOnClickListener wrap(OnClickListener onClickListener); static GuardedOnClickListener wrap(long watchPeriodMillis, OnClickListener onClickListener); static GuardedOnClickListener wrap(ClickGuard guard, OnClickListener onClickListener); static ClickGuard guard(View view, View... others); static ClickGuard guard(long watchPeriodMillis, View view, View... others); static ClickGuard guard(ClickGuard guard, View view, View... others); static ClickGuard guardAll(Iterable<View> views); static ClickGuard guardAll(long watchPeriodMillis, Iterable<View> views); static ClickGuard guardAll(ClickGuard guard, Iterable<View> views); static ClickGuard get(View view); static OnClickListener retrieveOnClickListener(View view); ClickGuard add(View view); ClickGuard addAll(View view, View... others); ClickGuard addAll(Iterable<View> views); GuardedOnClickListener wrapOnClickListener(OnClickListener onClickListener); abstract void watch(); abstract void rest(); abstract boolean isWatching(); static final long DEFAULT_WATCH_PERIOD_MILLIS; }
@Test(expected = IllegalArgumentException.class) public void shouldThrowWhenGuardNullView() { ClickGuard.guard(null); }
@Test(expected = IllegalStateException.class) public void shouldThrowWhenGuardViewWithoutOnClickListener() { ClickGuard.guard(new View(Robolectric.application)); }
@Test public void guardMultipleViews() { CountClickListener listener = new CountClickListener() { @Override public void onClick(View v) { super.onClick(v); assertEquals(1, getClickedCount()); } }; View view1 = new View(Robolectric.application); view1.setOnClickListener(listener); View view2 = new View(Robolectric.application); view2.setOnClickListener(listener); View view3 = new View(Robolectric.application); view3.setOnClickListener(listener); ClickGuard.guard(view1, view2, view3); clickViews(view1, view2, view3); }