Started work on cucumber tests. Trying to sort through threads, getting inconsistent results.

#story[1111] #pair[kre39,ptg19]
This commit is contained in:
Kusal Ekanayake
2017-08-07 17:54:34 +12:00
parent f97b18d594
commit 97696cc95b
8 changed files with 74 additions and 6 deletions
@@ -26,6 +26,7 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
private ArrayList<ServerToClientThread> serverToClientThreads = new ArrayList<>(); private ArrayList<ServerToClientThread> serverToClientThreads = new ArrayList<>();
public MainServerThread() { public MainServerThread() {
new GameState("localhost");
try { try {
serverSocket = new ServerSocket(PORT); serverSocket = new ServerSocket(PORT);
} catch (IOException e) { } catch (IOException e) {
@@ -25,6 +25,8 @@ import seng302.gameServer.server.messages.Message;
*/ */
public class ClientToServerThread implements Runnable { public class ClientToServerThread implements Runnable {
/** /**
* Functional interface for receiving packets from client socket. * Functional interface for receiving packets from client socket.
*/ */
@@ -250,9 +250,8 @@ public class GameClient {
private void processRaceStatusUpdate(RaceStatusData data) { private void processRaceStatusUpdate(RaceStatusData data) {
if (allXMLReceived()) { if (allXMLReceived()) {
raceState.updateState(data); raceState.updateState(data);
if (raceView != null) { if (raceView != null)
raceView.getGameView().setWindDir(raceState.getWindDirection()); raceView.getGameView().setWindDir(raceState.getWindDirection());
}
for (long[] boatData : data.getBoatData()) { for (long[] boatData : data.getBoatData()) {
Yacht yacht = allBoatsMap.get((int) boatData[0]); Yacht yacht = allBoatsMap.get((int) boatData[0]);
yacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]); yacht.setEstimateTimeTillNextMark(raceState.getRaceTime() - boatData[1]);
@@ -66,7 +66,7 @@ public class StartScreenController implements Initializable {
*/ */
@FXML @FXML
public void hostButtonPressed() { public void hostButtonPressed() {
new GameState(getLocalHostIp()); // new GameState(getLocalHostIp());
gameClient = new GameClient(holder); gameClient = new GameClient(holder);
gameClient.runAsHost(getLocalHostIp(), 4942); gameClient.runAsHost(getLocalHostIp(), 4942);
// try { // try {
+12
View File
@@ -0,0 +1,12 @@
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
/**
* Created by kre39 on 7/08/17.
*/
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/java/features")
public class RunCucumberTests {
}
@@ -0,0 +1,5 @@
Feature: SailsToggle
Scenario: User toggles in sail
Given The game is running
When the user has pressed "shift"
Then the sails are "in"
@@ -16,13 +16,11 @@ public class BoatSailAnimationToggleTest {
private Yacht yacht; private Yacht yacht;
@Before @Before
public void setup() throws Exception{ public void setup() throws Exception{
yacht = new Yacht("Yacht", 1, "YACHT", "YAC", "Test Yacht", "NZ"); yacht = new Yacht("Yacht", 1, "YACHT", "YAC", "Test Yacht", "NZ");
} }
@Test @Test
public void sailToggleTest() throws Exception { public void sailToggleTest() throws Exception {
assertFalse(yacht.getSailIn()); assertFalse(yacht.getSailIn());
+51
View File
@@ -0,0 +1,51 @@
package steps;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import seng302.gameServer.GameStages;
import seng302.gameServer.GameState;
import seng302.gameServer.MainServerThread;
import seng302.gameServer.server.messages.BoatActionMessage;
import seng302.gameServer.server.messages.BoatActionType;
import seng302.model.Yacht;
import seng302.visualiser.ClientToServerThread;
/**
* Created by kre39 on 7/08/17.
*/
public class ToggleSailSteps {
MainServerThread mst;
ClientToServerThread client;
boolean sailsIn = false;
long startTime;
private Yacht yacht;
@Given("^The game is running$")
public void the_game_is_running() throws Throwable {
mst = new MainServerThread();
client = new ClientToServerThread("localhost", 4942);
GameState.setCurrentStage(GameStages.RACING);
}
@When("^the user has pressed \"([^\"]*)\"$")
public void the_user_has_pressed(String arg1) throws Throwable {
startTime = System.currentTimeMillis();
if (arg1 == "shift") {
if (sailsIn) {
client.sendBoatActionMessage(new BoatActionMessage(BoatActionType.SAILS_OUT));
} else {
client.sendBoatActionMessage(new BoatActionMessage(BoatActionType.SAILS_IN));
}
}
}
@Then("^the sails are \"([^\"]*)\"$")
public void the_sails_are(String arg1) throws Throwable {
System.out.println(GameState.getYachts().values());
}
}