2012-01-12 21:09:01 +00:00
|
|
|
package net.socialgamer.cah.data;
|
|
|
|
|
2012-01-19 00:42:18 +00:00
|
|
|
import static org.easymock.EasyMock.anyInt;
|
2012-01-12 21:09:01 +00:00
|
|
|
import static org.easymock.EasyMock.anyObject;
|
|
|
|
import static org.easymock.EasyMock.createMock;
|
|
|
|
import static org.easymock.EasyMock.eq;
|
|
|
|
import static org.easymock.EasyMock.expectLastCall;
|
|
|
|
import static org.easymock.EasyMock.replay;
|
2012-01-12 21:13:51 +00:00
|
|
|
import static org.easymock.EasyMock.verify;
|
2012-01-12 21:09:01 +00:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2012-01-19 00:42:18 +00:00
|
|
|
import net.socialgamer.cah.data.Game.TooManyPlayersException;
|
2012-01-13 04:05:39 +00:00
|
|
|
import net.socialgamer.cah.data.QueuedMessage.MessageType;
|
2012-01-12 21:09:01 +00:00
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
public class GameTest {
|
|
|
|
|
|
|
|
private Game game;
|
2012-01-19 00:42:18 +00:00
|
|
|
private ConnectedUsers cuMock;
|
|
|
|
private GameManager gmMock;
|
2012-01-12 21:09:01 +00:00
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
2012-01-19 00:42:18 +00:00
|
|
|
cuMock = createMock(ConnectedUsers.class);
|
|
|
|
gmMock = createMock(GameManager.class);
|
|
|
|
game = new Game(0, cuMock, gmMock);
|
2012-01-12 21:09:01 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 21:13:51 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-01-12 21:09:01 +00:00
|
|
|
@Test
|
2012-01-19 00:42:18 +00:00
|
|
|
public void testRemovePlayer() throws IllegalStateException, TooManyPlayersException {
|
|
|
|
cuMock.broadcastToList(anyObject(Collection.class), eq(MessageType.GAME_PLAYER_EVENT),
|
2012-01-12 21:09:01 +00:00
|
|
|
anyObject(HashMap.class));
|
2012-01-12 21:13:51 +00:00
|
|
|
expectLastCall().times(4);
|
2012-01-19 00:42:18 +00:00
|
|
|
replay(cuMock);
|
|
|
|
gmMock.destroyGame(anyInt());
|
|
|
|
expectLastCall().once();
|
|
|
|
replay(gmMock);
|
2012-01-12 21:09:01 +00:00
|
|
|
|
|
|
|
final User user1 = new User("test1");
|
|
|
|
final User user2 = new User("test2");
|
|
|
|
game.addPlayer(user1);
|
|
|
|
game.addPlayer(user2);
|
|
|
|
|
|
|
|
assertEquals(user1, game.getHost());
|
|
|
|
assertFalse(game.removePlayer(user1));
|
|
|
|
assertEquals(user2, game.getHost());
|
|
|
|
assertTrue(game.removePlayer(user2));
|
|
|
|
assertEquals(null, game.getHost());
|
|
|
|
|
2012-01-19 00:42:18 +00:00
|
|
|
verify(cuMock);
|
|
|
|
verify(gmMock);
|
2012-01-12 21:09:01 +00:00
|
|
|
}
|
|
|
|
}
|