@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 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); }