package caltool.schedule; import caltool.caldb.*; import mvp.*; import java.util.*; /**** * * Class ScheduleTest is the companion testing class for class Schedule . It implements the following module test plan: *
* Test * Case Input Output Remarks * ==================================================================== * 1 schedule.categories null Null case * = null * * 2 schedule.categories same non-null Non-null case * = non-null value value **/ protected void testGetCategories() { Categories result; // method return value /* * Dump a unit test header. */ dumpUnitTestHeader("getCategories"); // NOT IN JUNIT /* * Do case 1 and validate the result. */ dumpUnitTestCaseHeader("getCategories ", 1); // NOT IN JUNIT schedule.categories = null; // setup result = schedule.getCategories(); // invoke if (!validateGetCategoriesPostcond(result)) // ASSERT IN JUNIT dumpMessage("FAILED"); dump("Case 1 Result:"); // NOT IN JUNIT /* * Do case 2 and validate the result. */ dumpUnitTestCaseHeader("getCategories ", 2); schedule.categories = new Categories(); // setup result = schedule.getCategories(); // invoke if (!validateGetCategoriesPostcond(result)) // validate dumpMessage("FAILED"); dump("Case 2 Result:"); dumpUnitTestEndSpacing(); } /** * Unit test scheduleAppointment by ... */ protected void testScheduleAppointment() { /* ... */ } /** * Unit test scheduleAppointment by ... */ protected void testScheduleTask() { /* ... */ } /** * Unit test scheduleEvent by supplying inputs that test the value range of * each Event data field and exercise each precondition clause. The cases * are as follows: *
* Test * Case Input Output Remarks * ==================================================================== * 1 {"Event 0", Input event Lower end of possible * {"Sunday",1, added to items event data range * "January",1}, no junk, no * null, confusion * null, * null} * * 2 {10000-char string, Input event Upper end of possible * {"Sunday",1, added to items event data range * "January",1}, no junk, * {"Saturday",31, no confusion * "December", 9999}, * 10000-char string * reversed, * 10000-char string} * * 3 events with start and Input event Events with all combos * thru end date ranging thru added to items of days, dates, and * 2564 each legal day, each no junk, no months * legal date, and each confusion * legal month, with * arbitrary year, * category, and security * * 2565 32 cases to exercise Schedule Events that violate * thru possible boolean Event precond logic. * 2597 values for 5 precond Precond * clauses Exception * thrown **/ protected void testScheduleEvent() { /* * Dump a unit test header. */ dumpUnitTestHeader("scheduleEvent"); /* * Do the cases. */ try { testScheduleEventCase1(); testScheduleEventCase2(); testScheduleEventCases3Thru2564(); testScheduleEventCases2565Thru2597(); } catch (ScheduleEventPrecondViolation e) { /* This should not happen at this level, but in case it does ... */ System.out.println("scheduleEvent EXCEPTION:"); for (int i = 0; i < e.numberOfErrors(); i++) { System.out.println(e.getErrors()[i]); } } /* * Dump the test case results. */ dump(""); dumpUnitTestEndSpacing(); } /** * Run testScheduleEvent case 1. */ protected void testScheduleEventCase1() throws ScheduleEventPrecondViolation { dumpUnitTestCaseHeader("scheduleEvent", 1); schedule.scheduleEvent(new Event( "Event 0", // title new Date(DayName.Sunday, // start date 1, MonthName.January, 1), null, // end date new Category("Category 1"), // category SimpleSecurity.Public // security )); } /** * Run testScheduleEvent case 2. */ protected void testScheduleEventCase2() throws ScheduleEventPrecondViolation { int i; String longString = ""; String longStringReversed = ""; for (i = 0; i < 10000; i++) { longString += (char) i % 256; longStringReversed = (char) i + longStringReversed; } dumpUnitTestCaseHeader("scheduleEvent", 2); schedule.scheduleEvent(new Event( longString, // title new Date(DayName.Sunday, // start date 1, MonthName.January, 1), new Date(DayName.Saturday, // end date 2, MonthName.December, 9999), new Category(longStringReversed), // category SimpleSecurity.Private // security )); } /** * Run testScheduleEvent cases 3 through 2564 by looping through various * combinations of days, weeks, and months. */ protected void testScheduleEventCases3Thru2564() throws ScheduleEventPrecondViolation { int day, number, month, year, i, n; Date date; for (i = 3, day = 0; day < 7; day++) { for (number = 1; number <= 31; number++) { for (month = 0; month < 12; month++) { date = new Date( DayName.values()[day], number, MonthName.values()[month], year = number * 100); if (date.isValid()) { dumpUnitTestCaseHeader("scheduleEvent", i++); schedule.scheduleEvent(new Event( "Event " + // title String.valueOf(n = year + month + day), date, // start date, // end new Category(String.valueOf(n*10)), // category ((number % 2) == 0) ? // security SimpleSecurity.Public : SimpleSecurity.Private )); } } } } } /** * Run testScheduleEvent cases 2565 through 2597 to fully exercise the * precond logic. */ protected void testScheduleEventCases2565Thru2597() { /* ... */ } /*-* * Postcondition validation methods. */ /** * Evaluate the Schedule constructor postcond on the given calDB and * cheduleEventPrecondViolation inputs, with this as the actual output. */ boolean validateSchedulePostcond(CalendarDB calDB, ScheduleEventPrecondViolation scheduleEventPrecondViolation) { return this.calDB == calDB && scheduleEventPrecondViolation != null; } /** * Evaluate the getCategories postcond with the given returnVal as the * actual output. */ boolean validateGetCategoriesPostcond(Categories returnVal) { return schedule.categories == returnVal; } /*-* * Testing utility methods. */ /** * Output a header message to stdout identifying the test phase. */ protected void dumpPhaseHeader(int phasenum) { System.out.print("**** Schedule Testing Phase "); System.out.print(phasenum); System.out.println(" ****"); } /** * Output a header message to stdout for the unit test of the given * testname. */ protected void dumpUnitTestHeader(String testname) { System.out.print("** Unit Test " + testname + " **\n"); } /** * Output a header message to stdout for a unit test case. */ protected void dumpUnitTestCaseHeader(String testname, int caseNumber) { System.out.print("* Unit Test Case " + testname + String.valueOf(caseNumber) + " **\n"); } /** * Dump three blank lines following a test phase. */ protected void dumpPhaseEndSpacing() { System.out.print("\n\n\n"); } /** * Dump a couple blank lines following a unit test. */ protected void dumpUnitTestEndSpacing() { System.out.print("\n\n"); } /** * Dump just a string message. */ protected void dumpMessage(String message) { System.out.println(message); } /** * Dump the data values of schedule to stdout. For test validation * purposes, include a print of the number of elements in the dumped items. * Precede the dump with the given message, if the message is non-null. */ protected void dump(String message) { int l; // Temp if (message != null) { System.out.print("* " + message + " *" + "\n"); } System.out.print("Schedule contains\n" + "Categories: " + schedule.categories + "\n" + (l = schedule.calDB.getCurrentCalendar().numItems()) + " " + (l == 1 ? " item" : " items") + "\n" + schedule.toString() + "\n" ); } /** * Schedule data object to support the tests. */ protected Schedule schedule; }