MainPresenter extends AbstractMvpPresenter<Main.View, Void> implements Main.Presenter<Main.View, Void> { @Override @Subscribe(threadMode = ThreadMode.MAIN) public void refreshFetchingStatus(FetchingEvent fetchingEvent) { FetchingEvent stickyEvent = getEventBus().getStickyEvent(FetchingEvent.class); if (mView != null) { boolean needToEnd = stickyEvent == null || !stickyEvent.isFetching(); boolean needToStart = !needToEnd && stickyEvent.getFechingResult() != FetchingEvent.RESULT.REFRESHING; mView.updateManualFetchFabAnimator(needToEnd, needToStart); if (stickyEvent != null) { switch (stickyEvent.getFechingResult()) { case REFRESHING: mView.showFetchingResult(R.string.refreshing); break; case NO_NETWORK: mView.showFetchingResult(R.string.refresh_no_network); break; case FAIL: case ABORT: mView.showFetchingResult(R.string.refresh_fail); break; case SUCCESS: mView.showFetchingResult(R.string.refresh_finish); break; case GOT_NEW: mView.showFetchingResult(R.string.got_new); break; case EXISTED: mView.showFetchingResult(R.string.already_got); break; } } } if (stickyEvent != null) { stickyEvent.setFechingResult(FetchingEvent.RESULT.NONE); } } MainPresenter();  MainPresenter(UseCaseHandler useCaseHandler, ManuallyFetchTodaysSentenceUC fetchTodaysSentenceUseCase); @Override void fetchTodaysSentence(); @Override void onCreate(long widgetSentenceId); @Override void onStart(); @Override void updateManualFetchFabStatus(boolean isDisplayingList, boolean isFavoriteList); @Subscribe(threadMode = ThreadMode.MAIN) void updateManualFetchFabStatus(UpdateManualFetchFabEvent event); @Override void onResume(); @Override void onStop(); @Override void onBackPressed(boolean isDrawerOpen, boolean isDetailFragment, int backStackEntryCount); @Override @Subscribe(threadMode = ThreadMode.MAIN) void refreshFetchingStatus(FetchingEvent fetchingEvent); @Override void onNavigationItemSelected(int menuId); @VisibleForTesting EventBus getEventBus();  }
@Test public void testRefreshFetchingStatus_IsFetching_REFRESHING() { when(mFetchingEvent.isFetching()).thenReturn(true); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.REFRESHING); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(false, false); verify(mView).showFetchingResult(R.string.refreshing); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }
@Test public void testRefreshFetchingStatus_IsFetching_START() { when(mFetchingEvent.isFetching()).thenReturn(true); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.NONE); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(false, true); verify(mView, times(0)).showFetchingResult(anyInt()); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }
@Test public void testRefreshFetchingStatus_NotFetching_NO_NETWORK() { when(mFetchingEvent.isFetching()).thenReturn(false); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.NO_NETWORK); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(true, false); verify(mView).showFetchingResult(R.string.refresh_no_network); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }
@Test public void testRefreshFetchingStatus_NotFetching_FAIL() { when(mFetchingEvent.isFetching()).thenReturn(false); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.FAIL); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(true, false); verify(mView).showFetchingResult(R.string.refresh_fail); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }
@Test public void testRefreshFetchingStatus_NotFetching_ABORT() { when(mFetchingEvent.isFetching()).thenReturn(false); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.ABORT); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(true, false); verify(mView).showFetchingResult(R.string.refresh_fail); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }
@Test public void testRefreshFetchingStatus_NotFetching_SUCCESS() { when(mFetchingEvent.isFetching()).thenReturn(false); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.SUCCESS); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(true, false); verify(mView).showFetchingResult(R.string.refresh_finish); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }
@Test public void testRefreshFetchingStatus_NotFetching_GOT_NEW() { when(mFetchingEvent.isFetching()).thenReturn(false); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.GOT_NEW); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(true, false); verify(mView).showFetchingResult(R.string.got_new); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }
@Test public void testRefreshFetchingStatus_NotFetching_EXISTED() { when(mFetchingEvent.isFetching()).thenReturn(false); when(mFetchingEvent.getFechingResult()).thenReturn(FetchingEvent.RESULT.EXISTED); when(mEventBus.getStickyEvent(any(Class.class))).thenReturn(mFetchingEvent); mMainPresenter.refreshFetchingStatus(mFetchingEvent); verify(mView).updateManualFetchFabAnimator(true, false); verify(mView).showFetchingResult(R.string.already_got); verify(mFetchingEvent).setFechingResult(FetchingEvent.RESULT.NONE); }