//Create new Match
{
SoccerMatchModel soccerMatch = SoccerMatchBuilder.build();
MemoryEventStore memoryEventStore = new MemoryEventStore();
MatchHandler matchHandler = new MatchHandler(soccerMatch.getMatch(), memoryEventStore);
//Restore MatchA
matchHandler.restoreState(resultA);
MatchState state = matchHandler.getMatch().getState();
assertThat("MatchA should be correctly restored.", state, equalTo(MatchState.ended));
// Check if assigned cards are restored
boolean frankHasCard = false, frankHasRedCard = false, pietHasCard = false, henkHasCard = false;
for (PlayerModel playerModel : matchHandler.getMatch().getAssignedYellowCards()) {
if (playerModel.getPlayerName().equals("frank")) {
frankHasCard = true;
break;
}
}
for (PlayerModel playerModel : matchHandler.getMatch().getAssignedRedCards()) {
if (playerModel.getPlayerName().equals("piet")) {
pietHasCard = true;
}
if (playerModel.getPlayerName().equals("henk")) {
henkHasCard = true;
}
if (playerModel.getPlayerName().equals("frank")) {
frankHasRedCard = true;
}
}
assertThat("MatchA should have assigned a yellow card to frank.", frankHasCard, equalTo(true));
assertThat("MatchA should have assigned a red card to piet.", pietHasCard, equalTo(true));
assertThat("MatchA should have assigned a red card to henk.", henkHasCard, equalTo(true));
assertThat("MatchA should not have assigned a red card to frank.", frankHasRedCard, equalTo(false));
}
{
//Create new Match
SoccerMatchModel soccerMatchB = SoccerMatchBuilder.build();
MemoryEventStore memoryEventStoreB = new MemoryEventStore();
MatchHandler matchHandlerB = new MatchHandler(soccerMatchB.getMatch(), memoryEventStoreB);
//Restore MatchB
matchHandlerB.restoreState(resultB);
MatchState stateB = matchHandlerB.getMatch().getState();
boolean equals = stateB.equals(MatchState.started);
assertThat("MatchB should be correctly restored.", equals, equalTo(true));
}
}