Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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);
}
// ...
}
@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