flightsystemtest.java

来自「This project developed in java leads us 」· Java 代码 · 共 406 行 · 第 1/2 页

JAVA
406
字号
        errorString = "the value of booking number is null\t\t";        try {            fs.cancel (0, ArrayToSet (new String[]{"Adam","Caroline"}));            fail ("Exception not catch :" + errorString);        } catch (Exception e) {System.out.println (errorString + " OK :" + e.getMessage ());}                errorString = "a name is null\t\t";        try {            fs.cancel (2, ArrayToSet (new String[]{null,"Lars"}));            fail ("Exception not catch :" + errorString);        } catch (Exception e) {System.out.println (errorString + " OK :" + e.getMessage ());}                cancelException ("Person name null", 1, ArrayToSet (new String []{null}));        cancelException ("Person name null and ArraytoSet Null)", 1, null);        cancelException ("Booking Number null", 0, ArrayToSet (new String []{"Lars"}));        cancelException ("Booking Number negative", -1, ArrayToSet (new String []{"Lars"}));        cancelException ("Name doesn't correspond to the booking number", 1, ArrayToSet (new String []{"Lys"}));        cancelException ("Name with unexpected characters", 2, ArrayToSet (new String []{"Lys054"}));        cancelException ("Name with unexpected characters", 2, ArrayToSet (new String []{"lys"}));        cancelException ("Name with unexpected characters", 2, ArrayToSet (new String []{"Lys","Lars",null}));        Functions function = new Cancel ();            errorString = "Booking number is not a number";        functionsException (errorString, function, new String[]{"a", "Adam", "Eve"} );        errorString = "Illegal character for one person name";        functionsException (errorString, function, new String[]{"1", "5", "Eve"} );        errorString = "booking number null";        functionsException (errorString, function, new String[]{null, "Adam", "Eve"} );        errorString = "One name null";        functionsException (errorString, function, new String[]{"1", null, "Eve"} );        errorString = "arguments null";        functionsException (errorString, function,null);        errorString = "array arguments contains one null element";        functionsException (errorString, function, new String[]{null} );    }        static public void cancelException (String errorString, int bookingNumber, Set name) {        int listLenght =0;        System.out.println ("\r\n Test :" +errorString);        try {            Integer bookingList[] = fs.getBookingList ();            listLenght = fs.getBookingList ().length;        } catch (Exception e) {fail (e.getMessage ());}        try {            boolean res = fs.cancel (bookingNumber, name);            if (res)            fail ("Exception not catch :" + errorString);        } catch (Exception e) {System.out.println ("\r\nError received :"+ e.getMessage ());}        try {            int newListLenght = fs.getBookingList ().length;            assertEquals (newListLenght, listLenght);            System.out.println ("OK ( state of flightSystem unchanged :"+fs.getFlightList ().length+" flights counted )");        } catch (Exception e) {fail (e.getMessage ());}    }        static public void cancelException (String errorString, int bookingNumber) {        int listLenght =0;        System.out.println ("\r\n Test :" +errorString);        try {            Integer bookingList[] = fs.getBookingList ();            listLenght = bookingList.length;        } catch (Exception e) {fail (e.getMessage ());}        try {            boolean res = fs.cancel (bookingNumber);            if (res)                fail ("Exception not catch :" + errorString);        } catch (Exception e) {System.out.println ("\r\nError received :"+ e.getMessage ());}        try {            int newListLenght = fs.getBookingList ().length;            assertEquals (fs.getBookingList ().length, listLenght);            System.out.println ("OK ( state of flightSystem unchanged :"+fs.getFlightList ().length+" flights counted )");        } catch (Exception e) {fail (e.getMessage ());}    }        /**     * Test of cancel method, of class FlightSystem.     */    static public void test1Cancel () {        System.out.println ("\n\r testCancel");        String errorString;        Functions function = new Cancel ();        errorString = "the bookingNumber doesn't exist\t\t";        cancelException ("Booking Number null", 0);        cancelException ("Booking Number negative", -1);        cancelException ("Booking number doesn't exist", 56);                errorString = "Booking number is not a number";        functionsException (errorString, function, new String[]{"a"} );        errorString = "booking number null";        functionsException (errorString, function, new String[]{null} );        errorString = "Booking number equal 0";        functionsException (errorString, function, new String[]{"0"} );        errorString = "arguments null";        functionsException (errorString, function,null);        errorString = "array arguments contains one null element";        functionsException (errorString, function, new String[]{null} );    }        /**     * Test of identify method, of class FlightSystem.     */    public void testIdentify () {        System.out.println ("\n\r testIdentify");        String errorString;        Functions function = new Identify ();        errorString = "the booking number doesn't exist\t\t";        try {            assertTrue (fs.identify (19).isEmpty ());        } catch (Exception e) {System.out.println (errorString + " OK :" + e.getMessage ());}                errorString = "a name is null\t\t";        try {            fs.identify (0);            fail ("Exception not catch :" + errorString);        } catch (Exception e) {System.out.println (errorString + " OK :" + e.getMessage ());}        errorString = "Booking number is not a number";        functionsException (errorString, function, new String[]{"a"} );        errorString = "booking number null";        functionsException (errorString, function, new String[]{null} );        errorString = "Booking number equal 0";        functionsException (errorString, function, new String[]{"0"} );        errorString = "Too much arguments";        functionsException (errorString, function, new String[]{"a", "5", "5","java"} );        errorString = "arguments null";        functionsException (errorString, function,null);    }        /**     * Test of list method, of class FlightSystem.     */    public void testList () {        System.out.println (" \n\r testList");        String errorString;        Functions function = new Lists ();        errorString = "the flight name doesn't exist\t\t";        try {            fs.list ("g");            fail ("Exception not catch :" + errorString);        } catch (Exception e) {System.out.println (errorString + " OK :" + e.getMessage ());}                errorString = "the flight name is null\t\t";        try {            fs.list (null );            fail ("Exception not catch :" + errorString);        } catch (Exception e) {System.out.println (errorString + " OK :" + e.getMessage ());}        errorString = "Flight null";        functionsException (errorString, function, new String[]{null} );        errorString = "Illegal character";        functionsException (errorString, function, new String[]{"a*/"} );        errorString = "Too much arguments";        functionsException (errorString, function, new String[]{"a", "5", "5","java"} );        errorString = "arguments null";        functionsException (errorString, function,null);    }            /**     * Test of selectFlight method, of class FlightSystem.     */    public void testSelectFlight () {        System.out.println (" \n\r testSelectFlight");                try {            Flight flight = new Flight ("h",new Pos ((short)2,(short)1));            fs.create (flight);            assertEquals (flight,fs.selectFlight ("h"));        } catch (Exception e) {fail (e.getMessage ());}    }        /**     * Test of getFlightList method, of class FlightSystem.     */    public void testGetFlightList () {        System.out.println ("\n\r testGetFlightList");        String test[] =  {"a","b","c","d"};        try {            for (int i = 0; i<4; i++)                assertEquals (fs.getFlightList ()[i], test[i]);        } catch (Exception e) {fail (e.getMessage ());}    }        /**     * Test of getBookingList method, of class FlightSystem.     */    public void testGetBookingList () {        System.out.println ("\n\r testGetBookingList");        System.out.println (fs);        Set bookingNumberTest = new HashSet ();        bookingNumberTest.add (new Integer (1));        bookingNumberTest.add (new Integer (2));        bookingNumberTest.add (new Integer (3));        try {            for (int i = 0; i<3; i++) {                assertTrue (bookingNumberTest.contains (fs.getBookingList ()[i]));            }        } catch (Exception e) {fail (e.getMessage ());}    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?