@Test public void roomReadyAndPlayerDontMove() throws JSONException { UserProfile profile = new UserProfile("aaaa", "bbbb"); GameProfile gameProfile = profile.getGameProfile(); final int defaultTestX = 500; gameProfile.setX(defaultTestX); final int defaultTestY = 500; gameProfile.setY(defaultTestY); gameProfile.setScore(1); Room room = mock(Room.class); doReturn(profile).when(gameServer).getPlayerBySession(anyString()); doReturn(room).when(gameServer).getPlayerRoomBySession(anyString()); when(room.isFinished()).thenReturn(false); JSONObject object = new JSONObject(); object.put("direction", -1); moveActionStrategy.processGameAction(object, httpSession); assertEquals(gameProfile.getX(), defaultTestX, 0); object.put("direction", 100); moveActionStrategy.processGameAction(object, httpSession); moveActionStrategy.processGameAction(object, httpSession); assertNotEquals(gameProfile.getX(), 1.0d, 0d); assertNotEquals(gameProfile.getY(), 1.0d, 0d); }
@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())); }
private GameProfile getTestGameProfileForRoom(Room room, double x, double y, double direction) { UserProfile testProfile = new UserProfile("test", "test"); room.addUser(testProfile); GameProfile profile = testProfile.getGameProfile(); profile.setX(x); profile.setY(y); profile.setDirection(direction); return profile; }
@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 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 testProcessGameFinished() throws JSONException { UserProfile profile = new UserProfile("aaaa", "bbbb"); GameProfile gameProfile = profile.getGameProfile(); gameProfile.setX(1); gameProfile.setY(1); gameProfile.setScore(1); Room room = mock(Room.class); doReturn(profile).when(gameServer).getPlayerBySession(anyString()); doReturn(room).when(gameServer).getPlayerRoomBySession(anyString()); when(room.isFinished()).thenReturn(true); JSONObject object = new JSONObject(); object.put("direction", 2); moveActionStrategy.processGameAction(object, httpSession); assertEquals(gameProfile.getX(), 1.0d, 0); }