示例#1
0
  @Test
  public void testCreateRoomByUser() {
    when(service.getUserBySession(anyString())).thenReturn(null);
    Room endRoom = gameServer.createRoom("aaa", "aaa", null);
    assertNull(endRoom);

    Room room = new RoomFFA("aaa");
    UserProfile profile = spy(new UserProfile("aa", "bb"));
    when(service.getUserBySession(anyString())).thenReturn(profile);
    when(profile.getCurrentroom()).thenReturn(room);

    endRoom = gameServer.createRoom("aaa", "aaa", null);
    assertNull(endRoom);
  }
示例#2
0
 @Test
 public void testJoinRoomNoRoom() {
   when(service.getUserBySession(anyString())).thenReturn(new UserProfile("aa", "bb"));
   when(rooms.containsKey(anyString())).thenReturn(false);
   Room room = gameServer.joinRoom("aa", "aa", "aa");
   assertNull(room);
 }
示例#3
0
  @Test
  public void isCorrectPlayerInGameNoPlayer() {
    when(service.isAuthorized(anyString())).thenReturn(true);
    when(service.getUserBySession(anyString())).thenReturn(null);

    assertFalse(gameServer.isCorrectPlayerInGame("aa"));
  }
示例#4
0
  @Test
  public void testJoinRoomUserPassToRoom() {
    UserProfile profile = spy(new UserProfile("aa", "bb"));
    when(service.getUserBySession(anyString())).thenReturn(profile);
    when(rooms.containsKey(anyString())).thenReturn(true);
    when(profile.getCurrentroom()).thenReturn(null);
    Room room = new RoomFFA("aaa", "cc");
    when(rooms.get(anyString())).thenReturn(room);

    Room endRoom = gameServer.joinRoom("aaa", "", "aa");

    assertNull(endRoom);

    endRoom = gameServer.joinRoom("aa", null, "aa");

    assertNull(endRoom);
  }
示例#5
0
 @Before
 public void setUp() {
   new ProjectDB().initBD("hibernate-test.cfg.xml");
   service = mock(AccountService.class);
   rooms = spy(new HashMap<>());
   gameServer = new GameServer(service);
   gameServer.setRooms(rooms);
 }
示例#6
0
  @Test
  public void testIsGameReady() throws Exception {
    UserProfile profile = new UserProfile("test", "test");

    Room room = new RoomFFA("testRoom");
    room.addUser(profile);
    profile.setCurrentroom(room);

    doReturn(profile).when(service).getUserBySession(anyString());

    assertFalse(gameServer.isGameReady(anyString()));

    UserProfile profile1 = new UserProfile("test1", "test1");
    room.addUser(profile1);

    assertTrue(gameServer.isGameReady(anyString()));
  }
示例#7
0
  @Test
  public void testGetPlayerRoomBySession() throws Exception {
    UserProfile profile = new UserProfile("test", "test");
    Room room = new RoomFFA("testRoom");
    room.addUser(profile);
    profile.setCurrentroom(room);

    when(service.getUserBySession(anyString())).thenReturn(profile);

    Room testingRoom = gameServer.getPlayerRoomBySession(anyString());

    assertNotNull(testingRoom);
    assertTrue(testingRoom.checkUser(profile));

    when(service.getUserBySession(anyString())).thenReturn(null);

    assertNull(gameServer.getPlayerRoomBySession(anyString()));
  }
示例#8
0
  @Test
  public void testIsCorrectPlayerInGameAlready() throws Exception {
    when(service.isAuthorized(anyString())).thenReturn(true);
    UserProfile profile = new UserProfile("test", "test");
    Room room = new RoomFFA("testRoom");
    profile.setCurrentroom(room);
    when(service.getUserBySession(anyString())).thenReturn(profile);

    assertTrue(gameServer.isCorrectPlayerInGame("aa"));
  }
示例#9
0
  @Test
  public void testCreateRoomAlreadyExist() {
    UserProfile profile = spy(new UserProfile("aa", "bb"));
    when(service.getUserBySession(anyString())).thenReturn(profile);
    when(profile.getCurrentroom()).thenReturn(null);
    when(rooms.containsKey(anyString())).thenReturn(true);

    Room room = gameServer.createRoom("aaa", "aaa", null);

    assertNull(room);
  }
示例#10
0
 @Test
 public void testJoinRoomNoPlayer() {
   when(service.getUserBySession(anyString())).thenReturn(null);
   Room room = gameServer.joinRoom("aa", "aa", "aa");
   assertNull(room);
 }
示例#11
0
  @Test
  public void testIsCorrectPlayerInGameNoAuth() throws Exception {
    when(service.isAuthorized(anyString())).thenReturn(false);

    assertFalse(gameServer.isCorrectPlayerInGame("aa"));
  }