mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 20:11:59 -08:00
Test framework: added support to test client side data in unit tests (getGameView -> CardView, etc);
This commit is contained in:
parent
26fea5d07b
commit
fc0ff6c22d
7 changed files with 59 additions and 22 deletions
|
|
@ -25,6 +25,7 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.constants.*;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchType;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.tournament.TournamentType;
|
||||
|
|
@ -92,6 +93,8 @@ public abstract class MageTestPlayerBase {
|
|||
*/
|
||||
protected static Game currentGame = null;
|
||||
|
||||
protected static Match currentMatch = null;
|
||||
|
||||
/**
|
||||
* Player thats starts the game first. By default, it is ComputerA.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,19 +16,19 @@ import mage.counters.CounterType;
|
|||
import mage.filter.Filter;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameException;
|
||||
import mage.game.GameOptions;
|
||||
import mage.game.*;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.player.ai.ComputerPlayer7;
|
||||
import mage.player.ai.ComputerPlayerMCTS;
|
||||
import mage.players.ManaPool;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.GameSessionPlayer;
|
||||
import mage.server.util.SystemUtil;
|
||||
import mage.util.CardUtil;
|
||||
import mage.view.GameView;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.mage.test.player.PlayerAction;
|
||||
|
|
@ -216,6 +216,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
currentGame = null;
|
||||
}
|
||||
|
||||
// prepare fake match (needs for testing some client-server code)
|
||||
// always 4 seats
|
||||
MatchOptions matchOptions = new MatchOptions("test match", "test game type", true, 4);
|
||||
currentMatch = new FreeForAllMatch(matchOptions);
|
||||
currentGame = createNewGameAndPlayers();
|
||||
|
||||
activePlayer = playerA;
|
||||
|
|
@ -267,6 +271,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
game.loadCards(deck.getCards(), player.getId());
|
||||
game.loadCards(deck.getSideboard(), player.getId());
|
||||
game.addPlayer(player, deck);
|
||||
currentMatch.addPlayer(player, deck); // fake match
|
||||
|
||||
return player;
|
||||
}
|
||||
|
|
@ -2116,4 +2121,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
Assert.assertFalse(player.getName() + " has lost the game.", player.hasLost());
|
||||
}
|
||||
|
||||
public GameView getGameView(Player player) {
|
||||
// prepare client-server data for tests
|
||||
return GameSessionPlayer.prepareGameView(currentGame, player.getId(), null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.mulligan.LondonMulligan;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.permanent.PermanentImpl;
|
||||
import mage.remote.traffic.ZippedObjectImpl;
|
||||
import mage.util.CardUtil;
|
||||
import mage.utils.CompressUtil;
|
||||
import mage.view.GameView;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
|
@ -76,9 +76,10 @@ public class SerializationTest extends CardTestPlayerBase {
|
|||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
Object compressed = CompressUtil.compress(currentGame);
|
||||
GameView gameView = getGameView(playerA);
|
||||
Object compressed = CompressUtil.compress(gameView);
|
||||
Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
|
||||
Game uncompressed = (Game) CompressUtil.decompress(compressed);
|
||||
Assert.assertEquals("Must be same", 1, uncompressed.getBattlefield().getAllActivePermanents().size());
|
||||
GameView uncompressed = (GameView) CompressUtil.decompress(compressed);
|
||||
Assert.assertEquals("Must be same", 1, uncompressed.getPlayers().get(0).getBattlefield().size());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue