MainPresenter implements IMainPresenter { @Override public void loadSpinnerData() { mSpinnerData = mMainModel.loadSpinnerData(); if (mSpinnerData == null || mSpinnerData.size() == 0){ mMainView.showErrorMsg(); return; } mMainView.updateSpinnerData(mSpinnerData); } MainPresenter(IMainView mainView); @VisibleForTesting  MainPresenter(IMainView mainView,IMainModel mainModel); @Override void loadSpinnerData(); @Override void loadListData(int position);  }
@Test public void loadSpinnerDataWhenDataEmpty() throws Exception { mMainPresenter.loadSpinnerData(); Mockito.verify(mMainModel).loadSpinnerData(); List<String> data = new ArrayList<>(); Mockito.when(mMainModel.loadSpinnerData()).thenReturn(data); Mockito.verify(mMainView).showErrorMsg(); }
@Test public void loadSpinnerDataWhenDataNull() throws Exception { mMainPresenter.loadSpinnerData(); Mockito.verify(mMainModel).loadSpinnerData(); Mockito.when(mMainModel.loadSpinnerData()).thenReturn(null); Mockito.verify(mMainView).showErrorMsg(); }