@Test
  @TargetApi(Build.VERSION_CODES.KITKAT)
  public void testContextualActionBar() {
    accountDb.add(
        "first", "7777777777777777", OtpType.HOTP, null, null, AccountDb.GOOGLE_ISSUER_NAME);
    accountDb.add("second", "6666666666666666", OtpType.TOTP, null, null, null);
    accountDb.add("third", "5555555555555555", OtpType.TOTP, null, null, "Yahoo");

    activityTestRule.launchActivity(null);

    ListView userList = activityTestRule.getActivity().findViewById(R.id.user_list);

    // Test that clicking on a list item starts the CAB and that only one item is checked/selected
    // at a time.
    ActionMode actionMode =
        (ActionMode) openListViewContextualActionBar(activityTestRule.getActivity(), userList, 1);
    assertThat(String.valueOf(actionMode.getTitle())).isEqualTo("second");
    assertThat(userList.getCheckedItemCount()).isEqualTo(1);

    // Check that clicking on another list item marks that item as checked and unchecks all other
    // items.
    assertThat(TestUtilities.clickListViewItem(userList, 0)).isTrue();
    assertThat(String.valueOf(actionMode.getTitle())).isEqualTo("first");
    assertThat(userList.getCheckedItemCount()).isEqualTo(1);
    // Check that clicking on a HOTP item while the CAB is being displayed does not generate a
    // code.
    assertThat(accountDb.getCounter(new AccountIndex("first", AccountDb.GOOGLE_ISSUER_NAME)))
        .isEqualTo(Integer.valueOf(0));
  }
Unit tests for {@link AuthenticatorActivity} (part/shard 1).
javatests/com/google/android/apps/authenticator/AuthenticatorActivityTest.java