@Test
  public void testContextMenuRename() {
    accountDb.add(HOTP_ACCOUNT_NAME, "7777777777777777", OtpType.HOTP, null, null, "Yahoo");

    activityTestRule.launchActivity(null);

    ListView userList = activityTestRule.getActivity().findViewById(R.id.user_list);
    openContextualActionBarOrMenuAndInvokeItem(userList, 0, R.string.rename);
    // Type new name and select save on dialog.
    onView(withId(R.id.rename_edittext))
        .check(matches(withText(HOTP_ACCOUNT_NAME)))
        .perform(ViewActions.clearText())
        .perform(typeText("newname@gmail.com"));
    onView(withText(R.string.submit)).perform(click());
    // check main screen gets focus back;
    onView(is(userList)).check(matches(hasFocus()));
    // check update to database.
    assertThat(accountDb.getAccounts())
        .containsExactly(new AccountIndex("newname@gmail.com", "Yahoo"))
        .inOrder();
  }
Unit tests for {@link AuthenticatorActivity} (part/shard 1).
javatests/com/google/android/apps/authenticator/AuthenticatorActivityTest.java