Last active
February 12, 2016 19:17
-
-
Save Pacane/f64a6b913df7327abc51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApplicationPresenter | |
extends Presenter<ApplicationPresenter.MyView, ApplicationPresenter.MyProxy> | |
implements ApplicationUiHandlers { // Added the UiHandlers | |
interface MyView extends View, HasUiHandlers<ApplicationUiHandlers> { | |
void displayUsername(String username); | |
} | |
// ... | |
@Inject | |
ApplicationPresenter( | |
EventBus eventBus, | |
MyView view, | |
MyProxy proxy, | |
UserService userService) { | |
super(eventBus, view, proxy, RevealType.Root); | |
this.userService = userService; | |
getView().setUiHandlers(this); // <- This is also checked by a test. | |
} | |
@Override | |
public void saveUsername(String username) { | |
userService.saveUsername(username); | |
String newName = userService.getUsername(); | |
getView().displayUsername(newName); | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(JukitoRunner.class) | |
public class ApplicationPresenterTest { | |
// New tests | |
@Test | |
public void ctor_setsUiHandlers() { | |
verify(view).setUiHandlers(same(presenter)); | |
} | |
@Test | |
public void saveUsername_delegatesToService() { | |
presenter.saveUsername(A_USERNAME); | |
verify(userService).saveUsername(A_USERNAME); | |
} | |
@Test | |
public void saveUsername_displaysNewUsernameInView() { | |
given(userService.getUsername()).willReturn(A_USERNAME); | |
presenter.saveUsername(A_USERNAME); | |
verify(view).displayUsername(A_USERNAME); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment