Added tests for BoatXMLReader
- Verifies correct operation on boat and mark reading from boatTest.xml #story[782]
This commit is contained in:
@@ -80,14 +80,14 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
|
||||
*/
|
||||
private void readSingleBoat(Node boatNode) {
|
||||
Boat boat;
|
||||
String country = null;
|
||||
|
||||
int sourceID = Integer.parseInt(boatNode.getAttributes().getNamedItem("SourceID").getTextContent());
|
||||
String name = boatNode.getAttributes().getNamedItem("BoatName").getTextContent();
|
||||
String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent();
|
||||
if (exists(boatNode, "Country")) country = boatNode.getAttributes().getNamedItem("Country").getTextContent();
|
||||
|
||||
if (isYachtNode(boatNode)) {
|
||||
if (country != null) {
|
||||
String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent();
|
||||
if (exists(boatNode, "Country")) {
|
||||
String country = boatNode.getAttributes().getNamedItem("Country").getTextContent();
|
||||
boat = new Boat(sourceID, name, country);
|
||||
} else {
|
||||
boat = new Boat(sourceID, name, shortName);
|
||||
|
||||
@@ -9,4 +9,8 @@ public class Mark {
|
||||
public Mark(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package seng302.DataInput;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.Mark;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 10/05/17.
|
||||
*/
|
||||
public class BoatXMLReaderTest {
|
||||
BoatDataSource boatData;
|
||||
List<Boat> boats;
|
||||
List<Mark> marks;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
try {
|
||||
boatData = new BoatXMLReader("mockXML/boatTest.xml");
|
||||
boats = boatData.getBoats();
|
||||
marks = boatData.getMarkerBoats();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user