Moved mock.app.App#readFile(...) to shared.dataInput.XMLReader#readXMLFileToString(...).

Did the bare minimum to get the mock.model, mock.dataInput, shared.model tests working - many of them need to be tidied/refactored/moved as they don't take into account most of the refactorings.
This commit is contained in:
fjc40
2017-07-19 22:30:21 +12:00
parent d0c6b5f716
commit 10e80bca05
22 changed files with 836 additions and 493 deletions
@@ -0,0 +1,81 @@
package shared.dataInput;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.XMLReaderException;
import shared.model.Boat;
import shared.model.Mark;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
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;
/**
* Created by cbt24 on 10/05/17.
*/
public class BoatXMLReaderTest {
private BoatDataSource boatData;
private List<Boat> boats;
private List<Mark> marks;
@Before
public void setUp() {
String boatXMLString = null;
try {
boatXMLString = XMLReader.readXMLFileToString("mock/mockXML/boatTest.xml", StandardCharsets.UTF_8);
} catch (Exception e) {
e.printStackTrace();
fail("could not read boat xml file into a string");
}
try {
boatData = new BoatXMLReader(boatXMLString);
boats = new ArrayList<>(boatData.getBoats().values());
marks = new ArrayList<>(boatData.getMarkerBoats().values());
} catch (XMLReaderException | InvalidBoatDataException e) {
e.printStackTrace();
assertTrue(false);
}
}
@Test
public void boatsReadNameFromFile() {
String[] names = {
"Team ORACLE USA","Land Rover BAR","SoftBank Team Japan","Groupama Team France","Artemis Racing","Emirates Team New Zealand"
};
for(int i = 0; i < boats.size(); i++) {
assertEquals(names[i], boats.get(i).getName());
}
}
@Test
public void marksReadNameFromFile() {
String[] names = {
"PRO","PIN","Marker1","WGL","WGR","LGL","LGR","FL","FR"
};
for(int i = 0; i < marks.size(); i++) {
assertEquals(names[i], marks.get(i).getName());
}
}
//TODO should add more tests for various BoatXMLReader functions.
}
@@ -0,0 +1,7 @@
package shared.model;
import static org.junit.Assert.*;
public class AngleTest {
//TODO
}
@@ -0,0 +1,7 @@
package shared.model;
import static org.junit.Assert.*;
public class AzimuthTest {
//TODO
}
@@ -0,0 +1,7 @@
package shared.model;
import static org.junit.Assert.*;
public class BearingTest {
//TODO
}
@@ -0,0 +1,173 @@
package shared.model;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by esa46 on 22/03/17.
*/
public class BoatTest {
private GPSCoordinate ORIGIN_COORDS;
private Boat TEST_BOAT;
@Before
public void setUp() {
ORIGIN_COORDS = new GPSCoordinate(0, 0);
TEST_BOAT = new Boat(1, "Test", "tt");
TEST_BOAT.setCurrentPosition(ORIGIN_COORDS);
}
//TODO these bearing tests could be tidied up to reduce code repetition.
//TODO also, most of these tests may be more appropriate in GPSCoordinateTest
@Test
public void calculateDueNorthAzimuthReturns0() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(50, 0)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
}
@Test
public void calculateDueSouthAzimuthReturns180() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
}
@Test
public void calculateDueEastAzimuthReturns90() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(0, 50)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
}
@Test
public void calculateDueWestAzimuthReturnsNegative90() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(0, -50)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -90, 1e-8);
}
@Test
public void calculateDueNorthHeadingReturns0() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(50, 0)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
}
@Test
public void calculateDueEastHeadingReturns90() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(0, 50)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
}
@Test
public void calculateDueSouthHeadingReturns180() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
}
@Test
public void calculateDueWestHeadingReturns270() {
CompoundMark startMarker = new CompoundMark(
1,
"start",
new Mark(1, "test origin 1", ORIGIN_COORDS) );
CompoundMark endMarker = new CompoundMark(
2,
"end",
new Mark(2, "test mark 2", new GPSCoordinate(0, -50)) );
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateBearing(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 270, 1e-8);
}
//TODO test Boat#setCurrentLeg and it's effects.
}
@@ -0,0 +1,92 @@
package shared.model;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Created by esa46 on 29/03/17.
*/
public class CompoundMarkTest {
private GPSCoordinate ORIGIN_COORD;
@Before
public void setUp() throws Exception {
ORIGIN_COORD = new GPSCoordinate(0, 0);
}
@Test
public void averageOfSingleMarkAtOriginIsSingleMark() {
CompoundMark testMark = new CompoundMark(
1,
"test",
new Mark(1, "test origin 1", ORIGIN_COORD) );
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD) );
}
@Test
public void averageOfSingleMarkIsSingleMark() {
GPSCoordinate testCoord = new GPSCoordinate(20, 25);
CompoundMark testMark = new CompoundMark(
1,
"test",
new Mark(1, "test origin 1", testCoord));
assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord));
}
@Test
public void averageLatOfTwoMarksIsAccurate() {
GPSCoordinate testCoord = new GPSCoordinate(0.001, 0);
CompoundMark testMark = new CompoundMark(
1,
"test",
new Mark(1, "test origin 1", ORIGIN_COORD),
new Mark(2, "test origin 2", testCoord) );
assertEquals(testMark.getAverageGPSCoordinate(), new GPSCoordinate(0.0005, 0));
}
@Test
public void averageLongOfTwoMarksIsAccurate() {
GPSCoordinate testCoord = new GPSCoordinate(0, 10);
CompoundMark testMark = new CompoundMark(
1,
"test",
new Mark(1, "test origin 1", ORIGIN_COORD),
new Mark(2, "test origin 2", testCoord) );
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5)));
}
@Test
public void averageLatAndLongOfTwoMarksIsAccurate() {
GPSCoordinate testCoord1 = new GPSCoordinate(0.0, 30);
GPSCoordinate testCoord2 = new GPSCoordinate(0.001, 60);
CompoundMark testMark = new CompoundMark(
1,
"test",
new Mark(1, "test origin 1", testCoord1),
new Mark(2, "test origin 2", testCoord2) );
assertEquals(testMark.getAverageGPSCoordinate().getLatitude(), 0.00051776, 1e-8);
assertEquals(testMark.getAverageGPSCoordinate().getLongitude(), 45.000000, 1e-8);
}
}
@@ -0,0 +1,107 @@
package shared.model;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Created by jjg64 on 11/05/17.
*/
public class GPSCoordinateTest {
List<GPSCoordinate> boundary;
@Before
public void init() {
boundary = new ArrayList<>();
}
/**
* -------
* | |
* | * |
* -------
*/
@Test
public void insideSquareTest() {
boundary.add(new GPSCoordinate(0, 0));
boundary.add(new GPSCoordinate(10, 0));
boundary.add(new GPSCoordinate(10, 10));
boundary.add(new GPSCoordinate(0, 10));
GPSCoordinate coordinate = new GPSCoordinate(2, 8);
boolean inside = GPSCoordinate.isInsideBoundary(coordinate, boundary);
assertTrue(inside);
}
/**
* -------
* | |
* * | |
* -------
*/
@Test
public void outsideSquareTest() {
boundary.add(new GPSCoordinate(0, 0));
boundary.add(new GPSCoordinate(10, 0));
boundary.add(new GPSCoordinate(10, 10));
boundary.add(new GPSCoordinate(0, 10));
GPSCoordinate coordinate = new GPSCoordinate(-2, 8);
boolean inside = GPSCoordinate.isInsideBoundary(coordinate, boundary);
assertFalse(inside);
}
@Test
public void insideShapeWithObtuseAnglesTest() {
boundary.add(new GPSCoordinate(0, 0));
boundary.add(new GPSCoordinate(4, 4));
boundary.add(new GPSCoordinate(7, 2));
boundary.add(new GPSCoordinate(9, 5));
boundary.add(new GPSCoordinate(10, 10));
boundary.add(new GPSCoordinate(6, 6));
boundary.add(new GPSCoordinate(2, 10));
GPSCoordinate coordinate = new GPSCoordinate(5, 5);
boolean inside = GPSCoordinate.isInsideBoundary(coordinate, boundary);
assertTrue(inside);
}
@Test
public void outsideShapeWithObtuseAnglesTest() {
boundary.add(new GPSCoordinate(0, 0));
boundary.add(new GPSCoordinate(4, 4));
boundary.add(new GPSCoordinate(7, 2));
boundary.add(new GPSCoordinate(9, 5));
boundary.add(new GPSCoordinate(10, 10));
boundary.add(new GPSCoordinate(6, 6));
boundary.add(new GPSCoordinate(2, 10));
GPSCoordinate coordinate = new GPSCoordinate(4, 3);
boolean inside = GPSCoordinate.isInsideBoundary(coordinate, boundary);
assertFalse(inside);
}
/**
* -------
* | |
* * | |
* -------
*/
@Test
public void earlyTerminationTest() {
boundary.add(new GPSCoordinate(0, 0));
boundary.add(new GPSCoordinate(10, 0));
boundary.add(new GPSCoordinate(10, 10));
boundary.add(new GPSCoordinate(0, 10));
GPSCoordinate coordinate = new GPSCoordinate(-2, 8);
boolean inside = GPSCoordinate.isInsideBoundary(coordinate, boundary, new GPSCoordinate(0, 0), new GPSCoordinate(10, 10));
assertFalse(inside);
}
}
@@ -0,0 +1,89 @@
package shared.model;
import org.geotools.referencing.GeodeticCalculator;
import org.junit.Before;
import org.junit.Test;
import java.awt.geom.Point2D;
import static org.junit.Assert.assertEquals;
/**
*
*/
public class LegTest {
private CompoundMark ORIGIN_COMPOUND_MARKER;
@Before
public void setUp() throws Exception {
ORIGIN_COMPOUND_MARKER = new CompoundMark(
1,
"origin",
new Mark(1, "test mark1", new GPSCoordinate(0, 0)) );
}
@Test
public void calculateDistanceHandles5nmNorth() {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(0, 5 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 5, 1e-8);
}
@Test
public void calculateDistanceHandles12nmEast() {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(90, 12 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 12, 1e-8);
}
@Test
public void calculateDistanceHandlesHalfnmSouth() {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 0.5, 1e-8);
}
@Test
public void calculateDistanceHandlesPoint1nmWest() {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 0.1, 1e-8);
}
@Test
public void calculateDistanceHandlesZeroDifference() {
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, ORIGIN_COMPOUND_MARKER, 0);
assertEquals(test.getDistanceNauticalMiles(), 0, 1e-8);
}
private CompoundMark getEndMarker(Point2D point) {
GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX());
return new CompoundMark(
1,
"test compound 3",
new Mark(3, "test mark3", coords) );
}
}
@@ -0,0 +1,7 @@
package shared.model;
import static org.junit.Assert.*;
public class MarkTest {
//TODO
}
@@ -0,0 +1,7 @@
package shared.model;
import static org.junit.Assert.*;
public class RaceClockTest {
//TODO
}
@@ -0,0 +1,345 @@
//package shared.model;
//
//
//import mock.model.Polars;
//import org.junit.Before;
//import org.junit.Ignore;
//import org.junit.Test;
//import org.mockito.Mockito;
//import org.xml.sax.SAXException;
//
//import javax.xml.parsers.ParserConfigurationException;
//import java.io.IOException;
//import java.text.ParseException;
//import java.util.ArrayList;
//
//import static org.junit.Assert.*;
//import static org.mockito.Mockito.*;
//
///**
// * Created by esa46 on 15/03/17.
// */
//public class RaceTest{
//
//
// private CompoundMark ORIGIN;
//
// private CompoundMark THREE_NM_FROM_ORIGIN;
//
// private CompoundMark FIFTEEN_NM_FROM_ORIGIN;
//
// private ArrayList<Leg> TEST_LEGS = new ArrayList<>();
//
// private int START_LEG_DISTANCE = 3;
// private int MIDDLE_LEG_DISTANCE = 12;
//
// private Leg START_LEG;
//
// private Leg MIDDLE_LEG;
//
// private Leg FINISH_LEG;
//
//
// @Before
// public void setUp() {
//
// ORIGIN = new CompoundMark(
// 1,
// "origin compound",
// new Mark(1, "test origin 1", new GPSCoordinate(0, 0)) );
//
//
// THREE_NM_FROM_ORIGIN = new CompoundMark(
// 2,
// "3 NM from origin compound",
// new Mark(2, "test mark 2", new GPSCoordinate(0.050246769, 0)) );
//
//
// FIFTEEN_NM_FROM_ORIGIN = new CompoundMark(
// 3,
// "15 NM from origin compound",
// new Mark(3, "test mark 3", new GPSCoordinate(0.251233845, 0)) );
//
//
// START_LEG = new Leg("Start", ORIGIN, THREE_NM_FROM_ORIGIN, 0);
//
//
// MIDDLE_LEG = new Leg("Middle", THREE_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 1);
//
//
// FINISH_LEG = new Leg("Finish", FIFTEEN_NM_FROM_ORIGIN, FIFTEEN_NM_FROM_ORIGIN, 2);
//
//
// TEST_LEGS.add(START_LEG);
// TEST_LEGS.add(MIDDLE_LEG);
// TEST_LEGS.add(FINISH_LEG);
// }
//
// @Ignore
// @Test
// public void countdownTimerSendsBoatLocations() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
// 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(), anyLong());
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void countdownTimerSendsRaceStatusMessages() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
// 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();
// }
// }
//
// @Ignore
// @Test
// public void checkPositionFinishedUpdatesNumberFinishedBoats() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
// Race testRace = new Race(dataSource, mockOutput);
// testRace.initialiseBoats();
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(FINISH_LEG);
// testBoat.setDistanceTravelledInLeg(1);
// testRace.checkPosition(testBoat, 1);
//
// assertEquals(testRace.getNumberOfActiveBoats(), 0);
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void checkPositionSetFinishedBoatVelocityTo0() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
// Race testRace = new Race(dataSource, mockOutput);
// testRace.initialiseBoats();
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(FINISH_LEG);
// testBoat.setDistanceTravelledInLeg(1);
// testRace.checkPosition(testBoat, 1);
//
// assertEquals(testBoat.getCurrentSpeed(), 0, 1e-8);
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void checkPositionSetsFinishTime() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
// Race testRace = new Race(dataSource, mockOutput);
// testRace.initialiseBoats();
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(FINISH_LEG);
// testBoat.setDistanceTravelledInLeg(1);
// testRace.checkPosition(testBoat, 1);
//
// assertEquals(testBoat.getTimeFinished(), 1, 1e-8);
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void checkPositionUnfinishedDoesntUpdateNumberFinishedBoats() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
// Race testRace = new Race(dataSource, mockOutput);
// testRace.initialiseBoats();
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(START_LEG);
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE);
// testRace.checkPosition(testBoat, 1);
//
// assertEquals(testRace.getNumberOfActiveBoats(), 1);
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
//
// @Ignore
// @Test
// public void distanceTravelledBeforeUpdatingLegIsRetained() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// RaceDataSource dataSource = new RaceXMLReader("mockXML/raceTest.xml", new BoatXMLReader("mockXML/boatTest.xml", new Polars()));
// Race testRace = new Race(dataSource, mockOutput);
// testRace.initialiseBoats();
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(START_LEG);
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1);
// testRace.checkPosition(testBoat, 0);
//
// assertEquals(testBoat.getDistanceTravelledInLeg(), 1, 1e-7);
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void doNotFinishAnswersYesIf100PercentChance() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
// Race testRace = new Race(raceDataSource, mockOutput);
//
// testRace.setDnfChance(100);
// assertTrue(testRace.doNotFinish());
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void doNotFinishAnswersNoIf0PercentChance() {
//
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
// Race testRace = new Race(raceDataSource, mockOutput);
// testRace.setDnfChance(0);
// assertFalse(testRace.doNotFinish());
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void boatsAreSetToDNF() {
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
// Race testRace = new Race(raceDataSource, mockOutput);
// testRace.setDnfChance(100);
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(START_LEG);
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE + 1);
// testRace.checkPosition(testBoat, 1);
// assertEquals(testBoat.getCurrentLeg().getName(), "DNF");
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
//
// }
//
// @Ignore
// @Test
// public void updatePositionIgnoresFinishedBoats() {
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
// Race testRace = new Race(raceDataSource, mockOutput);
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(FINISH_LEG);
// testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
// testRace.updatePosition(testBoat, 1, 1);
// assertEquals(testBoat.getCurrentPosition(), ORIGIN.getAverageGPSCoordinate());
//
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void updatePositionChangesBoatPosition() {
// try {
// MockOutput mockOutput = Mockito.mock(MockOutput.class);
// BoatDataSource boatDataSource = new BoatXMLReader("mockXML/boatTest.xml", new Polars());
// RaceDataSource raceDataSource = new RaceXMLReader("mockXML/raceTest.xml", boatDataSource);
// Race testRace = new Race(raceDataSource, mockOutput);
// testRace.initialiseBoats();
// Boat testBoat = testRace.getBoats().get(0);
// testBoat.setCurrentLeg(START_LEG);
// testBoat.setDistanceTravelledInLeg(START_LEG_DISTANCE - 1);
// testBoat.setCurrentPosition(ORIGIN.getAverageGPSCoordinate());
// testRace.updatePosition(testBoat, 100, 100);
// assertFalse(testBoat.getCurrentPosition() == ORIGIN.getAverageGPSCoordinate());
// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
// e.printStackTrace();
// fail();
// }
// }
//
// @Ignore
// @Test
// public void windDirectionCorrectValues(){
//// 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.setChangeWind(1);
//// testRace.setWindDir(65535);
//// testRace.changeWindDir();
//// assertEquals(100, testRace.getWind());
//// } catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
//// e.printStackTrace();
//// fail();
//// }
// }
//
//
//}