@Test
  public void shouldCallFinishInOnBackPressed() {
    Activity activity = new Activity();
    activity.onBackPressed();

    ShadowActivity shadowActivity = shadowOf(activity);
    assertTrue(shadowActivity.isFinishing());
  }
  @Test
  public void pauseAndThenResumeGoesThroughTheFullLifeCycle() throws Exception {
    TestActivity activity = new TestActivity();

    ShadowActivity shadow = shadowOf(activity);
    shadow.pauseAndThenResume();

    activity.transcript.assertEventsSoFar("onPause", "onStop", "onRestart", "onStart", "onResume");
  }
  @Test
  public void shouldSupportCurrentFocus() {
    activity = create(DialogLifeCycleActivity.class);
    ShadowActivity shadow = shadowOf(activity);

    assertNull(shadow.getCurrentFocus());
    View view = new View(activity);
    shadow.setCurrentFocus(view);
    assertEquals(view, shadow.getCurrentFocus());
  }
  @Test
  public void shouldSupportStartActivityForResult() throws Exception {
    activity = create(DialogLifeCycleActivity.class);
    ShadowActivity shadowActivity = shadowOf(activity);
    Intent intent = new Intent().setClass(activity, DialogLifeCycleActivity.class);
    assertThat(shadowActivity.getNextStartedActivity()).isNull();

    activity.startActivityForResult(intent, 142);

    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertThat(startedIntent).isNotNull();
    assertThat(startedIntent).isSameAs(intent);
  }
  @Test
  public void shouldSupportPeekStartedActivitiesForResult() throws Exception {
    activity = create(DialogLifeCycleActivity.class);
    ShadowActivity shadowActivity = shadowOf(activity);
    Intent intent = new Intent().setClass(activity, DialogLifeCycleActivity.class);

    activity.startActivityForResult(intent, 142);

    ShadowActivity.IntentForResult intentForResult =
        shadowActivity.peekNextStartedActivityForResult();
    assertThat(intentForResult).isNotNull();
    assertThat(shadowActivity.peekNextStartedActivityForResult()).isSameAs(intentForResult);
    assertThat(intentForResult.intent).isNotNull();
    assertThat(intentForResult.intent).isSameAs(intent);
    assertThat(intentForResult.requestCode).isEqualTo(142);
  }
  @Test
  public void setDefaultKeyMode_shouldSetKeyMode() {
    int[] modes = {
      Activity.DEFAULT_KEYS_DISABLE,
      Activity.DEFAULT_KEYS_SHORTCUT,
      Activity.DEFAULT_KEYS_DIALER,
      Activity.DEFAULT_KEYS_SEARCH_LOCAL,
      Activity.DEFAULT_KEYS_SEARCH_GLOBAL
    };
    Activity activity = new Activity();
    ShadowActivity shadow = shadowOf(activity);

    for (int mode : modes) {
      activity.setDefaultKeyMode(mode);
      assertThat(shadow.getDefaultKeymode()).isEqualTo(mode).as("Unexpected key mode");
    }
  }
  @Test
  public void startAndStopManagingCursorTracksCursors() throws Exception {
    TestActivity activity = new TestActivity();

    ShadowActivity shadow = shadowOf(activity);

    assertThat(shadow.getManagedCursors()).isNotNull();
    assertThat(shadow.getManagedCursors().size()).isEqualTo(0);

    Cursor c = Shadow.newInstanceOf(SQLiteCursor.class);
    activity.startManagingCursor(c);

    assertThat(shadow.getManagedCursors()).isNotNull();
    assertThat(shadow.getManagedCursors().size()).isEqualTo(1);
    assertThat(shadow.getManagedCursors().get(0)).isSameAs(c);

    activity.stopManagingCursor(c);

    assertThat(shadow.getManagedCursors()).isNotNull();
    assertThat(shadow.getManagedCursors().size()).isEqualTo(0);
  }