Deleted and modified previous sprint parser to cater the sprint2’s new requirement

- also added new method for GateMark

#story[9] #story[10] #fix
This commit is contained in:
Haoming Yin
2017-03-17 00:53:08 +13:00
parent b7631c0b46
commit e7ba9d962d
4 changed files with 40 additions and 21 deletions
+31 -12
View File
@@ -4,17 +4,36 @@ package seng302.models;
* Created by ptg19 on 16/03/17. * Created by ptg19 on 16/03/17.
*/ */
public class GateMark { public class GateMark {
private double lat; private double lat;
private double lon; private double lon;
private Mark mark1; private Mark mark1;
private Mark mark2; private Mark mark2;
private String name;
public GateMark(String name, Mark mark1, Mark mark2, double lat, double lon){ public Mark getMark1() {
this.lat = lat; return mark1;
this.lon = lon; }
this.mark1 = mark1;
this.mark2 = mark2; public Mark getMark2() {
this.name = name; return mark2;
} }
public String getName() {
return name;
}
private String name;
public GateMark(String name, Mark mark1, Mark mark2, double lat, double lon) {
this.lat = lat;
this.lon = lon;
this.mark1 = mark1;
this.mark2 = mark2;
this.name = name;
}
public GateMark(String name, Mark mark1, Mark mark2) {
this.mark1 = mark1;
this.mark2 = mark2;
this.name = name;
}
} }
+2 -2
View File
@@ -16,11 +16,11 @@ public class OldApp {
*/ */
public static Race createRace(String configFile) throws Exception { public static Race createRace(String configFile) throws Exception {
Race race = new Race(); Race race = new Race();
FileParser fp; OldFileParser fp;
// Read team names from file // Read team names from file
try{ try{
fp = new FileParser(configFile); fp = new OldFileParser(configFile);
} }
catch (FileNotFoundException e){ catch (FileNotFoundException e){
System.out.println("Config file does not exist"); System.out.println("Config file does not exist");
@@ -16,7 +16,7 @@ import java.util.Map;
* efficiently from external files. * efficiently from external files.
*/ */
public class FileParser { public class OldFileParser {
private String filePath; private String filePath;
private JSONObject content; private JSONObject content;
@@ -27,7 +27,7 @@ public class FileParser {
* @param filePath a string like path to show location of desired file to * @param filePath a string like path to show location of desired file to
* be parsed * be parsed
*/ */
public FileParser(String filePath) throws Exception { public OldFileParser(String filePath) throws Exception {
this.filePath = filePath; this.filePath = filePath;
this.readFile(); this.readFile();
} }
@@ -1,7 +1,7 @@
package seng302; package seng302;
import org.junit.Test; import org.junit.Test;
import seng302.models.FileParser; import seng302.models.OldFileParser;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -11,14 +11,14 @@ import static org.junit.Assert.assertEquals;
* Unit test for FileParser class * Unit test for FileParser class
* Created by Haoming on 5/03/17. * Created by Haoming on 5/03/17.
*/ */
public class FileParserTest { public class OldFileParserTest {
/** /**
* test if it fails from reading non existed file * test if it fails from reading non existed file
*/ */
@Test(expected = FileNotFoundException.class) @Test(expected = FileNotFoundException.class)
public void readNonExistedFile() throws Exception { public void readNonExistedFile() throws Exception {
FileParser fileParser = new FileParser("test/java/seng302/non-existed.json"); OldFileParser fileParser = new OldFileParser("test/java/seng302/non-existed.json");
} }
/** /**
@@ -26,7 +26,7 @@ public class FileParserTest {
*/ */
@Test @Test
public void readValidFile() throws Exception { public void readValidFile() throws Exception {
FileParser fileParser = new FileParser("src/test/java/seng302/valid.json"); OldFileParser fileParser = new OldFileParser("src/test/java/seng302/valid.json");
assertEquals("AC35", fileParser.getRaceName()); assertEquals("AC35", fileParser.getRaceName());
@@ -42,7 +42,7 @@ public class FileParserTest {
*/ */
@Test @Test
public void readInvalidFile() throws Exception { public void readInvalidFile() throws Exception {
FileParser fileParser = new FileParser("src/test/java/seng302/invalid.json"); OldFileParser fileParser = new OldFileParser("src/test/java/seng302/invalid.json");
assertEquals(null, fileParser.getRaceName()); assertEquals(null, fileParser.getRaceName());
assertEquals(null, fileParser.getTeams()); assertEquals(null, fileParser.getTeams());