Added some index checks and relavent Tests for them
This commit is contained in:
@@ -11,6 +11,7 @@ import seng202.group9.Core.Route;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Test the functions for the Airline
|
||||
@@ -102,15 +103,35 @@ public class AirlineTest{
|
||||
assertEquals(allNipponAirways.getRoutes().get(1), route2);
|
||||
assertEquals(allNipponAirways.getRoutes().get(2), route1);
|
||||
assertEquals(allNipponAirways.getRoutes().get(3), route2);
|
||||
|
||||
allNipponAirways.delRoutes(3);
|
||||
try {
|
||||
allNipponAirways.delRoutes(3);
|
||||
}catch (DataException e){
|
||||
fail("3 is a valid deletable index.");
|
||||
}
|
||||
assertTrue(allNipponAirways.getRoutes().size() == 3);
|
||||
|
||||
allNipponAirways.delRoutes(route2);
|
||||
assertTrue(allNipponAirways.getRoutes().size() == 2);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void testInvalidRouteDelete() throws DataException{
|
||||
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
|
||||
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
|
||||
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
|
||||
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
|
||||
allNipponAirways.delRoutes(0);
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void testInvalidIndexRouteDelete() throws DataException{
|
||||
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
|
||||
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
|
||||
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
|
||||
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
|
||||
allNipponAirways.delRoutes(-1);
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void hasDuplicateNameTest() throws DataException {
|
||||
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
|
||||
|
||||
@@ -100,7 +100,12 @@ public class AirportUnitTest {
|
||||
assertEquals(heathrow.getArrivalRoutes().get(2).getArrivalAirport(), "LHR2");
|
||||
assertEquals(heathrow.getArrivalRoutes().get(3).getArrivalAirport(), "LHR3");
|
||||
|
||||
heathrow.delArrivalRoutes(0);
|
||||
try {
|
||||
heathrow.delArrivalRoutes(0);
|
||||
} catch (DataException e) {
|
||||
|
||||
}
|
||||
|
||||
assertTrue(heathrow.getArrivalRoutes().size() == 3);
|
||||
heathrow.delArrivalRoutes(heathrow.getArrivalRoutes().get(0));
|
||||
assertTrue(heathrow.getArrivalRoutes().size() == 2);
|
||||
@@ -114,7 +119,11 @@ public class AirportUnitTest {
|
||||
assertEquals(heathrow.getDepartureRoutes().get(2).getDepartureAirport(), "SIN2");
|
||||
assertEquals(heathrow.getDepartureRoutes().get(3).getDepartureAirport(), "SIN3");
|
||||
|
||||
heathrow.delDepartureRoutes(0);
|
||||
try {
|
||||
heathrow.delDepartureRoutes(0);
|
||||
} catch (DataException e) {
|
||||
|
||||
}
|
||||
assertTrue(heathrow.getDepartureRoutes().size() == 3);
|
||||
heathrow.delDepartureRoutes(heathrow.getDepartureRoutes().get(0));
|
||||
assertTrue(heathrow.getDepartureRoutes().size() == 2);
|
||||
@@ -214,6 +223,38 @@ public class AirportUnitTest {
|
||||
assertEquals(heathrow.getID(), 544);//check ID no id should be thrown
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void checkDelArrivalNoIndexFailure() throws DataException{
|
||||
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
||||
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
||||
heathrow.delArrivalRoutes(0);
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void checkDelArrivalNegativeIndexFailure() throws DataException{
|
||||
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
||||
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
||||
heathrow.delArrivalRoutes(-1);
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void checkDelDepartureNoIndexFailure() throws DataException{
|
||||
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
||||
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
||||
heathrow.delDepartureRoutes(0);
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void checkDelDepatureNegativeIndexFailure() throws DataException{
|
||||
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
||||
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
||||
heathrow.delDepartureRoutes(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkToString(){
|
||||
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||
|
||||
@@ -5,6 +5,7 @@ package seng202.group9;/**
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng202.group9.Controller.DataException;
|
||||
import seng202.group9.Core.Airport;
|
||||
import seng202.group9.Core.City;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class CityTest {
|
||||
@Test
|
||||
public void testAirports(){
|
||||
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
|
||||
Airport matsumotoAirport = new Airport(2280,"Matsumoto","Matsumoto","Japan","MMJ","RJAF",36.166758,137.922669,2182);
|
||||
Airport matsumotoAirport = new Airport(2280, "Matsumoto", "Matsumoto", "Japan", "MMJ", "RJAF", 36.166758, 137.922669, 2182);
|
||||
assertTrue(matsumoto.getAirports().size() == 0);
|
||||
matsumoto.addAirport(matsumotoAirport);
|
||||
assertEquals(matsumoto.getAirports().get(0), matsumotoAirport);
|
||||
@@ -49,17 +50,31 @@ public class CityTest {
|
||||
airports.add(matsumotoAirport);
|
||||
matsumoto.addAirport(airports);
|
||||
assertTrue(matsumoto.getAirports().size() == 2);
|
||||
matsumoto.delAirport(0);
|
||||
assertTrue(matsumoto.getAirports().size() == 1);
|
||||
matsumoto.delAirport(0);
|
||||
//try to remove more than the city has for airports
|
||||
matsumoto.delAirport(0);
|
||||
try {
|
||||
matsumoto.delAirport(0);
|
||||
assertTrue(matsumoto.getAirports().size() == 1);
|
||||
matsumoto.delAirport(0);
|
||||
}catch (DataException e){
|
||||
|
||||
}
|
||||
matsumoto.delAirport(matsumotoAirport);
|
||||
//set the airports
|
||||
matsumoto.setAirports(airports);
|
||||
assertTrue(matsumoto.getAirports().size() == 2);
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void testDelAirportsMissingIndexErrors() throws DataException{
|
||||
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
|
||||
matsumoto.delAirport(0);
|
||||
}
|
||||
|
||||
@Test(expected = DataException.class)
|
||||
public void testDelAirportsNegativeIndexErrors() throws DataException{
|
||||
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
|
||||
matsumoto.delAirport(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testString(){
|
||||
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
|
||||
|
||||
Reference in New Issue
Block a user