/** * Calls {@code performClick()} on a {@code View} after ensuring that it and its ancestors are visible and that it * is enabled. * * @param view the view to click on * @return true if {@code View.OnClickListener}s were found and fired, false otherwise. * @throws RuntimeException if the preconditions are not met. */ public static boolean clickOn(View view) { ShadowView shadowView = Shadow.extract(view); return shadowView.checkedPerformClick(); }
@Test(expected = RuntimeException.class) public void checkedClick_shouldThrowIfViewIsDisabled() throws Exception { view.setEnabled(false); shadowOf(view).checkedPerformClick(); }
@Test(expected = RuntimeException.class) public void checkedClick_shouldThrowIfViewIsNotVisible() throws Exception { ViewGroup grandParent = new LinearLayout(context); ViewGroup parent = new LinearLayout(context); grandParent.addView(parent); parent.addView(view); grandParent.setVisibility(View.GONE); shadowOf(view).checkedPerformClick(); }
@Test public void checkedClick_shouldClickOnView() throws Exception { OnClickListener clickListener = mock(OnClickListener.class); shadowOf(view).setMyParent(ReflectionHelpers.createNullProxy(ViewParent.class)); view.setOnClickListener(clickListener); shadowOf(view).checkedPerformClick(); verify(clickListener).onClick(view); }
@Test(expected = RuntimeException.class) @AccessibilityChecks public void checkedClick_withA11yChecksAnnotation_shouldThrow() throws Exception { shadowOf(view).checkedPerformClick(); }
/** * Calls {@code performClick()} on a {@code View} after ensuring that it and its ancestors are visible and that it * is enabled. * * @param view the view to click on * @return true if {@code View.OnClickListener}s were found and fired, false otherwise. * @throws RuntimeException if the preconditions are not met. */ public static boolean clickOn(View view) { return shadowOf(view).checkedPerformClick(); }
/** * Calls {@code performClick()} on a {@code View} after ensuring that it and its ancestors are visible and that it * is enabled. * * @param view the view to click on * @return true if {@code View.OnClickListener}s were found and fired, false otherwise. * @throws RuntimeException if the preconditions are not met. */ public static boolean clickOn(View view) { ShadowView shadowView = Shadow.extract(view); return shadowView.checkedPerformClick(); }
/** * Calls {@code performClick()} on a {@code View} after ensuring that it and its ancestors are visible and that it * is enabled. * * @param view the view to click on * @return true if {@code View.OnClickListener}s were found and fired, false otherwise. * @throws RuntimeException if the preconditions are not met. */ public static boolean clickOn(View view) { return shadowOf(view).checkedPerformClick(); }
/** * Calls {@code performClick()} on a {@code View} after ensuring that it and its ancestors are visible and that it * is enabled. * * @param view the view to click on * @return true if {@code View.OnClickListener}s were found and fired, false otherwise. * @throws RuntimeException if the preconditions are not met. */ public static boolean clickOn(View view) { return shadowOf(view).checkedPerformClick(); }