SearchUserPresenter implements Presenter<SearchUserView> { public void loadUsers(String username) { if(username == null || username.isEmpty()) { searchUserView.showMessage("Enter a username"); } else { searchUserView.showProgressIndicator(); searchUserUseCase.execute(new SearchUserSubscriber(), username); } } @Inject  SearchUserPresenter(@Named("searchUser") UseCase searchUserUseCase); @Override void attachView(SearchUserView searchUserView); void loadUsers(String username); void onUserClick(String username); @Override void detachView(); @Override void destroy(boolean unsubscribe);  }
@Test public void loadUsersShouldShowProgressIndicator() { searchUserPresenter.loadUsers(MockFactory.TEST_USERNAME); verify(searchUserView, times(1)).showProgressIndicator(); }
@Test public void loadUsersShouldShowErrorMessageIfNoInput() { searchUserPresenter.loadUsers(null); verify(searchUserView).showMessage("Enter a username"); }
@Test public void loadUsersShouldShowErrorMessageIfEmptyInput() { searchUserPresenter.loadUsers(""); verify(searchUserView).showMessage("Enter a username"); }
@Test public void loadUsersShouldDisplayMessageIfNoResults() { searchUserPresenter.loadUsers(MockFactory.TEST_USERNAME_NO_RESULTS); verify(searchUserView).showMessage("No results"); }
@Test public void loadUsersShouldAddUsersWhenReceivedResult() { searchUserPresenter.loadUsers(MockFactory.TEST_USERNAME); SearchResponse searchResponse = MockFactory.buildMockSearchResponse(); verify(searchUserView).showUsers(anyList()); }
@Test public void loadUsersShouldDisplayMessageOnError() { searchUserPresenter.loadUsers(MockFactory.TEST_USERNAME_ERROR); verify(searchUserView).showMessage("Error loading repositories"); }
@Test public void loadUsersShouldHideProgressIndicatorAfterCompleted() { searchUserPresenter.loadUsers(MockFactory.TEST_USERNAME); verify(searchUserView).hideProgressIndicator(); }