mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added tests for FileParser class, as well as test files
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/** Unit test for FileParser class
|
||||||
|
* Created by Haoming on 5/03/17.
|
||||||
|
*/
|
||||||
|
public class FileParserTest {
|
||||||
|
|
||||||
|
/*
|
||||||
|
test if it fails from reading non existed file
|
||||||
|
*/
|
||||||
|
@Test (expected = FileNotFoundException.class)
|
||||||
|
public void readNonExistedFile() throws Exception {
|
||||||
|
FileParser fileParser = new FileParser("test/java/seng302/non-existed.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
test a valid json file with valid content.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void readValidFile() throws Exception{
|
||||||
|
FileParser fileParser = new FileParser("src/test/java/seng302/valid.json");
|
||||||
|
|
||||||
|
assertEquals(fileParser.getRaceName(), "IDK");
|
||||||
|
|
||||||
|
ArrayList<String> teams = new ArrayList<>();
|
||||||
|
teams.add("team1");
|
||||||
|
teams.add("team2");
|
||||||
|
teams.add("team3");
|
||||||
|
assertTrue(teams.equals(fileParser.getTeams()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
test an invalid json file within wrong type value and misnamed
|
||||||
|
variable name.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void readInvaldFile() throws Exception {
|
||||||
|
FileParser fileParser = new FileParser("src/test/java/seng302/invalid.json");
|
||||||
|
|
||||||
|
assertEquals(fileParser.getRaceName(), null);
|
||||||
|
assertEquals(fileParser.getTeams(), null);
|
||||||
|
assertEquals(fileParser.getTimeScale(), -1);
|
||||||
|
assertEquals(fileParser.getTeams(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"time-scale": "abc",
|
||||||
|
"race-name": 123,
|
||||||
|
"teams-with-wrong-name":["team1","team2","team3"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"time-scale": 100,
|
||||||
|
"race-name": "IDK",
|
||||||
|
"teams":["team1","team2","team3"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user