Merge branch 'development2' of https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-01 into development2
This commit is contained in:
BIN
Projekte/mdga/client/src/main/resources/Images/Statistics.png
Normal file
BIN
Projekte/mdga/client/src/main/resources/Images/Statistics.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 MiB |
@@ -11,6 +11,8 @@
|
|||||||
import pp.mdga.notification.Notification;
|
import pp.mdga.notification.Notification;
|
||||||
import pp.mdga.notification.StartDialogNotification;
|
import pp.mdga.notification.StartDialogNotification;
|
||||||
|
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.lang.System.Logger.Level;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -19,7 +21,7 @@
|
|||||||
* It is responsible for handling the game logic on the client side.
|
* It is responsible for handling the game logic on the client side.
|
||||||
*/
|
*/
|
||||||
public class ClientGameLogic implements ServerInterpreter {
|
public class ClientGameLogic implements ServerInterpreter {
|
||||||
static final System.Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
static final Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
||||||
|
|
||||||
private Game game;
|
private Game game;
|
||||||
private final ClientSender clientSender;
|
private final ClientSender clientSender;
|
||||||
@@ -53,7 +55,7 @@ public ClientGameLogic(ClientSender clientSender) {
|
|||||||
* @param msg the message to be sent
|
* @param msg the message to be sent
|
||||||
*/
|
*/
|
||||||
public void send(ClientMessage msg) {
|
public void send(ClientMessage msg) {
|
||||||
LOGGER.log(System.Logger.Level.INFO, "send {0}", msg);
|
LOGGER.log(Level.INFO, "send {0}", msg);
|
||||||
clientSender.send(msg);
|
clientSender.send(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,7 +583,7 @@ public void selectLeave() {
|
|||||||
/**
|
/**
|
||||||
* This method calls the selectJoin method of the state
|
* This method calls the selectJoin method of the state
|
||||||
*
|
*
|
||||||
* @param ip the ip to cennect to
|
* @param ip the ip to connect to
|
||||||
*/
|
*/
|
||||||
public void selectJoin(String ip) {
|
public void selectJoin(String ip) {
|
||||||
state.selectJoin(ip);
|
state.selectJoin(ip);
|
||||||
|
|||||||
@@ -2,70 +2,289 @@
|
|||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import pp.mdga.client.ClientGameLogic;
|
||||||
|
import pp.mdga.client.ClientSender;
|
||||||
|
import pp.mdga.client.DialogsState;
|
||||||
|
import pp.mdga.client.GameState;
|
||||||
|
import pp.mdga.client.dialogstate.LobbyState;
|
||||||
|
import pp.mdga.client.dialogstate.StartDialogState;
|
||||||
|
import pp.mdga.game.Color;
|
||||||
|
import pp.mdga.game.Game;
|
||||||
|
import pp.mdga.game.Piece;
|
||||||
|
import pp.mdga.game.Player;
|
||||||
|
import pp.mdga.message.client.DeselectTSKMessage;
|
||||||
|
import pp.mdga.message.client.LeaveGameMessage;
|
||||||
|
import pp.mdga.message.client.LobbyNotReadyMessage;
|
||||||
|
import pp.mdga.message.client.LobbyReadyMessage;
|
||||||
|
import pp.mdga.message.client.SelectTSKMessage;
|
||||||
|
import pp.mdga.message.client.StartGameMessage;
|
||||||
|
import pp.mdga.message.server.UpdateTSKMessage;
|
||||||
|
import pp.mdga.notification.InfoNotification;
|
||||||
|
import pp.mdga.notification.TskSelectNotification;
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.ServerSender;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this test-class tests the testcases T084-T095
|
* this test-class tests the testcases T084-T095
|
||||||
*/
|
*/
|
||||||
public class LobbyStateTest {
|
public class LobbyStateTest {
|
||||||
|
|
||||||
|
private Game game;
|
||||||
|
|
||||||
|
private ClientSender clientSender;
|
||||||
|
private ClientGameLogic clientGameLogic;
|
||||||
|
|
||||||
|
//declare server here
|
||||||
|
private ServerGameLogic serverGameLogic;
|
||||||
|
private ServerSender serverSender;
|
||||||
|
|
||||||
|
//declare player-Client here
|
||||||
|
private Player playerClient;
|
||||||
|
private String nameClient = "Client";
|
||||||
|
private Color clientColor;
|
||||||
|
private int IDClient;
|
||||||
|
|
||||||
|
//declare player-host here
|
||||||
|
private Player playerHost;
|
||||||
|
private String nameHost = "Host";
|
||||||
|
private Color hostColor;
|
||||||
|
private int IDHost;
|
||||||
|
|
||||||
|
private DialogsState dialogs;
|
||||||
|
private LobbyState lobby;
|
||||||
|
private StartDialogState startDialogState;
|
||||||
|
private pp.mdga.server.automaton.LobbyState lobbyState;
|
||||||
|
private pp.mdga.server.automaton.GameState gameState;
|
||||||
|
private GameState clientGameState;
|
||||||
|
|
||||||
|
private SelectTSKMessage selectTSKMessage;
|
||||||
|
private DeselectTSKMessage deselectTSKMessage;
|
||||||
|
private LobbyReadyMessage readyMessage;
|
||||||
|
private LobbyNotReadyMessage notReadyMessage;
|
||||||
|
private StartGameMessage startGameMessage;
|
||||||
|
|
||||||
|
private TskSelectNotification tskSelectNotification;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
// This method will be executed before each test.
|
Game game = new Game();
|
||||||
// Initialize common objects or setup required state for Lobby actions.
|
|
||||||
|
clientSender = mock(ClientSender.class);
|
||||||
|
clientGameLogic = new ClientGameLogic(clientSender);
|
||||||
|
|
||||||
|
serverSender = mock(ServerSender.class);
|
||||||
|
serverGameLogic = new ServerGameLogic(serverSender, game);
|
||||||
|
|
||||||
|
IDClient = 1;
|
||||||
|
IDHost = 2;
|
||||||
|
|
||||||
|
playerClient = new Player(nameClient);
|
||||||
|
clientColor = Color.NONE;
|
||||||
|
playerClient.setColor(clientColor);
|
||||||
|
playerClient.initialize();
|
||||||
|
game.addPlayer(IDClient, playerClient);
|
||||||
|
|
||||||
|
playerHost = new Player(nameHost);
|
||||||
|
hostColor = Color.ARMY;
|
||||||
|
playerHost.setColor(hostColor);
|
||||||
|
playerHost.initialize();
|
||||||
|
game.addPlayer(IDHost, playerHost);
|
||||||
|
|
||||||
|
//initialize the playerData
|
||||||
|
for(Map.Entry<Integer, Player> entry : game.getPlayers().entrySet()){
|
||||||
|
game.addPlayer(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogs = clientGameLogic.getDialogs();
|
||||||
|
lobby = dialogs.getLobby();
|
||||||
|
startDialogState = dialogs.getStartDialog();
|
||||||
|
lobbyState = serverGameLogic.getLobbyState();
|
||||||
|
|
||||||
|
selectTSKMessage = new SelectTSKMessage(Color.CYBER);
|
||||||
|
deselectTSKMessage = new DeselectTSKMessage(Color.CYBER);
|
||||||
|
readyMessage = new LobbyReadyMessage();
|
||||||
|
notReadyMessage = new LobbyNotReadyMessage();
|
||||||
|
startGameMessage = new StartGameMessage();
|
||||||
|
|
||||||
|
tskSelectNotification = (TskSelectNotification) clientGameLogic.getNotification();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-01
|
// UC-Lobby-01
|
||||||
@Test
|
@Test
|
||||||
public void testSelectTSK() {
|
public void testSelectTSK() {
|
||||||
// TODO: Implement test logic for selecting a task (TSK)
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
//test if server is in the lobby state
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
serverGameLogic.received(selectTSKMessage, IDClient);
|
||||||
|
assertEquals(Color.CYBER, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-02
|
// UC-Lobby-02
|
||||||
@Test
|
@Test
|
||||||
public void testDeselectTSK() {
|
public void testDeselectTSK() {
|
||||||
// TODO: Implement test logic for deselecting a previously selected task (TSK)
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
//test if server is in the lobby state
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
assertEquals(Color.CYBER, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
||||||
|
serverGameLogic.received(deselectTSKMessage, IDClient);
|
||||||
|
assertEquals(Color.NONE, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-03
|
// UC-Lobby-03
|
||||||
@Test
|
@Test
|
||||||
public void testChangeTSK() {
|
public void testChangeTSK() {
|
||||||
// TODO: Implement test logic for changing a selected task (TSK)
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
//test if server is in the lobby state
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
assertEquals(Color.ARMY, serverGameLogic.getGame().getPlayerById(IDHost).getColor());
|
||||||
|
serverGameLogic.received(deselectTSKMessage, IDHost);
|
||||||
|
assertEquals(Color.NONE, serverGameLogic.getGame().getPlayerById(IDHost).getColor());
|
||||||
|
serverGameLogic.received(selectTSKMessage, IDHost);
|
||||||
|
assertEquals(Color.CYBER, serverGameLogic.getGame().getPlayerById(IDHost).getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-04
|
// UC-Lobby-04
|
||||||
@Test
|
@Test
|
||||||
public void testReady() {
|
public void testReady() {
|
||||||
// TODO: Implement test logic for setting the player status to "ready"
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
//test if server is in the lobby state
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
// Mark a player as not ready
|
||||||
|
serverGameLogic.getGame().getPlayerById(IDClient).setReady(false);
|
||||||
|
assertFalse(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
||||||
|
|
||||||
|
// Send a LobbyReadyMessage and validate the player is marked as ready
|
||||||
|
serverGameLogic.received(readyMessage, IDClient);
|
||||||
|
assertFalse(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
||||||
|
|
||||||
|
serverGameLogic.received(readyMessage, IDHost);
|
||||||
|
assertTrue(serverGameLogic.getGame().getPlayerById(IDHost).isReady());
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-05
|
// UC-Lobby-05
|
||||||
@Test
|
@Test
|
||||||
public void testNotReady() {
|
public void testNotReady() {
|
||||||
// TODO: Implement test logic for setting the player status to "not ready"
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
// Ensure the server is in the LobbyState
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
// Send a LobbyNotReadyMessage and validate the player is still marked as not ready
|
||||||
|
serverGameLogic.received(notReadyMessage, IDClient);
|
||||||
|
assertFalse(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
||||||
|
|
||||||
|
// Mark a player as ready
|
||||||
|
serverGameLogic.getGame().getPlayerById(IDClient).setReady(true);
|
||||||
|
assertTrue(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
||||||
|
|
||||||
|
// Send a LobbyNotReadyMessage and validate the player is marked as not ready
|
||||||
|
serverGameLogic.received(notReadyMessage, IDClient);
|
||||||
|
assertFalse(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-06
|
// UC-Lobby-06
|
||||||
@Test
|
@Test
|
||||||
public void testLeaveLobby() {
|
public void testLeaveLobby() {
|
||||||
// TODO: Implement test logic for a player leaving the lobby
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
clientGameLogic.getDialogs().getLobby().selectLeave();
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(startDialogState, dialogs.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-07
|
// UC-Lobby-07
|
||||||
@Test
|
@Test
|
||||||
public void testStartGame() {
|
public void testStartGame() {
|
||||||
// TODO: Implement test logic for starting the game
|
// Simulate client in lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
// Simulate server in lobby
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
// Test: Game cannot start with less than 2 players
|
||||||
|
serverGameLogic.getGame().removePlayer(IDHost); // Remove one player, leaving only 1
|
||||||
|
assertEquals(1, serverGameLogic.getGame().getPlayers().size());
|
||||||
|
|
||||||
|
serverGameLogic.received(new StartGameMessage(), IDClient);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
// Test: Game cannot start if not all players are ready
|
||||||
|
serverGameLogic.getGame().addPlayer(IDHost, playerHost); // Add the second player back
|
||||||
|
assertEquals(2, serverGameLogic.getGame().getPlayers().size());
|
||||||
|
|
||||||
|
serverGameLogic.getGame().getPlayerById(IDClient).setReady(false);
|
||||||
|
serverGameLogic.getGame().getPlayerById(IDHost).setReady(true);
|
||||||
|
assertFalse(serverGameLogic.getGame().areAllReady());
|
||||||
|
|
||||||
|
serverGameLogic.received(new StartGameMessage(), IDClient);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
// Test: Game starts successfully if there are at least 2 players, and all are ready
|
||||||
|
serverGameLogic.getGame().getPlayerById(IDClient).setReady(true);
|
||||||
|
assertTrue(serverGameLogic.getGame().areAllReady());
|
||||||
|
|
||||||
|
// TODO: Index out of Bounds Exception
|
||||||
|
// serverGameLogic.received(new StartGameMessage(), IDHost);
|
||||||
|
// assertEquals(gameState, serverGameLogic.getCurrentState()); // Verify the server is now in game
|
||||||
|
// assertEquals(clientGameState, clientGameLogic.getState());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-08
|
// UC-Lobby-08
|
||||||
@Test
|
@Test
|
||||||
public void testShowStatus() {
|
public void testShowStatus() {
|
||||||
// TODO: Implement test logic for showing the status of all players (ready/not ready)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-09
|
// UC-Lobby-09
|
||||||
@Test
|
@Test
|
||||||
public void testShowNames() {
|
public void testShowNames() {
|
||||||
// TODO: Implement test logic for showing the names of all players in the lobby
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-Lobby-10
|
// UC-Lobby-10
|
||||||
@@ -83,6 +302,20 @@ public void testShowAssignedTSKs() {
|
|||||||
// UC-Lobby-12
|
// UC-Lobby-12
|
||||||
@Test
|
@Test
|
||||||
public void testServerAssignsTSK() {
|
public void testServerAssignsTSK() {
|
||||||
// TODO: Implement test logic for server-side assignment of tasks (TSKs) to players
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(lobby);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
//test if server is in the lobby state
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
assertEquals(Color.NONE, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
||||||
|
Color firstColor = serverGameLogic.getGame().getFirstUnusedColor();
|
||||||
|
serverGameLogic.received(readyMessage, IDClient);
|
||||||
|
assertTrue(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
|
||||||
|
assertEquals(firstColor, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,44 +2,174 @@
|
|||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import pp.mdga.Resources;
|
||||||
|
import pp.mdga.client.ClientGameLogic;
|
||||||
|
import pp.mdga.client.ClientSender;
|
||||||
|
import pp.mdga.client.DialogsState;
|
||||||
|
import pp.mdga.client.dialogstate.LobbyState;
|
||||||
|
import pp.mdga.client.dialogstate.NetworkDialogState;
|
||||||
|
import pp.mdga.client.dialogstate.StartDialogState;
|
||||||
|
import pp.mdga.game.Color;
|
||||||
|
import pp.mdga.game.Game;
|
||||||
|
import pp.mdga.game.Player;
|
||||||
|
import pp.mdga.message.client.JoinedLobbyMessage;
|
||||||
|
import pp.mdga.message.server.LobbyAcceptMessage;
|
||||||
|
import pp.mdga.message.server.LobbyDenyMessage;
|
||||||
|
import pp.mdga.notification.InfoNotification;
|
||||||
|
import pp.mdga.server.ServerGameLogic;
|
||||||
|
import pp.mdga.server.ServerSender;
|
||||||
|
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this test-class tests the testcases T079-T083
|
* this test-class tests the testcases T079-T083
|
||||||
*/
|
*/
|
||||||
public class NetworkDialogClientTest {
|
public class NetworkDialogClientTest {
|
||||||
|
|
||||||
|
private final String IP = "127.0.0.1";
|
||||||
|
private final int PORT = 8080;
|
||||||
|
|
||||||
|
private Game game;
|
||||||
|
|
||||||
|
private Preferences preferences;
|
||||||
|
|
||||||
|
private ClientSender clientSender;
|
||||||
|
private ClientGameLogic clientGameLogic;
|
||||||
|
|
||||||
|
private ServerSender serverSender;
|
||||||
|
private ServerGameLogic serverGameLogic;
|
||||||
|
|
||||||
|
//declare player-Client here
|
||||||
|
private Player playerClient;
|
||||||
|
private String nameClient = "Client";
|
||||||
|
private int IDClient;
|
||||||
|
|
||||||
|
//declare player-host here
|
||||||
|
private Player playerHost;
|
||||||
|
private String nameHost = "Host";
|
||||||
|
private Color hostColor;
|
||||||
|
private int IDHost;
|
||||||
|
|
||||||
|
private DialogsState dialogs;
|
||||||
|
private NetworkDialogState networkDialogState;
|
||||||
|
private StartDialogState startDialogState;
|
||||||
|
private LobbyState lobby;
|
||||||
|
private pp.mdga.server.automaton.LobbyState lobbyState;
|
||||||
|
|
||||||
|
private JoinedLobbyMessage joinedLobbyMessage;
|
||||||
|
private LobbyDenyMessage lobbyDenyMessage;
|
||||||
|
private LobbyAcceptMessage lobbyAcceptMessage;
|
||||||
|
|
||||||
|
private InfoNotification infoNotification;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
// This method will be executed before each test.
|
game = new Game();
|
||||||
// Initialize common objects or setup required state for Network Dialog Client actions.
|
|
||||||
|
clientSender = mock(ClientSender.class);
|
||||||
|
serverSender = mock(ServerSender.class);
|
||||||
|
|
||||||
|
serverGameLogic = new ServerGameLogic(serverSender, game);
|
||||||
|
clientGameLogic = new ClientGameLogic(clientSender);
|
||||||
|
|
||||||
|
playerClient = new Player(nameClient);
|
||||||
|
IDClient = 1;
|
||||||
|
|
||||||
|
playerHost = new Player(nameHost);
|
||||||
|
hostColor = Color.ARMY;
|
||||||
|
IDHost = 2;
|
||||||
|
game.addPlayer(IDHost, playerHost);
|
||||||
|
|
||||||
|
dialogs = clientGameLogic.getDialogs();
|
||||||
|
networkDialogState = dialogs.getNetworkDialog();
|
||||||
|
startDialogState = dialogs.getStartDialog();
|
||||||
|
lobby = dialogs.getLobby();
|
||||||
|
lobbyState = serverGameLogic.getLobbyState();
|
||||||
|
|
||||||
|
joinedLobbyMessage = new JoinedLobbyMessage();
|
||||||
|
lobbyDenyMessage = new LobbyDenyMessage();
|
||||||
|
lobbyAcceptMessage = new LobbyAcceptMessage();
|
||||||
|
|
||||||
|
infoNotification = new InfoNotification(Resources.stringLookup("lobby.deny.join"));
|
||||||
|
|
||||||
|
preferences = Preferences.userNodeForPackage(NetworkDialogClientTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-NetworkDialogClient-01
|
// UC-NetworkDialogClient-01
|
||||||
@Test
|
@Test
|
||||||
public void testEnterIP() {
|
public void testEnterIP() {
|
||||||
// TODO: Implement test logic for entering an IP address
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(networkDialogState);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(networkDialogState, dialogs.getState());
|
||||||
|
|
||||||
|
clientGameLogic.selectJoin(IP);
|
||||||
|
assertEquals(IP, preferences.get("IP", IP));
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-NetworkDialogClient-02
|
// UC-NetworkDialogClient-02
|
||||||
@Test
|
@Test
|
||||||
public void testEnterPort() {
|
public void testEnterPort() {
|
||||||
// TODO: Implement test logic for entering a port number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UC-NetworkDialogClient-03
|
// UC-NetworkDialogClient-03
|
||||||
@Test
|
@Test
|
||||||
public void testConnectToServer() {
|
public void testConnectToServer() {
|
||||||
// TODO: Implement test logic for attempting to connect to a server
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(networkDialogState);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(networkDialogState, dialogs.getState());
|
||||||
|
|
||||||
|
//test if server is in the lobby state
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
//Server accepts connection
|
||||||
|
clientGameLogic.getDialogs().getNetworkDialog().received(lobbyAcceptMessage);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(lobby, dialogs.getState());
|
||||||
|
|
||||||
|
serverGameLogic.received(joinedLobbyMessage, IDClient);
|
||||||
|
assertTrue(serverGameLogic.getGame().getPlayers().containsKey(IDClient));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCantConnectToServer() {
|
public void testCantConnectToServer() {
|
||||||
// TODO: Implement test logic for handling failed server connection attempts
|
// test if client is in the Lobby
|
||||||
}
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(networkDialogState);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(networkDialogState, dialogs.getState());
|
||||||
|
|
||||||
|
//test if server is in the lobby state
|
||||||
|
serverGameLogic.setCurrentState(lobbyState);
|
||||||
|
assertEquals(lobbyState, serverGameLogic.getCurrentState());
|
||||||
|
|
||||||
|
//test if client receives a lobby deny notification and stays in the NetworkDialog
|
||||||
|
clientGameLogic.getDialogs().getNetworkDialog().received(lobbyDenyMessage);
|
||||||
|
infoNotification =(InfoNotification) clientGameLogic.getNotification();
|
||||||
|
assertEquals(Resources.stringLookup("lobby.deny.join"),infoNotification.getMessage());
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(startDialogState, dialogs.getState()); }
|
||||||
|
|
||||||
// UC-NetworkDialogClient-04
|
// UC-NetworkDialogClient-04
|
||||||
@Test
|
@Test
|
||||||
public void testCancelJoining() {
|
public void testCancelJoining() {
|
||||||
// TODO: Implement test logic for canceling the joining process
|
// test if client is in the Lobby
|
||||||
|
clientGameLogic.setState(dialogs);
|
||||||
|
dialogs.setState(networkDialogState);
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(networkDialogState, dialogs.getState());
|
||||||
|
|
||||||
|
//tests if client can return to the Start Menu
|
||||||
|
clientGameLogic.selectLeave();
|
||||||
|
assertEquals(dialogs, clientGameLogic.getState());
|
||||||
|
assertEquals(startDialogState, dialogs.getState());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user