private void pressButton(int buttonViewId) {
    View button = getActivity().findViewById(buttonViewId);
    // The button can only be pressed if it's on screen and visible
    assertNotNull(button);
    TestUtilities.assertViewVisibleOnScreen(button);
    assertTrue(button.isEnabled());
    TestUtilities.assertViewVisibleOnScreen(button);

    TestUtilities.clickView(getInstrumentation(), button);
  }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   DependencyInjector.resetForIntegrationTesting(getInstrumentation().getTargetContext());
   TestUtilities.withLaunchPreventingStartActivityListenerInDependencyResolver();
 }
  /** Asserts that pressing the {@code Back} key does not finish the Activity under test. */
  protected void assertBackKeyDoesNotFinishActivity()
      throws InterruptedException, TimeoutException {
    TestUtilities.invokeActivityOnBackPressedOnUiThread(getActivity());

    assertFalse(getActivity().isFinishing());
  }
  private Intent pressButtonAndCaptureActivityStartIntent(int buttonViewId) {
    pressButton(buttonViewId);

    return TestUtilities.verifyWithTimeoutThatStartActivityAttemptedExactlyOnce();
  }