コード例 #1
0
  @Test
  public void onStop_shouldUnregisterEventBus() {
    presenter.onCreate(mockGraph, view);
    presenter.onStop();

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

    assertThat(objectCaptor.getValue()).isEqualTo(presenter);
  }
コード例 #2
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);
  }
コード例 #3
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);
  }