@Test
  public void onOptionsItemSelected_shouldDoNothing() {
    presenter.onCreate(mockGraph, view);
    presenter.onPrepareOptionsMenu();
    assertThat(presenter.onOptionsItemSelected(0)).isFalse();

    verify(view, never()).showAboutScreen();
  }
  @Test
  public void onOptionsItemSelected_shouldShowAboutScreen() {
    presenter.onCreate(mockGraph, view);
    presenter.onPrepareOptionsMenu();
    assertThat(presenter.onOptionsItemSelected(R.id.action_about)).isTrue();

    verify(view).showAboutScreen();
  }
  @Test
  public void onPrepareOptionsMenu_shouldSetToolbarTitle() {
    presenter.onCreate(mockGraph, view);
    presenter.onPrepareOptionsMenu();

    verify(view).setToolbarTitle(toolbarTitleStringResCaptor.capture());

    assertThat(toolbarTitleStringResCaptor.getValue()).isEqualTo(R.string.movies);
  }
  @Test
  public void onStop_shouldUnregisterEventBus() {
    presenter.onCreate(mockGraph, view);
    presenter.onStop();

    verify(mockGraph.eventBus()).unregister(objectCaptor.capture());

    assertThat(objectCaptor.getValue()).isEqualTo(presenter);
  }
  @Test
  public void onStart_shouldRegisterEventBus() throws IOException {
    presenter.onCreate(mockGraph, view);
    presenter.onStart();

    verify(mockGraph.eventBus()).register(objectCaptor.capture());

    assertThat(objectCaptor.getValue()).isEqualTo(presenter);
  }
  @Test
  public void onMovieSelectEvent_shouldShowMovieSummaryScreen() throws IOException {
    MoviesList.Movie movie = generateMoviesList().movies().get(0);

    presenter.onCreate(mockGraph, view);
    presenter.onEvent(new MoviesListScreenEvents.OnMovieSelect(movie));

    verify(view).showMovieSummaryScreen(movieCaptor.capture());

    assertThat(movieCaptor.getValue()).isEqualTo(movie);
  }
  @Test
  public void onMovieSummaryScreenExitAnimationEvent_shouldDeBlurPrimaryContainer() {
    long expectDuration = 250L;

    presenter.onCreate(mockGraph, view);
    presenter.onEvent(
        new MovieSummaryScreenEvents.OnMovieSummaryScreenExitAnimation(expectDuration));

    verify(view).deBlurContainerPrimary(durationCaptor.capture());

    assertThat(durationCaptor.getValue()).isEqualTo(expectDuration);
  }
  @Test
  public void getPageTitleResources() {
    int[] expectTitleResources = {
      R.string.now_playing, R.string.popular, R.string.top_rated, R.string.upcoming
    };

    int[] resultTitleResources = {
      presenter.getPageTitle(0),
      presenter.getPageTitle(1),
      presenter.getPageTitle(2),
      presenter.getPageTitle(3)
    };

    assertThat(expectTitleResources).isEqualTo(resultTitleResources);
  }
  @Test
  public void getPageType() {
    MoviesListScreenListType expectPageTypes[] = {
      MoviesListScreenListType.NOW_PLAYING,
      MoviesListScreenListType.POPULAR,
      MoviesListScreenListType.TOP_RATED,
      MoviesListScreenListType.UPCOMING
    };

    MoviesListScreenListType resultPageTypes[] = {
      presenter.getPageType(0),
      presenter.getPageType(1),
      presenter.getPageType(2),
      presenter.getPageType(3)
    };

    assertThat(resultPageTypes).isEqualTo(expectPageTypes);
  }
  @Test
  public void onResumeOnPause_shouldReportPageViewTime() throws Exception {
    int expectPage = 0;
    long expectPageDuration = 1000;

    when(view.getCurrentPage()).thenReturn(expectPage);

    presenter.onCreate(mockGraph, view);
    presenter.onResume();
    Thread.sleep(expectPageDuration);
    presenter.onPause();

    verify(mockGraph.analytics())
        .onMoviesListPageChanged(
            pageNameCaptor.capture(), durationCaptor.capture(), timeUnitCaptor.capture());

    assertThat(pageNameCaptor.getValue()).isEqualTo(presenter.getPageType(expectPage).toString());

    assertThat(durationCaptor.getValue()).isIn(Range.open(990L, 1010L));

    assertThat(timeUnitCaptor.getValue()).isEqualTo(TimeUnit.MILLISECONDS);
  }
  @Test
  public void onCreate_shouldDoNothing() {
    presenter.onCreate(mockGraph, view);

    verifyZeroInteractions(view);
  }
 @Test
 public void getPageCount_shouldBeFour() {
   assertThat(presenter.getPageCount()).isEqualTo(4);
 }
 @Test(expected = NullPointerException.class)
 public void onDestroy_shouldRaiseExceptionIfTouchedAfter() {
   presenter.onCreate(mockGraph, view);
   presenter.onDestroy();
   presenter.onEvent(new MoviesListScreenEvents.OnMovieSelect(null));
 }
  @Test
  public void onSaveInstanceState_shouldDoNothing() {
    presenter.onSaveInstanceState(saver);

    verifyZeroInteractions(view);
  }