Last active
February 12, 2016 19:34
-
-
Save Pacane/5e8214ad3316427bb0ff 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
package com.arcbees.client.application.users; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.jukito.JukitoModule; | |
import org.jukito.JukitoRunner; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import com.arcbees.client.application.events.UserDeletedEvent; | |
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.AutobindDisable; | |
import com.gwtplatform.mvp.shared.proxy.PlaceRequest; | |
import static org.mockito.BDDMockito.given; | |
import static org.mockito.Matchers.eq; | |
import static org.mockito.Matchers.same; | |
import static org.mockito.Mockito.verify; | |
@RunWith(JukitoRunner.class) | |
public class UsersPresenterTest { | |
public static class Module extends JukitoModule { | |
@Override | |
protected void configureTest() { | |
// This prevents onBind() to be called twice when running tests | |
bind(AutobindDisable.class).toInstance(new AutobindDisable(true)); | |
} | |
} | |
private static final int USER_ID = 32131; | |
@Inject | |
private UsersPresenter presenter; | |
@Inject | |
private UserService userService; | |
@Inject | |
private UsersPresenter.MyView view; | |
@Inject | |
private EventBus eventBus; | |
private Map<Integer, String> users = new HashMap<>(); | |
@Before | |
public void setUp() { | |
given(userService.getUsers()).willReturn(users); | |
} | |
// ... | |
@Test | |
public void ctor_setsUiHandlers() { | |
verify(view).setUiHandlers(same(presenter)); | |
} | |
@Test | |
public void onBind_addsHandlers() { | |
presenter.onBind(); | |
verify(eventBus).addHandler(eq(UserDeletedEvent.TYPE), same(presenter)); | |
} | |
@Test | |
public void deleteUser_delegatesToService() { | |
presenter.deleteUser(USER_ID); | |
verify(userService).deleteUser(USER_ID); | |
} | |
@Test | |
public void onUserDeleted_displaysUsers() { | |
UserDeletedEvent event = new UserDeletedEvent(); | |
presenter.onUserDeleted(event); | |
verify(view).displayUsers(same(users)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment