KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > uicapture > v1 > event > CaptureEventIUTest


1 /*
2  * @(#)CaptureEventIUTest.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.uicapture.v1.event;
28
29 import java.awt.Robot JavaDoc;
30 import java.awt.Component JavaDoc;
31 import java.awt.Button JavaDoc;
32 import java.awt.event.InputEvent JavaDoc;
33 import java.awt.event.KeyEvent JavaDoc;
34
35 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
36 import junit.framework.Test;
37 import junit.framework.TestCase;
38 import junit.framework.TestSuite;
39
40
41 /**
42  * Tests the CaptureEvent class.
43  *
44  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
45  * @since Jan 6, 2002
46  * @version $Date: 2003/02/10 22:52:33 $
47  */

48 public class CaptureEventIUTest extends TestCase
49 {
50     //-------------------------------------------------------------------------
51
// Standard JUnit Class-specific declarations
52

53     private static final Class JavaDoc THIS_CLASS = CaptureEventIUTest.class;
54     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
55     
56     public CaptureEventIUTest( String JavaDoc name )
57     {
58         super( name );
59     }
60
61
62
63     //-------------------------------------------------------------------------
64
// Tests
65

66     
67     public void testNoEventConstructor()
68     {
69         CaptureEvent ce = createCaptureEvent();
70         assertEquals(
71             "Null event in creation must have null event returned.",
72             ce.getInputEvent(),
73             null );
74         assertEquals(
75             "Must return the passed-in event type.",
76             ce.getEventType(),
77             this.eventType );
78         assertEquals(
79             "Must not have a valid time of event.",
80             ce.getTimeOfEvent(),
81             -1 );
82     }
83     
84     public void testNullEventConstructor()
85     {
86         InputEvent JavaDoc ie = null;
87         CaptureEvent ce = createCaptureEvent( ie );
88         assertEquals(
89             "Event passed in creation must be the same event returned.",
90             ce.getInputEvent(),
91             ie );
92         assertEquals(
93             "Must return the passed-in event type.",
94             ce.getEventType(),
95             this.eventType );
96         assertEquals(
97             "Must not have a valid time of event.",
98             ce.getTimeOfEvent(),
99             -1 );
100     }
101     
102     public void testEventConstructor()
103     {
104         InputEvent JavaDoc ie = createInputEvent();
105         CaptureEvent ce = createCaptureEvent( ie );
106         assertEquals(
107             "Event passed in creation must be the same event returned.",
108             ce.getInputEvent(),
109             ie );
110         assertEquals(
111             "Must return the passed-in event type.",
112             ce.getEventType(),
113             this.eventType );
114         assertEquals(
115             "Must not have a valid time of event.",
116             ce.getTimeOfEvent(),
117             ie.getWhen() );
118     }
119     
120     
121     
122     protected int eventType = -3;
123     protected CaptureEvent createCaptureEvent( InputEvent JavaDoc ie )
124     {
125         return new CaptureEvent( this.eventType, ie ) {
126                 public void performEvent( Robot JavaDoc r )
127                 {
128                     // do nothing
129
}
130             };
131     }
132     protected CaptureEvent createCaptureEvent()
133     {
134         return new CaptureEvent( this.eventType ) {
135                 public void performEvent( Robot JavaDoc r )
136                 {
137                     // do nothing
138
}
139             };
140     }
141     protected InputEvent JavaDoc createInputEvent()
142     {
143         return new KeyEvent JavaDoc( createComponent(), 1, 2L, 0, KeyEvent.VK_S );
144     }
145     protected Component JavaDoc createComponent()
146     {
147         return new Button JavaDoc();
148     }
149     
150     
151     //-------------------------------------------------------------------------
152
// Standard JUnit declarations
153

154     
155     public static Test suite()
156     {
157         TestSuite suite = new TestSuite( THIS_CLASS );
158         
159         return suite;
160     }
161     
162     public static void main( String JavaDoc[] args )
163     {
164         String JavaDoc[] name = { THIS_CLASS.getName() };
165         
166         // junit.textui.TestRunner.main( name );
167
// junit.swingui.TestRunner.main( name );
168

169         junit.textui.TestRunner.main( name );
170     }
171     
172     /**
173      *
174      * @exception Exception thrown under any exceptional condition.
175      */

176     protected void setUp() throws Exception JavaDoc
177     {
178         super.setUp();
179         
180         // set ourself up
181
}
182     
183     
184     /**
185      *
186      * @exception Exception thrown under any exceptional condition.
187      */

188     protected void tearDown() throws Exception JavaDoc
189     {
190         // tear ourself down
191

192         
193         super.tearDown();
194     }
195 }
196
197
Popular Tags