Last active
February 3, 2016 16:29
-
-
Save Pacane/4bc96b24c061dcd84ba0 to your computer and use it in GitHub Desktop.
GWTP Test example - First pattern
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
package com.arcbees.client.application; | |
import com.arcbees.client.application.services.UserService; | |
import com.google.inject.Inject; | |
import com.google.web.bindery.event.shared.EventBus; | |
import com.gwtplatform.mvp.client.Presenter; | |
import com.gwtplatform.mvp.client.View; | |
import com.gwtplatform.mvp.client.annotations.ProxyStandard; | |
import com.gwtplatform.mvp.client.presenter.slots.NestedSlot; | |
import com.gwtplatform.mvp.client.proxy.Proxy; | |
public class ApplicationPresenter | |
extends Presenter<ApplicationPresenter.MyView, ApplicationPresenter.MyProxy> { | |
interface MyView extends View { | |
void displayUsername(String username); | |
} | |
@ProxyStandard | |
interface MyProxy extends Proxy<ApplicationPresenter> { | |
} | |
public static final NestedSlot SLOT_MAIN = new NestedSlot(); | |
private final UserService userService; | |
@Inject | |
ApplicationPresenter( | |
EventBus eventBus, | |
MyView view, | |
MyProxy proxy, | |
UserService userService) { | |
super(eventBus, view, proxy, RevealType.Root); | |
this.userService = userService; | |
} | |
@Override | |
protected void onBind() { | |
String username = userService.getUsername(); | |
getView().displayUsername(username); | |
} | |
} |
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
package com.arcbees.client.application; | |
import org.jukito.JukitoRunner; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import com.arcbees.client.application.services.UserService; | |
import com.google.inject.Inject; | |
import static org.mockito.BDDMockito.given; | |
import static org.mockito.Mockito.verify; | |
@RunWith(JukitoRunner.class) | |
public class ApplicationPresenterTest { | |
private static final String A_USERNAME = "bobby"; | |
@Inject | |
private ApplicationPresenter presenter; | |
@Inject | |
private ApplicationPresenter.MyView view; | |
@Inject | |
UserService userService; | |
@Test | |
public void onBind_displayUsername() { | |
given(userService.getUsername()).willReturn(A_USERNAME); | |
presenter.onBind(); | |
verify(view).displayUsername(A_USERNAME); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment