diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index 2ef104c7..aa6f37a2 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -54,7 +54,7 @@ public class Race implements Runnable { * Countdown timer until race starts. */ - private AnimationTimer countdownTimer = new AnimationTimer() { + protected AnimationTimer countdownTimer = new AnimationTimer() { long currentTime = System.currentTimeMillis(); long timeLeft; @Override diff --git a/mock/src/test/java/seng302/Model/RaceTest.java b/mock/src/test/java/seng302/Model/RaceTest.java index bbac7680..cb4a28dc 100644 --- a/mock/src/test/java/seng302/Model/RaceTest.java +++ b/mock/src/test/java/seng302/Model/RaceTest.java @@ -1,146 +1,104 @@ -//package seng302.Model; -// -//import javafx.scene.paint.Color; -//import org.junit.BeforeClass; -//import org.junit.Ignore; -//import org.junit.Test; -//import org.mockito.Mockito; -//import org.xml.sax.SAXException; -//import seng302.DataInput.RaceDataSource; -//import seng302.DataInput.RaceXMLReader; -//import seng302.MockOutput; -// -//import javax.xml.parsers.ParserConfigurationException; -//import java.io.IOException; -//import java.util.ArrayList; -//import java.util.List; -// -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertTrue; -//import static org.junit.Assert.fail; -//import static org.mockito.Matchers.any; -//import static org.mockito.Mockito.atLeast; -//import static org.mockito.Mockito.verify; -// -///** -// * Created by esa46 on 15/03/17. -// */ -//public class RaceTest{ -// -// private static MockOutput mockOutput; -// SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.Marker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), 0); -// SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.Marker(new SharedModel.GPSCoordinate(2, 2)), 0); -// -//// @Override -//// public void start(Stage primaryStage) throws Exception{} -//// -//// public static void main(String[] args) { -//// launch(args); -//// } -// -// -//// @BeforeClass -//// public static void initJFX() { -//// Thread t = new Thread("JavaFX Init Thread") { -//// public void run() { -//// Application.launch(TestApp.class, new String[0]); -//// } -//// }; -//// t.setDaemon(true); -//// t.start(); -//// } -// -// @BeforeClass -// public static void setUp() { -// try { -// mockOutput = new MockOutput(); -// } catch(IOException e) { -// fail(); -// } -// } -// -// @Ignore -// @Test -// public void boatLocationMessagesAreGenerated() { -// try { -// RaceDataSource raceDataSource = new RaceXMLReader("raceXML/bermuda_AC35.xml"); -// -// MockOutput mockOutput = Mockito.mock(MockOutput.class); -// Race race = new Race(raceDataSource, 100, mockOutput); -// new Thread((race)).start(); -// -// try { -// Thread.sleep(5000); -// } catch (InterruptedException e) { -// fail(); -// } -// verify(mockOutput, atLeast(400)).parseBoatLocation(any()); -// -// } catch (IOException e) { -// fail(); -// } catch (SAXException e) { -// fail(); -// } catch (ParserConfigurationException e) { -// fail(); -// } -// } -// -// @Test -// public void timerCanBeDisabled() { -// SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1", 1); -// SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2", 2); -// List boats = new ArrayList<>(); -// boats.add(boat1); -// boats.add(boat2); -// -// ArrayList legs = new ArrayList<>(); -// legs.add(START_LEG); -// legs.add(FINISH_LEG); -// -// -// Race race = new Race(boats, legs, 5, mockOutput); -// race.setDnfChance(0); -// long timeStarted = System.currentTimeMillis(); -// race.run(); -// assertTrue(System.currentTimeMillis() - timeStarted < 4000); -// } -// +package seng302.Model; + +import javafx.scene.paint.Color; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.Mockito; +import org.xml.sax.SAXException; +import seng302.DataInput.BoatDataSource; +import seng302.DataInput.BoatXMLReader; +import seng302.DataInput.RaceDataSource; +import seng302.DataInput.RaceXMLReader; +import seng302.Exceptions.StreamedCourseXMLException; +import seng302.MockOutput; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; + +/** + * Created by esa46 on 15/03/17. + */ +public class RaceTest{ + + @Test + public void countdownTimerSendsBoatLocations() { + + try { + MockOutput mockOutput = Mockito.mock(MockOutput.class); + BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml"); + RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource); + Race testRace = new Race(raceDataSource, mockOutput); + testRace.initialiseBoats(); + testRace.countdownTimer.handle(1); + verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble()); + + } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { + e.printStackTrace(); + fail(); + } + } + + @Test + public void countdownTimerSendsRaceStatusMessages() { + + try { + MockOutput mockOutput = Mockito.mock(MockOutput.class); + RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml")); + Race testRace = new Race(dataSource, mockOutput); + testRace.initialiseBoats(); + testRace.countdownTimer.handle(1); + verify(mockOutput, atLeast(1)).parseRaceStatus(any()); + + } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) { + e.printStackTrace(); + fail(); + } + } + // @Test // public void checkPositionUpdatesNumberFinishedBoats() { // -// SharedModel.BoatInRace finishedBoat = new SharedModel.BoatInRace("Test", 1000, Color.ALICEBLUE, "tt", 1); +// Boat finishedBoat = new Boat(1000, "Name", "Country"); // finishedBoat.setDistanceTravelledInLeg(500); // // finishedBoat.setCurrentLeg(FINISH_LEG); // -// ArrayList boats = new ArrayList<>(); +// ArrayList boats = new ArrayList<>(); // boats.add(finishedBoat); // -// ArrayList legs = new ArrayList<>(); +// ArrayList legs = new ArrayList<>(); // legs.add(FINISH_LEG); // // Race race = new Race(boats, legs, 5, mockOutput); -// race.setDnfChance(0); // assertEquals(race.boatsFinished, 0); // // race.checkPosition(finishedBoat, 100000); // assertEquals(race.boatsFinished, 1); // assertEquals(finishedBoat.getTimeFinished(), 100000); -// // } -// + // @Test // public void checkPositionDoesntUpdateNumberFinishedBoats() { // -// SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 1); +// Boat unFinishedBoat = new Boat("Test", 10, Color.ALICEBLUE, "tt", 1); // unFinishedBoat.setDistanceTravelledInLeg(0); // // unFinishedBoat.setCurrentLeg(FINISH_LEG); // -// ArrayList boats = new ArrayList<>(); +// ArrayList boats = new ArrayList<>(); // boats.add(unFinishedBoat); // -// ArrayList legs = new ArrayList<>(); +// ArrayList legs = new ArrayList<>(); // legs.add(FINISH_LEG); // // @@ -155,9 +113,9 @@ // @Test // public void distanceTravelledBeforeUpdatingLegIsRetained() { // -// ArrayList boats = new ArrayList<>(); +// ArrayList boats = new ArrayList<>(); // -// ArrayList legs = new ArrayList<>(); +// ArrayList legs = new ArrayList<>(); // // legs.add(START_LEG); // legs.add(FINISH_LEG); @@ -165,7 +123,7 @@ // Race race = new Race(boats, legs, 1, mockOutput); // race.setDnfChance(0); // -// SharedModel.BoatInRace unFinishedBoat = new SharedModel.BoatInRace("Test", 10, Color.ALICEBLUE, "tt", 4); +// Boat unFinishedBoat = new Boat("Test", 10, Color.ALICEBLUE, "tt", 4); // unFinishedBoat.setDistanceTravelledInLeg(100); // unFinishedBoat.setCurrentLeg(START_LEG); // @@ -179,9 +137,9 @@ // @Test // public void timerDelaysByHalfSecond() throws InterruptedException { // -// ArrayList boats = new ArrayList<>(); +// ArrayList boats = new ArrayList<>(); // -// ArrayList legs = new ArrayList<>(); +// ArrayList legs = new ArrayList<>(); // legs.add(START_LEG); // // Race race = new Race(boats, legs, 1, mockOutput); @@ -207,17 +165,17 @@ // float vel2 = (float) 1.999; // float vel3 = (float) 32.5; // float vel4 = 500; -// SharedModel.BoatInRace boat1 = new SharedModel.BoatInRace("test", vel1, Color.ALICEBLUE, "tt",1); -// SharedModel.BoatInRace boat2 = new SharedModel.BoatInRace("test", vel2, Color.ALICEBLUE, "tt", 2); -// SharedModel.BoatInRace boat3 = new SharedModel.BoatInRace("test", vel3, Color.ALICEBLUE, "tt", 3); -// SharedModel.BoatInRace boat4 = new SharedModel.BoatInRace("test", vel4, Color.ALICEBLUE, "tt", 4); -// ArrayList boats = new ArrayList<>(); +// Boat boat1 = new Boat("test", vel1, Color.ALICEBLUE, "tt",1); +// Boat boat2 = new Boat("test", vel2, Color.ALICEBLUE, "tt", 2); +// Boat boat3 = new Boat("test", vel3, Color.ALICEBLUE, "tt", 3); +// Boat boat4 = new Boat("test", vel4, Color.ALICEBLUE, "tt", 4); +// ArrayList boats = new ArrayList<>(); // boats.add(boat1); // boats.add(boat2); // boats.add(boat3); // boats.add(boat4); // -// ArrayList legs = new ArrayList<>(); +// ArrayList legs = new ArrayList<>(); // legs.add(START_LEG); // // @@ -232,9 +190,9 @@ // } // @Test // public void doNotFinishCorrectly() { -// ArrayList boats = new ArrayList<>(); +// ArrayList boats = new ArrayList<>(); // -// ArrayList legs = new ArrayList<>(); +// ArrayList legs = new ArrayList<>(); // legs.add(START_LEG); // // Race race = new Race(boats, legs, 1, mockOutput); @@ -245,7 +203,7 @@ // race.setDnfChance(0); // assertTrue(!race.doNotFinish()); // } -// -// -// -//} + + + +} diff --git a/mock/src/test/java/seng302/Model/RaceXMLTest.java b/mock/src/test/java/seng302/Model/RaceXMLTest.java deleted file mode 100644 index 50fac007..00000000 --- a/mock/src/test/java/seng302/Model/RaceXMLTest.java +++ /dev/null @@ -1,96 +0,0 @@ -//package seng302.Model;/** -// * Created by Gondr on 26/03/2017. -// */ -// -//import org.junit.Ignore; -//import org.junit.Test; -//import seng302.DataInput.RaceXMLReader; -// -// -//import java.util.List; -// -//import static org.junit.Assert.*; -// -//public class RaceXMLTest { -// RaceXMLReader raceXMLReader; -// -// @Test -// public void canFindFile() { -// try { -// RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false); -// } catch (Exception e) { -// fail("Cannot find raceXML/bermuda_AC35.xml in the resources folder"); -// } -// } -// -// @Ignore -// @Test -// public void canReadBoats() { -// try { -// RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false); -// raceXMLReader.readBoats(); -// List boats = raceXMLReader.getBoats(); -// assertTrue(boats.size() == 6); -// //test boat 1 -// assertEquals(boats.get(0).getName(), "ORACLE TEAM USA"); -// assertTrue(boats.get(0).getVelocity() == 20); -// //test boat 2 -// assertEquals(boats.get(1).getName(), "Land Rover BAR"); -// assertTrue(boats.get(1).getVelocity() == 30); -// assertEquals(boats.get(1).getCountry(), "GBR"); -// //test boat 3 -// assertEquals(boats.get(2).getName(), "SoftBank Team Japan"); -// assertTrue(boats.get(2).getVelocity() == 25); -// assertEquals(boats.get(2).getCountry(), "JPN"); -// //test boat 4 -// assertEquals(boats.get(3).getName(), "Groupama Team France"); -// assertTrue(boats.get(3).getVelocity() == 20); -// assertEquals(boats.get(3).getCountry(), "FRA"); -// //test boat 5 -// assertEquals(boats.get(4).getName(), "Artemis Racing"); -// assertTrue(boats.get(4).getVelocity() == 29); -// assertEquals(boats.get(4).getCountry(), "SWE"); -// //test boat 6 -// assertEquals(boats.get(5).getName(), "Emirates Team New Zealand"); -// assertTrue(boats.get(5).getVelocity() == 62); -// assertEquals(boats.get(5).getCountry(), "NZL"); -// } catch (Exception e) { -// fail("Boat Unreadable"); -// } -// } -// -// @Test -// public void canReadLegs() { -// try { -// RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false); -// raceXMLReader.readLegs(); -// assertTrue(raceXMLReader.getLegs().size() == 5); -// } catch (Exception e) { -// fail("Legs Unreadable"); -// } -// } -// -// @Test -// public void canReadCourse() { -// try { -// RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false); -// raceXMLReader.readCourse(); -// assertTrue(raceXMLReader.getMapTopLeft() != null); -// assertTrue(raceXMLReader.getMapBottomRight() != null); -// assertTrue(raceXMLReader.getFinishPt1() != null); -// assertTrue(raceXMLReader.getFinishPt2() != null); -// assertTrue(raceXMLReader.getStartPt1() != null); -// assertTrue(raceXMLReader.getStartPt2() != null); -// assertTrue(raceXMLReader.getLeewardPt1() != null); -// assertTrue(raceXMLReader.getLeewardPt2() != null); -// assertTrue(raceXMLReader.getWindwardPt1() != null); -// assertTrue(raceXMLReader.getWindwardPt2() != null); -// assertTrue(raceXMLReader.getMark() != null); -// assertTrue(raceXMLReader.getBoundary().size() == 11); -// } catch (Exception e) { -// e.printStackTrace(); -// fail("Course Unreadable"); -// } -// } -// -//} diff --git a/mock/src/test/resources/mockXML/boatTest.xml b/mock/src/test/resources/mockXML/boatTest.xml new file mode 100644 index 00000000..84f911bc --- /dev/null +++ b/mock/src/test/resources/mockXML/boatTest.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mock/src/test/resources/mockXML/boatXML/boatTest.xml b/mock/src/test/resources/mockXML/boatXML/boatTest.xml deleted file mode 100644 index 51f788b0..00000000 --- a/mock/src/test/resources/mockXML/boatXML/boatTest.xml +++ /dev/null @@ -1,251 +0,0 @@ - - - - - 2012-05-17T07:49:40+0200 - - 12 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mock/src/test/resources/mockXML/raceTest.xml b/mock/src/test/resources/mockXML/raceTest.xml new file mode 100644 index 00000000..4ad5f88f --- /dev/null +++ b/mock/src/test/resources/mockXML/raceTest.xml @@ -0,0 +1,57 @@ + + + 5326 + FLEET + 2017-04-19T15:30:00+1200 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mock/src/test/resources/mockXML/regattaTest.xml b/mock/src/test/resources/mockXML/regattaTest.xml index 9ec88ccc..86526130 100644 --- a/mock/src/test/resources/mockXML/regattaTest.xml +++ b/mock/src/test/resources/mockXML/regattaTest.xml @@ -1,20 +1,10 @@ - - 3 - New Zealand Test - North Head - -36.82791529 - 174.81218919 - 0.00 - 12 - 14.1 - \ No newline at end of file