diff --git a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java index 0193ef0f..eb22461b 100644 --- a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java @@ -30,7 +30,7 @@ public class BoatXMLReader extends XMLReader { * @throws ParserConfigurationException error */ public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException { - this(filePath, false); + this(filePath, true); } /** @@ -89,19 +89,14 @@ public class BoatXMLReader extends XMLReader { /** * Reads the information about one boat - * Ignored values: ShapeID, StoweName, HullNum, Skipper + * Ignored values: ShapeID, StoweName, HullNum, Skipper, Type */ private void readSingleBoat(Node boat) { StreamedBoat streamedBoat; - String type = "None"; - int sourceID = -1; - String boatName = null; - String shortName = null; String country = null; - if (exists(boat, "Type")) type = boat.getAttributes().getNamedItem("Type").getTextContent(); - if (exists(boat, "SourceID")) sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent()); - if (exists(boat, "BoatName")) boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent(); - if (exists(boat, "ShortName")) shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent(); + int sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent()); + String boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent(); + String shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent(); if (exists(boat, "Country")) country = boat.getAttributes().getNamedItem("Country").getTextContent(); // Ignore all non participating boats @@ -137,10 +132,6 @@ public class BoatXMLReader extends XMLReader { this.participants = participants; } - public Map getStreamedBoatMap() { - return streamedBoatMap; - } - public List getBoats() { return new ArrayList<>(streamedBoatMap.values()); } diff --git a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java index 19b27c9f..8b37b770 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java @@ -45,4 +45,8 @@ public class StreamedBoat extends Boat { } return azimuth; } + + public int getSourceID() { + return sourceID; + } } diff --git a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java index b13067c9..e4dc62a1 100644 --- a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java +++ b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java @@ -31,7 +31,7 @@ public class BoatsXMLTest { inputParticipants.put(420, new StreamedBoat(420)); boatXMLReader.setParticipants(inputParticipants); boatXMLReader.read(); - assertEquals(boatXMLReader.getStreamedBoatMap().size(), 0); + assertEquals(boatXMLReader.getBoats().size(), 0); } @Test @@ -40,6 +40,8 @@ public class BoatsXMLTest { inputParticipants.put(101, new StreamedBoat(101)); boatXMLReader.setParticipants(inputParticipants); boatXMLReader.read(); - assertTrue(boatXMLReader.getStreamedBoatMap().containsKey(101)); + assertEquals(boatXMLReader.getBoats().size(), 1); + StreamedBoat boat = (StreamedBoat) boatXMLReader.getBoats().get(0); + assertEquals(boat.getSourceID(), 101); } } diff --git a/visualiser/src/test/java/seng302/Mock/FailBoatXMLTest.java b/visualiser/src/test/java/seng302/Mock/FailBoatXMLTest.java new file mode 100644 index 00000000..5b616a4c --- /dev/null +++ b/visualiser/src/test/java/seng302/Mock/FailBoatXMLTest.java @@ -0,0 +1,39 @@ +package seng302.Mock; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by jjg64 on 1/05/17. + */ +public class FailBoatXMLTest { + String path = "mockXML/boatXML/"; + + @Test(expected = SAXException.class) + public void emptyFile() throws SAXException, ParserConfigurationException, ParseException, IOException { + new BoatXMLReader("empty.xml"); + } + + @Test(expected = NumberFormatException.class) + public void invalidSourceID() throws SAXException, ParserConfigurationException, ParseException, IOException { + new BoatXMLReader(path + "invalidSourceID.xml"); + } + + @Test(expected = NullPointerException.class) + public void insufficientInformation() throws SAXException, ParserConfigurationException, ParseException, IOException { + new BoatXMLReader(path + "insufficientInformation.xml"); + } + +} diff --git a/visualiser/src/test/resources/empty.xml b/visualiser/src/test/resources/empty.xml new file mode 100644 index 00000000..e69de29b diff --git a/visualiser/src/test/resources/mockXML/boatXML/insufficientInformation.xml b/visualiser/src/test/resources/mockXML/boatXML/insufficientInformation.xml new file mode 100644 index 00000000..a821565b --- /dev/null +++ b/visualiser/src/test/resources/mockXML/boatXML/insufficientInformation.xml @@ -0,0 +1,249 @@ + + + + + 2012-05-17T07:49:40+0200 + + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/src/test/resources/mockXML/boatXML/invalidSourceID.xml b/visualiser/src/test/resources/mockXML/boatXML/invalidSourceID.xml new file mode 100644 index 00000000..5c61eec5 --- /dev/null +++ b/visualiser/src/test/resources/mockXML/boatXML/invalidSourceID.xml @@ -0,0 +1,251 @@ + + + + + 2012-05-17T07:49:40+0200 + + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file