MainActivityPresenter { public void requestAlbumsClicked() { view.showProgressDialog(); service.requestAlbums(new ITopAlbumsService.Callback() { @Override public void success(List<AlbumDto> albums) { view.hideProgressDialog(); view.displayAlbums(albums); } @Override public void failure() { view.hideProgressDialog(); view.showErrorMessage(); } }); } MainActivityPresenter(MainActivityView view, ITopAlbumsService service); void requestAlbumsClicked();  }
@Test public void whenRequestAlbumsCalledShouldPerformCorrectly() { List<AlbumDto> testDtoList = Collections.singletonList(new AlbumDto("testImageUrl", "testLabel")); ArgumentCaptor<ITopAlbumsService.Callback> callbackArgumentCaptor = ArgumentCaptor.forClass(ITopAlbumsService.Callback.class); presenter.requestAlbumsClicked(); Mockito.verify(view).showProgressDialog(); Mockito.verify(topAlbumsService).requestAlbums(callbackArgumentCaptor.capture()); callbackArgumentCaptor.getValue().success(testDtoList); Mockito.verify(view).hideProgressDialog(); Mockito.verify(view).displayAlbums(testDtoList); }
@Test public void whenRequestAlbumsCalledAndNetworkCallFails() { ArgumentCaptor<ITopAlbumsService.Callback> callbackArgumentCaptor = ArgumentCaptor.forClass(ITopAlbumsService.Callback.class); presenter.requestAlbumsClicked(); Mockito.verify(view).showProgressDialog(); Mockito.verify(topAlbumsService).requestAlbums(callbackArgumentCaptor.capture()); callbackArgumentCaptor.getValue().failure(); Mockito.verify(view).hideProgressDialog(); Mockito.verify(view).showErrorMessage(); }