Update of /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/examples/timer2
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30309/input/javasrc/biz/xsoftware/examples/timer2
Modified Files:
TestExample.java
Log Message:
add more to the examples.
Index: TestExample.java
===================================================================
RCS file: /cvsroot/mocklib/mocklib3/input/javasrc/biz/xsoftware/examples/timer2/TestExample.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TestExample.java 11 Sep 2006 00:34:10 -0000 1.2
--- TestExample.java 11 Sep 2006 03:47:39 -0000 1.3
***************
*** 16,21 ****
/**
! * JUnit Suite of TestCases for demonstrating mocking out a user
! * created Timer interface.
*
* @author Dean Hiller
--- 16,31 ----
/**
! * This example has the following tests
! *
! * testBasicCalendar
! *
! * Tests a few things
! * 1. Tests scheduling an event
! * 2. Tests that event was scheduled at the propert time
! * 3. Tests the event going off and verifying expected event behavior
! *
! * testCancelOfEvent
! *
! * Tests scheduling and cancelling the event.
*
* @author Dean Hiller
***************
*** 38,43 ****
--- 48,57 ----
@Override
public void setUp() {
+ //Create a mockTimer which acts as a cache for TimerTasks.....
mockTimer = MockObjectFactory.createMock(TimerInterface.class);
calendar = new SysUnderTest((TimerInterface) mockTimer);
+
+ //Create and add a mockListener which we use to verify receiving of the
+ //proper events....
mockListener = MockObjectFactory.createMock(ScheduleListener.class);
calendar.addScheduleListener((ScheduleListener)mockListener);
***************
*** 51,54 ****
--- 65,73 ----
}
/**
+ * Tests a few things
+ * 1. Tests scheduling an event
+ * 2. Tests that event was scheduled at the propert time
+ * 3. Tests the event going off and verifying expected event behavior
+ *
* @showcode
*/
***************
*** 57,73 ****
long delay = 50000;
calendar.addEvent(title, delay);
!
CalledMethod method = mockTimer.expect("schedule");
! //param[0] is a timer task
TimerTask task = (TimerTask)method.getParameter(0);
assertEquals("Should have set the timer for "+delay+" ms", new Long(delay), method.getParameter(1));
//run the task now instead of waiting 50000ms
task.run();
method = mockListener.expect("eventStarted");
assertEquals("title should be the same", title, method.getParameter(0));
}
public void testCancelOfEvent() {
String title = "some event";
--- 76,102 ----
long delay = 50000;
calendar.addEvent(title, delay);
!
! //When an event is added, we expect schedule on the timer to be called...
CalledMethod method = mockTimer.expect("schedule");
! //param[0] is the mock object's cached timer task....
TimerTask task = (TimerTask)method.getParameter(0);
assertEquals("Should have set the timer for "+delay+" ms", new Long(delay), method.getParameter(1));
+ //We already verified it was scheduled in the future, so there is
+ //no need to wait till run the task then
//run the task now instead of waiting 50000ms
task.run();
+ //expect that the listener's eventStarted method is called with the
+ //propert event title
method = mockListener.expect("eventStarted");
assertEquals("title should be the same", title, method.getParameter(0));
}
+ /**
+ * Tests scheduling and cancelling the event.
+ *
+ * @showcode
+ */
public void testCancelOfEvent() {
String title = "some event";
***************
*** 82,87 ****
--- 111,118 ----
calendar.cancelEvent(title);
+ //make sure the event is actually cancelled
CalledMethod method2 = mockTimer.expect("cancelTask");
TimerTask cancelledTask = (TimerTask)method.getParameter(0);
+ //Make sure the correct TimerTask is cancelled....
assertSame(task, cancelledTask);
}
|