From 0adc57fc3618466b302eabb2c322a463a43f529c Mon Sep 17 00:00:00 2001 From: YaFedImYaEatIm Date: Sun, 18 Sep 2016 18:42:15 +1200 Subject: [PATCH] Airline Tests --- .../java/seng202/group9/Core/Airline.java | 2 +- src/test/java/seng202/group9/AirlineTest.java | 106 ++++++++++++++---- .../java/seng202/group9/AirportUnitTest.java | 3 + 3 files changed, 88 insertions(+), 23 deletions(-) diff --git a/src/main/java/seng202/group9/Core/Airline.java b/src/main/java/seng202/group9/Core/Airline.java index 4ab9dbf..4e60e17 100644 --- a/src/main/java/seng202/group9/Core/Airline.java +++ b/src/main/java/seng202/group9/Core/Airline.java @@ -264,7 +264,7 @@ public class Airline{ if (this.name.equals(airline.getName())){ throw new DataException("This Airline Name already Exists, Please Choose Another."); } - if (this.name.equals("")){ + if (airline.getName().equals("")){ throw new DataException("This Airline Name cannot be Empty"); } if (!this.IATA.equals("") && this.IATA.equals(airline.getIATA())){ diff --git a/src/test/java/seng202/group9/AirlineTest.java b/src/test/java/seng202/group9/AirlineTest.java index 1549f2a..d3e56b7 100644 --- a/src/test/java/seng202/group9/AirlineTest.java +++ b/src/test/java/seng202/group9/AirlineTest.java @@ -2,13 +2,16 @@ package seng202.group9; import java.util.ArrayList; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import javafx.scene.chart.PieChart; +import org.junit.Test; +import org.junit.rules.ExpectedException; import seng202.group9.Controller.DataException; import seng202.group9.Core.Airline; import seng202.group9.Core.Route; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Test the functions for the Airline * this is the get, set methods for in the class Airline @@ -16,30 +19,15 @@ import seng202.group9.Core.Route; * @author Fan-Wu Yang * */ -public class AirlineTest extends TestCase { - - /** - * Create the test case - * - * @param testName name of the test case - */ - public AirlineTest(String testName){ - super(testName); - } - +public class AirlineTest{ - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AirlineTest.class ); - } + public ExpectedException thrown = ExpectedException.none(); /** * Test for Airline get and setting methods * (Currently missing ADD ROUTES) */ + @Test public void testAirlineGetSet(){ //ID, Name, Alias, IATA, ICAO, CallSign, Country, Active //324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y" @@ -116,8 +104,82 @@ public class AirlineTest extends TestCase { assertEquals(allNipponAirways.getRoutes().get(1), route2); assertEquals(allNipponAirways.getRoutes().get(2), route1); assertEquals(allNipponAirways.getRoutes().get(3), route2); + + allNipponAirways.delRoutes(3); + assertTrue(allNipponAirways.getRoutes().size() == 3); + + allNipponAirways.delRoutes(route2); + assertTrue(allNipponAirways.getRoutes().size() == 2); + } - + + @Test(expected = DataException.class) + public void hasDuplicateNameTest() throws DataException { + Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways", + "NH", "ANA", "ALL NIPPON", "Japan", "Y"); + + Airline allNipponAirway = new Airline(325, "All Nippon Airways", "ANA All Nippon Airway", + "NP", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown + + allNipponAirways.hasDuplicate(allNipponAirway); + } + + @Test(expected = DataException.class) + public void hasDuplicateMissingNameTest() throws DataException { + Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways", + "NH", "ANA", "ALL NIPPON", "Japan", "Y"); + + Airline allNipponAirway = new Airline(325, "", "ANA All Nippon Airway", + "NP", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown + + allNipponAirways.hasDuplicate(allNipponAirway); + } + + @Test(expected = DataException.class) + public void hasDuplicateIATATest() throws DataException { + Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways", + "NH", "ANA", "ALL NIPPON", "Japan", "Y"); + + Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway", + "NH", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown + + allNipponAirways.hasDuplicate(allNipponAirway); + } + + @Test(expected = DataException.class) + public void hasDuplicateICAOTest() throws DataException { + Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways", + "NH", "ANA", "ALL NIPPON", "Japan", "Y"); + + Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway", + "NP", "ANA", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown + + allNipponAirways.hasDuplicate(allNipponAirway); + } + + @Test(expected = DataException.class) + public void hasDuplicateAliasTest() throws DataException { + Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways", + "NH", "ANA", "ALL NIPPON", "Japan", "Y"); + + Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airways", + "NH", "ANA", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown + + allNipponAirways.hasDuplicate(allNipponAirway); + } + + @Test(expected = DataException.class) + public void hasDuplicateCallTest() throws DataException { + Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways", + "NH", "ANA", "ALL NIPPON", "Japan", "Y"); + + Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway", + "NH", "ANP", "ALL NIPPON", "Japan", "Y");//duplicate name should be thrown + + allNipponAirways.hasDuplicate(allNipponAirway); + } + + @Test public void testToString(){ //ID, Name, Alias, IATA, ICAO, CallSign, Country, Active //324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y" diff --git a/src/test/java/seng202/group9/AirportUnitTest.java b/src/test/java/seng202/group9/AirportUnitTest.java index 6d3e379..66177d8 100644 --- a/src/test/java/seng202/group9/AirportUnitTest.java +++ b/src/test/java/seng202/group9/AirportUnitTest.java @@ -35,6 +35,7 @@ public class AirportUnitTest { } assertEquals(heathrow.getName(), "Heathrow"); assertEquals(heathrow.getCityName(), "London");//check city + assertEquals(heathrow.getCountryName(), "United Kingdom"); assertEquals(heathrow.getIATA_FFA(), "LHR");//check IATA/FFA assertEquals(heathrow.getICAO(), "EGLL");//check ICAO assertTrue(heathrow.getLatitude() == 51.4775);//check latitude @@ -53,6 +54,8 @@ public class AirportUnitTest { assertEquals(heathrow.getName(), "Hearthstone"); heathrow.setCityName("Blizzard Servers");//check city assertEquals(heathrow.getCityName(), "Blizzard Servers"); + heathrow.setCountryName("America"); + assertEquals(heathrow.getCountryName(), "America"); heathrow.setIATA_FFA("HTS");//test set IATA/FFA assertEquals(heathrow.getIATA_FFA(), "HTS"); heathrow.setICAO("BLIZ");// test set ICAO