// ------------------------------------------------------------------------- /** * This test class shows how one might specify acceptance criteria for an * assignment using a series of test cases. * * @author Stephen Edwards * @version Feb 22, 2013 */ public class AppointmentTests extends junit.framework.TestCase { //~ Instance/static variables ............................................. private Appointment app1; private Appointment app2; //~ Methods ............................................................... // ---------------------------------------------------------- /** * Sets up the test fixture. * Called automatically before every test case method. */ protected void setUp() { int hour = 10; String description = "CS 1114"; app1 = new Appointment(hour, description); hour = 13; description = "MATH 1506"; app2 = new Appointment(hour, description); } // ---------------------------------------------------------- /** * Test that the hour accessor works as expected. */ public void testHour() { assertEquals(10, app1.hour()); assertEquals(13, app2.hour()); } // ---------------------------------------------------------- /** * Test that the description accessor works as expected. */ public void testDescription() { assertEquals("CS 1114", app1.description()); assertEquals("MATH 1506", app2.description()); } // ---------------------------------------------------------- /** * Test that the setHour() setter works. */ public void testSetHour() { app1.setHour(15); assertEquals(15, app1.hour()); } // ---------------------------------------------------------- /** * Test that the setDescription() setter works. */ public void testSetDescription() { app1.setDescription("CS 1104"); assertEquals("CS 1104", app1.description()); } // ---------------------------------------------------------- /** * Test that the setTime() setter works. */ public void testSetTime() { assertEquals(10, app1.hour()); app1.setTime("3pm"); assertEquals(15, app1.hour()); app1.setTime("11am"); assertEquals(11, app1.hour()); app1.setTime("11pm"); assertEquals(23, app1.hour()); } // ---------------------------------------------------------- /** * Test that setTime() works with noon and midnight values. */ public void testSetTime2() { app1.setTime("12pm"); assertEquals(12, app1.hour()); app1.setTime("12am"); assertEquals(0, app1.hour()); } // ---------------------------------------------------------- /** * Test that toString() works. */ public void testToString() { assertEquals("10am: CS 1114", app1.toString()); assertEquals("1pm: MATH 1506", app2.toString()); } // ---------------------------------------------------------- /** * Test that setTime() and toString() work for noon and midnight. */ public void testToString2() { app1.setTime("12pm"); assertEquals("12pm: CS 1114", app1.toString()); app1.setTime("12am"); assertEquals("12am: CS 1114", app1.toString()); } }