Removed error checking within XML readers and ensured XML readers fail. Did this so an XML reader is not made with an invalid file. #story[782]

This commit is contained in:
Joseph Gardner
2017-05-01 14:15:34 +12:00
parent 7e569b59b7
commit 10dd066302
7 changed files with 552 additions and 16 deletions
@@ -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);
}
}
@@ -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");
}
}