Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #126 from baltuky/documentation/tipresenter_test
Browse files Browse the repository at this point in the history
Add Javadoc for TiPresenter.test() method
  • Loading branch information
passsy authored Oct 5, 2017
2 parents acd54fc + 899ea41 commit 8c03ac8
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,51 @@ public void setUiThreadExecutor(@Nullable final Executor uiThreadExecutor) {
mUiThreadExecutor = uiThreadExecutor;
}

/**
* Creates {@link TiTestPresenter} that simplifies testing by calling the presenter lifecycle
* methods automatically in the correct order. It also sets the ui thread Executors which allows
* the usage of {@link TiPresenter#sendToView(ViewAction)} in unit test.
* <code>
* <pre>
* &#64;Test
* public void testLoadData() throws Exception {
* final LoginPresenter loginPresenter = new LoginPresenter();
* final TiTestPresenter<LoginView> testPresenter = loginPresenter.test();
* final LoginView view = testPresenter.attachView(mock(LoginView.class));
*
* loginPresenter.onSubmitClicked();
* verify(view).showError("No username entered");
* }
*
* public class LoginPresenter extends TiPresenter<LoginView> {
*
* public void onSubmitClicked() {
* sendToView(new ViewAction<LoginView>() {
* &#64;Override
* public void call(final LoginView view) {
* view.showError("No username entered");
* }
* });
* }
* }
*
* public interface LoginView extends TiView {
* void showError(String msg);
* }
* </pre>
* </code>
*
* <p>
* The problem is that {@link TiPresenter#sendToView(ViewAction)} needs a ui executor thread.
* Unfortunately a ui executor thread isn't available in unit test. Instead a mock implementation
* is provided which executes the actions immediately on the testing thread.
* </p>
* <p>
* This {@link TiTestPresenter} holds the {@link TiPresenter} under test.
* </p>
*
* @return instance of {@link TiTestPresenter}
*/
public TiTestPresenter<V> test() {
return new TiTestPresenter<>(this);
}
Expand Down

0 comments on commit 8c03ac8

Please sign in to comment.