Esempio n. 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);
  }
Esempio n. 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);
 }
Esempio n. 3
0
  @Test
  public void isCorrectPlayerInGameNoPlayer() {
    when(service.isAuthorized(anyString())).thenReturn(true);
    when(service.getUserBySession(anyString())).thenReturn(null);

    assertFalse(gameServer.isCorrectPlayerInGame("aa"));
  }
Esempio n. 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);
  }
Esempio n. 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);
 }
Esempio n. 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()));
  }
Esempio n. 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()));
  }
Esempio n. 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"));
  }
Esempio n. 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);
  }
Esempio n. 10
0
 @Test
 public void testJoinRoomNoPlayer() {
   when(service.getUserBySession(anyString())).thenReturn(null);
   Room room = gameServer.joinRoom("aa", "aa", "aa");
   assertNull(room);
 }
Esempio n. 11
0
  @Test
  public void testIsCorrectPlayerInGameNoAuth() throws Exception {
    when(service.isAuthorized(anyString())).thenReturn(false);

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