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.
}