@Test
  public void isCorrectPlayerInGameNoPlayer() {
    when(service.isAuthorized(anyString())).thenReturn(true);
    when(service.getUserBySession(anyString())).thenReturn(null);

    assertFalse(gameServer.isCorrectPlayerInGame("aa"));
  }
  @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"));
  }
  @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);
  }
 @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);
 }
  @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()));
  }
  @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);
  }
  @Test
  public void joinRoomUserInRoom() {
    Room room = new RoomFFA("aaa");

    UserProfile profile = spy(new UserProfile("aa", "bb"));
    when(service.getUserBySession(anyString())).thenReturn(profile);
    when(rooms.containsKey(anyString())).thenReturn(true);
    when(profile.getCurrentroom()).thenReturn(room);

    when(rooms.get(anyString())).thenReturn(room);
    Room endRoom = gameServer.joinRoom("aa", "aa", "aa");

    assertNull(endRoom);
  }
  @Test
  public void testJoinRoomHasPass() {
    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", "aaa", "aa");
    assertNull(endRoom);

    room = new RoomFFA("aaa");
    when(rooms.get(anyString())).thenReturn(room);
    endRoom = gameServer.joinRoom("aa", "aa", "aa");
    assertNotNull(endRoom);
    assertEquals(endRoom.getPlayersCount(), 1);
  }
 @Test
 public void testJoinRoomNoPlayer() {
   when(service.getUserBySession(anyString())).thenReturn(null);
   Room room = gameServer.joinRoom("aa", "aa", "aa");
   assertNull(room);
 }
Beispiel #10
0
  @Test
  public void testIsCorrectPlayerInGameNoAuth() throws Exception {
    when(service.isAuthorized(anyString())).thenReturn(false);

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