コード例 #1
0
  @Test
  public void onOptionsItemSelected_shouldDoNothing() {
    presenter.onCreate(mockGraph, view);
    presenter.onPrepareOptionsMenu();
    assertThat(presenter.onOptionsItemSelected(0)).isFalse();

    verify(view, never()).showAboutScreen();
  }
コード例 #2
0
  @Test
  public void onOptionsItemSelected_shouldShowAboutScreen() {
    presenter.onCreate(mockGraph, view);
    presenter.onPrepareOptionsMenu();
    assertThat(presenter.onOptionsItemSelected(R.id.action_about)).isTrue();

    verify(view).showAboutScreen();
  }
コード例 #3
0
  @Test
  public void onPrepareOptionsMenu_shouldSetToolbarTitle() {
    presenter.onCreate(mockGraph, view);
    presenter.onPrepareOptionsMenu();

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

    assertThat(toolbarTitleStringResCaptor.getValue()).isEqualTo(R.string.movies);
  }
コード例 #4
0
  @Test
  public void onStop_shouldUnregisterEventBus() {
    presenter.onCreate(mockGraph, view);
    presenter.onStop();

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

    assertThat(objectCaptor.getValue()).isEqualTo(presenter);
  }
コード例 #5
0
  @Test
  public void onStart_shouldRegisterEventBus() throws IOException {
    presenter.onCreate(mockGraph, view);
    presenter.onStart();

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

    assertThat(objectCaptor.getValue()).isEqualTo(presenter);
  }
コード例 #6
0
  @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);
  }
コード例 #7
0
  @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);
  }
コード例 #8
0
  @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);
  }
コード例 #9
0
  @Test
  public void onCreate_shouldDoNothing() {
    presenter.onCreate(mockGraph, view);

    verifyZeroInteractions(view);
  }
コード例 #10
0
 @Test(expected = NullPointerException.class)
 public void onDestroy_shouldRaiseExceptionIfTouchedAfter() {
   presenter.onCreate(mockGraph, view);
   presenter.onDestroy();
   presenter.onEvent(new MoviesListScreenEvents.OnMovieSelect(null));
 }