KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > jobs > JobStateTest


1 /*
2  * Copyright 2004, Rob Gordon.
3  */

4 package org.oddjob.jobs;
5
6 import junit.framework.TestCase;
7
8 import org.oddjob.images.IconEvent;
9 import org.oddjob.images.IconHelper;
10 import org.oddjob.images.IconListener;
11 import org.oddjob.state.JobState;
12 import org.oddjob.state.JobStateEvent;
13 import org.oddjob.state.JobStateListener;
14
15 /**
16  *
17  * @author Rob Gordon.
18  */

19 public class JobStateTest extends TestCase {
20
21     JobState jobState;
22     String JavaDoc iconId;
23     
24     JobStateListener stateListener = new JobStateListener() {
25         public void jobStateChange(JobStateEvent event) {
26             JobStateTest.this.jobState = event.getJobState();
27         }
28     };
29     
30     IconListener iconListener = new IconListener() {
31         public void iconEvent(IconEvent event) {
32             JobStateTest.this.iconId = event.getIconId();
33         }
34     };
35         
36     public void testException() {
37         final DummyStateJob j = new DummyStateJob ();
38         j.setName("Exception Test");
39         j.setDesired("exception");
40         
41         j.addJobStateListener(stateListener);
42         j.addIconListener(iconListener);
43         assertTrue("job state not READY.",
44                 jobState == JobState.READY);
45         
46         j.run();
47
48         assertTrue("job state not EXCEPTION.",
49                 jobState == JobState.EXCEPTION);
50         assertTrue("Icon not EXCEPTION",
51                 iconId.equals(IconHelper.EXCEPTION));
52     }
53     
54     public void testNotComplete() {
55         final DummyStateJob j = new DummyStateJob ();
56         j.setName("Test Not Complete");
57         j.setDesired("not complete");
58         
59         j.addJobStateListener(stateListener);
60         j.addIconListener(iconListener);
61         assertTrue("job state not READY.",
62                 jobState == JobState.READY);
63         j.run();
64
65         assertTrue("job state not NOT COMPLETE.",
66                 jobState == JobState.NOT_COMPLETE);
67         assertTrue("Icon not NOT COMPLETE",
68                 iconId.equals(IconHelper.NOT_COMPLETE));
69     }
70     
71     public void testComplete() {
72         final DummyStateJob j = new DummyStateJob ();
73         j.setName("Test Complete");
74         j.setDesired("complete");
75         
76         j.addJobStateListener(stateListener);
77         j.addIconListener(iconListener);
78         assertTrue("job state not READY.",
79                 jobState == JobState.READY);
80         
81         j.run();
82
83         assertTrue("job state not COMPLETE.",
84                 jobState == JobState.COMPLETE);
85         assertTrue("Icon not COMPLETE",
86                 iconId.equals(IconHelper.COMPLETE));
87     }
88 }
89
Popular Tags