Delete ClientControllerTest
This commit is contained in:
@@ -1,141 +0,0 @@
|
||||
package it.polimi.ingsw.gc14.Controller;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ClientControllerTest {
|
||||
|
||||
private FakeView view;
|
||||
private FakeClient client;
|
||||
private ClientController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
view = new FakeView();
|
||||
client = new FakeClient();
|
||||
controller = new ClientController(view);
|
||||
controller.setClient(client);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConstructorInitialization() {
|
||||
assertSame(view, controller.view);
|
||||
assertNotNull(controller.localController);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetModelUpdatesLocalControllerAndView() {
|
||||
Game game = createGame();
|
||||
controller.setModel(game);
|
||||
|
||||
assertSame(game, controller.localController.getModel());
|
||||
assertSame(game, view.model);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOnError() {
|
||||
controller.onError("Errore di test");
|
||||
assertEquals("Errore di test", view.lastError);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetClientDelegatesAction() {
|
||||
FakeClient newClient = new FakeClient();
|
||||
controller.setClient(newClient);
|
||||
|
||||
Game game = createGame();
|
||||
controller.setModel(game);
|
||||
|
||||
String current = game.getCurrentState().getCurrentPlayer().getUserName();
|
||||
controller.drawUpperTribeCard(current, 0);
|
||||
|
||||
assertEquals("drawUpperTribeCard", newClient.lastMethodCalled);
|
||||
assertEquals(current, newClient.lastUsername);
|
||||
assertEquals(0, newClient.lastPos);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDrawUpperTribeCardDelegatesCorrectly() {
|
||||
Game game = createGame();
|
||||
controller.setModel(game);
|
||||
|
||||
String current = game.getCurrentState().getCurrentPlayer().getUserName();
|
||||
controller.drawUpperTribeCard(current, 0);
|
||||
|
||||
assertEquals("drawUpperTribeCard", client.lastMethodCalled);
|
||||
assertEquals(current, client.lastUsername);
|
||||
assertEquals(0, client.lastPos);
|
||||
assertNull(view.lastError);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDrawUpperTribeCardWrongPlayerShowsError() {
|
||||
Game game = createGame();
|
||||
controller.setModel(game);
|
||||
|
||||
String current = game.getCurrentState().getCurrentPlayer().getUserName();
|
||||
String wrong = current.equals("p1") ? "p2" : "p1";
|
||||
controller.drawUpperTribeCard(wrong, 0);
|
||||
|
||||
assertEquals("It's not your turn!", view.lastError);
|
||||
assertNull(client.lastMethodCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSlotChoiceDelegatesCorrectly() {
|
||||
Game game = createGame();
|
||||
controller.setModel(game);
|
||||
|
||||
String current = game.getCurrentState().getCurrentPlayer().getUserName();
|
||||
controller.slotChoice(current, 1);
|
||||
|
||||
assertEquals("slotChoice", client.lastMethodCalled);
|
||||
assertEquals(current, client.lastUsername);
|
||||
assertEquals(1, client.lastPos);
|
||||
assertNull(view.lastError);
|
||||
}
|
||||
|
||||
|
||||
private Game createGame() {
|
||||
Game game = new Game(2);
|
||||
game.addPlayer(new Player("p1"));
|
||||
game.addPlayer(new Player("p2"));
|
||||
return game;
|
||||
}
|
||||
|
||||
|
||||
private static class FakeView implements IView {
|
||||
Game model;
|
||||
String lastError;
|
||||
|
||||
@Override public void setModel(Game game) { this.model = game; }
|
||||
@Override public void render() {}
|
||||
@Override public void showMessage(String message) {}
|
||||
@Override public void showError(String message) { this.lastError = message; }
|
||||
}
|
||||
|
||||
private static class FakeClient implements IClient {
|
||||
String lastMethodCalled;
|
||||
String lastUsername;
|
||||
int lastPos;
|
||||
|
||||
@Override public boolean connect(String username, int preferredInt) { return true; }
|
||||
@Override public void drawUpperTribeCard(String u, int pos) throws RemoteException { lastMethodCalled = "drawUpperTribeCard"; lastUsername = u; lastPos = pos; }
|
||||
@Override public void drawLowerTribeCard(String u, int pos) throws RemoteException { lastMethodCalled = "drawLowerTribeCard"; lastUsername = u; lastPos = pos; }
|
||||
@Override public void drawUpperBuildingCard(String u, int pos) throws RemoteException { lastMethodCalled = "drawUpperBuildingCard"; lastUsername = u; lastPos = pos; }
|
||||
@Override public void drawLowerBuildingCard(String u, int pos) throws RemoteException { lastMethodCalled = "drawLowerBuildingCard"; lastUsername = u; lastPos = pos; }
|
||||
@Override public void skipTurn(String u) throws RemoteException { lastMethodCalled = "skipTurn"; lastUsername = u; }
|
||||
@Override public void pickOptionalTribeCard(String u, int pos) throws RemoteException { lastMethodCalled = "pickOptionalTribeCard"; lastUsername = u; lastPos = pos; }
|
||||
@Override public void pickOptionalBuildingCard(String u, int pos) throws RemoteException { lastMethodCalled = "pickOptionalBuildingCard"; lastUsername = u; lastPos = pos; }
|
||||
@Override public void noOptionalCard(String u) throws RemoteException { lastMethodCalled = "noOptionalCard"; lastUsername = u; }
|
||||
@Override public void slotChoice(String u, int pos) throws RemoteException { lastMethodCalled = "slotChoice"; lastUsername = u; lastPos = pos; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user